mirror of
https://github.com/wger-project/flutter.git
synced 2026-11-30 01:41:05 +01:00
Merge branch 'feature/offline-mode' into feat/nutrition-ingredients-implementation
This commit is contained in:
@@ -27,79 +27,77 @@ import 'package:wger/models/exercises/translation.dart';
|
||||
import 'package:wger/models/exercises/video.dart';
|
||||
|
||||
class Exercise extends Equatable {
|
||||
final _logger = Logger('ExerciseModel');
|
||||
static final _logger = Logger('ExerciseModel');
|
||||
|
||||
late final int id;
|
||||
late final String uuid;
|
||||
late final String? variationGroup;
|
||||
late final DateTime? created;
|
||||
late final DateTime? lastUpdate;
|
||||
late final DateTime? lastUpdateGlobal;
|
||||
late int categoryId;
|
||||
final int id;
|
||||
final String uuid;
|
||||
final String? variationGroup;
|
||||
final DateTime? created;
|
||||
final DateTime? lastUpdate;
|
||||
final ExerciseCategory category;
|
||||
final List<Muscle> muscles;
|
||||
final List<Muscle> musclesSecondary;
|
||||
final List<Equipment> equipment;
|
||||
final List<ExerciseImage> images;
|
||||
final List<Translation> translations;
|
||||
final List<Video> videos;
|
||||
final List<String> authors;
|
||||
final List<String> authorsGlobal;
|
||||
|
||||
ExerciseCategory? category;
|
||||
List<int> musclesIds = [];
|
||||
List<Muscle> muscles = [];
|
||||
List<int> musclesSecondaryIds = [];
|
||||
List<Muscle> musclesSecondary = [];
|
||||
List<int> equipmentIds = [];
|
||||
List<Equipment> equipment = [];
|
||||
List<ExerciseImage> images = [];
|
||||
List<Translation> translations = [];
|
||||
List<Video> videos = [];
|
||||
List<String> authors = [];
|
||||
List<String> authorsGlobal = [];
|
||||
int get categoryId => category.id;
|
||||
List<int> get musclesIds => muscles.map((e) => e.id).toList();
|
||||
List<int> get musclesSecondaryIds => musclesSecondary.map((e) => e.id).toList();
|
||||
List<int> get equipmentIds => equipment.map((e) => e.id).toList();
|
||||
|
||||
Exercise({
|
||||
const Exercise({
|
||||
required this.id,
|
||||
required this.uuid,
|
||||
this.created,
|
||||
this.lastUpdate,
|
||||
this.variationGroup,
|
||||
required this.categoryId,
|
||||
required this.category,
|
||||
this.muscles = const [],
|
||||
this.musclesSecondary = const [],
|
||||
this.equipment = const [],
|
||||
this.images = const [],
|
||||
this.translations = const [],
|
||||
this.videos = const [],
|
||||
this.authors = const [],
|
||||
this.authorsGlobal = const [],
|
||||
});
|
||||
|
||||
Exercise copyWith({
|
||||
int? id,
|
||||
String? uuid,
|
||||
DateTime? created,
|
||||
DateTime? lastUpdate,
|
||||
String? variationGroup,
|
||||
ExerciseCategory? category,
|
||||
List<Muscle>? muscles,
|
||||
List<Muscle>? musclesSecondary,
|
||||
List<Equipment>? equipment,
|
||||
List<ExerciseImage>? images,
|
||||
List<Translation>? translations,
|
||||
ExerciseCategory? category,
|
||||
List<Video>? videos,
|
||||
List<String>? authors,
|
||||
List<String>? authorsGlobal,
|
||||
}) {
|
||||
this.images = images ?? [];
|
||||
this.equipment = equipment ?? [];
|
||||
if (category != null) {
|
||||
this.category = category;
|
||||
categoryId = category.id;
|
||||
}
|
||||
|
||||
if (muscles != null) {
|
||||
this.muscles = muscles;
|
||||
musclesIds = muscles.map((e) => e.id).toList();
|
||||
}
|
||||
|
||||
if (musclesSecondary != null) {
|
||||
this.musclesSecondary = musclesSecondary;
|
||||
musclesSecondaryIds = musclesSecondary.map((e) => e.id).toList();
|
||||
}
|
||||
|
||||
if (equipment != null) {
|
||||
this.equipment = equipment;
|
||||
equipmentIds = equipment.map((e) => e.id).toList();
|
||||
}
|
||||
|
||||
if (translations != null) {
|
||||
this.translations = translations;
|
||||
}
|
||||
|
||||
if (videos != null) {
|
||||
this.videos = videos;
|
||||
}
|
||||
this.authors = authors ?? [];
|
||||
this.authorsGlobal = authorsGlobal ?? [];
|
||||
|
||||
lastUpdateGlobal = DateTime.now();
|
||||
return Exercise(
|
||||
id: id ?? this.id,
|
||||
uuid: uuid ?? this.uuid,
|
||||
created: created ?? this.created,
|
||||
lastUpdate: lastUpdate ?? this.lastUpdate,
|
||||
variationGroup: variationGroup ?? this.variationGroup,
|
||||
category: category ?? this.category,
|
||||
muscles: muscles ?? this.muscles,
|
||||
musclesSecondary: musclesSecondary ?? this.musclesSecondary,
|
||||
equipment: equipment ?? this.equipment,
|
||||
images: images ?? this.images,
|
||||
translations: translations ?? this.translations,
|
||||
videos: videos ?? this.videos,
|
||||
authors: authors ?? this.authors,
|
||||
authorsGlobal: authorsGlobal ?? this.authorsGlobal,
|
||||
);
|
||||
}
|
||||
|
||||
bool get showPlateCalculator => equipment.map((e) => e.id).contains(ID_EQUIPMENT_BARBELL);
|
||||
@@ -117,13 +115,13 @@ class Exercise extends Equatable {
|
||||
final languageCode = language.split('-')[0];
|
||||
|
||||
return translations.firstWhere(
|
||||
(e) => e.languageObj.shortName == languageCode,
|
||||
(e) => e.language.shortName == languageCode,
|
||||
orElse: () => translations.firstWhere(
|
||||
(e) => e.languageObj.shortName == LANGUAGE_SHORT_ENGLISH,
|
||||
(e) => e.language.shortName == LANGUAGE_SHORT_ENGLISH,
|
||||
orElse: () {
|
||||
_logger.info(
|
||||
'Could not find fallback english translation for exercise-ID $id, returning '
|
||||
'first language (${translations.first.languageObj.shortName}) instead.',
|
||||
'first language (${translations.first.language.shortName}) instead.',
|
||||
);
|
||||
return translations.first;
|
||||
},
|
||||
@@ -135,11 +133,6 @@ class Exercise extends Equatable {
|
||||
return images.firstWhereOrNull((image) => image.isMain);
|
||||
}
|
||||
|
||||
set setCategory(ExerciseCategory category) {
|
||||
categoryId = category.id;
|
||||
this.category = category;
|
||||
}
|
||||
|
||||
@override
|
||||
List<Object?> get props => [
|
||||
id,
|
||||
|
||||
@@ -16,6 +16,27 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/// Art style of an [ExerciseImage].
|
||||
///
|
||||
/// The wire values mirror Django's `ExerciseImage.STYLE` choices (`CharField`
|
||||
/// with `'1'`–`'5'`), so the same string round-trips through PowerSync
|
||||
/// without any extra mapping on the connector.
|
||||
enum ExerciseImageStyle {
|
||||
lineArt('1'),
|
||||
threeD('2'),
|
||||
lowPoly('3'),
|
||||
photo('4'),
|
||||
other('5')
|
||||
;
|
||||
|
||||
final String wireValue;
|
||||
const ExerciseImageStyle(this.wireValue);
|
||||
|
||||
/// Looks up an enum case by its Django wire value.
|
||||
static ExerciseImageStyle fromWire(String value) =>
|
||||
ExerciseImageStyle.values.firstWhere((e) => e.wireValue == value);
|
||||
}
|
||||
|
||||
class ExerciseImage {
|
||||
final int id;
|
||||
final String uuid;
|
||||
@@ -26,6 +47,23 @@ class ExerciseImage {
|
||||
final String image;
|
||||
|
||||
final bool isMain;
|
||||
final bool isAiGenerated;
|
||||
final ExerciseImageStyle style;
|
||||
|
||||
final int? width;
|
||||
final int? height;
|
||||
final DateTime created;
|
||||
final DateTime lastUpdate;
|
||||
|
||||
/// FK to the `License` row.
|
||||
final int licenseId;
|
||||
final String licenseTitle;
|
||||
final String licenseObjectUrl;
|
||||
|
||||
/// Author may be null on the server (`TextField(null=True)`).
|
||||
final String? licenseAuthor;
|
||||
final String licenseAuthorUrl;
|
||||
final String licenseDerivativeSourceUrl;
|
||||
|
||||
const ExerciseImage({
|
||||
required this.id,
|
||||
@@ -33,6 +71,18 @@ class ExerciseImage {
|
||||
required this.exerciseId,
|
||||
required this.image,
|
||||
required this.isMain,
|
||||
required this.isAiGenerated,
|
||||
required this.style,
|
||||
required this.width,
|
||||
required this.height,
|
||||
required this.created,
|
||||
required this.lastUpdate,
|
||||
required this.licenseId,
|
||||
required this.licenseTitle,
|
||||
required this.licenseObjectUrl,
|
||||
required this.licenseAuthor,
|
||||
required this.licenseAuthorUrl,
|
||||
required this.licenseDerivativeSourceUrl,
|
||||
});
|
||||
|
||||
@override
|
||||
|
||||
@@ -20,51 +20,33 @@ import 'package:equatable/equatable.dart';
|
||||
import 'package:wger/models/core/language.dart';
|
||||
import 'package:wger/models/exercises/alias.dart';
|
||||
import 'package:wger/models/exercises/comment.dart';
|
||||
import 'package:wger/models/exercises/exercise.dart';
|
||||
|
||||
class Translation extends Equatable {
|
||||
final int? id;
|
||||
final String? uuid;
|
||||
late final int languageId;
|
||||
late final Language languageObj;
|
||||
final Language language;
|
||||
final DateTime? created;
|
||||
late final int? exerciseId;
|
||||
final int? exerciseId;
|
||||
final String name;
|
||||
final String description;
|
||||
|
||||
final String descriptionSource;
|
||||
final List<Comment> notes;
|
||||
final List<Alias> aliases;
|
||||
|
||||
List<Comment> notes = [];
|
||||
List<Alias> aliases = [];
|
||||
int get languageId => language.id;
|
||||
|
||||
Translation({
|
||||
const Translation({
|
||||
this.id,
|
||||
this.uuid,
|
||||
this.created,
|
||||
required this.name,
|
||||
required this.description,
|
||||
this.descriptionSource = '',
|
||||
int? exerciseId,
|
||||
Language? language,
|
||||
}) {
|
||||
if (exerciseId != null) {
|
||||
this.exerciseId = exerciseId;
|
||||
}
|
||||
|
||||
if (language != null) {
|
||||
languageObj = language;
|
||||
languageId = language.id;
|
||||
}
|
||||
}
|
||||
|
||||
set exercise(Exercise exercise) {
|
||||
exerciseId = exercise.id;
|
||||
}
|
||||
|
||||
set language(Language language) {
|
||||
languageObj = language;
|
||||
languageId = language.id;
|
||||
}
|
||||
this.exerciseId,
|
||||
required this.language,
|
||||
this.notes = const [],
|
||||
this.aliases = const [],
|
||||
});
|
||||
|
||||
@override
|
||||
List<Object?> get props => [
|
||||
|
||||
@@ -19,32 +19,51 @@
|
||||
class Video {
|
||||
final int id;
|
||||
final String uuid;
|
||||
final int exerciseId;
|
||||
final bool isMain;
|
||||
|
||||
final String url;
|
||||
|
||||
Uri get uri => Uri.parse(url);
|
||||
|
||||
final int exerciseId;
|
||||
final int size;
|
||||
final num duration;
|
||||
final int width;
|
||||
final int height;
|
||||
final String codec;
|
||||
final String codecLong;
|
||||
final DateTime created;
|
||||
final DateTime lastUpdate;
|
||||
|
||||
/// FK to the `License` row.
|
||||
final int licenseId;
|
||||
final String licenseTitle;
|
||||
final String licenseObjectUrl;
|
||||
|
||||
/// Author may be null on the server (`TextField(null=True)`).
|
||||
final String? licenseAuthor;
|
||||
final String licenseAuthorUrl;
|
||||
final String licenseDerivativeSourceUrl;
|
||||
|
||||
const Video({
|
||||
required this.id,
|
||||
required this.uuid,
|
||||
required this.exerciseId,
|
||||
required this.size,
|
||||
required this.isMain,
|
||||
required this.url,
|
||||
required this.size,
|
||||
required this.duration,
|
||||
required this.width,
|
||||
required this.height,
|
||||
required this.codec,
|
||||
required this.codecLong,
|
||||
required this.created,
|
||||
required this.lastUpdate,
|
||||
required this.licenseId,
|
||||
required this.licenseTitle,
|
||||
required this.licenseObjectUrl,
|
||||
required this.licenseAuthor,
|
||||
required this.licenseAuthorUrl,
|
||||
required this.licenseDerivativeSourceUrl,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ T _$identity<T>(T value) => value;
|
||||
/// @nodoc
|
||||
mixin _$MeasurementCategory {
|
||||
|
||||
/// Client-generated UUID, is `null` only before the first persist
|
||||
String? get id; String get name; String get unit; List<MeasurementEntry> get entries;
|
||||
/// Create a copy of MeasurementCategory
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
|
||||
@@ -14,6 +14,7 @@ T _$identity<T>(T value) => value;
|
||||
/// @nodoc
|
||||
mixin _$MeasurementEntry {
|
||||
|
||||
/// Client-generated UUID, is `null` only before the first persist
|
||||
String? get id; String get categoryId; DateTime get date; num get value; String get notes;
|
||||
/// Create a copy of MeasurementEntry
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
|
||||
@@ -40,15 +40,31 @@ class IngredientImage {
|
||||
@JsonKey(required: true)
|
||||
final int size;
|
||||
|
||||
/// Image width in pixels
|
||||
@JsonKey(required: true)
|
||||
final int width;
|
||||
|
||||
/// Image height in pixels
|
||||
@JsonKey(required: true)
|
||||
final int height;
|
||||
|
||||
/// Server creation timestamp
|
||||
@JsonKey(required: true)
|
||||
final DateTime created;
|
||||
|
||||
/// Server last-modification timestamp
|
||||
@JsonKey(required: true, name: 'last_update')
|
||||
final DateTime lastUpdate;
|
||||
|
||||
// License information
|
||||
|
||||
/// License ID
|
||||
@JsonKey(required: true, name: 'license')
|
||||
final int licenseId;
|
||||
|
||||
/// Author(s)
|
||||
/// Author(s) — may be null on the server (`TextField(null=True)`)
|
||||
@JsonKey(required: true, name: 'license_author')
|
||||
final String author;
|
||||
final String? author;
|
||||
|
||||
/// Author profile, if available
|
||||
@JsonKey(required: true, name: 'license_author_url')
|
||||
@@ -72,6 +88,10 @@ class IngredientImage {
|
||||
required this.ingredientId,
|
||||
required this.image,
|
||||
required this.size,
|
||||
required this.width,
|
||||
required this.height,
|
||||
required this.created,
|
||||
required this.lastUpdate,
|
||||
required this.licenseId,
|
||||
required this.author,
|
||||
required this.authorUrl,
|
||||
|
||||
@@ -15,6 +15,10 @@ IngredientImage _$IngredientImageFromJson(Map<String, dynamic> json) {
|
||||
'ingredient_id',
|
||||
'image',
|
||||
'size',
|
||||
'width',
|
||||
'height',
|
||||
'created',
|
||||
'last_update',
|
||||
'license',
|
||||
'license_author',
|
||||
'license_author_url',
|
||||
@@ -29,8 +33,12 @@ IngredientImage _$IngredientImageFromJson(Map<String, dynamic> json) {
|
||||
ingredientId: (json['ingredient_id'] as num).toInt(),
|
||||
image: json['image'] as String,
|
||||
size: (json['size'] as num).toInt(),
|
||||
width: (json['width'] as num).toInt(),
|
||||
height: (json['height'] as num).toInt(),
|
||||
created: DateTime.parse(json['created'] as String),
|
||||
lastUpdate: DateTime.parse(json['last_update'] as String),
|
||||
licenseId: (json['license'] as num).toInt(),
|
||||
author: json['license_author'] as String,
|
||||
author: json['license_author'] as String?,
|
||||
authorUrl: json['license_author_url'] as String,
|
||||
title: json['license_title'] as String,
|
||||
objectUrl: json['license_object_url'] as String,
|
||||
@@ -44,6 +52,10 @@ Map<String, dynamic> _$IngredientImageToJson(IngredientImage instance) => <Strin
|
||||
'ingredient_id': instance.ingredientId,
|
||||
'image': instance.image,
|
||||
'size': instance.size,
|
||||
'width': instance.width,
|
||||
'height': instance.height,
|
||||
'created': instance.created.toIso8601String(),
|
||||
'last_update': instance.lastUpdate.toIso8601String(),
|
||||
'license': instance.licenseId,
|
||||
'license_author': instance.author,
|
||||
'license_author_url': instance.authorUrl,
|
||||
|
||||
Reference in New Issue
Block a user