feat: updated container management system with core models, providers, and UI pages

This commit is contained in:
ElPoyo
2026-05-26 21:34:35 +02:00
parent fb740d97a3
commit 64a9fe382a
13 changed files with 1363 additions and 797 deletions
+43 -21
View File
@@ -242,34 +242,55 @@ class ContainerModel {
/// Factory depuis Firestore
factory ContainerModel.fromMap(Map<String, dynamic> map, String id) {
// Fonction helper pour convertir Timestamp ou String ISO en DateTime
// Fonction helper pour convertir de manière sécurisée en double
double? parseDouble(dynamic value) {
if (value == null) return null;
if (value is num) return value.toDouble();
if (value is String) return double.tryParse(value);
return null;
}
// Fonction helper pour convertir Timestamp ou String ISO ou int epoch en DateTime
DateTime? parseDate(dynamic value) {
if (value == null) return null;
if (value is Timestamp) return value.toDate();
if (value is String) return DateTime.tryParse(value);
if (value is int) return DateTime.fromMillisecondsSinceEpoch(value);
return null;
}
final List<dynamic> equipmentIdsRaw = map['equipmentIds'] ?? [];
final List<String> equipmentIds = equipmentIdsRaw.map((e) => e.toString()).toList();
// Gestion sécurisée de la liste d'IDs d'équipements
final List<String> equipmentIds = [];
if (map['equipmentIds'] is List) {
for (final e in map['equipmentIds'] as List) {
if (e != null) {
equipmentIds.add(e.toString());
}
}
}
final List<dynamic> historyRaw = map['history'] ?? [];
final List<ContainerHistoryEntry> history = historyRaw
.map((e) => ContainerHistoryEntry.fromMap(e as Map<String, dynamic>))
.toList();
// Gestion sécurisée de l'historique
final List<ContainerHistoryEntry> history = [];
if (map['history'] is List) {
for (final e in map['history'] as List) {
if (e is Map<String, dynamic>) {
history.add(ContainerHistoryEntry.fromMap(e));
}
}
}
return ContainerModel(
id: id,
name: map['name'] ?? '',
type: containerTypeFromString(map['type']),
status: equipmentStatusFromString(map['status']),
weight: map['weight']?.toDouble(),
length: map['length']?.toDouble(),
width: map['width']?.toDouble(),
height: map['height']?.toDouble(),
name: (map['name'] ?? '').toString(),
type: containerTypeFromString(map['type']?.toString()),
status: equipmentStatusFromString(map['status']?.toString()),
weight: parseDouble(map['weight']),
length: parseDouble(map['length']),
width: parseDouble(map['width']),
height: parseDouble(map['height']),
equipmentIds: equipmentIds,
eventId: map['eventId'],
notes: map['notes'],
eventId: map['eventId']?.toString(),
notes: map['notes']?.toString(),
createdAt: parseDate(map['createdAt']) ?? DateTime.now(),
updatedAt: parseDate(map['updatedAt']) ?? DateTime.now(),
history: history,
@@ -355,16 +376,17 @@ class ContainerHistoryEntry {
if (value == null) return DateTime.now();
if (value is Timestamp) return value.toDate();
if (value is String) return DateTime.tryParse(value) ?? DateTime.now();
if (value is int) return DateTime.fromMillisecondsSinceEpoch(value);
return DateTime.now();
}
return ContainerHistoryEntry(
timestamp: parseDate(map['timestamp']),
action: map['action'] ?? '',
equipmentId: map['equipmentId'],
previousValue: map['previousValue'],
newValue: map['newValue'],
userId: map['userId'],
action: (map['action'] ?? '').toString(),
equipmentId: map['equipmentId']?.toString(),
previousValue: map['previousValue']?.toString(),
newValue: map['newValue']?.toString(),
userId: map['userId']?.toString(),
);
}