[Pharo] Personal fitness tracker web app.
Weights and Workouts pages shouldn't access their collections by index.
Since the weights and workouts collections are susceptible to sorting/reordering for presentation purposes, modifying these collections by specifying an index is less robust than identifying the precise instance in the collection which needs to be modified.
Changed files
src/MyFitnessTracker/MFTWeightsListPage.class.st
@@ -12,26 +12,35 @@
12
12
13
13
| newWeight |
14
14
newWeight := self call: MFTWeightDialog new.
15
Removed:
(newWeight isNotNil and: [ newWeight value ~~ '' ]) ifTrue: [
16
Removed:
self session user weights add: newWeight ]
15
Added:
newWeight value = 0 ifTrue: [ ^ self ].
16
Added:
(weights anySatisfy: [ :existingWeight |
17
Added:
newWeight date = existingWeight date and: [
18
Added:
newWeight value = existingWeight value ] ]) ifTrue: [ ^ self ].
19
Added:
20
Added:
self session user weights add: newWeight.
21
Added:
self session user isLoggedIn ifTrue: [
22
Added:
self session db insert: newWeight ]
17
23
]
18
24
19
25
{ #category : #accessing }
20
Removed:
MFTWeightsListPage >> editWeightAt: i [
26
Added:
MFTWeightsListPage >> editWeight: oldWeight [
21
27
22
Removed:
| oldWeight newWeight |
23
Removed:
oldWeight := weights at: i.
28
Added:
| newWeight |
24
29
newWeight := self call: (MFTWeightDialog edit: oldWeight).
25
Removed:
newWeight ifNil: [ ^ nil ].
26
Removed:
newWeight value ~~ 0 ifTrue: [
27
Removed:
self session user weights at: i put: newWeight ]
30
Added:
(newWeight isNil or: [ newWeight value = 0 ]) ifTrue: [ ^ self ].
31
Added:
self session user weights
32
Added:
remove: oldWeight;
33
Added:
add: newWeight.
34
Added:
self session user isLoggedIn ifTrue: [
35
Added:
self session db update: oldWeight with: newWeight ]
28
36
]
29
37
30
38
{ #category : #initialization }
31
39
MFTWeightsListPage >> initialize [
32
40
33
41
super initialize.
34
Removed:
title := 'weights'
42
Added:
title := 'weights'.
43
Added:
weights := OrderedCollection new
35
44
]
36
45
37
46
{ #category : #'as yet unclassified' }
@@ -51,9 +60,11 @@
51
60
]
52
61
53
62
{ #category : #accessing }
54
Removed:
MFTWeightsListPage >> removeWeightAt: i [
63
Added:
MFTWeightsListPage >> removeWeight: aMFTWeight [
55
64
56
Removed:
self session user weights removeAt: i
65
Added:
self session user weights remove: aMFTWeight.
66
Added:
self session user isLoggedIn ifTrue: [
67
Added:
self session db delete: aMFTWeight ]
57
68
]
58
69
59
70
{ #category : #rendering }
@@ -83,7 +94,7 @@
83
94
]
84
95
85
96
{ #category : #rendering }
86
Removed:
MFTWeightsListPage >> renderWeightActionsButtonGroupOn: html at: i [
97
Added:
MFTWeightsListPage >> renderWeightActionsButtonGroupOn: html for: aMFTWeight [
87
98
88
99
html form: [
89
100
html buttonGroup
@@ -92,12 +103,12 @@
92
103
html formButton
93
104
beSecondary;
94
105
formControl;
95
Removed:
callback: [ self editWeightAt: i ];
106
Added:
callback: [ self editWeight: aMFTWeight ];
96
107
with: 'Edit'.
97
108
html formButton
98
109
beDanger;
99
110
formControl;
100
Removed:
callback: [ self removeWeightAt: i ];
111
Added:
callback: [ self removeWeight: aMFTWeight ];
101
112
with: 'Delete' ] ]
102
113
]
103
114
@@ -114,10 +125,10 @@
114
125
html tableHeading
115
126
style: 'text-align: right';
116
127
with: 'Value' ].
117
Removed:
weights doWithIndex: [ :weight :i |
128
Added:
weights do: [ :weight |
118
129
html tableRow: [
119
130
html tableData: [
120
Removed:
self renderWeightActionsButtonGroupOn: html at: i ].
131
Added:
self renderWeightActionsButtonGroupOn: html for: weight ].
121
132
html tableData: weight date yyyymmdd.
122
133
html tableData
123
134
style: 'text-align: right';
src/MyFitnessTracker/MFTWorkoutsListPage.class.st
@@ -79,6 +79,17 @@
79
79
yourself
80
80
]
81
81
82
Added:
{ #category : #adding }
83
Added:
MFTWorkoutsListPage >> addWorkout [
84
Added:
85
Added:
| workout |
86
Added:
workout := self call: MFTWorkoutTask new.
87
Added:
workout ifNotNil: [
88
Added:
self session user workouts add: workout.
89
Added:
self session user isLoggedIn ifTrue: [
90
Added:
self session db insert: workout ] ]
91
Added:
]
92
Added:
82
93
{ #category : #hooks }
83
94
MFTWorkoutsListPage >> children [
84
95
@@ -86,22 +97,23 @@
86
97
]
87
98
88
99
{ #category : #accessing }
89
Removed:
MFTWorkoutsListPage >> confirmDeleteAt: i [
100
Added:
MFTWorkoutsListPage >> confirmDelete: workout [
90
101
91
Removed:
| workout |
92
Removed:
workout := self session user workouts at: i.
93
102
(self call: (MFTConfirmDialog delete: workout)) ifTrue: [
94
Removed:
self session user workouts removeAt: i ]
103
Added:
self session user workouts remove: workout ]
95
104
]
96
105
97
106
{ #category : #'as yet unclassified' }
98
Removed:
MFTWorkoutsListPage >> editWorkoutAt: i [
107
Added:
MFTWorkoutsListPage >> editWorkout: oldWorkout [
99
108
100
Removed:
| oldWorkout newWorkout |
101
Removed:
oldWorkout := workouts at: i.
109
Added:
| newWorkout |
102
110
newWorkout := self call: (MFTWorkoutTask edit: oldWorkout).
103
Removed:
newWorkout ifNotNil: [
104
Removed:
self session user workouts at: i put: newWorkout ]
111
Added:
newWorkout ifNil: [ ^ self ].
112
Added:
self session user workouts
113
Added:
remove: oldWorkout;
114
Added:
add: newWorkout.
115
Added:
self session user isLoggedIn ifTrue: [
116
Added:
self session db update: oldWorkout with: newWorkout ]
105
117
]
106
118
107
119
{ #category : #initialization }
@@ -136,7 +148,7 @@
136
148
html buttonGroup: [
137
149
html formButton
138
150
bePrimary;
139
Removed:
callback: [ self call: MFTWorkoutTask new ];
151
Added:
callback: [ self addWorkout ];
140
152
with: 'Log workout'.
141
153
html formButton
142
154
beSecondary;
@@ -157,17 +169,17 @@
157
169
]
158
170
159
171
{ #category : #rendering }
160
Removed:
MFTWorkoutsListPage >> renderWorkoutActionsButtonGroup: html at: i [
172
Added:
MFTWorkoutsListPage >> renderWorkoutActionsButtonGroup: html for: workout [
161
173
162
174
html form: [
163
175
html buttonGroup: [
164
176
html formButton
165
177
bePrimary;
166
Removed:
callback: [ self editWorkoutAt: i ];
178
Added:
callback: [ self editWorkout: workout ];
167
179
with: 'Edit'.
168
180
html formButton
169
181
beDanger;
170
Removed:
callback: [ self confirmDeleteAt: i ];
182
Added:
callback: [ self confirmDelete: workout ];
171
183
with: 'Delete' ] ]
172
184
]
173
185
@@ -199,13 +211,7 @@
199
211
with: [
200
212
html accordionBody with: [
201
213
html render: workout.
202
Removed:
self renderWorkoutActionsButtonGroup: html at: i ] ] ] ] ]
203
Removed:
]
204
Removed:
205
Removed:
{ #category : #'as yet unclassified' }
206
Removed:
MFTWorkoutsListPage >> userWorkouts [
207
Removed:
208
Removed:
self session db selectWorkoutsWhereUser: self session user
214
Added:
self renderWorkoutActionsButtonGroup: html for: workout ] ] ] ] ]
209
215
]
210
216
211
217
{ #category : #adding }