Skip to content

Commit c551b17

Browse files
authored
Merge pull request #950 from wger-project/feature/day-type
Set day and set types
2 parents bc6a5eb + b0d1bce commit c551b17

File tree

52 files changed

+2934
-4677
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+2934
-4677
lines changed

.github/actions/flutter-common/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ runs:
99
uses: subosito/flutter-action@v2
1010
with:
1111
channel: stable
12-
flutter-version: 3.35.2
12+
flutter-version: 3.35.5
1313
cache: true
1414

1515
- name: Install Flutter dependencies

lib/l10n/app_en.arb

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,25 @@
156156
"description": "Category for an exercise, ingredient, etc."
157157
},
158158
"startDate": "Start date",
159+
"@startDate": {
160+
"description": "The start date of a nutritional plan or routine"
161+
},
162+
"dayTypeCustom": "Custom",
163+
"dayTypeEnom": "Every minute on the minute",
164+
"dayTypeAmrap": "As many rounds as possible",
165+
"dayTypeHiit": "High intensity interval training",
166+
"dayTypeTabata": "Tabata",
167+
"dayTypeEdt": "Escalating density training",
168+
"dayTypeRft": "Rounds for time",
169+
"dayTypeAfap": "As fast as possible",
170+
"slotEntryTypeNormal": "Normal",
171+
"slotEntryTypeDropset": "Dropset",
172+
"slotEntryTypeMyo": "Myo",
173+
"slotEntryTypePartial": "Partial",
174+
"slotEntryTypeForced": "Forced",
175+
"slotEntryTypeTut": "Time under Tension",
176+
"slotEntryTypeIso": "Isometric hold",
177+
"slotEntryTypeJump": "Jump",
159178
"routines": "Routines",
160179
"newRoutine": "New routine",
161180
"noRoutines": "You have no routines",
@@ -386,13 +405,9 @@
386405
"@date": {
387406
"description": "The date of a workout log or body weight entry"
388407
},
389-
"creationDate": "Start date",
390-
"@creationDate": {
391-
"description": "The Start date of a nutritional plan"
392-
},
393408
"endDate": "End date",
394409
"@endDate": {
395-
"description": "The End date of a nutritional plan"
410+
"description": "The End date of a nutritional plan or routine"
396411
},
397412
"openEnded": "Open ended",
398413
"@openEnded": {

lib/models/workouts/day.dart

Lines changed: 62 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,36 @@
1717
*/
1818

1919
import 'package:json_annotation/json_annotation.dart';
20+
import 'package:wger/l10n/generated/app_localizations.dart';
2021
import 'package:wger/models/workouts/slot.dart';
2122

2223
part 'day.g.dart';
2324

25+
enum DayType { custom, enom, amrap, hiit, tabata, edt, rft, afap }
26+
27+
extension DayTypeExtension on DayType {
28+
String i18Label(AppLocalizations i18n) {
29+
switch (this) {
30+
case DayType.custom:
31+
return i18n.dayTypeCustom;
32+
case DayType.enom:
33+
return i18n.dayTypeEnom;
34+
case DayType.amrap:
35+
return i18n.dayTypeAmrap;
36+
case DayType.hiit:
37+
return i18n.dayTypeHiit;
38+
case DayType.tabata:
39+
return i18n.dayTypeTabata;
40+
case DayType.edt:
41+
return i18n.dayTypeEdt;
42+
case DayType.rft:
43+
return i18n.dayTypeRft;
44+
case DayType.afap:
45+
return i18n.dayTypeAfap;
46+
}
47+
}
48+
}
49+
2450
@JsonSerializable()
2551
class Day {
2652
static const MIN_LENGTH_NAME = 3;
@@ -39,48 +65,67 @@ class Day {
3965
@JsonKey(required: true)
4066
late String description;
4167

68+
@JsonKey(required: true)
69+
late DayType type;
70+
4271
@JsonKey(required: true, name: 'is_rest')
4372
late bool isRest;
4473

4574
@JsonKey(required: true, name: 'need_logs_to_advance')
4675
late bool needLogsToAdvance;
4776

48-
@JsonKey(required: true)
49-
late String type;
50-
5177
@JsonKey(required: true)
5278
late num order;
5379

5480
@JsonKey(required: true)
5581
late Object? config;
5682

57-
@JsonKey(required: false, defaultValue: [], includeFromJson: true, includeToJson: false)
83+
@JsonKey(required: false, includeFromJson: true, includeToJson: false)
5884
List<Slot> slots = [];
5985

6086
Day({
6187
this.id,
6288
required this.routineId,
6389
required this.name,
64-
required this.description,
90+
this.description = '',
6591
this.isRest = false,
6692
this.needLogsToAdvance = false,
67-
this.type = 'custom',
68-
this.order = 0,
69-
this.config = null,
93+
this.type = DayType.custom,
94+
this.order = 1,
95+
this.config,
7096
this.slots = const [],
7197
});
7298

73-
Day.empty() {
74-
name = 'new day';
75-
description = '';
76-
type = 'custom';
77-
isRest = false;
78-
needLogsToAdvance = false;
79-
order = 0;
80-
config = {};
81-
slots = [];
99+
Day copyWith({
100+
int? id,
101+
int? routineId,
102+
String? name,
103+
String? description,
104+
DayType? type,
105+
bool? isRest,
106+
bool? needLogsToAdvance,
107+
num? order,
108+
Object? config,
109+
List<Slot>? slots,
110+
}) {
111+
return Day(
112+
id: id ?? this.id,
113+
routineId: routineId ?? this.routineId,
114+
name: name ?? this.name,
115+
description: description ?? this.description,
116+
type: type ?? this.type,
117+
isRest: isRest ?? this.isRest,
118+
needLogsToAdvance: needLogsToAdvance ?? this.needLogsToAdvance,
119+
order: order ?? this.order,
120+
config: config ?? this.config,
121+
slots: slots ?? this.slots,
122+
);
82123
}
83124

125+
bool get isSpecialType => type != DayType.custom;
126+
127+
String get nameWithType => isSpecialType ? '${type.name.toUpperCase()} - $name' : name;
128+
84129
// Boilerplate
85130
factory Day.fromJson(Map<String, dynamic> json) => _$DayFromJson(json);
86131

lib/models/workouts/day.g.dart

Lines changed: 18 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/models/workouts/set_config_data.dart

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import 'package:wger/helpers/consts.dart';
2121
import 'package:wger/helpers/json.dart';
2222
import 'package:wger/models/exercises/exercise.dart';
2323
import 'package:wger/models/workouts/repetition_unit.dart';
24+
import 'package:wger/models/workouts/slot_entry.dart';
2425
import 'package:wger/models/workouts/weight_unit.dart';
2526

2627
part 'set_config_data.g.dart';
@@ -37,11 +38,13 @@ class SetConfigData {
3738
late int slotEntryId;
3839

3940
@JsonKey(required: true)
40-
late String type;
41+
late SlotEntryType type;
4142

4243
@JsonKey(required: true, name: 'text_repr')
4344
late String textRepr;
4445

46+
String get textReprWithType => '$textRepr${type.typeLabel}';
47+
4548
@JsonKey(required: true, name: 'sets')
4649
late num? nrOfSets;
4750

@@ -99,17 +102,17 @@ class SetConfigData {
99102
SetConfigData({
100103
required this.exerciseId,
101104
required this.slotEntryId,
102-
this.type = 'normal',
105+
this.type = SlotEntryType.normal,
103106
required this.nrOfSets,
104107
this.maxNrOfSets,
105108
required this.weight,
106109
this.maxWeight,
107110
this.weightUnitId = WEIGHT_UNIT_KG,
108-
this.weightRounding = null,
111+
this.weightRounding,
109112
required this.repetitions,
110113
this.maxRepetitions,
111114
this.repetitionsUnitId = REP_UNIT_REPETITIONS_ID,
112-
this.repetitionsRounding = null,
115+
this.repetitionsRounding,
113116
required this.rir,
114117
this.maxRir,
115118
required this.rpe,

lib/models/workouts/set_config_data.g.dart

Lines changed: 17 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/models/workouts/slot_data.g.dart

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)