Class { #name : 'MFTWorkoutLogEditorComponent', #superclass : 'WAComponent', #instVars : [ 'workoutLog', 'onSaveWorkout', 'onDiscardWorkout' ], #category : 'MyFitnessTracker-Web-Components', #package : 'MyFitnessTracker-Web', #tag : 'Components' } { #category : 'as yet unclassified' } MFTWorkoutLogEditorComponent class >> forWorkoutLog: aMFTWorkoutLog [ ^ self new workoutLog: aMFTWorkoutLog; yourself ] { #category : 'as yet unclassified' } MFTWorkoutLogEditorComponent class >> forWorkoutPrescription: aMFTWorkoutPrescription [ ^ self forWorkoutLog: (MFTWorkoutLog forPrescription: aMFTWorkoutPrescription) startNow ] { #category : 'as yet unclassified' } MFTWorkoutLogEditorComponent >> onDiscardWorkout: aBlock [ onDiscardWorkout := aBlock ] { #category : 'as yet unclassified' } MFTWorkoutLogEditorComponent >> onSaveWorkout: aBlock [ onSaveWorkout := aBlock ] { #category : 'rendering' } MFTWorkoutLogEditorComponent >> renderContentOn: html [ html form: [ self renderWorkoutLogMetadataOn: html. html horizontalRule. self renderSetGroupLogsOn: html. html horizontalRule. self renderFormActionsOn: html ] ] { #category : 'as yet unclassified' } MFTWorkoutLogEditorComponent >> renderFormActionsOn: html [ html fieldSet class: 'grid'; with: [ html legend. html submitButton callback: [ onSaveWorkout value ]; with: 'Finish and save workout'. html submitButton class: 'secondary'; callback: [ onDiscardWorkout value ]; with: 'Discard workout' ] ] { #category : 'rendering' } MFTWorkoutLogEditorComponent >> renderSetGroupLogData: setGroupLog on: html [ html table: [ html tableHead: [ html tableRow: [ html tableHeading: 'Exercise'; tableHeading: 'Reps'; tableHeading: 'Load'; tableHeading: 'Failure Achieved' ] ]; tableBody: [ setGroupLog sets do: [ :setLog | html tableRow: [ html tableData: setLog exercise; tableData: setLog reps; tableData: setLog load; tableData: setLog failureAchieved ] ] ] ] ] { #category : 'rendering' } MFTWorkoutLogEditorComponent >> renderSetGroupLogsOn: html [ workoutLog setGroups do: [ :setGroupLog | | isCompletelyLogged | isCompletelyLogged := setGroupLog isCompletelyLogged. html heading level: 3; with: setGroupLog canonicalName capitalized. html heading level: 4; with: (setGroupLog uniqueExercisesInSets asOrderedCollection joinUsing: ', '). html paragraph: [ isCompletelyLogged ifTrue: [ html definitionList: [ html definitionTerm: 'Intensity factor'; definitionData: setGroupLog intensityFactor ]. self renderSetGroupLogData: setGroupLog on: html ]. html anchor callback: [ self call: (MFTSetGroupLogEditorComponent forSetGroupLog: setGroupLog) ]; with: (isCompletelyLogged ifTrue: [ 'Edit' ] ifFalse: [ 'Log' ]) ] ] ] { #category : 'as yet unclassified' } MFTWorkoutLogEditorComponent >> renderWorkoutLogMetadataOn: html [ html heading level: 3; with: 'Duration'. html fieldSet class: 'grid'; with: [ html legend: 'Start'. html div: [ html label for: 'start-date'; with: 'Date'. html dateInput5 id: 'start-date'; value: Date today yyyymmdd; callback: [ :value | workoutLog startDate: (Date readFrom: value pattern: 'yyyy-mm-dd') ] ]. html div: [ html label for: 'start-time'; with: 'Time'. html timeInput5 id: 'start-time'; value: workoutLog start asTime print24; callback: [ :value | workoutLog startTime: (Time fromString: value) ] ]. html div style: 'margin-top: auto'; with: [ html button class: 'secondary outline'; callback: [ workoutLog startNow. workoutLog finish: nil ]; with: 'Start now' ] ]. html fieldSet class: 'grid'; with: [ html legend: 'Finish'. html div: [ html label for: 'finish-date'; with: 'Date'. html dateInput5 value: Date today yyyymmdd; callback: [ :value | workoutLog finishDate: (Date readFrom: value pattern: 'yyyy-mm-dd') ] ]. html div: [ html label for: 'finish-time'; with: 'Time'. html timeInput5 value: (workoutLog finish ifNotNil: [ workoutLog finish asTime print24 ]); callback: [ :value | value ifNotEmpty: [ workoutLog finishTime: (Time fromString: value) ] ] ]. html div style: 'margin-top: auto'; with: [ html button class: 'secondary outline'; callback: [ workoutLog finishNow ]; with: 'Finish now' ] ] ] { #category : 'accessing' } MFTWorkoutLogEditorComponent >> title [ ^ 'Log workout' ] { #category : 'accessing' } MFTWorkoutLogEditorComponent >> workoutLog: aMFTWorkoutLog [ workoutLog := aMFTWorkoutLog ]