New MFT Form Components :fire:

Commit
a16c186d69c1d4b4b05d5d00f4306bef27f39ccf
Author
Marius Peter <marius.peter@tutanota.com>
Author date
Committer
Marius Peter <marius.peter@tutanota.com>
Committer date
Changed files
src/MyFitnessTracker/MFTDateFormComponent.class.st
index 867c5093..2b262ef5 100644..100644
@@ -1,39 +1,25 @@
1 1 Class {
2 2 #name : 'MFTDateFormComponent',
3 3 #superclass : 'MFTFormComponent',
4 Removed: #instVars : [
5 Removed: 'date'
6 Removed: ],
7 4 #category : 'MyFitnessTracker-Forms',
8 5 #package : 'MyFitnessTracker',
9 6 #tag : 'Forms'
10 7 }
11 8
12 Removed: { #category : 'accessing' }
13 Removed: MFTDateFormComponent >> date [
14 Removed:
15 Removed: ^ date
16 Removed: ]
17 Removed:
18 Removed: { #category : 'accessing' }
19 Removed: MFTDateFormComponent >> date: anObject [
20 Removed:
21 Removed: date := anObject
22 Removed: ]
23 Removed:
24 9 { #category : 'initialization' }
25 10 MFTDateFormComponent >> initialize [
26 11
27 12 super initialize.
28 Removed: date := Date today
13 Added: heading := 'Date'.
14 Added: data := Date today
29 15 ]
30 16
31 17 { #category : 'rendering' }
32 18 MFTDateFormComponent >> renderContentOn: html [
33 19
34 Removed: self renderDialogOn: html with: [
20 Added: self renderFormComponentOn: html with: [
35 21 html dateInput5 formControl
36 Removed: value: date yyyymmdd;
22 Added: value: data yyyymmdd;
37 23 callback: [ :value |
38 Removed: date := Date readFrom: value pattern: 'yyyy-mm-dd' ] ]
24 Added: data := Date readFrom: value pattern: 'yyyy-mm-dd' ] ]
39 25 ]
src/MyFitnessTracker/MFTFormComponent.class.st
index afb119cd..517eae45 100644..100644
@@ -1,7 +1,33 @@
1 1 Class {
2 2 #name : 'MFTFormComponent',
3 3 #superclass : 'SBSComponent',
4 Added: #instVars : [
5 Added: 'heading',
6 Added: 'data'
7 Added: ],
4 8 #category : 'MyFitnessTracker-Forms',
5 9 #package : 'MyFitnessTracker',
6 10 #tag : 'Forms'
7 11 }
12 Added:
13 Added: { #category : 'accessing' }
14 Added: MFTFormComponent >> data [
15 Added:
16 Added: ^ data
17 Added: ]
18 Added:
19 Added: { #category : 'accessing' }
20 Added: MFTFormComponent >> data: anObject [
21 Added:
22 Added: data := anObject
23 Added: ]
24 Added:
25 Added: { #category : 'rendering' }
26 Added: MFTFormComponent >> renderFormComponentOn: html with: aBlock [
27 Added:
28 Added: html formGroup
29 Added: class: 'my-3';
30 Added: with: [
31 Added: html heading level3 with: heading.
32 Added: aBlock value ]
33 Added: ]
src/MyFitnessTracker/MFTPrimaryMuscleGroupFormComponent.class.st
index 00000000..c2e642ab 000000..100644
@@ -0,0 +1,32 @@
1 Added: Class {
2 Added: #name : 'MFTPrimaryMuscleGroupFormComponent',
3 Added: #superclass : 'MFTFormComponent',
4 Added: #category : 'MyFitnessTracker-Forms',
5 Added: #package : 'MyFitnessTracker',
6 Added: #tag : 'Forms'
7 Added: }
8 Added:
9 Added: { #category : 'initialization' }
10 Added: MFTPrimaryMuscleGroupFormComponent >> initialize [
11 Added:
12 Added: super initialize.
13 Added: heading := 'Primary Muscle Group'.
14 Added: data := MFTSQLite3Database allMuscleGroups first
15 Added: ]
16 Added:
17 Added: { #category : 'rendering' }
18 Added: MFTPrimaryMuscleGroupFormComponent >> renderContentOn: html [
19 Added:
20 Added: | allMuscleGroups selectedMuscleGroup |
21 Added: allMuscleGroups := MFTSQLite3Database allMuscleGroups.
22 Added: selectedMuscleGroup := data ifNotNil: [
23 Added: allMuscleGroups detect: [ :muscleGroup |
24 Added: muscleGroup englishName = data englishName ] ].
25 Added:
26 Added: self renderFormComponentOn: html with: [
27 Added: html select formControl
28 Added: list: allMuscleGroups;
29 Added: selected: selectedMuscleGroup;
30 Added: labels: [ :muscleGroup | muscleGroup englishName ];
31 Added: callback: [ :group | data := group ] ]
32 Added: ]
src/MyFitnessTracker/MFTSetGroupsFormComponent.class.st
index 00000000..daed43b2 000000..100644
@@ -0,0 +1,121 @@
1 Added: Class {
2 Added: #name : 'MFTSetGroupsFormComponent',
3 Added: #superclass : 'MFTFormComponent',
4 Added: #instVars : [
5 Added: 'setGroups'
6 Added: ],
7 Added: #category : 'MyFitnessTracker-Forms',
8 Added: #package : 'MyFitnessTracker',
9 Added: #tag : 'Forms'
10 Added: }
11 Added:
12 Added: { #category : 'adding' }
13 Added: MFTSetGroupsFormComponent >> addExercise [
14 Added:
15 Added: | setGroup |
16 Added: setGroup := self session pageManager activePage call:
17 Added: (MFTSetGroupDialog new heading: 'Exercise').
18 Added: setGroup ifNotNil: [ setGroups add: setGroup ]
19 Added: ]
20 Added:
21 Added: { #category : 'adding' }
22 Added: MFTSetGroupsFormComponent >> addSetGroupForExerciseCount: anInteger [
23 Added:
24 Added: | setGroup |
25 Added: setGroup := self session pageManager activePage call:
26 Added: (MFTSetGroupTask forExerciseCount: anInteger).
27 Added: setGroup ifNotNil: [ setGroups add: setGroup ]
28 Added: ]
29 Added:
30 Added: { #category : 'rendering' }
31 Added: MFTSetGroupsFormComponent >> editSetGroup: aMFTSetGroup [
32 Added:
33 Added: | oldSetGroup newSetGroup |
34 Added: oldSetGroup := aMFTSetGroup.
35 Added: newSetGroup := self call: (MFTSetGroupDialog edit: aMFTSetGroup copy).
36 Added: newSetGroup ifNotNil: [
37 Added: setGroups at: (setGroups indexOf: oldSetGroup) put: newSetGroup ]
38 Added: ]
39 Added:
40 Added: { #category : 'initialization' }
41 Added: MFTSetGroupsFormComponent >> initialize [
42 Added:
43 Added: super initialize.
44 Added: heading := 'Set Groups'.
45 Added: setGroups := OrderedCollection new
46 Added: ]
47 Added:
48 Added: { #category : 'rendering' }
49 Added: MFTSetGroupsFormComponent >> renderAddSetGroupButtonsOn: html [
50 Added:
51 Added: html buttonGroup: [
52 Added: html outlineButton
53 Added: bePrimary;
54 Added: beSmall;
55 Added: callback: [ self addSetGroupForExerciseCount: 1 ];
56 Added: with: 'Add exercise'.
57 Added: html outlineButton
58 Added: beSecondary;
59 Added: beSmall;
60 Added: callback: [ self addSetGroupForExerciseCount: 2 ];
61 Added: with: 'Add super set'.
62 Added: html outlineButton
63 Added: beSecondary;
64 Added: beSmall;
65 Added: callback: [ self addSetGroupForExerciseCount: 3 ];
66 Added: with: 'Add tri-set'.
67 Added: html outlineButton
68 Added: beSecondary;
69 Added: beSmall;
70 Added: callback: [ self addSetGroupForExerciseCount: 4 ];
71 Added: with: 'Add giant set' ]
72 Added: ]
73 Added:
74 Added: { #category : 'rendering' }
75 Added: MFTSetGroupsFormComponent >> renderContentOn: html [
76 Added:
77 Added: self renderFormComponentOn: html with: [
78 Added: setGroups ifNotEmpty: [ self renderSetsTableOn: html ].
79 Added: self renderAddSetGroupButtonsOn: html ]
80 Added: ]
81 Added:
82 Added: { #category : 'rendering' }
83 Added: MFTSetGroupsFormComponent >> renderLoad [
84 Added:
85 Added: ^ (setGroups flatCollect: #sets) anySatisfy: #hasLoad
86 Added: ]
87 Added:
88 Added: { #category : 'rendering' }
89 Added: MFTSetGroupsFormComponent >> renderRestAfter [
90 Added:
91 Added: ^ (setGroups flatCollect: #sets) anySatisfy: #hasRestAfter
92 Added: ]
93 Added:
94 Added: { #category : 'rendering' }
95 Added: MFTSetGroupsFormComponent >> renderRpe [
96 Added:
97 Added: ^ (setGroups flatCollect: #sets) anySatisfy: #hasRpe
98 Added: ]
99 Added:
100 Added: { #category : 'rendering' }
101 Added: MFTSetGroupsFormComponent >> renderSetGroupsTableHeaderOn: html [
102 Added:
103 Added: html tableHead: [
104 Added: html
105 Added: tableHeading;
106 Added: tableHeading: 'Exercise';
107 Added: tableHeading: 'Reps'.
108 Added: self renderLoad ifTrue: [ html tableHeading: 'Load' ].
109 Added: self renderRpe ifTrue: [ html tableHeading: 'RPE' ].
110 Added: self renderRestAfter ifTrue: [ html tableHeading: 'Rest after (s) ' ] ]
111 Added: ]
112 Added:
113 Added: { #category : 'rendering' }
114 Added: MFTSetGroupsFormComponent >> renderSetsTableOn: html [
115 Added:
116 Added: html table
117 Added: class: 'table table-bordered';
118 Added: with: [
119 Added: self renderSetGroupsTableHeaderOn: html.
120 Added: self renderSetGroupsRowsOn: html ]
121 Added: ]
src/MyFitnessTracker/MFTWorkoutDialog.class.st
index 2f2b8919..d12c05bc 100644..100644
@@ -3,7 +3,10 @@
3 3 #superclass : 'MFTDialog',
4 4 #instVars : [
5 5 'workout',
6 Removed: 'allMuscleGroups'
6 Added: 'datePicker',
7 Added: 'setGroupsPicker',
8 Added: 'primaryMuscleGroupPicker',
9 Added: 'secondaryMuscleGroupsPicker'
7 10 ],
8 11 #category : 'MyFitnessTracker-Dialogs',
9 12 #package : 'MyFitnessTracker',
@@ -19,198 +22,55 @@
19 22 yourself
20 23 ]
21 24
22 Removed: { #category : 'adding' }
23 Removed: MFTWorkoutDialog >> addExercise [
24 Removed:
25 Removed: | setGroup |
26 Removed: setGroup := self call: (MFTSetGroupDialog new heading: 'Exercise').
27 Removed: setGroup ifNotNil: [ workout addSetGroup: setGroup ]
28 Removed: ]
29 Removed:
30 25 { #category : 'initialization' }
31 26 MFTWorkoutDialog >> initialize [
32 27
33 28 super initialize.
34 29 workout := MFTWorkout placeholderCollection first.
35 Removed: allMuscleGroups := MFTSQLite3Database allMuscleGroups
30 Added: datePicker := MFTDateFormComponent new.
31 Added: setGroupsPicker := MFTSetGroupsFormComponent new.
32 Added: primaryMuscleGroupPicker := MFTPrimaryMuscleGroupFormComponent new
36 33 ]
37 34
38 Removed: { #category : 'adding' }
39 Removed: MFTWorkoutDialog >> renderAddSetsButtonGroupOn: html [
40 Removed:
41 Removed: html buttonGroup: [
42 Removed: html outlineButton
43 Removed: bePrimary;
44 Removed: beSmall;
45 Removed: callback: [ self addExercise ];
46 Removed: with: 'Add exercise'.
47 Removed: html outlineButton
48 Removed: beSecondary;
49 Removed: beSmall;
50 Removed: callback: [ self addSuperset ];
51 Removed: with: 'Add superset'.
52 Removed: html outlineButton
53 Removed: beSecondary;
54 Removed: beSmall;
55 Removed: callback: [ self addTriSet ];
56 Removed: with: 'Add tri-set'.
57 Removed: html outlineButton
58 Removed: beSecondary;
59 Removed: beSmall;
60 Removed: callback: [ self addGiantSet ];
61 Removed: with: 'Add giant set' ]
62 Removed: ]
63 Removed:
64 35 { #category : 'rendering' }
65 36 MFTWorkoutDialog >> renderContentOn: html [
66 37
67 38 self renderDialogOn: html with: [
68 Removed: self renderDatePickerOn: html.
69 Removed: self renderExercisePickerOn: html.
70 Removed: self renderPrimaryMuscleGroupPickerOn: html.
71 Removed: self renderSecondaryMuscleGroupsPickerOn: html ]
39 Added: html render: datePicker.
40 Added: html render: setGroupsPicker.
41 Added: html render: primaryMuscleGroupPicker ]
72 42 ]
73 43
74 44 { #category : 'rendering' }
75 Removed: MFTWorkoutDialog >> renderDatePickerOn: html [
76 Removed:
77 Removed: html formGroup: [
78 Removed: html heading level2 with: 'Date'.
79 Removed: html dateInput5 formControl
80 Removed: value: workout date yyyymmdd;
81 Removed: callback: [ :value |
82 Removed: workout date: (Date readFrom: value pattern: 'yyyy-mm-dd') ] ]
83 Removed: ]
84 Removed:
85 Removed: { #category : 'rendering' }
86 Removed: MFTWorkoutDialog >> renderExercisePickerOn: html [
87 Removed:
88 Removed: html formGroup: [
89 Removed: html heading level2 with: 'Exercises'.
90 Removed: self renderAddSetsButtonGroupOn: html.
91 Removed: self renderSetsTableOn: html ]
92 Removed: ]
93 Removed:
94 Removed: { #category : 'rendering' }
95 Removed: MFTWorkoutDialog >> renderLoad [
96 Removed:
97 Removed: ^ (workout setGroups flatCollect: #sets) anySatisfy: #hasLoad
98 Removed: ]
99 Removed:
100 Removed: { #category : 'rendering' }
101 Removed: MFTWorkoutDialog >> renderPrimaryMuscleGroupPickerOn: html [
102 Removed:
103 Removed: html formGroup: [
104 Removed: html heading level3 with: 'Primary Muscle Group'.
105 Removed: html formGroup: [
106 Removed: html select formControl
107 Removed: list: allMuscleGroups;
108 Removed: selected: workout primaryMuscleGroup;
109 Removed: labels: [ :muscleGroup | muscleGroup englishName ];
110 Removed: callback: [ :group | workout primaryMuscleGroup: group ] ] ]
111 Removed: ]
112 Removed:
113 Removed: { #category : 'rendering' }
114 Removed: MFTWorkoutDialog >> renderRestAfter [
115 Removed:
116 Removed: ^ (workout setGroups flatCollect: #sets) anySatisfy: #hasRestAfter
117 Removed: ]
118 Removed:
119 Removed: { #category : 'rendering' }
120 Removed: MFTWorkoutDialog >> renderRpe [
121 Removed:
122 Removed: ^ (workout setGroups flatCollect: #sets) anySatisfy: #hasRpe
123 Removed: ]
124 Removed:
125 Removed: { #category : 'rendering' }
126 Removed: MFTWorkoutDialog >> renderSecondaryMuscleGroupsPickerOn: html [
127 Removed:
128 Removed: ^ html formGroup: [
129 Removed: html heading level3 with: 'Secondary Muscle Groups'.
130 Removed: html multiSelect formControl
131 Removed: list: allMuscleGroups;
132 Removed: selected: workout secondaryMuscleGroups;
133 Removed: labels: [ :muscleGroup | muscleGroup englishName ];
134 Removed: callback: [ :groups | workout secondaryMuscleGroups: groups ] ]
135 Removed: ]
136 Removed:
137 Removed: { #category : 'rendering' }
138 Removed: MFTWorkoutDialog >> renderSetGroupButtonsOn: html For: setGroup [
139 Removed:
140 Removed: html buttonGroupVertical: [
141 Removed: html outlineButton
142 Removed: beDanger;
143 Removed: beSmall;
144 Removed: callback: [ workout setGroups remove: setGroup ];
145 Removed: with: 'Remove'.
146 Removed: html outlineButton
147 Removed: beSecondary;
148 Removed: beSmall;
149 Removed: callback: [ self editSetGroup: setGroup ];
150 Removed: with: 'Edit'.
151 Removed: html outlineButton
152 Removed: beSecondary;
153 Removed: beSmall;
154 Removed: callback: [
155 Removed: workout setGroups
156 Removed: add: setGroup
157 Removed: afterIndex: (workout setGroups indexOf: setGroup) ];
158 Removed: with: 'Duplicate' ]
159 Removed: ]
160 Removed:
161 Removed: { #category : 'rendering' }
162 Removed: MFTWorkoutDialog >> renderSetGroupsRowsOn: html [
163 Removed:
164 Removed: workout setGroups do: [ :setGroup |
165 Removed: html tableRow with: [
166 Removed: html tableData
167 Removed: attributeAt: 'rowspan' put: setGroup sets size + 1;
168 Removed: style: 'vertical-align: middle';
169 Removed: with: [ self renderSetGroupButtonsOn: html For: setGroup ] ].
170 Removed: setGroup sets do: [ :set |
171 Removed: html tableRow: [
172 Removed: html tableData: set exercise englishName.
173 Removed: html tableData: set reps.
174 Removed: setGroup hasLoad ifTrue: [ html tableData: set load ].
175 Removed: setGroup hasRpe ifTrue: [ html tableData: set rpe ].
176 Removed: setGroup hasRestAfter ifTrue: [ html tableData: set restAfter ] ] ] ]
177 Removed: ]
178 Removed:
179 Removed: { #category : 'rendering' }
180 Removed: MFTWorkoutDialog >> renderSetGroupsTableHeaderOn: html [
181 Removed:
182 Removed: html tableHead: [
183 Removed: html
184 Removed: tableHeading;
185 Removed: tableHeading: 'Exercise';
186 Removed: tableHeading: 'Reps'.
187 Removed: self renderLoad ifTrue: [ html tableHeading: 'Load' ].
188 Removed: self renderRpe ifTrue: [ html tableHeading: 'RPE' ].
189 Removed: self renderRestAfter ifTrue: [ html tableHeading: 'Rest after (s) ' ] ]
190 Removed: ]
191 Removed:
192 Removed: { #category : 'rendering' }
193 Removed: MFTWorkoutDialog >> renderSetsTableOn: html [
194 Removed:
195 Removed: html table
196 Removed: class: 'table table-bordered';
197 Removed: with: [
198 Removed: self renderSetGroupsTableHeaderOn: html.
199 Removed: self renderSetGroupsRowsOn: html ]
200 Removed: ]
201 Removed:
202 Removed: { #category : 'rendering' }
203 45 MFTWorkoutDialog >> renderSubmitOn: html [
204 46
205 47 html buttonGroup: [
206 48 html formButton
207 49 beSubmit;
208 50 bePrimary;
209 Removed: callback: [ self answer: workout ];
51 Added: callback: [
52 Added: workout
53 Added: date: datePicker data;
54 Added: setGroups: setGroupsPicker data;
55 Added: primaryMuscleGroup: primaryMuscleGroupPicker data. ";
56 Added: secondaryMuscleGroups: secondaryMuscleGroupsPicker data"
57 Added: self answer: workout ];
210 58 with: 'Submit'.
211 59 html formButton
212 60 beSubmit;
213 61 beSecondary;
214 62 callback: [ self answer: nil ];
215 63 with: 'Cancel' ]
64 Added: ]
65 Added:
66 Added: { #category : 'accessing' }
67 Added: MFTWorkoutDialog >> workout [
68 Added:
69 Added: ^ workout
70 Added: ]
71 Added:
72 Added: { #category : 'accessing' }
73 Added: MFTWorkoutDialog >> workout: anObject [
74 Added:
75 Added: workout := anObject
216 76 ]
src/MyFitnessTracker/MFTWorkoutsLog.class.st
index b819d2ff..f587c465 100644..100644
@@ -36,7 +36,7 @@
36 36 MFTWorkoutsLog >> addWorkout [
37 37
38 38 | newWorkout |
39 Removed: newWorkout := self call: MFTWorkoutTask new.
39 Added: newWorkout := self call: MFTWorkoutDialog new.
40 40 newWorkout ifNil: [ ^ self ].
41 41
42 42 self session user isLoggedIn