From 9ab55a6c831236bc2a982254fb9c1b1d8512b272 Mon Sep 17 00:00:00 2001 From: Roland Geider Date: Sat, 18 Jan 2025 16:43:29 +0100 Subject: [PATCH] Save iteration and slot entry id to the logs --- lib/models/workouts/log.dart | 11 +- lib/models/workouts/log.g.dart | 6 ++ lib/models/workouts/set_config_data.dart | 22 ++-- lib/models/workouts/set_config_data.g.dart | 16 +-- lib/providers/routines.dart | 4 +- lib/screens/gym_mode.dart | 2 +- lib/widgets/routines/gym_mode.dart | 115 +++++++++++---------- test/workout/workout_log_model_test.dart | 4 + test_data/routines.dart | 32 +++--- 9 files changed, 122 insertions(+), 90 deletions(-) diff --git a/lib/models/workouts/log.dart b/lib/models/workouts/log.dart index dd89f960..85f94ebf 100644 --- a/lib/models/workouts/log.dart +++ b/lib/models/workouts/log.dart @@ -39,6 +39,12 @@ class Log { @JsonKey(required: true, name: 'routine') late int routineId; + @JsonKey(required: true) + late int iteration; + + @JsonKey(required: true, name: 'slot_entry') + late int slotEntryId; + @JsonKey(required: false) String? rir; @@ -72,12 +78,11 @@ class Log { @JsonKey(required: true, toJson: dateToYYYYMMDD) late DateTime date; - //@JsonKey(required: true) - //String comment; - Log({ this.id, required this.exerciseId, + required this.iteration, + required this.slotEntryId, required this.routineId, required this.repetitions, this.repetitionsTarget, diff --git a/lib/models/workouts/log.g.dart b/lib/models/workouts/log.g.dart index 55527730..24d75ecf 100644 --- a/lib/models/workouts/log.g.dart +++ b/lib/models/workouts/log.g.dart @@ -13,6 +13,8 @@ Log _$LogFromJson(Map json) { 'id', 'exercise', 'routine', + 'iteration', + 'slot_entry', 'repetitions', 'repetitions_target', 'repetitions_unit', @@ -25,6 +27,8 @@ Log _$LogFromJson(Map json) { return Log( id: (json['id'] as num?)?.toInt(), exerciseId: (json['exercise'] as num).toInt(), + iteration: (json['iteration'] as num).toInt(), + slotEntryId: (json['slot_entry'] as num).toInt(), routineId: (json['routine'] as num).toInt(), repetitions: stringToNum(json['repetitions'] as String?), repetitionsTarget: stringToNum(json['repetitions_target'] as String?), @@ -42,6 +46,8 @@ Map _$LogToJson(Log instance) => { 'id': instance.id, 'exercise': instance.exerciseId, 'routine': instance.routineId, + 'iteration': instance.iteration, + 'slot_entry': instance.slotEntryId, 'rir': instance.rir, 'rir_target': instance.rirTarget, 'repetitions': instance.repetitions, diff --git a/lib/models/workouts/set_config_data.dart b/lib/models/workouts/set_config_data.dart index f096209a..70c315fc 100644 --- a/lib/models/workouts/set_config_data.dart +++ b/lib/models/workouts/set_config_data.dart @@ -63,20 +63,20 @@ class SetConfigData { @JsonKey(required: true, name: 'weight_rounding', fromJson: stringToNumNull) late num? weightRounding; - @JsonKey(required: true, fromJson: stringToNumNull) - late num? reps; + @JsonKey(required: true, fromJson: stringToNumNull, name: 'reps') + late num? repetitions; @JsonKey(required: true, name: 'max_reps', fromJson: stringToNumNull) - late num? maxReps; + late num? maxRepetitions; @JsonKey(required: true, name: 'reps_unit') - late int? repsUnitId; + late int? repetitionsUnitId; @JsonKey(includeToJson: false, includeFromJson: false) - late RepetitionUnit repsUnit; + late RepetitionUnit repetitionsUnit; @JsonKey(required: true, name: 'reps_rounding', fromJson: stringToNumNull) - late num? repsRounding; + late num? repetitionsRounding; @JsonKey(required: true) late String? rir; @@ -106,10 +106,10 @@ class SetConfigData { this.maxWeight, this.weightUnitId = WEIGHT_UNIT_KG, this.weightRounding = 1.25, - required this.reps, - this.maxReps, - this.repsUnitId = REP_UNIT_REPETITIONS_ID, - this.repsRounding = 1, + required this.repetitions, + this.maxRepetitions, + this.repetitionsUnitId = REP_UNIT_REPETITIONS_ID, + this.repetitionsRounding = 1, required this.rir, this.maxRir, required this.rpe, @@ -128,7 +128,7 @@ class SetConfigData { this.weightUnit = weightUnit; } if (repsUnit != null) { - this.repsUnit = repsUnit; + this.repetitionsUnit = repsUnit; } } diff --git a/lib/models/workouts/set_config_data.g.dart b/lib/models/workouts/set_config_data.g.dart index 962a3775..b0850730 100644 --- a/lib/models/workouts/set_config_data.g.dart +++ b/lib/models/workouts/set_config_data.g.dart @@ -44,10 +44,10 @@ SetConfigData _$SetConfigDataFromJson(Map json) { weightRounding: json['weight_rounding'] == null ? 1.25 : stringToNumNull(json['weight_rounding'] as String?), - reps: stringToNumNull(json['reps'] as String?), - maxReps: stringToNumNull(json['max_reps'] as String?), - repsUnitId: (json['reps_unit'] as num?)?.toInt() ?? REP_UNIT_REPETITIONS_ID, - repsRounding: + repetitions: stringToNumNull(json['reps'] as String?), + maxRepetitions: stringToNumNull(json['max_reps'] as String?), + repetitionsUnitId: (json['reps_unit'] as num?)?.toInt() ?? REP_UNIT_REPETITIONS_ID, + repetitionsRounding: json['reps_rounding'] == null ? 1 : stringToNumNull(json['reps_rounding'] as String?), rir: json['rir'] as String?, maxRir: json['max_rir'] as String?, @@ -70,10 +70,10 @@ Map _$SetConfigDataToJson(SetConfigData instance) => e.id == setConfig.repsUnitId, + setConfig.repetitionsUnit = _repetitionUnits.firstWhere( + (e) => e.id == setConfig.repetitionsUnitId, ); setConfig.weightUnit = _weightUnits.firstWhere( diff --git a/lib/screens/gym_mode.dart b/lib/screens/gym_mode.dart index b2ab02bc..57e03fbf 100644 --- a/lib/screens/gym_mode.dart +++ b/lib/screens/gym_mode.dart @@ -49,7 +49,7 @@ class GymModeScreen extends StatelessWidget { return Scaffold( body: SafeArea( child: Consumer( - builder: (context, value, child) => GymMode(dayDataGym, dayDataDisplay), + builder: (context, value, child) => GymMode(dayDataGym, dayDataDisplay, args.iteration), ), ), ); diff --git a/lib/widgets/routines/gym_mode.dart b/lib/widgets/routines/gym_mode.dart index b45729b6..ecdbc8eb 100644 --- a/lib/widgets/routines/gym_mode.dart +++ b/lib/widgets/routines/gym_mode.dart @@ -51,9 +51,10 @@ import 'package:wger/widgets/routines/forms/weight_unit.dart'; class GymMode extends ConsumerStatefulWidget { final DayData _dayDataGym; final DayData _dayDataDisplay; + final int _iteration; late final TimeOfDay _start; - GymMode(this._dayDataGym, this._dayDataDisplay) { + GymMode(this._dayDataGym, this._dayDataDisplay, this._iteration) { _start = TimeOfDay.now(); } @@ -139,6 +140,7 @@ class _GymModeState extends ConsumerState { workoutProvider.findById(widget._dayDataGym.day!.routineId), ratioCompleted, state.exercisePages, + widget._iteration, )); out.add(TimerWidget(_controller, ratioCompleted, state.exercisePages)); firstPage = false; @@ -235,6 +237,7 @@ class LogPage extends StatefulWidget { final double _ratioCompleted; final Map _exercisePages; final Log _log = Log.empty(); + final int _iteration; LogPage( this._controller, @@ -244,13 +247,19 @@ class LogPage extends StatefulWidget { this._workoutPlan, this._ratioCompleted, this._exercisePages, + this._iteration, ) { _log.date = DateTime.now(); _log.routineId = _workoutPlan.id!; _log.exerciseBase = _exercise; _log.weightUnit = _configData.weightUnit; - _log.repetitionUnit = _configData.repsUnit; + _log.weightTarget = _configData.weight; + _log.repetitionUnit = _configData.repetitionsUnit; + _log.repetitionsTarget = _configData.repetitions; _log.rir = _configData.rir; + _log.rirTarget = _configData.rir; + _log.iteration = _iteration; + _log.slotEntryId = _configData.slotEntryId; } @override @@ -273,8 +282,8 @@ class _LogPageState extends State { focusNode = FocusNode(); - if (widget._configData.reps != null) { - _repsController.text = widget._configData.reps!.toString(); + if (widget._configData.repetitions != null) { + _repsController.text = widget._configData.repetitions!.toString(); } if (widget._configData.weight != null) { @@ -432,10 +441,11 @@ class _LogPageState extends State { Flexible(child: getRepsWidget()), const SizedBox(width: 8), Flexible( - child: RepetitionUnitInputWidget( - widget._log.repetitionsUnitId, - onChanged: (v) => {}, - )), + child: RepetitionUnitInputWidget( + widget._log.repetitionsUnitId, + onChanged: (v) => {}, + ), + ), ], ), if (_detailed) @@ -445,7 +455,8 @@ class _LogPageState extends State { Flexible(child: getWeightWidget()), const SizedBox(width: 8), Flexible( - child: WeightUnitInputWidget(widget._log.weightUnitId, onChanged: (v) => {})), + child: WeightUnitInputWidget(widget._log.weightUnitId, onChanged: (v) => {}), + ), ], ), if (_detailed) @@ -463,52 +474,52 @@ class _LogPageState extends State { }, ), ElevatedButton( - onPressed: _isSaving - ? null - : () async { - // Validate and save the current values to the weightEntry - final isValid = _form.currentState!.validate(); - if (!isValid) { - return; - } - _isSaving = true; - _form.currentState!.save(); + onPressed: _isSaving + ? null + : () async { + // Validate and save the current values to the weightEntry + final isValid = _form.currentState!.validate(); + if (!isValid) { + return; + } + _isSaving = true; + _form.currentState!.save(); - // Save the entry on the server - try { - await provider.Provider.of( - context, - listen: false, - ).addLog(widget._log); - ScaffoldMessenger.of(context).showSnackBar( - SnackBar( - duration: const Duration(seconds: 2), // default is 4 - content: Text( - AppLocalizations.of(context).successfullySaved, - textAlign: TextAlign.center, - ), + // Save the entry on the server + try { + await provider.Provider.of( + context, + listen: false, + ).addLog(widget._log); + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + duration: const Duration(seconds: 2), // default is 4 + content: Text( + AppLocalizations.of(context).successfullySaved, + textAlign: TextAlign.center, ), - ); - widget._controller.nextPage( - duration: DEFAULT_ANIMATION_DURATION, - curve: DEFAULT_ANIMATION_CURVE, - ); - _isSaving = false; - } on WgerHttpException catch (error) { - if (mounted) { - showHttpExceptionErrorDialog(error, context); - } - _isSaving = false; - } catch (error) { - if (mounted) { - showErrorDialog(error, context); - } - _isSaving = false; + ), + ); + widget._controller.nextPage( + duration: DEFAULT_ANIMATION_DURATION, + curve: DEFAULT_ANIMATION_CURVE, + ); + _isSaving = false; + } on WgerHttpException catch (error) { + if (mounted) { + showHttpExceptionErrorDialog(error, context); } - }, - child: _isSaving - ? const FormProgressIndicator() - : Text(AppLocalizations.of(context).save)), + _isSaving = false; + } catch (error) { + if (mounted) { + showErrorDialog(error, context); + } + _isSaving = false; + } + }, + child: + _isSaving ? const FormProgressIndicator() : Text(AppLocalizations.of(context).save), + ), ], ), ); diff --git a/test/workout/workout_log_model_test.dart b/test/workout/workout_log_model_test.dart index 18a23240..9bfdfe93 100644 --- a/test/workout/workout_log_model_test.dart +++ b/test/workout/workout_log_model_test.dart @@ -27,6 +27,8 @@ void main() { setUp(() { log1 = Log( id: 123, + iteration: 1, + slotEntryId: 100, routineId: 100, exerciseId: 1, repetitions: 10, @@ -38,6 +40,8 @@ void main() { ); log2 = Log( id: 9, + iteration: 2, + slotEntryId: 42, routineId: 42, exerciseId: 1, repetitions: 10, diff --git a/test_data/routines.dart b/test_data/routines.dart index 15d9670e..38d5b680 100644 --- a/test_data/routines.dart +++ b/test_data/routines.dart @@ -44,6 +44,8 @@ Routine getTestRoutine({List? exercises}) { final log1 = Log.empty() ..id = 1 + ..iteration = 2 + ..slotEntryId = 3 ..weight = 10 ..rir = '1.5' ..date = DateTime(2021, 5, 1) @@ -55,6 +57,8 @@ Routine getTestRoutine({List? exercises}) { final log2 = Log.empty() ..id = 2 + ..iteration = 4 + ..slotEntryId = 1 ..weight = 10 ..rir = '2' ..date = DateTime(2021, 5, 1) @@ -66,6 +70,8 @@ Routine getTestRoutine({List? exercises}) { final log3 = Log.empty() ..id = 3 + ..iteration = 5 + ..slotEntryId = 1 ..weight = 50 ..rir = '' ..date = DateTime(2021, 5, 2) @@ -209,7 +215,7 @@ Routine getTestRoutine({List? exercises}) { exercise: testExercises[0], slotEntryId: 1, nrOfSets: 4, - reps: 3, + repetitions: 3, repsUnit: testRepetitionUnit1, weight: 100, weightUnit: testWeightUnit1, @@ -230,7 +236,7 @@ Routine getTestRoutine({List? exercises}) { exercise: testExercises[5], slotEntryId: 1, nrOfSets: 4, - reps: 12, + repetitions: 12, repsUnit: testRepetitionUnit1, weight: 10, weightUnit: testWeightUnit1, @@ -259,7 +265,7 @@ Routine getTestRoutine({List? exercises}) { exercise: testExercises[4], slotEntryId: 1, nrOfSets: 4, - reps: 3, + repetitions: 3, repsUnit: testRepetitionUnit1, weight: 100, weightUnit: testWeightUnit1, @@ -315,7 +321,7 @@ Routine getTestRoutine({List? exercises}) { exercise: testExercises[4], slotEntryId: 1, nrOfSets: 5, - reps: 8, + repetitions: 8, repsUnit: testRepetitionUnit1, weight: 105, weightUnit: testWeightUnit1, @@ -346,7 +352,7 @@ Routine getTestRoutine({List? exercises}) { exercise: testExercises[0], slotEntryId: 1, nrOfSets: 1, - reps: 3, + repetitions: 3, repsUnit: testRepetitionUnit1, weight: 100, weightUnit: testWeightUnit1, @@ -360,7 +366,7 @@ Routine getTestRoutine({List? exercises}) { exercise: testExercises[0], slotEntryId: 1, nrOfSets: 1, - reps: 3, + repetitions: 3, repsUnit: testRepetitionUnit1, weight: 100, weightUnit: testWeightUnit1, @@ -374,7 +380,7 @@ Routine getTestRoutine({List? exercises}) { exercise: testExercises[0], slotEntryId: 1, nrOfSets: 1, - reps: 3, + repetitions: 3, repsUnit: testRepetitionUnit1, weight: 100, weightUnit: testWeightUnit1, @@ -395,7 +401,7 @@ Routine getTestRoutine({List? exercises}) { exercise: testExercises[5], slotEntryId: 1, nrOfSets: 1, - reps: 12, + repetitions: 12, repsUnit: testRepetitionUnit1, weight: 10, weightUnit: testWeightUnit1, @@ -409,7 +415,7 @@ Routine getTestRoutine({List? exercises}) { exercise: testExercises[5], slotEntryId: 1, nrOfSets: 1, - reps: 12, + repetitions: 12, repsUnit: testRepetitionUnit1, weight: 10, weightUnit: testWeightUnit1, @@ -423,7 +429,7 @@ Routine getTestRoutine({List? exercises}) { exercise: testExercises[5], slotEntryId: 1, nrOfSets: 1, - reps: 12, + repetitions: 12, repsUnit: testRepetitionUnit1, weight: 10, weightUnit: testWeightUnit1, @@ -452,7 +458,7 @@ Routine getTestRoutine({List? exercises}) { exercise: testExercises[4], slotEntryId: 1, nrOfSets: 1, - reps: 3, + repetitions: 3, repsUnit: testRepetitionUnit1, weight: 100, weightUnit: testWeightUnit1, @@ -466,7 +472,7 @@ Routine getTestRoutine({List? exercises}) { exercise: testExercises[4], slotEntryId: 1, nrOfSets: 1, - reps: 3, + repetitions: 3, repsUnit: testRepetitionUnit1, weight: 100, weightUnit: testWeightUnit1, @@ -480,7 +486,7 @@ Routine getTestRoutine({List? exercises}) { exercise: testExercises[4], slotEntryId: 1, nrOfSets: 1, - reps: 3, + repetitions: 3, repsUnit: testRepetitionUnit1, weight: 100, weightUnit: testWeightUnit1,