Update workout and weight logs.

Commit
0c976308b5cdf58fa9c0a68e1da4589110c20f37
Author
Marius Peter <marius.peter@tutanota.com>
Author date
Committer
Marius Peter <marius.peter@tutanota.com>
Committer date
Changed files
src/MyFitnessTracker-Components/MFTLogsPage.class.st
index 11058155..ea48d76d 100644..100644
@@ -2,8 +2,8 @@
2 2 #name : 'MFTLogsPage',
3 3 #superclass : 'MFTPage',
4 4 #instVars : [
5 Removed: 'activeLog',
6 Removed: 'logs'
5 Added: 'logs',
6 Added: 'activeLog'
7 7 ],
8 8 #category : 'MyFitnessTracker-Components-Pages',
9 9 #package : 'MyFitnessTracker-Components',
@@ -21,29 +21,45 @@
21 21
22 22 super initialize.
23 23 title := 'logs'.
24 Removed: logs := {
25 Removed: MFTWorkoutsLog new.
26 Removed: MFTWeightsLog new }.
27 Removed: activeLog := logs first
24 Added: logs := OrderedDictionary withAll: {
25 Added: (#workouts -> MFTWorkoutsLog new).
26 Added: (#weights -> MFTWeightsLog new) }.
27 Added: activeLog := logs at: #workouts
28 28 ]
29 29
30 30 { #category : 'rendering' }
31 31 MFTLogsPage >> renderContentOn: html [
32 32
33 33 self renderPageOn: html with: [
34 Removed: self renderLogNavigationOn: html.
34 Added: self renderLogsDropdownOn: html.
35 35 html render: activeLog ]
36 36 ]
37 37
38 38 { #category : 'rendering' }
39 Removed: MFTLogsPage >> renderLogNavigationOn: html [
39 Added: MFTLogsPage >> renderLogsDropdownOn: html [
40 40
41 Removed: html form
42 Removed: class: 'mb-3';
41 Added: html dropdown
42 Added: class: 'my-3';
43 43 with: [
44 Removed: html navigation flexColumn with: [
45 Removed: logs do: [ :log |
46 Removed: html navigationLink
47 Removed: callback: [ activeLog := log ];
48 Removed: with: log title ] ] ]
44 Added: html formButton
45 Added: id: 'dropdownMenuButton';
46 Added: beLarge;
47 Added: dropdown;
48 Added: dataToggle: 'dropdown';
49 Added: with: activeLog title capitalized.
50 Added: html dropdownMenu
51 Added: attributeAt: 'aria-labelledby' put: '"dropdownMenuButton"';
52 Added: with: [
53 Added: | inactiveLogs |
54 Added: inactiveLogs := logs reject: [ :log | log = activeLog ].
55 Added: inactiveLogs keysAndValuesDo: [ :name :log |
56 Added: html dropdownItem
57 Added: callback: [ self setActiveLogAt: name ];
58 Added: with: log title capitalized ] ] ]
59 Added: ]
60 Added:
61 Added: { #category : 'accessing' }
62 Added: MFTLogsPage >> setActiveLogAt: aKey [
63 Added:
64 Added: activeLog := logs at: aKey
49 65 ]
src/MyFitnessTracker-Components/MFTWeightsLog.class.st
index 82c25bc5..a73e87eb 100644..100644
@@ -13,7 +13,8 @@
13 13 MFTWeightsLog >> addWeight [
14 14
15 15 | newWeight |
16 Removed: newWeight := self call: MFTWeightDialog new.
16 Added: newWeight := self session pageManager activePage call:
17 Added: MFTWeightForm new.
17 18 newWeight ifNil: [ ^ self ].
18 19 (weights anySatisfy: [ :existingWeight |
19 20 existingWeight date = newWeight date and: [
@@ -28,7 +29,7 @@
28 29 MFTWeightsLog >> editWeight: oldWeight [
29 30
30 31 | newWeight |
31 Removed: newWeight := self call: (MFTWeightDialog edit: oldWeight copy).
32 Added: newWeight := self call: (MFTWeightForm new weight: oldWeight copy).
32 33 (oldWeight value = newWeight value and: [
33 34 oldWeight date = newWeight date ]) ifTrue: [ ^ self ].
34 35
@@ -99,12 +100,12 @@
99 100 html buttonGroup
100 101 beSmall;
101 102 with: [
102 Removed: html formButton
103 Added: html outlineButton
103 104 beSecondary;
104 105 formControl;
105 106 callback: [ self editWeight: aMFTWeight ];
106 107 with: 'Edit'.
107 Removed: html formButton
108 Added: html outlineButton
108 109 beDanger;
109 110 formControl;
110 111 callback: [ self removeWeight: aMFTWeight ];
src/MyFitnessTracker-Components/MFTWorkoutsLog.class.st
index be40d837..c93ad305 100644..100644
@@ -36,7 +36,8 @@
36 36 MFTWorkoutsLog >> addWorkout [
37 37
38 38 | newWorkout |
39 Removed: newWorkout := self call: MFTWorkoutForm new.
39 Added: newWorkout := self session pageManager activePage call:
40 Added: MFTWorkoutForm new.
40 41 newWorkout ifNil: [ ^ self ].
41 42
42 43 self session user isLoggedIn
@@ -44,16 +45,12 @@
44 45 ifFalse: [ workouts add: newWorkout ]
45 46 ]
46 47
47 Removed: { #category : 'hooks' }
48 Removed: MFTWorkoutsLog >> children [
49 Removed:
50 Removed: ^ self session user workouts
51 Removed: ]
52 Removed:
53 48 { #category : 'accessing' }
54 49 MFTWorkoutsLog >> confirmDelete: workout [
55 50
56 Removed: (self call: (MFTConfirmForm delete)) ifFalse: [ ^ self ].
51 Added: (self call: (MFTConfirmForm new message:
52 Added: 'Are you sure you want to delete this workout?')) ifFalse: [
53 Added: ^ self ].
57 54 self session user isLoggedIn
58 55 ifTrue: [ self session db delete: workout ]
59 56 ifFalse: [ workouts remove: workout ]
@@ -63,7 +60,8 @@
63 60 MFTWorkoutsLog >> editWorkout: oldWorkout [
64 61
65 62 | newWorkout |
66 Removed: newWorkout := self call: (MFTWorkoutForm edit: oldWorkout copy).
63 Added: newWorkout := self call:
64 Added: (MFTWorkoutForm new workout: oldWorkout copy).
67 65 newWorkout ifNil: [ ^ self ].
68 66
69 67 self session user isLoggedIn