[Pharo] Personal fitness tracker web app.
1
Class {
2
#name : 'MFTWorkoutLogEditorComponent',
3
#superclass : 'WAComponent',
4
#instVars : [
5
'workoutLog',
6
'onSaveWorkout',
7
'onDiscardWorkout'
8
],
9
#category : 'MyFitnessTracker-Web-Components',
10
#package : 'MyFitnessTracker-Web',
11
#tag : 'Components'
12
}
13
14
{ #category : 'as yet unclassified' }
15
MFTWorkoutLogEditorComponent class >> forWorkoutLog: aMFTWorkoutLog [
16
17
^ self new
18
workoutLog: aMFTWorkoutLog;
19
yourself
20
]
21
22
{ #category : 'as yet unclassified' }
23
MFTWorkoutLogEditorComponent class >> forWorkoutPrescription: aMFTWorkoutPrescription [
24
25
^ self forWorkoutLog:
26
(MFTWorkoutLog forPrescription: aMFTWorkoutPrescription) startNow
27
]
28
29
{ #category : 'as yet unclassified' }
30
MFTWorkoutLogEditorComponent >> onDiscardWorkout: aBlock [
31
32
onDiscardWorkout := aBlock
33
]
34
35
{ #category : 'as yet unclassified' }
36
MFTWorkoutLogEditorComponent >> onSaveWorkout: aBlock [
37
38
onSaveWorkout := aBlock
39
]
40
41
{ #category : 'rendering' }
42
MFTWorkoutLogEditorComponent >> renderContentOn: html [
43
44
html form: [
45
self renderWorkoutLogMetadataOn: html.
46
html horizontalRule.
47
self renderSetGroupLogsOn: html.
48
html horizontalRule.
49
self renderFormActionsOn: html ]
50
]
51
52
{ #category : 'as yet unclassified' }
53
MFTWorkoutLogEditorComponent >> renderFormActionsOn: html [
54
55
html fieldSet
56
class: 'grid';
57
with: [
58
html legend.
59
html submitButton
60
callback: [ onSaveWorkout value ];
61
with: 'Finish and save workout'.
62
63
html submitButton
64
class: 'secondary';
65
callback: [ onDiscardWorkout value ];
66
with: 'Discard workout' ]
67
]
68
69
{ #category : 'rendering' }
70
MFTWorkoutLogEditorComponent >> renderSetGroupLogData: setGroupLog on: html [
71
72
html table: [
73
html
74
tableHead: [
75
html tableRow: [
76
html
77
tableHeading: 'Exercise';
78
tableHeading: 'Reps';
79
tableHeading: 'Load';
80
tableHeading: 'Failure Achieved' ] ];
81
tableBody: [
82
setGroupLog sets do: [ :setLog |
83
html tableRow: [
84
html
85
tableData: setLog exercise;
86
tableData: setLog reps;
87
tableData: setLog load;
88
tableData: setLog failureAchieved ] ] ] ]
89
]
90
91
{ #category : 'rendering' }
92
MFTWorkoutLogEditorComponent >> renderSetGroupLogsOn: html [
93
94
workoutLog setGroups do: [ :setGroupLog |
95
| isCompletelyLogged |
96
isCompletelyLogged := setGroupLog isCompletelyLogged.
97
98
html heading
99
level: 3;
100
with: setGroupLog canonicalName capitalized.
101
html heading
102
level: 4;
103
with:
104
(setGroupLog uniqueExercisesInSets asOrderedCollection joinUsing:
105
', ').
106
html paragraph: [
107
isCompletelyLogged ifTrue: [
108
html definitionList: [
109
html
110
definitionTerm: 'Intensity factor';
111
definitionData: setGroupLog intensityFactor ].
112
self renderSetGroupLogData: setGroupLog on: html ].
113
html anchor
114
callback: [
115
self call:
116
(MFTSetGroupLogEditorComponent forSetGroupLog: setGroupLog) ];
117
with: (isCompletelyLogged
118
ifTrue: [ 'Edit' ]
119
ifFalse: [ 'Log' ]) ] ]
120
]
121
122
{ #category : 'as yet unclassified' }
123
MFTWorkoutLogEditorComponent >> renderWorkoutLogMetadataOn: html [
124
125
html heading
126
level: 3;
127
with: 'Duration'.
128
html fieldSet
129
class: 'grid';
130
with: [
131
html legend: 'Start'.
132
html div: [
133
html label
134
for: 'start-date';
135
with: 'Date'.
136
html dateInput5
137
id: 'start-date';
138
value: Date today yyyymmdd;
139
callback: [ :value |
140
workoutLog startDate:
141
(Date readFrom: value pattern: 'yyyy-mm-dd') ] ].
142
html div: [
143
html label
144
for: 'start-time';
145
with: 'Time'.
146
html timeInput5
147
id: 'start-time';
148
value: workoutLog start asTime print24;
149
callback: [ :value |
150
workoutLog startTime: (Time fromString: value) ] ].
151
html div
152
style: 'margin-top: auto';
153
with: [
154
html button
155
class: 'secondary outline';
156
callback: [
157
workoutLog startNow.
158
workoutLog finish: nil ];
159
with: 'Start now' ] ].
160
html fieldSet
161
class: 'grid';
162
with: [
163
html legend: 'Finish'.
164
html div: [
165
html label
166
for: 'finish-date';
167
with: 'Date'.
168
html dateInput5
169
value: Date today yyyymmdd;
170
callback: [ :value |
171
workoutLog finishDate:
172
(Date readFrom: value pattern: 'yyyy-mm-dd') ] ].
173
html div: [
174
html label
175
for: 'finish-time';
176
with: 'Time'.
177
html timeInput5
178
value:
179
(workoutLog finish ifNotNil: [ workoutLog finish asTime print24 ]);
180
callback: [ :value |
181
value ifNotEmpty: [
182
workoutLog finishTime: (Time fromString: value) ] ] ].
183
html div
184
style: 'margin-top: auto';
185
with: [
186
html button
187
class: 'secondary outline';
188
callback: [ workoutLog finishNow ];
189
with: 'Finish now' ] ]
190
]
191
192
{ #category : 'accessing' }
193
MFTWorkoutLogEditorComponent >> title [
194
195
^ 'Log workout'
196
]
197
198
{ #category : 'accessing' }
199
MFTWorkoutLogEditorComponent >> workoutLog: aMFTWorkoutLog [
200
201
workoutLog := aMFTWorkoutLog
202
]
203