mirror of
https://github.com/wger-project/flutter.git
synced 2026-12-06 15:54:31 +01:00
Merge PR #1248 (cross-midnight session split fix) for 2.7 integration testing
# Conflicts: # lib/core/network/auth_notifier.g.dart # lib/features/routines/providers/workout_logs_repository.dart # test/features/routines/providers/workout_logs_repository_test.dart
This commit is contained in:
commit
dd2e37828d
31 files changed
+599
-236
No files matched your search
@@ -107,11 +107,12 @@ class _DashboardCalendarWidgetState extends riverpod.ConsumerState<DashboardCale
|
||||
}
|
||||
|
||||
for (final session in sessions) {
|
||||
final date = DateFormatLists.format(session.date);
|
||||
final date = DateFormatLists.format(session.localDay);
|
||||
events.putIfAbsent(date, () => []);
|
||||
var time = '';
|
||||
if (session.timeStart != null && session.timeEnd != null) {
|
||||
time = '(${timeToString(session.timeStart)} - ${timeToString(session.timeEnd)})';
|
||||
if (session.datetimeEnd != null) {
|
||||
time =
|
||||
'(${timeToString(TimeOfDay.fromDateTime(session.datetimeStart))} - ${timeToString(TimeOfDay.fromDateTime(session.datetimeEnd!))})';
|
||||
}
|
||||
events[date]!.add(
|
||||
Event(
|
||||
|
||||
@@ -42,3 +42,18 @@ class DateOnlyTextConverter extends TypeConverter<DateTime, String> {
|
||||
'${value.month.toString().padLeft(2, '0')}-'
|
||||
'${value.day.toString().padLeft(2, '0')}';
|
||||
}
|
||||
|
||||
/// Stores a moment as UTC ISO8601, the same wire format the server speaks.
|
||||
///
|
||||
/// Keeping every row in UTC with an identical layout means a plain string
|
||||
/// comparison on the column is also a comparison in time, which the session
|
||||
/// lookup in the log repository relies on.
|
||||
class DateTimeTextConverter extends TypeConverter<DateTime, String> {
|
||||
const DateTimeTextConverter();
|
||||
|
||||
@override
|
||||
DateTime fromSql(String fromDb) => DateTime.parse(fromDb).toLocal();
|
||||
|
||||
@override
|
||||
String toSql(DateTime value) => value.toUtc().toIso8601String();
|
||||
}
|
||||
@@ -6273,14 +6273,6 @@ class $WorkoutSessionTableTable extends WorkoutSessionTable
|
||||
type: DriftSqlType.int,
|
||||
requiredDuringInsert: false,
|
||||
);
|
||||
@override
|
||||
late final GeneratedColumnWithTypeConverter<DateTime, String> date = GeneratedColumn<String>(
|
||||
'date',
|
||||
aliasedName,
|
||||
false,
|
||||
type: DriftSqlType.string,
|
||||
requiredDuringInsert: true,
|
||||
).withConverter<DateTime>($WorkoutSessionTableTable.$converterdate);
|
||||
static const VerificationMeta _notesMeta = const VerificationMeta('notes');
|
||||
@override
|
||||
late final GeneratedColumn<String> notes = GeneratedColumn<String>(
|
||||
@@ -6302,6 +6294,36 @@ class $WorkoutSessionTableTable extends WorkoutSessionTable
|
||||
$WorkoutSessionTableTable.$converterimpression,
|
||||
);
|
||||
@override
|
||||
late final GeneratedColumnWithTypeConverter<DateTime?, String> datetimeStart =
|
||||
GeneratedColumn<String>(
|
||||
'datetime_start',
|
||||
aliasedName,
|
||||
true,
|
||||
type: DriftSqlType.string,
|
||||
requiredDuringInsert: false,
|
||||
).withConverter<DateTime?>(
|
||||
$WorkoutSessionTableTable.$converterdatetimeStartn,
|
||||
);
|
||||
@override
|
||||
late final GeneratedColumnWithTypeConverter<DateTime?, String> datetimeEnd =
|
||||
GeneratedColumn<String>(
|
||||
'datetime_end',
|
||||
aliasedName,
|
||||
true,
|
||||
type: DriftSqlType.string,
|
||||
requiredDuringInsert: false,
|
||||
).withConverter<DateTime?>(
|
||||
$WorkoutSessionTableTable.$converterdatetimeEndn,
|
||||
);
|
||||
@override
|
||||
late final GeneratedColumnWithTypeConverter<DateTime?, String> date = GeneratedColumn<String>(
|
||||
'date',
|
||||
aliasedName,
|
||||
true,
|
||||
type: DriftSqlType.string,
|
||||
requiredDuringInsert: false,
|
||||
).withConverter<DateTime?>($WorkoutSessionTableTable.$converterdaten);
|
||||
@override
|
||||
late final GeneratedColumnWithTypeConverter<TimeOfDay?, String> timeStart =
|
||||
GeneratedColumn<String>(
|
||||
'time_start',
|
||||
@@ -6325,9 +6347,11 @@ class $WorkoutSessionTableTable extends WorkoutSessionTable
|
||||
id,
|
||||
routineId,
|
||||
dayId,
|
||||
date,
|
||||
notes,
|
||||
impression,
|
||||
datetimeStart,
|
||||
datetimeEnd,
|
||||
date,
|
||||
timeStart,
|
||||
timeEnd,
|
||||
];
|
||||
@@ -6372,24 +6396,22 @@ class $WorkoutSessionTableTable extends WorkoutSessionTable
|
||||
@override
|
||||
WorkoutSession map(Map<String, dynamic> data, {String? tablePrefix}) {
|
||||
final effectivePrefix = tablePrefix != null ? '$tablePrefix.' : '';
|
||||
return WorkoutSession(
|
||||
return WorkoutSession.fromDb(
|
||||
id: attachedDatabase.typeMapping.read(
|
||||
DriftSqlType.string,
|
||||
data['${effectivePrefix}id'],
|
||||
)!,
|
||||
dayId: attachedDatabase.typeMapping.read(
|
||||
DriftSqlType.int,
|
||||
data['${effectivePrefix}day_id'],
|
||||
),
|
||||
routineId: attachedDatabase.typeMapping.read(
|
||||
DriftSqlType.int,
|
||||
data['${effectivePrefix}routine_id'],
|
||||
),
|
||||
date: $WorkoutSessionTableTable.$converterdate.fromSql(
|
||||
attachedDatabase.typeMapping.read(
|
||||
DriftSqlType.string,
|
||||
data['${effectivePrefix}date'],
|
||||
)!,
|
||||
dayId: attachedDatabase.typeMapping.read(
|
||||
DriftSqlType.int,
|
||||
data['${effectivePrefix}day_id'],
|
||||
),
|
||||
notes: attachedDatabase.typeMapping.read(
|
||||
DriftSqlType.string,
|
||||
data['${effectivePrefix}notes'],
|
||||
),
|
||||
impression: $WorkoutSessionTableTable.$converterimpression.fromSql(
|
||||
attachedDatabase.typeMapping.read(
|
||||
@@ -6397,9 +6419,23 @@ class $WorkoutSessionTableTable extends WorkoutSessionTable
|
||||
data['${effectivePrefix}impression'],
|
||||
)!,
|
||||
),
|
||||
notes: attachedDatabase.typeMapping.read(
|
||||
DriftSqlType.string,
|
||||
data['${effectivePrefix}notes'],
|
||||
datetimeStart: $WorkoutSessionTableTable.$converterdatetimeStartn.fromSql(
|
||||
attachedDatabase.typeMapping.read(
|
||||
DriftSqlType.string,
|
||||
data['${effectivePrefix}datetime_start'],
|
||||
),
|
||||
),
|
||||
datetimeEnd: $WorkoutSessionTableTable.$converterdatetimeEndn.fromSql(
|
||||
attachedDatabase.typeMapping.read(
|
||||
DriftSqlType.string,
|
||||
data['${effectivePrefix}datetime_end'],
|
||||
),
|
||||
),
|
||||
date: $WorkoutSessionTableTable.$converterdaten.fromSql(
|
||||
attachedDatabase.typeMapping.read(
|
||||
DriftSqlType.string,
|
||||
data['${effectivePrefix}date'],
|
||||
),
|
||||
),
|
||||
timeStart: $WorkoutSessionTableTable.$convertertimeStartn.fromSql(
|
||||
attachedDatabase.typeMapping.read(
|
||||
@@ -6421,9 +6457,20 @@ class $WorkoutSessionTableTable extends WorkoutSessionTable
|
||||
return $WorkoutSessionTableTable(attachedDatabase, alias);
|
||||
}
|
||||
|
||||
static TypeConverter<DateTime, String> $converterdate = const DateOnlyTextConverter();
|
||||
static TypeConverter<WorkoutImpression, String> $converterimpression =
|
||||
const WorkoutImpressionConverter();
|
||||
static TypeConverter<DateTime, String> $converterdatetimeStart = const DateTimeTextConverter();
|
||||
static TypeConverter<DateTime?, String?> $converterdatetimeStartn = NullAwareTypeConverter.wrap(
|
||||
$converterdatetimeStart,
|
||||
);
|
||||
static TypeConverter<DateTime, String> $converterdatetimeEnd = const DateTimeTextConverter();
|
||||
static TypeConverter<DateTime?, String?> $converterdatetimeEndn = NullAwareTypeConverter.wrap(
|
||||
$converterdatetimeEnd,
|
||||
);
|
||||
static TypeConverter<DateTime, String> $converterdate = const DateOnlyTextConverter();
|
||||
static TypeConverter<DateTime?, String?> $converterdaten = NullAwareTypeConverter.wrap(
|
||||
$converterdate,
|
||||
);
|
||||
static TypeConverter<TimeOfDay, String> $convertertimeStart = const TimeOfDayConverter();
|
||||
static TypeConverter<TimeOfDay?, String?> $convertertimeStartn = NullAwareTypeConverter.wrap(
|
||||
$convertertimeStart,
|
||||
@@ -6438,9 +6485,11 @@ class WorkoutSessionTableCompanion extends UpdateCompanion<WorkoutSession> {
|
||||
final Value<String> id;
|
||||
final Value<int?> routineId;
|
||||
final Value<int?> dayId;
|
||||
final Value<DateTime> date;
|
||||
final Value<String?> notes;
|
||||
final Value<WorkoutImpression> impression;
|
||||
final Value<DateTime?> datetimeStart;
|
||||
final Value<DateTime?> datetimeEnd;
|
||||
final Value<DateTime?> date;
|
||||
final Value<TimeOfDay?> timeStart;
|
||||
final Value<TimeOfDay?> timeEnd;
|
||||
final Value<int> rowid;
|
||||
@@ -6448,9 +6497,11 @@ class WorkoutSessionTableCompanion extends UpdateCompanion<WorkoutSession> {
|
||||
this.id = const Value.absent(),
|
||||
this.routineId = const Value.absent(),
|
||||
this.dayId = const Value.absent(),
|
||||
this.date = const Value.absent(),
|
||||
this.notes = const Value.absent(),
|
||||
this.impression = const Value.absent(),
|
||||
this.datetimeStart = const Value.absent(),
|
||||
this.datetimeEnd = const Value.absent(),
|
||||
this.date = const Value.absent(),
|
||||
this.timeStart = const Value.absent(),
|
||||
this.timeEnd = const Value.absent(),
|
||||
this.rowid = const Value.absent(),
|
||||
@@ -6459,21 +6510,24 @@ class WorkoutSessionTableCompanion extends UpdateCompanion<WorkoutSession> {
|
||||
this.id = const Value.absent(),
|
||||
this.routineId = const Value.absent(),
|
||||
this.dayId = const Value.absent(),
|
||||
required DateTime date,
|
||||
this.notes = const Value.absent(),
|
||||
required WorkoutImpression impression,
|
||||
this.datetimeStart = const Value.absent(),
|
||||
this.datetimeEnd = const Value.absent(),
|
||||
this.date = const Value.absent(),
|
||||
this.timeStart = const Value.absent(),
|
||||
this.timeEnd = const Value.absent(),
|
||||
this.rowid = const Value.absent(),
|
||||
}) : date = Value(date),
|
||||
impression = Value(impression);
|
||||
}) : impression = Value(impression);
|
||||
static Insertable<WorkoutSession> custom({
|
||||
Expression<String>? id,
|
||||
Expression<int>? routineId,
|
||||
Expression<int>? dayId,
|
||||
Expression<String>? date,
|
||||
Expression<String>? notes,
|
||||
Expression<String>? impression,
|
||||
Expression<String>? datetimeStart,
|
||||
Expression<String>? datetimeEnd,
|
||||
Expression<String>? date,
|
||||
Expression<String>? timeStart,
|
||||
Expression<String>? timeEnd,
|
||||
Expression<int>? rowid,
|
||||
@@ -6482,9 +6536,11 @@ class WorkoutSessionTableCompanion extends UpdateCompanion<WorkoutSession> {
|
||||
if (id != null) 'id': id,
|
||||
if (routineId != null) 'routine_id': routineId,
|
||||
if (dayId != null) 'day_id': dayId,
|
||||
if (date != null) 'date': date,
|
||||
if (notes != null) 'notes': notes,
|
||||
if (impression != null) 'impression': impression,
|
||||
if (datetimeStart != null) 'datetime_start': datetimeStart,
|
||||
if (datetimeEnd != null) 'datetime_end': datetimeEnd,
|
||||
if (date != null) 'date': date,
|
||||
if (timeStart != null) 'time_start': timeStart,
|
||||
if (timeEnd != null) 'time_end': timeEnd,
|
||||
if (rowid != null) 'rowid': rowid,
|
||||
@@ -6495,9 +6551,11 @@ class WorkoutSessionTableCompanion extends UpdateCompanion<WorkoutSession> {
|
||||
Value<String>? id,
|
||||
Value<int?>? routineId,
|
||||
Value<int?>? dayId,
|
||||
Value<DateTime>? date,
|
||||
Value<String?>? notes,
|
||||
Value<WorkoutImpression>? impression,
|
||||
Value<DateTime?>? datetimeStart,
|
||||
Value<DateTime?>? datetimeEnd,
|
||||
Value<DateTime?>? date,
|
||||
Value<TimeOfDay?>? timeStart,
|
||||
Value<TimeOfDay?>? timeEnd,
|
||||
Value<int>? rowid,
|
||||
@@ -6506,9 +6564,11 @@ class WorkoutSessionTableCompanion extends UpdateCompanion<WorkoutSession> {
|
||||
id: id ?? this.id,
|
||||
routineId: routineId ?? this.routineId,
|
||||
dayId: dayId ?? this.dayId,
|
||||
date: date ?? this.date,
|
||||
notes: notes ?? this.notes,
|
||||
impression: impression ?? this.impression,
|
||||
datetimeStart: datetimeStart ?? this.datetimeStart,
|
||||
datetimeEnd: datetimeEnd ?? this.datetimeEnd,
|
||||
date: date ?? this.date,
|
||||
timeStart: timeStart ?? this.timeStart,
|
||||
timeEnd: timeEnd ?? this.timeEnd,
|
||||
rowid: rowid ?? this.rowid,
|
||||
@@ -6527,11 +6587,6 @@ class WorkoutSessionTableCompanion extends UpdateCompanion<WorkoutSession> {
|
||||
if (dayId.present) {
|
||||
map['day_id'] = Variable<int>(dayId.value);
|
||||
}
|
||||
if (date.present) {
|
||||
map['date'] = Variable<String>(
|
||||
$WorkoutSessionTableTable.$converterdate.toSql(date.value),
|
||||
);
|
||||
}
|
||||
if (notes.present) {
|
||||
map['notes'] = Variable<String>(notes.value);
|
||||
}
|
||||
@@ -6540,6 +6595,25 @@ class WorkoutSessionTableCompanion extends UpdateCompanion<WorkoutSession> {
|
||||
$WorkoutSessionTableTable.$converterimpression.toSql(impression.value),
|
||||
);
|
||||
}
|
||||
if (datetimeStart.present) {
|
||||
map['datetime_start'] = Variable<String>(
|
||||
$WorkoutSessionTableTable.$converterdatetimeStartn.toSql(
|
||||
datetimeStart.value,
|
||||
),
|
||||
);
|
||||
}
|
||||
if (datetimeEnd.present) {
|
||||
map['datetime_end'] = Variable<String>(
|
||||
$WorkoutSessionTableTable.$converterdatetimeEndn.toSql(
|
||||
datetimeEnd.value,
|
||||
),
|
||||
);
|
||||
}
|
||||
if (date.present) {
|
||||
map['date'] = Variable<String>(
|
||||
$WorkoutSessionTableTable.$converterdaten.toSql(date.value),
|
||||
);
|
||||
}
|
||||
if (timeStart.present) {
|
||||
map['time_start'] = Variable<String>(
|
||||
$WorkoutSessionTableTable.$convertertimeStartn.toSql(timeStart.value),
|
||||
@@ -6562,9 +6636,11 @@ class WorkoutSessionTableCompanion extends UpdateCompanion<WorkoutSession> {
|
||||
..write('id: $id, ')
|
||||
..write('routineId: $routineId, ')
|
||||
..write('dayId: $dayId, ')
|
||||
..write('date: $date, ')
|
||||
..write('notes: $notes, ')
|
||||
..write('impression: $impression, ')
|
||||
..write('datetimeStart: $datetimeStart, ')
|
||||
..write('datetimeEnd: $datetimeEnd, ')
|
||||
..write('date: $date, ')
|
||||
..write('timeStart: $timeStart, ')
|
||||
..write('timeEnd: $timeEnd, ')
|
||||
..write('rowid: $rowid')
|
||||
@@ -17659,9 +17735,11 @@ typedef $$WorkoutSessionTableTableCreateCompanionBuilder =
|
||||
Value<String> id,
|
||||
Value<int?> routineId,
|
||||
Value<int?> dayId,
|
||||
required DateTime date,
|
||||
Value<String?> notes,
|
||||
required WorkoutImpression impression,
|
||||
Value<DateTime?> datetimeStart,
|
||||
Value<DateTime?> datetimeEnd,
|
||||
Value<DateTime?> date,
|
||||
Value<TimeOfDay?> timeStart,
|
||||
Value<TimeOfDay?> timeEnd,
|
||||
Value<int> rowid,
|
||||
@@ -17671,9 +17749,11 @@ typedef $$WorkoutSessionTableTableUpdateCompanionBuilder =
|
||||
Value<String> id,
|
||||
Value<int?> routineId,
|
||||
Value<int?> dayId,
|
||||
Value<DateTime> date,
|
||||
Value<String?> notes,
|
||||
Value<WorkoutImpression> impression,
|
||||
Value<DateTime?> datetimeStart,
|
||||
Value<DateTime?> datetimeEnd,
|
||||
Value<DateTime?> date,
|
||||
Value<TimeOfDay?> timeStart,
|
||||
Value<TimeOfDay?> timeEnd,
|
||||
Value<int> rowid,
|
||||
@@ -17703,11 +17783,6 @@ class $$WorkoutSessionTableTableFilterComposer
|
||||
builder: (column) => ColumnFilters(column),
|
||||
);
|
||||
|
||||
ColumnWithTypeConverterFilters<DateTime, DateTime, String> get date => $composableBuilder(
|
||||
column: $table.date,
|
||||
builder: (column) => ColumnWithTypeConverterFilters(column),
|
||||
);
|
||||
|
||||
ColumnFilters<String> get notes => $composableBuilder(
|
||||
column: $table.notes,
|
||||
builder: (column) => ColumnFilters(column),
|
||||
@@ -17719,6 +17794,22 @@ class $$WorkoutSessionTableTableFilterComposer
|
||||
builder: (column) => ColumnWithTypeConverterFilters(column),
|
||||
);
|
||||
|
||||
ColumnWithTypeConverterFilters<DateTime?, DateTime, String> get datetimeStart =>
|
||||
$composableBuilder(
|
||||
column: $table.datetimeStart,
|
||||
builder: (column) => ColumnWithTypeConverterFilters(column),
|
||||
);
|
||||
|
||||
ColumnWithTypeConverterFilters<DateTime?, DateTime, String> get datetimeEnd => $composableBuilder(
|
||||
column: $table.datetimeEnd,
|
||||
builder: (column) => ColumnWithTypeConverterFilters(column),
|
||||
);
|
||||
|
||||
ColumnWithTypeConverterFilters<DateTime?, DateTime, String> get date => $composableBuilder(
|
||||
column: $table.date,
|
||||
builder: (column) => ColumnWithTypeConverterFilters(column),
|
||||
);
|
||||
|
||||
ColumnWithTypeConverterFilters<TimeOfDay?, TimeOfDay, String> get timeStart => $composableBuilder(
|
||||
column: $table.timeStart,
|
||||
builder: (column) => ColumnWithTypeConverterFilters(column),
|
||||
@@ -17754,11 +17845,6 @@ class $$WorkoutSessionTableTableOrderingComposer
|
||||
builder: (column) => ColumnOrderings(column),
|
||||
);
|
||||
|
||||
ColumnOrderings<String> get date => $composableBuilder(
|
||||
column: $table.date,
|
||||
builder: (column) => ColumnOrderings(column),
|
||||
);
|
||||
|
||||
ColumnOrderings<String> get notes => $composableBuilder(
|
||||
column: $table.notes,
|
||||
builder: (column) => ColumnOrderings(column),
|
||||
@@ -17769,6 +17855,21 @@ class $$WorkoutSessionTableTableOrderingComposer
|
||||
builder: (column) => ColumnOrderings(column),
|
||||
);
|
||||
|
||||
ColumnOrderings<String> get datetimeStart => $composableBuilder(
|
||||
column: $table.datetimeStart,
|
||||
builder: (column) => ColumnOrderings(column),
|
||||
);
|
||||
|
||||
ColumnOrderings<String> get datetimeEnd => $composableBuilder(
|
||||
column: $table.datetimeEnd,
|
||||
builder: (column) => ColumnOrderings(column),
|
||||
);
|
||||
|
||||
ColumnOrderings<String> get date => $composableBuilder(
|
||||
column: $table.date,
|
||||
builder: (column) => ColumnOrderings(column),
|
||||
);
|
||||
|
||||
ColumnOrderings<String> get timeStart => $composableBuilder(
|
||||
column: $table.timeStart,
|
||||
builder: (column) => ColumnOrderings(column),
|
||||
@@ -17798,9 +17899,6 @@ class $$WorkoutSessionTableTableAnnotationComposer
|
||||
GeneratedColumn<int> get dayId =>
|
||||
$composableBuilder(column: $table.dayId, builder: (column) => column);
|
||||
|
||||
GeneratedColumnWithTypeConverter<DateTime, String> get date =>
|
||||
$composableBuilder(column: $table.date, builder: (column) => column);
|
||||
|
||||
GeneratedColumn<String> get notes =>
|
||||
$composableBuilder(column: $table.notes, builder: (column) => column);
|
||||
|
||||
@@ -17809,6 +17907,19 @@ class $$WorkoutSessionTableTableAnnotationComposer
|
||||
builder: (column) => column,
|
||||
);
|
||||
|
||||
GeneratedColumnWithTypeConverter<DateTime?, String> get datetimeStart => $composableBuilder(
|
||||
column: $table.datetimeStart,
|
||||
builder: (column) => column,
|
||||
);
|
||||
|
||||
GeneratedColumnWithTypeConverter<DateTime?, String> get datetimeEnd => $composableBuilder(
|
||||
column: $table.datetimeEnd,
|
||||
builder: (column) => column,
|
||||
);
|
||||
|
||||
GeneratedColumnWithTypeConverter<DateTime?, String> get date =>
|
||||
$composableBuilder(column: $table.date, builder: (column) => column);
|
||||
|
||||
GeneratedColumnWithTypeConverter<TimeOfDay?, String> get timeStart =>
|
||||
$composableBuilder(column: $table.timeStart, builder: (column) => column);
|
||||
|
||||
@@ -17856,9 +17967,11 @@ class $$WorkoutSessionTableTableTableManager
|
||||
Value<String> id = const Value.absent(),
|
||||
Value<int?> routineId = const Value.absent(),
|
||||
Value<int?> dayId = const Value.absent(),
|
||||
Value<DateTime> date = const Value.absent(),
|
||||
Value<String?> notes = const Value.absent(),
|
||||
Value<WorkoutImpression> impression = const Value.absent(),
|
||||
Value<DateTime?> datetimeStart = const Value.absent(),
|
||||
Value<DateTime?> datetimeEnd = const Value.absent(),
|
||||
Value<DateTime?> date = const Value.absent(),
|
||||
Value<TimeOfDay?> timeStart = const Value.absent(),
|
||||
Value<TimeOfDay?> timeEnd = const Value.absent(),
|
||||
Value<int> rowid = const Value.absent(),
|
||||
@@ -17866,9 +17979,11 @@ class $$WorkoutSessionTableTableTableManager
|
||||
id: id,
|
||||
routineId: routineId,
|
||||
dayId: dayId,
|
||||
date: date,
|
||||
notes: notes,
|
||||
impression: impression,
|
||||
datetimeStart: datetimeStart,
|
||||
datetimeEnd: datetimeEnd,
|
||||
date: date,
|
||||
timeStart: timeStart,
|
||||
timeEnd: timeEnd,
|
||||
rowid: rowid,
|
||||
@@ -17878,9 +17993,11 @@ class $$WorkoutSessionTableTableTableManager
|
||||
Value<String> id = const Value.absent(),
|
||||
Value<int?> routineId = const Value.absent(),
|
||||
Value<int?> dayId = const Value.absent(),
|
||||
required DateTime date,
|
||||
Value<String?> notes = const Value.absent(),
|
||||
required WorkoutImpression impression,
|
||||
Value<DateTime?> datetimeStart = const Value.absent(),
|
||||
Value<DateTime?> datetimeEnd = const Value.absent(),
|
||||
Value<DateTime?> date = const Value.absent(),
|
||||
Value<TimeOfDay?> timeStart = const Value.absent(),
|
||||
Value<TimeOfDay?> timeEnd = const Value.absent(),
|
||||
Value<int> rowid = const Value.absent(),
|
||||
@@ -17888,9 +18005,11 @@ class $$WorkoutSessionTableTableTableManager
|
||||
id: id,
|
||||
routineId: routineId,
|
||||
dayId: dayId,
|
||||
date: date,
|
||||
notes: notes,
|
||||
impression: impression,
|
||||
datetimeStart: datetimeStart,
|
||||
datetimeEnd: datetimeEnd,
|
||||
date: date,
|
||||
timeStart: timeStart,
|
||||
timeEnd: timeEnd,
|
||||
rowid: rowid,
|
||||
|
||||
@@ -112,7 +112,7 @@ const PowersyncWorkoutLogTable = ps.Table(
|
||||
],
|
||||
);
|
||||
|
||||
@UseRowClass(WorkoutSession)
|
||||
@UseRowClass(WorkoutSession, constructor: 'fromDb')
|
||||
class WorkoutSessionTable extends Table {
|
||||
@override
|
||||
String get tableName => 'manager_workoutsession';
|
||||
@@ -120,9 +120,20 @@ class WorkoutSessionTable extends Table {
|
||||
TextColumn get id => text().clientDefault(() => ps.uuid.v7())();
|
||||
IntColumn get routineId => integer().named('routine_id').nullable()();
|
||||
IntColumn get dayId => integer().named('day_id').nullable()();
|
||||
TextColumn get date => text().map(const DateOnlyTextConverter())();
|
||||
TextColumn get notes => text().nullable()();
|
||||
TextColumn get impression => text().map(const WorkoutImpressionConverter())();
|
||||
|
||||
// Nullable, and permanently so: rows that were replicated before 2.7 have no
|
||||
// such key in the stored JSON and read as NULL for as long as that local
|
||||
// database lives. WorkoutSession.fromDb rebuilds them from the columns below.
|
||||
TextColumn get datetimeStart =>
|
||||
text().named('datetime_start').nullable().map(const DateTimeTextConverter())();
|
||||
TextColumn get datetimeEnd =>
|
||||
text().named('datetime_end').nullable().map(const DateTimeTextConverter())();
|
||||
|
||||
// Pre-2.7 shape, only ever read. Remove once MIN_APP_VERSION has passed the
|
||||
// versions that wrote them.
|
||||
TextColumn get date => text().nullable().map(const DateOnlyTextConverter())();
|
||||
TextColumn get timeStart =>
|
||||
text().named('time_start').nullable().map(const TimeOfDayConverter())();
|
||||
TextColumn get timeEnd => text().named('time_end').nullable().map(const TimeOfDayConverter())();
|
||||
@@ -133,9 +144,11 @@ const PowersyncWorkoutSessionTable = ps.Table(
|
||||
[
|
||||
ps.Column.integer('routine_id'),
|
||||
ps.Column.integer('day_id'),
|
||||
ps.Column.text('date'),
|
||||
ps.Column.text('notes'),
|
||||
ps.Column.text('impression'),
|
||||
ps.Column.text('datetime_start'),
|
||||
ps.Column.text('datetime_end'),
|
||||
ps.Column.text('date'),
|
||||
ps.Column.text('time_start'),
|
||||
ps.Column.text('time_end'),
|
||||
],
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import 'package:clock/clock.dart';
|
||||
import 'package:drift/drift.dart' as drift;
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
@@ -56,6 +57,9 @@ extension WorkoutImpressionL10n on WorkoutImpression {
|
||||
}
|
||||
}
|
||||
|
||||
/// How long after its start an ongoing session still picks up new logs
|
||||
const sessionMaxDuration = Duration(hours: 5);
|
||||
|
||||
@freezed
|
||||
class WorkoutSession with _$WorkoutSession {
|
||||
/// Inclusive upper bound for [notes]
|
||||
@@ -69,15 +73,13 @@ class WorkoutSession with _$WorkoutSession {
|
||||
@override
|
||||
final int? dayId;
|
||||
@override
|
||||
final DateTime date;
|
||||
@override
|
||||
final WorkoutImpression impression;
|
||||
@override
|
||||
final String? notes;
|
||||
@override
|
||||
final TimeOfDay? timeStart;
|
||||
final DateTime datetimeStart;
|
||||
@override
|
||||
final TimeOfDay? timeEnd;
|
||||
final DateTime? datetimeEnd;
|
||||
@override
|
||||
final List<Log> logs;
|
||||
|
||||
@@ -85,42 +87,86 @@ class WorkoutSession with _$WorkoutSession {
|
||||
this.id,
|
||||
this.dayId,
|
||||
required this.routineId,
|
||||
required this.date,
|
||||
required this.datetimeStart,
|
||||
this.datetimeEnd,
|
||||
this.impression = WorkoutImpression.neutral,
|
||||
this.notes = '',
|
||||
this.timeStart,
|
||||
this.timeEnd,
|
||||
this.logs = const [],
|
||||
});
|
||||
|
||||
/// Builds the model from a database row.
|
||||
///
|
||||
/// Rows that were replicated before 2.7 have no `datetime_start` in their
|
||||
/// stored JSON and read as NULL, for as long as that local database lives.
|
||||
/// They are rebuilt from the pre-2.7 date and time columns. Application code
|
||||
/// uses the default constructor.
|
||||
factory WorkoutSession.fromDb({
|
||||
String? id,
|
||||
int? routineId,
|
||||
int? dayId,
|
||||
String? notes,
|
||||
WorkoutImpression impression = WorkoutImpression.neutral,
|
||||
DateTime? datetimeStart,
|
||||
DateTime? datetimeEnd,
|
||||
DateTime? date,
|
||||
TimeOfDay? timeStart,
|
||||
TimeOfDay? timeEnd,
|
||||
}) {
|
||||
DateTime on(DateTime day, TimeOfDay? time) =>
|
||||
DateTime(day.year, day.month, day.day, time?.hour ?? 0, time?.minute ?? 0);
|
||||
|
||||
final start = datetimeStart ?? (date == null ? clock.now() : on(date, timeStart));
|
||||
|
||||
var end = datetimeEnd;
|
||||
if (end == null && date != null && timeEnd != null) {
|
||||
end = on(date, timeEnd);
|
||||
// An end before the start means the session ran past midnight
|
||||
if (end.isBefore(start)) {
|
||||
end = end.add(const Duration(days: 1));
|
||||
}
|
||||
}
|
||||
|
||||
return WorkoutSession(
|
||||
id: id,
|
||||
routineId: routineId,
|
||||
dayId: dayId,
|
||||
notes: notes,
|
||||
impression: impression,
|
||||
datetimeStart: start,
|
||||
datetimeEnd: end,
|
||||
);
|
||||
}
|
||||
|
||||
WorkoutSessionTableCompanion toCompanion() {
|
||||
return WorkoutSessionTableCompanion(
|
||||
id: id != null ? drift.Value(id!) : const drift.Value.absent(),
|
||||
routineId: drift.Value(routineId),
|
||||
dayId: drift.Value(dayId),
|
||||
// Server-side `date` is a `DateField` (no time, no TZ). We send here the
|
||||
// calendar day the user picked, packaged as midnight-UTC so it round-trips
|
||||
// through PowerSync's ISO8601 wire format and lands on the right day on
|
||||
// the server.
|
||||
date: drift.Value(DateTime.utc(date.year, date.month, date.day)),
|
||||
notes: drift.Value(notes),
|
||||
impression: drift.Value(impression),
|
||||
// Explicit NULL, not absent: clearing a time has to clear the column too
|
||||
timeStart: drift.Value(timeStart),
|
||||
timeEnd: drift.Value(timeEnd),
|
||||
// Explicit NULL, not absent: clearing the end has to clear the column too.
|
||||
// The pre-2.7 columns are never written again, only read by fromDb.
|
||||
datetimeStart: drift.Value(datetimeStart),
|
||||
datetimeEnd: drift.Value(datetimeEnd),
|
||||
);
|
||||
}
|
||||
|
||||
/// The calendar day this session counts for, e.g. for the dashboard calendar
|
||||
///
|
||||
/// A session that runs over midnight counts for the day it started on.
|
||||
DateTime get localDay => DateTime(datetimeStart.year, datetimeStart.month, datetimeStart.day);
|
||||
|
||||
/// Duration between start and end, null while the session is still open
|
||||
Duration? get duration {
|
||||
if (timeStart == null || timeEnd == null) {
|
||||
final end = datetimeEnd;
|
||||
if (end == null) {
|
||||
return null;
|
||||
}
|
||||
final now = DateTime.now();
|
||||
final startDate = DateTime(now.year, now.month, now.day, timeStart!.hour, timeStart!.minute);
|
||||
final endDate = DateTime(now.year, now.month, now.day, timeEnd!.hour, timeEnd!.minute);
|
||||
return endDate.difference(startDate);
|
||||
|
||||
return end.difference(datetimeStart);
|
||||
}
|
||||
|
||||
/// Returns a localized string representation of the duration (e.g., "2h 30m").
|
||||
String durationTxt(BuildContext context) {
|
||||
final duration = this.duration;
|
||||
if (duration == null) {
|
||||
@@ -131,14 +177,16 @@ class WorkoutSession with _$WorkoutSession {
|
||||
).durationHoursMinutes(duration.inHours, duration.inMinutes.remainder(60));
|
||||
}
|
||||
|
||||
/// Returns a formatted string: "2h 30m (09:00 AM - 11:30 AM)".
|
||||
String durationTxtWithStartEnd(BuildContext context) {
|
||||
final duration = this.duration;
|
||||
if (duration == null) {
|
||||
final end = datetimeEnd;
|
||||
if (end == null) {
|
||||
return '-/-';
|
||||
}
|
||||
|
||||
final startTime = MaterialLocalizations.of(context).formatTimeOfDay(timeStart!);
|
||||
final endTime = MaterialLocalizations.of(context).formatTimeOfDay(timeEnd!);
|
||||
final localizations = MaterialLocalizations.of(context);
|
||||
final startTime = localizations.formatTimeOfDay(TimeOfDay.fromDateTime(datetimeStart));
|
||||
final endTime = localizations.formatTimeOfDay(TimeOfDay.fromDateTime(end));
|
||||
|
||||
return '${durationTxt(context)} ($startTime - $endTime)';
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ T _$identity<T>(T value) => value;
|
||||
mixin _$WorkoutSession {
|
||||
|
||||
/// Client-generated UUID, is `null` only before the first persist
|
||||
String? get id; int? get routineId; int? get dayId; DateTime get date; WorkoutImpression get impression; String? get notes; TimeOfDay? get timeStart; TimeOfDay? get timeEnd; List<Log> get logs;
|
||||
String? get id; int? get routineId; int? get dayId; WorkoutImpression get impression; String? get notes; DateTime get datetimeStart; DateTime? get datetimeEnd; List<Log> get logs;
|
||||
/// Create a copy of WorkoutSession
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@@ -26,16 +26,16 @@ $WorkoutSessionCopyWith<WorkoutSession> get copyWith => _$WorkoutSessionCopyWith
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) || (other.runtimeType == runtimeType&&other is WorkoutSession&&(identical(other.id, id) || other.id == id)&&(identical(other.routineId, routineId) || other.routineId == routineId)&&(identical(other.dayId, dayId) || other.dayId == dayId)&&(identical(other.date, date) || other.date == date)&&(identical(other.impression, impression) || other.impression == impression)&&(identical(other.notes, notes) || other.notes == notes)&&(identical(other.timeStart, timeStart) || other.timeStart == timeStart)&&(identical(other.timeEnd, timeEnd) || other.timeEnd == timeEnd)&&const DeepCollectionEquality().equals(other.logs, logs));
|
||||
return identical(this, other) || (other.runtimeType == runtimeType&&other is WorkoutSession&&(identical(other.id, id) || other.id == id)&&(identical(other.routineId, routineId) || other.routineId == routineId)&&(identical(other.dayId, dayId) || other.dayId == dayId)&&(identical(other.impression, impression) || other.impression == impression)&&(identical(other.notes, notes) || other.notes == notes)&&(identical(other.datetimeStart, datetimeStart) || other.datetimeStart == datetimeStart)&&(identical(other.datetimeEnd, datetimeEnd) || other.datetimeEnd == datetimeEnd)&&const DeepCollectionEquality().equals(other.logs, logs));
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
int get hashCode => Object.hash(runtimeType,id,routineId,dayId,date,impression,notes,timeStart,timeEnd,const DeepCollectionEquality().hash(logs));
|
||||
int get hashCode => Object.hash(runtimeType,id,routineId,dayId,impression,notes,datetimeStart,datetimeEnd,const DeepCollectionEquality().hash(logs));
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'WorkoutSession(id: $id, routineId: $routineId, dayId: $dayId, date: $date, impression: $impression, notes: $notes, timeStart: $timeStart, timeEnd: $timeEnd, logs: $logs)';
|
||||
return 'WorkoutSession(id: $id, routineId: $routineId, dayId: $dayId, impression: $impression, notes: $notes, datetimeStart: $datetimeStart, datetimeEnd: $datetimeEnd, logs: $logs)';
|
||||
}
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ abstract mixin class $WorkoutSessionCopyWith<$Res> {
|
||||
factory $WorkoutSessionCopyWith(WorkoutSession value, $Res Function(WorkoutSession) _then) = _$WorkoutSessionCopyWithImpl;
|
||||
@useResult
|
||||
$Res call({
|
||||
String? id, int? dayId, int? routineId, DateTime date, WorkoutImpression impression, String? notes, TimeOfDay? timeStart, TimeOfDay? timeEnd, List<Log> logs
|
||||
String? id, int? dayId, int? routineId, DateTime datetimeStart, DateTime? datetimeEnd, WorkoutImpression impression, String? notes, List<Log> logs
|
||||
});
|
||||
|
||||
|
||||
@@ -63,17 +63,16 @@ class _$WorkoutSessionCopyWithImpl<$Res>
|
||||
|
||||
/// Create a copy of WorkoutSession
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@pragma('vm:prefer-inline') @override $Res call({Object? id = freezed,Object? dayId = freezed,Object? routineId = freezed,Object? date = null,Object? impression = null,Object? notes = freezed,Object? timeStart = freezed,Object? timeEnd = freezed,Object? logs = null,}) {
|
||||
@pragma('vm:prefer-inline') @override $Res call({Object? id = freezed,Object? dayId = freezed,Object? routineId = freezed,Object? datetimeStart = null,Object? datetimeEnd = freezed,Object? impression = null,Object? notes = freezed,Object? logs = null,}) {
|
||||
return _then(WorkoutSession(
|
||||
id: freezed == id ? _self.id : id // ignore: cast_nullable_to_non_nullable
|
||||
as String?,dayId: freezed == dayId ? _self.dayId : dayId // ignore: cast_nullable_to_non_nullable
|
||||
as int?,routineId: freezed == routineId ? _self.routineId : routineId // ignore: cast_nullable_to_non_nullable
|
||||
as int?,date: null == date ? _self.date : date // ignore: cast_nullable_to_non_nullable
|
||||
as DateTime,impression: null == impression ? _self.impression : impression // ignore: cast_nullable_to_non_nullable
|
||||
as int?,datetimeStart: null == datetimeStart ? _self.datetimeStart : datetimeStart // ignore: cast_nullable_to_non_nullable
|
||||
as DateTime,datetimeEnd: freezed == datetimeEnd ? _self.datetimeEnd : datetimeEnd // ignore: cast_nullable_to_non_nullable
|
||||
as DateTime?,impression: null == impression ? _self.impression : impression // ignore: cast_nullable_to_non_nullable
|
||||
as WorkoutImpression,notes: freezed == notes ? _self.notes : notes // ignore: cast_nullable_to_non_nullable
|
||||
as String?,timeStart: freezed == timeStart ? _self.timeStart : timeStart // ignore: cast_nullable_to_non_nullable
|
||||
as TimeOfDay?,timeEnd: freezed == timeEnd ? _self.timeEnd : timeEnd // ignore: cast_nullable_to_non_nullable
|
||||
as TimeOfDay?,logs: null == logs ? _self.logs : logs // ignore: cast_nullable_to_non_nullable
|
||||
as String?,logs: null == logs ? _self.logs : logs // ignore: cast_nullable_to_non_nullable
|
||||
as List<Log>,
|
||||
));
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
import 'package:drift/drift.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:wger/core/json.dart';
|
||||
import 'package:wger/database/powersync/database.dart';
|
||||
import 'package:wger/features/routines/models/log.dart';
|
||||
import 'package:wger/features/routines/models/session.dart';
|
||||
@@ -121,37 +122,84 @@ class WorkoutLogRepository {
|
||||
_logger.finer('Adding local workout log entry ${log.date}');
|
||||
|
||||
await _db.transaction(() async {
|
||||
if (log.sessionId == null) {
|
||||
final dayMidnightUtc = DateTime.utc(log.date.year, log.date.month, log.date.day);
|
||||
|
||||
final existing =
|
||||
await (_db.select(_db.workoutSessionTable)
|
||||
..where(
|
||||
(t) =>
|
||||
t.routineId.equalsNullable(log.routineId) &
|
||||
t.date.equalsValue(dayMidnightUtc),
|
||||
)
|
||||
..limit(1))
|
||||
.getSingleOrNull();
|
||||
|
||||
if (existing != null) {
|
||||
log.sessionId = existing.id;
|
||||
} else {
|
||||
final newSession = WorkoutSession(
|
||||
routineId: log.routineId,
|
||||
dayId: dayId,
|
||||
date: dayMidnightUtc,
|
||||
);
|
||||
final inserted = await _db
|
||||
.into(_db.workoutSessionTable)
|
||||
.insertReturning(newSession.toCompanion());
|
||||
log.sessionId = inserted.id;
|
||||
_logger.finer('Created lazy session ${inserted.id} for log');
|
||||
}
|
||||
}
|
||||
log.sessionId ??= await _sessionIdFor(log, dayId: dayId);
|
||||
|
||||
final inserted = await _db.into(_db.workoutLogTable).insertReturning(log.toCompanion());
|
||||
log.id = inserted.id;
|
||||
});
|
||||
}
|
||||
|
||||
/// The session a log without one belongs to, creating it if nothing fits.
|
||||
///
|
||||
/// In order: a session the log falls into, then the most recent session that
|
||||
/// is still open and started no more than [sessionMaxDuration] ago, then one
|
||||
/// on the same day that carries no time at all, otherwise a new one. The first
|
||||
/// three mirror what the server does for logs uploaded without a session.
|
||||
Future<String?> _sessionIdFor(Log log, {int? dayId}) async {
|
||||
final at = dateToUtcIso8601(log.date);
|
||||
|
||||
final covering =
|
||||
await (_db.select(_db.workoutSessionTable)
|
||||
..where(
|
||||
(t) =>
|
||||
t.routineId.equalsNullable(log.routineId) &
|
||||
t.datetimeStart.isSmallerOrEqualValue(at) &
|
||||
t.datetimeEnd.isBiggerOrEqualValue(at),
|
||||
)
|
||||
..limit(1))
|
||||
.getSingleOrNull();
|
||||
if (covering != null) {
|
||||
return covering.id;
|
||||
}
|
||||
|
||||
final windowStart = dateToUtcIso8601(log.date.subtract(sessionMaxDuration));
|
||||
final open =
|
||||
await (_db.select(_db.workoutSessionTable)
|
||||
..where(
|
||||
(t) =>
|
||||
t.routineId.equalsNullable(log.routineId) &
|
||||
t.datetimeEnd.isNull() &
|
||||
t.datetimeStart.isBiggerOrEqualValue(windowStart) &
|
||||
t.datetimeStart.isSmallerOrEqualValue(at),
|
||||
)
|
||||
..orderBy([(t) => OrderingTerm.desc(t.datetimeStart)])
|
||||
..limit(1))
|
||||
.getSingleOrNull();
|
||||
if (open != null) {
|
||||
return open.id;
|
||||
}
|
||||
|
||||
// Sessions that came from the server without a time can only be matched by
|
||||
// their day. Dropping this would create a duplicate next to every one of them.
|
||||
final dayMidnightUtc = DateTime.utc(log.date.year, log.date.month, log.date.day);
|
||||
final sameDay =
|
||||
await (_db.select(_db.workoutSessionTable)
|
||||
..where(
|
||||
(t) =>
|
||||
t.routineId.equalsNullable(log.routineId) &
|
||||
t.datetimeStart.isNull() &
|
||||
t.date.equalsValue(dayMidnightUtc),
|
||||
)
|
||||
..limit(1))
|
||||
.getSingleOrNull();
|
||||
if (sameDay != null) {
|
||||
return sameDay.id;
|
||||
}
|
||||
|
||||
// The start has to be set, otherwise the lookups above can never find this
|
||||
// session again and every further log would create one of its own. The day
|
||||
// is set so the routine's date sequence advances (issue wger#2460).
|
||||
final created = await _db
|
||||
.into(_db.workoutSessionTable)
|
||||
.insertReturning(
|
||||
WorkoutSession(
|
||||
routineId: log.routineId,
|
||||
dayId: dayId,
|
||||
datetimeStart: log.date,
|
||||
).toCompanion(),
|
||||
);
|
||||
_logger.finer('Created lazy session ${created.id} for log');
|
||||
|
||||
return created.id;
|
||||
}
|
||||
}
|
||||
@@ -42,20 +42,23 @@ class WorkoutSessionRepository {
|
||||
Stream<List<WorkoutSession>> watchAllDrift() {
|
||||
_logger.finer('Watching all local workout session entries');
|
||||
|
||||
final query = _db.select(_db.workoutSessionTable).join([
|
||||
leftOuterJoin(
|
||||
_db.workoutLogTable,
|
||||
_db.workoutLogTable.sessionId.equalsExp(_db.workoutSessionTable.id),
|
||||
),
|
||||
leftOuterJoin(
|
||||
_db.routineRepetitionUnitTable,
|
||||
_db.routineRepetitionUnitTable.id.equalsExp(_db.workoutLogTable.repetitionsUnitId),
|
||||
),
|
||||
leftOuterJoin(
|
||||
_db.routineWeightUnitTable,
|
||||
_db.routineWeightUnitTable.id.equalsExp(_db.workoutLogTable.weightUnitId),
|
||||
),
|
||||
])..orderBy([OrderingTerm(expression: _db.workoutSessionTable.date, mode: OrderingMode.desc)]);
|
||||
final query =
|
||||
_db.select(_db.workoutSessionTable).join([
|
||||
leftOuterJoin(
|
||||
_db.workoutLogTable,
|
||||
_db.workoutLogTable.sessionId.equalsExp(_db.workoutSessionTable.id),
|
||||
),
|
||||
leftOuterJoin(
|
||||
_db.routineRepetitionUnitTable,
|
||||
_db.routineRepetitionUnitTable.id.equalsExp(_db.workoutLogTable.repetitionsUnitId),
|
||||
),
|
||||
leftOuterJoin(
|
||||
_db.routineWeightUnitTable,
|
||||
_db.routineWeightUnitTable.id.equalsExp(_db.workoutLogTable.weightUnitId),
|
||||
),
|
||||
])..orderBy([
|
||||
OrderingTerm(expression: _db.workoutSessionTable.datetimeStart, mode: OrderingMode.desc),
|
||||
]);
|
||||
|
||||
return query.watch().map((rows) {
|
||||
final sessions = <String, WorkoutSession>{};
|
||||
@@ -103,7 +106,7 @@ class WorkoutSessionRepository {
|
||||
/// `session.id` is null, Drift mints one, so the returned session carries
|
||||
/// the id the caller needs to reference it.
|
||||
Future<WorkoutSession> addLocalDrift(WorkoutSession session) async {
|
||||
_logger.finer('Adding local workout session entry ${session.date}');
|
||||
_logger.finer('Adding local workout session entry ${session.datetimeStart}');
|
||||
return _db.into(_db.workoutSessionTable).insertReturning(session.toCompanion());
|
||||
}
|
||||
}
|
||||
@@ -16,7 +16,7 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:wger/features/routines/models/session.dart';
|
||||
import 'package:wger/l10n/generated/app_localizations.dart';
|
||||
|
||||
/// Cross-field validation for a workout log entry, mirroring the
|
||||
@@ -33,21 +33,19 @@ String? validateWorkoutLogCrossField({
|
||||
return null;
|
||||
}
|
||||
|
||||
/// Cross-field validation for a workout session, mirroring the backend
|
||||
/// `WorkoutSession.clean()` rules:
|
||||
/// Cross-field validation for a workout session, mirroring the backend rule.
|
||||
///
|
||||
/// - [timeStart] and [timeEnd] must both be set or both be empty,
|
||||
/// - if both are set, [timeStart] must not be after [timeEnd].
|
||||
/// An end before the start is not an error, the form reads it as a session that
|
||||
/// ran past midnight. What the server does reject is a session longer than
|
||||
/// [sessionMaxDuration].
|
||||
String? validateWorkoutSessionTimes({
|
||||
required TimeOfDay? timeStart,
|
||||
required TimeOfDay? timeEnd,
|
||||
required DateTime datetimeStart,
|
||||
required DateTime? datetimeEnd,
|
||||
required AppLocalizations i18n,
|
||||
}) {
|
||||
if ((timeStart == null) != (timeEnd == null)) {
|
||||
return i18n.timeStartEndBothOrNeither;
|
||||
}
|
||||
if (timeStart != null && timeEnd != null && timeStart.isAfter(timeEnd)) {
|
||||
return i18n.timeStartAhead;
|
||||
if (datetimeEnd != null && datetimeEnd.difference(datetimeStart) > sessionMaxDuration) {
|
||||
return i18n.sessionTooLong(sessionMaxDuration.inHours);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
@@ -60,7 +60,11 @@ class _SessionFormState extends ConsumerState<SessionForm> {
|
||||
super.initState();
|
||||
_draft =
|
||||
widget._session ??
|
||||
WorkoutSession(routineId: widget._routineId, dayId: widget._dayId, date: clock.now());
|
||||
WorkoutSession(
|
||||
routineId: widget._routineId,
|
||||
dayId: widget._dayId,
|
||||
datetimeStart: clock.now(),
|
||||
);
|
||||
notesController.text = _draft.notes ?? '';
|
||||
}
|
||||
|
||||
@@ -82,6 +86,20 @@ class _SessionFormState extends ConsumerState<SessionForm> {
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
/// Anchors a picked time on the day the session belongs to
|
||||
DateTime _onSessionDay(TimeOfDay time) {
|
||||
final day = _draft.localDay;
|
||||
|
||||
return DateTime(day.year, day.month, day.day, time.hour, time.minute);
|
||||
}
|
||||
|
||||
/// Same, but an end before the start means the session ran past midnight
|
||||
DateTime _endOnSessionDay(TimeOfDay time) {
|
||||
final end = _onSessionDay(time);
|
||||
|
||||
return end.isBefore(_draft.datetimeStart) ? end.add(const Duration(days: 1)) : end;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final sessionProvider = ref.read(workoutSessionProvider.notifier);
|
||||
@@ -133,19 +151,21 @@ class _SessionFormState extends ConsumerState<SessionForm> {
|
||||
Flexible(
|
||||
child: TimeInputWidget(
|
||||
key: const ValueKey('time-start'),
|
||||
value: _draft.timeStart,
|
||||
value: TimeOfDay.fromDateTime(_draft.datetimeStart),
|
||||
labelText: AppLocalizations.of(context).timeStart,
|
||||
onCleared: () => _draft = _draft.copyWith(timeStart: null),
|
||||
onChanged: (time) => _draft = _draft.copyWith(timeStart: time),
|
||||
onChanged: (time) => _draft = _draft.copyWith(datetimeStart: _onSessionDay(time)),
|
||||
),
|
||||
),
|
||||
Flexible(
|
||||
child: TimeInputWidget(
|
||||
key: const ValueKey('time-end'),
|
||||
value: _draft.timeEnd,
|
||||
value: _draft.datetimeEnd != null
|
||||
? TimeOfDay.fromDateTime(_draft.datetimeEnd!)
|
||||
: null,
|
||||
labelText: AppLocalizations.of(context).timeEnd,
|
||||
onCleared: () => _draft = _draft.copyWith(timeEnd: null),
|
||||
onChanged: (time) => _draft = _draft.copyWith(timeEnd: time),
|
||||
onCleared: () => _draft = _draft.copyWith(datetimeEnd: null),
|
||||
onChanged: (time) =>
|
||||
_draft = _draft.copyWith(datetimeEnd: _endOnSessionDay(time)),
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -162,8 +182,8 @@ class _SessionFormState extends ConsumerState<SessionForm> {
|
||||
|
||||
final i18n = AppLocalizations.of(context);
|
||||
final error = validateWorkoutSessionTimes(
|
||||
timeStart: _draft.timeStart,
|
||||
timeEnd: _draft.timeEnd,
|
||||
datetimeStart: _draft.datetimeStart,
|
||||
datetimeEnd: _draft.datetimeEnd,
|
||||
i18n: i18n,
|
||||
);
|
||||
if (error != null) {
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
*/
|
||||
|
||||
import 'package:clock/clock.dart';
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:wger/core/consts.dart';
|
||||
@@ -52,22 +53,31 @@ class _SessionPageState extends ConsumerState<SessionPage> {
|
||||
value: ref.watch(workoutSessionProvider),
|
||||
loggerName: 'SessionPage',
|
||||
data: (sessions) {
|
||||
final found = sessions.firstWhere(
|
||||
(s) => s.date.isSameDayAs(clock.now()) && s.routineId == gymState.routine.id,
|
||||
orElse: () => WorkoutSession(
|
||||
dayId: gymState.dayId,
|
||||
date: clock.now(),
|
||||
routineId: gymState.routine.id,
|
||||
),
|
||||
);
|
||||
final now = clock.now();
|
||||
final ours = sessions.where((s) => s.routineId == gymState.routine.id);
|
||||
|
||||
// A session that is still running wins over one that merely shares
|
||||
// a calendar day, because a workout can cross midnight. The day is
|
||||
// still the fallback, so an already finished one stays editable.
|
||||
final found =
|
||||
ours.firstWhereOrNull(
|
||||
(s) =>
|
||||
s.datetimeEnd == null &&
|
||||
now.difference(s.datetimeStart) <= sessionMaxDuration,
|
||||
) ??
|
||||
ours.firstWhereOrNull((s) => s.datetimeStart.isSameDayAs(now)) ??
|
||||
WorkoutSession(
|
||||
dayId: gymState.dayId,
|
||||
datetimeStart: gymState.workoutStart,
|
||||
routineId: gymState.routine.id,
|
||||
);
|
||||
|
||||
// Prefill missing times. A session may have been created lazily
|
||||
// while logging sets (without times), so fall back to the gym
|
||||
// session's start and the current time.
|
||||
final session = found.copyWith(
|
||||
timeStart: found.timeStart ?? gymState.startTime,
|
||||
timeEnd: found.timeEnd ?? TimeOfDay.fromDateTime(clock.now()),
|
||||
);
|
||||
// A session created lazily while logging has no end yet; prefill
|
||||
// the current time so the form opens on a complete interval.
|
||||
final session = found.copyWith(datetimeEnd: found.datetimeEnd ?? now);
|
||||
|
||||
return Column(
|
||||
children: [
|
||||
|
||||
@@ -101,7 +101,7 @@ class _WorkoutSummaryState extends ConsumerState<WorkoutSummary> {
|
||||
}
|
||||
|
||||
final session = routine.sessions.firstWhereOrNull(
|
||||
(s) => s.date.isSameDayAs(clock.now()),
|
||||
(s) => s.localDay.isSameDayAs(clock.now()),
|
||||
);
|
||||
final userTrophies = trophyState.prTrophies
|
||||
.where((t) => t.contextData?.sessionId == session?.id)
|
||||
|
||||
@@ -43,7 +43,7 @@ class DayLogWidget extends ConsumerWidget {
|
||||
final trophyState = ref.read(trophyStateProvider);
|
||||
|
||||
final session = _routine.sessions.firstWhere(
|
||||
(s) => s.date.isSameDayAs(_date),
|
||||
(s) => s.localDay.isSameDayAs(_date),
|
||||
);
|
||||
final exercises = session.exercises;
|
||||
|
||||
|
||||
@@ -94,8 +94,8 @@ class _WorkoutLogCalendarState extends State<WorkoutLogCalendar> {
|
||||
|
||||
void loadEvents() {
|
||||
for (final session in widget._routine.sessions) {
|
||||
_events[DateFormatLists.format(session.date)] = [
|
||||
session.date,
|
||||
_events[DateFormatLists.format(session.localDay)] = [
|
||||
session.localDay,
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ class _SessionInfoState extends State<SessionInfo> {
|
||||
style: Theme.of(context).textTheme.headlineSmall,
|
||||
),
|
||||
subtitle: Text(
|
||||
localizedDate(context).format(widget._session.date),
|
||||
localizedDate(context).format(widget._session.localDay),
|
||||
),
|
||||
onTap: () => setState(() => editMode = !editMode),
|
||||
trailing: Icon(editMode ? Icons.edit_off : Icons.edit),
|
||||
|
||||
+2
-1
@@ -1168,5 +1168,6 @@
|
||||
"certsNotVerifiedTitle": "Zertifikatsvalidierung ist deaktiviert",
|
||||
"certsNotVerifiedDetail": "Zertifikate für {host} werden nicht geprüft. Zum Ändern melde dich ab und passe die Option im Anmeldebildschirm an.",
|
||||
"settingsVerboseLogging": "Ausführliches Protokoll",
|
||||
"settingsVerboseLoggingDescription": "Hilfreich, wenn du anhaltende Probleme meldest."
|
||||
"settingsVerboseLoggingDescription": "Hilfreich, wenn du anhaltende Probleme meldest.",
|
||||
"sessionTooLong": "Eine Trainingseinheit darf nicht länger als {hours} Stunden dauern"
|
||||
}
|
||||
@@ -1496,5 +1496,14 @@
|
||||
"timeStartEndBothOrNeither": "Either set both start and end time or leave both empty",
|
||||
"@timeStartEndBothOrNeither": {
|
||||
"description": "Validation error when only one of start/end time is set on a workout session"
|
||||
},
|
||||
"sessionTooLong": "A session cannot be longer than {hours} hours",
|
||||
"@sessionTooLong": {
|
||||
"description": "Validation error when a workout session exceeds the maximum length",
|
||||
"placeholders": {
|
||||
"hours": {
|
||||
"type": "int"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -1207,5 +1207,6 @@
|
||||
"certsNotVerifiedTitle": "La validación de certificados está desactivada",
|
||||
"certsNotVerifiedDetail": "Los certificados de {host} no se comprueban. Para cambiarlo, cierra la sesión y ajusta la opción en la pantalla de inicio de sesión.",
|
||||
"settingsVerboseLogging": "Registro detallado",
|
||||
"settingsVerboseLoggingDescription": "Útil cuando informas de problemas persistentes."
|
||||
"settingsVerboseLoggingDescription": "Útil cuando informas de problemas persistentes.",
|
||||
"sessionTooLong": "Una sesión de entrenamiento no puede durar más de {hours} horas"
|
||||
}
|
||||
+2
-1
@@ -1178,5 +1178,6 @@
|
||||
"certsNotVerifiedTitle": "La validation des certificats est désactivée",
|
||||
"certsNotVerifiedDetail": "Les certificats de {host} ne sont pas vérifiés. Pour changer cela, déconnectez-vous et modifiez l'option sur l'écran de connexion.",
|
||||
"settingsVerboseLogging": "Journalisation détaillée",
|
||||
"settingsVerboseLoggingDescription": "Utile lorsque vous signalez des problèmes persistants."
|
||||
"settingsVerboseLoggingDescription": "Utile lorsque vous signalez des problèmes persistants.",
|
||||
"sessionTooLong": "Une session d’entraînement ne peut pas durer plus de {hours} heures"
|
||||
}
|
||||
@@ -208,7 +208,6 @@ class DjangoConnector extends PowerSyncBackendConnector {
|
||||
/// are read-only on the serializer and therefore safe to leave out.
|
||||
static const Map<String, Set<String>> _dateOnlyFields = {
|
||||
'manager_routine': {'start', 'end'},
|
||||
'manager_workoutsession': {'date'},
|
||||
'nutrition_nutritionplan': {'start', 'end'},
|
||||
'gallery_image': {'date'},
|
||||
};
|
||||
|
||||
@@ -3669,6 +3669,28 @@ class MockAppLocalizations extends _i1.Mock implements _i2.AppLocalizations {
|
||||
)
|
||||
as String);
|
||||
|
||||
@override
|
||||
String get settingsVerboseLogging =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.getter(#settingsVerboseLogging),
|
||||
returnValue: _i3.dummyValue<String>(
|
||||
this,
|
||||
Invocation.getter(#settingsVerboseLogging),
|
||||
),
|
||||
)
|
||||
as String);
|
||||
|
||||
@override
|
||||
String get settingsVerboseLoggingDescription =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.getter(#settingsVerboseLoggingDescription),
|
||||
returnValue: _i3.dummyValue<String>(
|
||||
this,
|
||||
Invocation.getter(#settingsVerboseLoggingDescription),
|
||||
),
|
||||
)
|
||||
as String);
|
||||
|
||||
@override
|
||||
String get aboutPageTitle =>
|
||||
(super.noSuchMethod(
|
||||
|
||||
@@ -16,12 +16,57 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:wger/core/consts.dart';
|
||||
import 'package:wger/features/routines/models/log.dart';
|
||||
import 'package:wger/features/routines/models/session.dart';
|
||||
|
||||
void main() {
|
||||
group('WorkoutSession.fromDb', () {
|
||||
test('takes the new columns when they are set', () {
|
||||
final session = WorkoutSession.fromDb(
|
||||
routineId: 1,
|
||||
datetimeStart: DateTime(2026, 4, 15, 18, 30),
|
||||
datetimeEnd: DateTime(2026, 4, 15, 19, 45),
|
||||
);
|
||||
|
||||
expect(session.datetimeStart, DateTime(2026, 4, 15, 18, 30));
|
||||
expect(session.datetimeEnd, DateTime(2026, 4, 15, 19, 45));
|
||||
});
|
||||
|
||||
test('rebuilds a row that predates 2.7 from its date and times', () {
|
||||
final session = WorkoutSession.fromDb(
|
||||
routineId: 1,
|
||||
date: DateTime(2026, 4, 15),
|
||||
timeStart: const TimeOfDay(hour: 18, minute: 30),
|
||||
timeEnd: const TimeOfDay(hour: 19, minute: 45),
|
||||
);
|
||||
|
||||
expect(session.datetimeStart, DateTime(2026, 4, 15, 18, 30));
|
||||
expect(session.datetimeEnd, DateTime(2026, 4, 15, 19, 45));
|
||||
});
|
||||
|
||||
test('reads an end before the start as the next day', () {
|
||||
final session = WorkoutSession.fromDb(
|
||||
routineId: 1,
|
||||
date: DateTime(2026, 4, 15),
|
||||
timeStart: const TimeOfDay(hour: 23, minute: 0),
|
||||
timeEnd: const TimeOfDay(hour: 1, minute: 30),
|
||||
);
|
||||
|
||||
expect(session.datetimeStart, DateTime(2026, 4, 15, 23, 0));
|
||||
expect(session.datetimeEnd, DateTime(2026, 4, 16, 1, 30));
|
||||
});
|
||||
|
||||
test('an old row without times starts at midnight and stays open', () {
|
||||
final session = WorkoutSession.fromDb(routineId: 1, date: DateTime(2026, 4, 15));
|
||||
|
||||
expect(session.datetimeStart, DateTime(2026, 4, 15));
|
||||
expect(session.datetimeEnd, isNull);
|
||||
});
|
||||
});
|
||||
|
||||
group('WorkoutSession.volume', () {
|
||||
test('sums metric volumes correctly', () {
|
||||
final a = Log(
|
||||
@@ -46,7 +91,7 @@ void main() {
|
||||
repetitionsUnitId: REP_UNIT_REPETITIONS_ID,
|
||||
);
|
||||
|
||||
final session = WorkoutSession(routineId: 1, date: DateTime(2021), logs: [a, b]);
|
||||
final session = WorkoutSession(routineId: 1, datetimeStart: DateTime(2021), logs: [a, b]);
|
||||
|
||||
final vol = session.volume;
|
||||
expect(vol['metric'], equals(100 * 3 + 50 * 2));
|
||||
@@ -76,7 +121,7 @@ void main() {
|
||||
repetitionsUnitId: REP_UNIT_REPETITIONS_ID,
|
||||
);
|
||||
|
||||
final session = WorkoutSession(routineId: 1, date: DateTime(2021), logs: [a, b]);
|
||||
final session = WorkoutSession(routineId: 1, datetimeStart: DateTime(2021), logs: [a, b]);
|
||||
|
||||
final vol = session.volume;
|
||||
expect(vol['imperial'], equals(220 * 4 + 150 * 1));
|
||||
@@ -117,7 +162,7 @@ void main() {
|
||||
repetitionsUnitId: 999, // some other repetition unit -> should be ignored
|
||||
);
|
||||
|
||||
final session = WorkoutSession(routineId: 1, date: DateTime(2021), logs: [a, b, c]);
|
||||
final session = WorkoutSession(routineId: 1, datetimeStart: DateTime(2021), logs: [a, b, c]);
|
||||
|
||||
final vol = session.volume;
|
||||
// only 'a' should count for metric, only 'b' for imperial
|
||||
@@ -126,7 +171,7 @@ void main() {
|
||||
});
|
||||
|
||||
test('returns zero for empty logs', () {
|
||||
final session = WorkoutSession(routineId: 1, date: DateTime(2021), logs: []);
|
||||
final session = WorkoutSession(routineId: 1, datetimeStart: DateTime(2021), logs: []);
|
||||
|
||||
final vol = session.volume;
|
||||
expect(vol['metric'], equals(0));
|
||||
@@ -156,7 +201,7 @@ void main() {
|
||||
repetitionsUnitId: REP_UNIT_REPETITIONS_ID,
|
||||
);
|
||||
|
||||
final session = WorkoutSession(routineId: 1, date: DateTime(2021), logs: [a, b]);
|
||||
final session = WorkoutSession(routineId: 1, datetimeStart: DateTime(2021), logs: [a, b]);
|
||||
|
||||
final vol = session.volume;
|
||||
expect(vol['metric'], closeTo(10.5 * 3 + 5.25 * 2.5, 1e-9));
|
||||
|
||||
@@ -387,7 +387,7 @@ void main() {
|
||||
final session = WorkoutSession(
|
||||
id: 'session-1',
|
||||
routineId: 101,
|
||||
date: DateTime(2025, 1, 1),
|
||||
datetimeStart: DateTime(2025, 1, 1),
|
||||
logs: [log],
|
||||
);
|
||||
when(
|
||||
|
||||
@@ -81,11 +81,11 @@ void main() {
|
||||
});
|
||||
|
||||
group('addLocalDrift, log without sessionId', () {
|
||||
test('reuses an existing session for the same routine and day', () async {
|
||||
test('reuses an open session within the window', () async {
|
||||
final existingSession = WorkoutSession(
|
||||
id: 'existing-session-1',
|
||||
routineId: 100,
|
||||
date: DateTime.utc(2026, 4, 15),
|
||||
datetimeStart: DateTime.utc(2026, 4, 15, 16),
|
||||
);
|
||||
await db.into(db.workoutSessionTable).insert(existingSession.toCompanion());
|
||||
|
||||
@@ -99,11 +99,9 @@ void main() {
|
||||
});
|
||||
|
||||
test('reuses a server-synced session whose date has no time component', () async {
|
||||
// After a round-trip the backend stores the date as a bare 'YYYY-MM-DD'
|
||||
// (Django DateField), not the local 'T00:00:00.000Z' format. The day
|
||||
// lookup must still match it, otherwise a duplicate session is created
|
||||
// and the server rejects it on the unique (date, routine, user)
|
||||
// constraint, taking every log on it down with it.
|
||||
// A row replicated before 2.7 carries only the bare 'YYYY-MM-DD' date and
|
||||
// no datetime_start. The day lookup has to keep matching it, otherwise a
|
||||
// duplicate session appears next to every one of them.
|
||||
await db.customStatement(
|
||||
"INSERT INTO manager_workoutsession (id, routine_id, date, impression) VALUES ('server-session', 100, '2026-04-15', '2')",
|
||||
);
|
||||
@@ -117,14 +115,16 @@ void main() {
|
||||
expect(logs.single.sessionId, 'server-session');
|
||||
});
|
||||
|
||||
test('creates a new session at midnight UTC of the log date', () async {
|
||||
test('creates a new session starting at the moment of the log', () async {
|
||||
// Without a start the lookups above could never find it again and every
|
||||
// further log would create one of its own.
|
||||
final log = makeLog(date: DateTime.utc(2026, 4, 15, 18, 30));
|
||||
|
||||
await repo.addLocalDrift(log);
|
||||
|
||||
final sessions = await readSessions();
|
||||
expect(sessions, hasLength(1));
|
||||
expect(sessions.single.date, DateTime.utc(2026, 4, 15));
|
||||
expect(sessions.single.datetimeStart, DateTime.utc(2026, 4, 15, 18, 30).toLocal());
|
||||
expect(log.sessionId, sessions.single.id);
|
||||
});
|
||||
|
||||
@@ -139,11 +139,26 @@ void main() {
|
||||
expect(sessions.single.dayId, 42);
|
||||
});
|
||||
|
||||
test('starts a new session when the open one is older than the window', () async {
|
||||
await db
|
||||
.into(db.workoutSessionTable)
|
||||
.insert(
|
||||
WorkoutSession(
|
||||
routineId: 100,
|
||||
datetimeStart: DateTime.utc(2026, 4, 15, 8),
|
||||
).toCompanion(),
|
||||
);
|
||||
|
||||
await repo.addLocalDrift(makeLog(routineId: 100, date: DateTime.utc(2026, 4, 15, 18)));
|
||||
|
||||
expect(await readSessions(), hasLength(2));
|
||||
});
|
||||
|
||||
test('does not reuse a session from a different day', () async {
|
||||
await db
|
||||
.into(db.workoutSessionTable)
|
||||
.insert(
|
||||
WorkoutSession(routineId: 100, date: DateTime.utc(2026, 4, 14)).toCompanion(),
|
||||
WorkoutSession(routineId: 100, datetimeStart: DateTime.utc(2026, 4, 14)).toCompanion(),
|
||||
);
|
||||
|
||||
await repo.addLocalDrift(makeLog(date: DateTime.utc(2026, 4, 15)));
|
||||
@@ -155,7 +170,7 @@ void main() {
|
||||
await db
|
||||
.into(db.workoutSessionTable)
|
||||
.insert(
|
||||
WorkoutSession(routineId: 999, date: DateTime.utc(2026, 4, 15)).toCompanion(),
|
||||
WorkoutSession(routineId: 999, datetimeStart: DateTime.utc(2026, 4, 15)).toCompanion(),
|
||||
);
|
||||
|
||||
await repo.addLocalDrift(makeLog(routineId: 100, date: DateTime.utc(2026, 4, 15)));
|
||||
@@ -178,7 +193,7 @@ void main() {
|
||||
final existingSession = WorkoutSession(
|
||||
id: 'free-session',
|
||||
routineId: null,
|
||||
date: DateTime.utc(2026, 4, 15),
|
||||
datetimeStart: DateTime.utc(2026, 4, 15, 16),
|
||||
);
|
||||
await db.into(db.workoutSessionTable).insert(existingSession.toCompanion());
|
||||
|
||||
@@ -193,7 +208,7 @@ void main() {
|
||||
await db
|
||||
.into(db.workoutSessionTable)
|
||||
.insert(
|
||||
WorkoutSession(routineId: 100, date: DateTime.utc(2026, 4, 15)).toCompanion(),
|
||||
WorkoutSession(routineId: 100, datetimeStart: DateTime.utc(2026, 4, 15)).toCompanion(),
|
||||
);
|
||||
|
||||
await repo.addLocalDrift(makeLog(routineId: null, date: DateTime.utc(2026, 4, 15)));
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:wger/database/powersync/database.dart';
|
||||
import 'package:wger/features/routines/models/log.dart';
|
||||
@@ -55,7 +54,7 @@ void main() {
|
||||
return WorkoutSession(
|
||||
id: id,
|
||||
routineId: routineId,
|
||||
date: date ?? DateTime.utc(2026, 4, 15),
|
||||
datetimeStart: date ?? DateTime.utc(2026, 4, 15),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -96,20 +95,20 @@ void main() {
|
||||
expect(rows.single.notes, 'updated');
|
||||
});
|
||||
|
||||
test('editLocalDrift clears times that were nulled', () async {
|
||||
test('editLocalDrift clears an end that was nulled', () async {
|
||||
final inserted = await repo.addLocalDrift(
|
||||
makeSession().copyWith(
|
||||
timeStart: const TimeOfDay(hour: 8, minute: 0),
|
||||
timeEnd: const TimeOfDay(hour: 9, minute: 30),
|
||||
datetimeStart: DateTime(2021, 5, 1, 8, 0),
|
||||
datetimeEnd: DateTime(2021, 5, 1, 9, 30),
|
||||
),
|
||||
);
|
||||
|
||||
// The user clears both times via the form's clear buttons
|
||||
await repo.editLocalDrift(inserted.copyWith(timeStart: null, timeEnd: null));
|
||||
// The user clears the end via the form's clear button
|
||||
await repo.editLocalDrift(inserted.copyWith(datetimeEnd: null));
|
||||
|
||||
final row = await db.select(db.workoutSessionTable).getSingle();
|
||||
expect(row.timeStart, isNull);
|
||||
expect(row.timeEnd, isNull);
|
||||
expect(row.datetimeStart, DateTime(2021, 5, 1, 8, 0));
|
||||
expect(row.datetimeEnd, isNull);
|
||||
});
|
||||
|
||||
test('deleteLocalDrift removes the row with matching id', () async {
|
||||
@@ -134,7 +133,7 @@ void main() {
|
||||
expect(await repo.watchAllDrift().first, isEmpty);
|
||||
});
|
||||
|
||||
test('emits sessions sorted by date desc', () async {
|
||||
test('emits sessions sorted by start desc', () async {
|
||||
await repo.addLocalDrift(makeSession(routineId: 1, date: DateTime.utc(2026, 4, 14)));
|
||||
await repo.addLocalDrift(makeSession(routineId: 2, date: DateTime.utc(2026, 4, 16)));
|
||||
await repo.addLocalDrift(makeSession(routineId: 3, date: DateTime.utc(2026, 4, 15)));
|
||||
|
||||
@@ -56,7 +56,7 @@ void main() {
|
||||
|
||||
setUp(() {
|
||||
routine = getTestRoutine();
|
||||
routine.sessions[0] = routine.sessions[0].copyWith(date: DateTime(2025, 3, 29));
|
||||
routine.sessions[0] = routine.sessions[0].copyWith(datetimeStart: DateTime(2025, 3, 29));
|
||||
// Pin every log to a known session id so we can verify the edit
|
||||
// dialog round-trips the value through the model.
|
||||
for (final log in routine.sessions[0].logs) {
|
||||
|
||||
@@ -55,9 +55,8 @@ void main() {
|
||||
routineId: 1,
|
||||
notes: 'Existing notes',
|
||||
impression: WorkoutImpression.bad,
|
||||
date: DateTime.now(),
|
||||
timeStart: const TimeOfDay(hour: 10, minute: 0),
|
||||
timeEnd: const TimeOfDay(hour: 11, minute: 0),
|
||||
datetimeStart: DateTime.now().copyWith(hour: 10, minute: 0),
|
||||
datetimeEnd: DateTime.now().copyWith(hour: 11, minute: 0),
|
||||
);
|
||||
|
||||
//Act
|
||||
@@ -97,7 +96,7 @@ void main() {
|
||||
routineId: 1,
|
||||
notes: 'Old notes',
|
||||
impression: WorkoutImpression.neutral,
|
||||
date: DateTime.now(),
|
||||
datetimeStart: DateTime.now(),
|
||||
);
|
||||
|
||||
when(mockRepository.editLocalDrift(any as dynamic)).thenAnswer(
|
||||
|
||||
@@ -105,13 +105,12 @@ void main() {
|
||||
});
|
||||
});
|
||||
|
||||
testWidgets('Existing session with null times falls back to defaults', (
|
||||
testWidgets('An open session keeps its start and gets the current time as end', (
|
||||
WidgetTester tester,
|
||||
) async {
|
||||
// A session created lazily while logging has no times; the page should
|
||||
// prefill the gym session's start and the current time instead of leaving
|
||||
// both fields blank.
|
||||
testRoutine.sessions[0] = testRoutine.sessions[0].copyWith(timeStart: null, timeEnd: null);
|
||||
// A session created lazily while logging has a start but no end yet; the
|
||||
// page prefills the current time so the form opens on a full interval.
|
||||
testRoutine.sessions[0] = testRoutine.sessions[0].copyWith(datetimeEnd: null);
|
||||
|
||||
notifier.state = notifier.state.copyWith(
|
||||
routine: testRoutine,
|
||||
@@ -123,7 +122,7 @@ void main() {
|
||||
await tester.pumpWidget(renderSessionPage());
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('1:35 PM'), findsOneWidget);
|
||||
expect(find.text('10:00 AM'), findsOneWidget);
|
||||
expect(find.text('3:23 PM'), findsOneWidget);
|
||||
});
|
||||
});
|
||||
@@ -159,8 +158,8 @@ void main() {
|
||||
expect(captured.id, '1');
|
||||
expect(captured.impression, WorkoutImpression.good);
|
||||
expect(captured.notes, equals('This is a note'));
|
||||
expect(captured.timeStart, equals(const TimeOfDay(hour: 10, minute: 0)));
|
||||
expect(captured.timeEnd, equals(const TimeOfDay(hour: 12, minute: 34)));
|
||||
expect(captured.datetimeStart, equals(DateTime(2021, 5, 1, 10, 0)));
|
||||
expect(captured.datetimeEnd, equals(DateTime(2021, 5, 1, 12, 34)));
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -103,17 +103,19 @@ void main() {
|
||||
expect(out['created'], '2024-10-30T10:15:00.000Z');
|
||||
});
|
||||
|
||||
test('strips the time component on `manager_workoutsession.date`', () {
|
||||
test('leaves the session timestamps untouched', () {
|
||||
// The session no longer has a date-only column, both timestamps go to
|
||||
// the server as the full ISO8601 values they are.
|
||||
final out = connector.genericTransform(
|
||||
'manager_workoutsession',
|
||||
{
|
||||
'date': '2024-11-01T00:00:00.000Z',
|
||||
'datetime_start': '2024-11-01T18:30:00.000Z',
|
||||
'notes': 'felt great',
|
||||
'impression': '1',
|
||||
},
|
||||
'12',
|
||||
);
|
||||
expect(out['date'], '2024-11-01');
|
||||
expect(out['datetime_start'], '2024-11-01T18:30:00.000Z');
|
||||
expect(out['notes'], 'felt great');
|
||||
});
|
||||
|
||||
|
||||
@@ -100,7 +100,7 @@ Widget createGymModeResultsScreen({Locale? locale}) {
|
||||
|
||||
final key = GlobalKey<NavigatorState>();
|
||||
final routine = getTestRoutine(exercises: getScreenshotExercises());
|
||||
routine.sessions[0] = routine.sessions.first.copyWith(date: clock.now());
|
||||
routine.sessions[0] = routine.sessions.first.copyWith(datetimeStart: clock.now());
|
||||
|
||||
return riverpod.UncontrolledProviderScope(
|
||||
container: riverpod.ProviderContainer.test(
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:wger/features/exercises/models/exercise.dart';
|
||||
import 'package:wger/features/routines/models/base_config.dart';
|
||||
import 'package:wger/features/routines/models/day.dart';
|
||||
@@ -92,22 +91,20 @@ Routine getTestRoutine({List<Exercise>? exercises}) {
|
||||
final session1 = WorkoutSession(
|
||||
id: '1',
|
||||
routineId: 1,
|
||||
date: DateTime(2021, 5, 1),
|
||||
impression: WorkoutImpression.good,
|
||||
notes: 'This is a note',
|
||||
timeStart: const TimeOfDay(hour: 10, minute: 0),
|
||||
timeEnd: const TimeOfDay(hour: 12, minute: 34),
|
||||
datetimeStart: DateTime(2021, 5, 1, 10, 0),
|
||||
datetimeEnd: DateTime(2021, 5, 1, 12, 34),
|
||||
logs: [log1, log2],
|
||||
);
|
||||
|
||||
final session2 = WorkoutSession(
|
||||
id: '2',
|
||||
routineId: 1,
|
||||
date: DateTime(2021, 5, 2),
|
||||
impression: WorkoutImpression.bad,
|
||||
notes: 'This is a note',
|
||||
timeStart: const TimeOfDay(hour: 6, minute: 12),
|
||||
timeEnd: const TimeOfDay(hour: 8, minute: 1),
|
||||
datetimeStart: DateTime(2021, 5, 2, 6, 12),
|
||||
datetimeEnd: DateTime(2021, 5, 2, 8, 1),
|
||||
logs: [log3],
|
||||
);
|
||||
|
||||
|
||||
Reference in new issue
Block a user