87 lines
2.6 KiB
Dart
87 lines
2.6 KiB
Dart
|
|
enum ProjectStatus { active, archived }
|
||
|
|
|
||
|
|
enum ProjectCrs { eov, wgs84 }
|
||
|
|
|
||
|
|
class Project {
|
||
|
|
final int? id;
|
||
|
|
final String uuid;
|
||
|
|
final String name;
|
||
|
|
final String client; // megrendelő
|
||
|
|
final String description;
|
||
|
|
final ProjectCrs crs;
|
||
|
|
final String color; // hex, a UI-ban azonosításhoz
|
||
|
|
final ProjectStatus status;
|
||
|
|
final bool isLocalOnly;
|
||
|
|
final DateTime? lastSyncedAt;
|
||
|
|
final DateTime createdAt;
|
||
|
|
final DateTime updatedAt;
|
||
|
|
|
||
|
|
const Project({
|
||
|
|
this.id,
|
||
|
|
required this.uuid,
|
||
|
|
required this.name,
|
||
|
|
this.client = '',
|
||
|
|
this.description = '',
|
||
|
|
this.crs = ProjectCrs.eov,
|
||
|
|
this.color = '#185FA5',
|
||
|
|
this.status = ProjectStatus.active,
|
||
|
|
this.isLocalOnly = false,
|
||
|
|
this.lastSyncedAt,
|
||
|
|
required this.createdAt,
|
||
|
|
required this.updatedAt,
|
||
|
|
});
|
||
|
|
|
||
|
|
Project copyWith(
|
||
|
|
{String? name,
|
||
|
|
String? client,
|
||
|
|
String? description,
|
||
|
|
ProjectCrs? crs,
|
||
|
|
String? color,
|
||
|
|
ProjectStatus? status}) =>
|
||
|
|
Project(
|
||
|
|
id: id,
|
||
|
|
uuid: uuid,
|
||
|
|
name: name ?? this.name,
|
||
|
|
client: client ?? this.client,
|
||
|
|
description: description ?? this.description,
|
||
|
|
crs: crs ?? this.crs,
|
||
|
|
color: color ?? this.color,
|
||
|
|
status: status ?? this.status,
|
||
|
|
isLocalOnly: isLocalOnly,
|
||
|
|
lastSyncedAt: lastSyncedAt,
|
||
|
|
createdAt: createdAt,
|
||
|
|
updatedAt: DateTime.now(),
|
||
|
|
);
|
||
|
|
|
||
|
|
Map<String, dynamic> toMap() => {
|
||
|
|
if (id != null) 'id': id,
|
||
|
|
'uuid': uuid,
|
||
|
|
'name': name,
|
||
|
|
'client': client,
|
||
|
|
'description': description,
|
||
|
|
'crs': crs.name,
|
||
|
|
'color': color,
|
||
|
|
'status': status.name,
|
||
|
|
'isLocalOnly': isLocalOnly,
|
||
|
|
if (lastSyncedAt != null)
|
||
|
|
'last_synced_at': lastSyncedAt!.toIso8601String(),
|
||
|
|
'created_at': createdAt.toIso8601String(),
|
||
|
|
'updated_at': updatedAt.toIso8601String(),
|
||
|
|
};
|
||
|
|
|
||
|
|
factory Project.fromMap(Map<String, dynamic> m) => Project(
|
||
|
|
id: m['id'] as int?,
|
||
|
|
uuid: m['uuid'] as String,
|
||
|
|
name: m['name'] as String,
|
||
|
|
client: m['client'] as String? ?? '',
|
||
|
|
description: m['description'] as String? ?? '',
|
||
|
|
crs: ProjectCrs.values.byName(m['crs'] as String? ?? 'eov'),
|
||
|
|
color: m['color'] as String? ?? '#185FA5',
|
||
|
|
status: ProjectStatus.values.byName(m['status'] as String? ?? 'active'),
|
||
|
|
isLocalOnly: m['is__local_only'] as bool ?? true,
|
||
|
|
lastSyncedAt: DateTime.parse(m['last_synced_at'] as String),
|
||
|
|
createdAt: DateTime.parse(m['created_at'] as String),
|
||
|
|
updatedAt: DateTime.parse(m['updated_at'] as String),
|
||
|
|
);
|
||
|
|
}
|