View raw

1 Class { 2 #name : 'MFTSetGroupLogEditorComponent', 3 #superclass : 'WAComponent', 4 #instVars : [ 5 'setGroupLog' 6 ], 7 #category : 'MyFitnessTracker-Web-Components', 8 #package : 'MyFitnessTracker-Web', 9 #tag : 'Components' 10 } 11 12 { #category : 'as yet unclassified' } 13 MFTSetGroupLogEditorComponent class >> forSetGroupLog: aMFTSetGroupLog [ 14 15 ^ self new 16 setGroupLog: aMFTSetGroupLog; 17 yourself 18 ] 19 20 { #category : 'rendering' } 21 MFTSetGroupLogEditorComponent >> renderContentOn: html [ 22 23 html heading 24 level: 3; 25 with: setGroupLog prescription canonicalName capitalized. 26 html form: [ 27 setGroupLog setsGroupedByExercise keysAndValuesDo: [ :exercise :sets | 28 self renderOn: html exercise: exercise sets: sets ]. 29 self renderFormActionsOn: html ] 30 ] 31 32 { #category : 'rendering' } 33 MFTSetGroupLogEditorComponent >> renderFormActionsOn: html [ 34 35 html fieldSet 36 class: 'grid'; 37 with: [ 38 html button 39 callback: [ self answer: setGroupLog ]; 40 with: 'Save'. 41 html button 42 class: 'secondary'; 43 callback: [ 44 setGroupLog := MFTSetGroupLog forPrescription: 45 setGroupLog prescription ]; 46 with: 'Reset' ] 47 ] 48 49 { #category : 'rendering' } 50 MFTSetGroupLogEditorComponent >> renderOn: html exercise: exercise sets: sets [ 51 52 html div: [ 53 html heading 54 level: 4; 55 with: exercise canonicalName capitalized. 56 html div 57 class: 'grid'; 58 with: [ 59 html button 60 class: 'outline'; 61 callback: [ 62 setGroupLog 63 addSet: (MFTSetLog forPrescription: sets last prescription) 64 before: sets first ]; 65 with: 'Add set'. 66 html button 67 class: 'outline secondary'; 68 callback: [ 69 | alternativeExercises selectedExercise | 70 alternativeExercises := setGroupLog prescription 71 alternativeExercisesFor: exercise. 72 selectedExercise := self call: 73 ((MFTExerciseSelectorComponent 74 forExercises: alternativeExercises) 75 selectedExercise: exercise). 76 selectedExercise ifNotNil: [ "TODO" setGroupLog ] ]; 77 with: 'Substitute exercise' ]. 78 self renderTableOn: html forSets: sets ] 79 ] 80 81 { #category : 'rendering' } 82 MFTSetGroupLogEditorComponent >> renderTableOn: html forSets: sets [ 83 84 html table: [ 85 html 86 tableHead: [ 87 html tableRow: [ 88 html 89 tableHeading; 90 tableHeading: 'Reps'; 91 tableHeading: 'Load'; 92 tableHeading: 'Failure' ] ]; 93 tableBody: [ 94 sets doWithIndex: [ :setLog :setLogIdx | 95 html tableRow: [ 96 html 97 tableData: setLogIdx; 98 tableData: [ 99 html numberInput 100 placeholder: setLog prescription repScheme; 101 callback: [ :value | 102 value ifNotEmpty: [ setLog reps: value asNumber ] ]; 103 value: setLog reps ]; 104 tableData: [ 105 html numberInput 106 callback: [ :value | 107 value ifNotEmpty: [ setLog load: value asNumber ] ]; 108 value: setLog load ]; 109 tableData: [ 110 html button 111 class: 'outline'; 112 callback: [ ]; 113 value: setLog failureAchieved ] ] ] ] ] 114 ] 115 116 { #category : 'accessing' } 117 MFTSetGroupLogEditorComponent >> setGroupLog: aMFTSetGroupLog [ 118 119 setGroupLog := aMFTSetGroupLog 120 ] 121