feat: updated container management system with core models, providers, and UI pages
This commit is contained in:
@@ -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(),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -387,40 +387,64 @@ class EquipmentModel {
|
||||
});
|
||||
|
||||
factory EquipmentModel.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 de manière sécurisée en int
|
||||
int? parseInt(dynamic value) {
|
||||
if (value == null) return null;
|
||||
if (value is num) return value.toInt();
|
||||
if (value is String) return int.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;
|
||||
}
|
||||
|
||||
// Gestion des listes
|
||||
final List<dynamic> maintenanceIdsRaw = map['maintenanceIds'] ?? [];
|
||||
final List<String> maintenanceIds = maintenanceIdsRaw.map((e) => e.toString()).toList();
|
||||
// Gestion sécurisée des listes d'IDs de maintenance
|
||||
final List<String> maintenanceIds = [];
|
||||
if (map['maintenanceIds'] is List) {
|
||||
for (final e in map['maintenanceIds'] as List) {
|
||||
if (e != null) {
|
||||
maintenanceIds.add(e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return EquipmentModel(
|
||||
id: id,
|
||||
name: map['name'] ?? '',
|
||||
brand: map['brand'],
|
||||
model: map['model'],
|
||||
category: equipmentCategoryFromString(map['category']),
|
||||
subCategory: map['subCategory'],
|
||||
status: equipmentStatusFromString(map['status']),
|
||||
purchasePrice: map['purchasePrice']?.toDouble(),
|
||||
rentalPrice: map['rentalPrice']?.toDouble(),
|
||||
totalQuantity: map['totalQuantity']?.toInt(),
|
||||
availableQuantity: map['availableQuantity']?.toInt(),
|
||||
criticalThreshold: map['criticalThreshold']?.toInt(),
|
||||
weight: map['weight']?.toDouble(),
|
||||
length: map['length']?.toDouble(),
|
||||
width: map['width']?.toDouble(),
|
||||
height: map['height']?.toDouble(),
|
||||
name: (map['name'] ?? '').toString(),
|
||||
brand: map['brand']?.toString(),
|
||||
model: map['model']?.toString(),
|
||||
category: equipmentCategoryFromString(map['category']?.toString()),
|
||||
subCategory: map['subCategory']?.toString(),
|
||||
status: equipmentStatusFromString(map['status']?.toString()),
|
||||
purchasePrice: parseDouble(map['purchasePrice']),
|
||||
rentalPrice: parseDouble(map['rentalPrice']),
|
||||
totalQuantity: parseInt(map['totalQuantity']),
|
||||
availableQuantity: parseInt(map['availableQuantity']),
|
||||
criticalThreshold: parseInt(map['criticalThreshold']),
|
||||
weight: parseDouble(map['weight']),
|
||||
length: parseDouble(map['length']),
|
||||
width: parseDouble(map['width']),
|
||||
height: parseDouble(map['height']),
|
||||
purchaseDate: parseDate(map['purchaseDate']),
|
||||
lastMaintenanceDate: parseDate(map['lastMaintenanceDate']),
|
||||
nextMaintenanceDate: parseDate(map['nextMaintenanceDate']),
|
||||
maintenanceIds: maintenanceIds,
|
||||
imageUrl: map['imageUrl'],
|
||||
notes: map['notes'],
|
||||
imageUrl: map['imageUrl']?.toString(),
|
||||
notes: map['notes']?.toString(),
|
||||
createdAt: parseDate(map['createdAt']) ?? DateTime.now(),
|
||||
updatedAt: parseDate(map['updatedAt']) ?? DateTime.now(),
|
||||
);
|
||||
|
||||
@@ -60,29 +60,44 @@ class MaintenanceModel {
|
||||
});
|
||||
|
||||
factory MaintenanceModel.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;
|
||||
}
|
||||
|
||||
// Gestion de la liste des équipements
|
||||
final List<dynamic> equipmentIdsRaw = map['equipmentIds'] ?? [];
|
||||
final List<String> equipmentIds = equipmentIdsRaw.map((e) => e.toString()).toList();
|
||||
final List<String> equipmentIds = [];
|
||||
if (map['equipmentIds'] is List) {
|
||||
for (final e in map['equipmentIds'] as List) {
|
||||
if (e != null) {
|
||||
equipmentIds.add(e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return MaintenanceModel(
|
||||
id: id,
|
||||
equipmentIds: equipmentIds,
|
||||
type: maintenanceTypeFromString(map['type']),
|
||||
type: maintenanceTypeFromString(map['type']?.toString()),
|
||||
scheduledDate: parseDate(map['scheduledDate']) ?? DateTime.now(),
|
||||
completedDate: parseDate(map['completedDate']),
|
||||
name: map['name'] ?? '',
|
||||
description: map['description'] ?? '',
|
||||
performedBy: map['performedBy'],
|
||||
cost: map['cost']?.toDouble(),
|
||||
notes: map['notes'],
|
||||
name: (map['name'] ?? '').toString(),
|
||||
description: (map['description'] ?? '').toString(),
|
||||
performedBy: map['performedBy']?.toString(),
|
||||
cost: parseDouble(map['cost']),
|
||||
notes: map['notes']?.toString(),
|
||||
createdAt: parseDate(map['createdAt']) ?? DateTime.now(),
|
||||
updatedAt: parseDate(map['updatedAt']) ?? DateTime.now(),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user