perf: nettoyage code mort, sécurisation clé, et remplacement des prints
This commit is contained in:
@@ -40,7 +40,7 @@ class AlertProvider extends ChangeNotifier {
|
||||
return AlertModel.fromMap(data as Map<String, dynamic>, data['id'] as String);
|
||||
}).toList();
|
||||
} catch (e) {
|
||||
print('Error loading alerts: $e');
|
||||
if (kDebugMode) debugPrint('Error loading alerts: $e');
|
||||
_alerts = [];
|
||||
} finally {
|
||||
_isLoading = false;
|
||||
@@ -67,7 +67,7 @@ class AlertProvider extends ChangeNotifier {
|
||||
notifyListeners();
|
||||
}
|
||||
} catch (e) {
|
||||
print('Error marking alert as read: $e');
|
||||
if (kDebugMode) debugPrint('Error marking alert as read: $e');
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
@@ -81,7 +81,7 @@ class AlertProvider extends ChangeNotifier {
|
||||
_alerts.removeWhere((a) => a.id == alertId);
|
||||
notifyListeners();
|
||||
} catch (e) {
|
||||
print('Error deleting alert: $e');
|
||||
if (kDebugMode) debugPrint('Error deleting alert: $e');
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
@@ -95,7 +95,7 @@ class AlertProvider extends ChangeNotifier {
|
||||
await markAsRead(alertId);
|
||||
}
|
||||
} catch (e) {
|
||||
print('Error marking all alerts as read: $e');
|
||||
if (kDebugMode) debugPrint('Error marking all alerts as read: $e');
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
@@ -109,7 +109,7 @@ class AlertProvider extends ChangeNotifier {
|
||||
await deleteAlert(alertId);
|
||||
}
|
||||
} catch (e) {
|
||||
print('Error deleting read alerts: $e');
|
||||
if (kDebugMode) debugPrint('Error deleting read alerts: $e');
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,62 +0,0 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:em2rp/models/alert_model.dart';
|
||||
import 'package:em2rp/services/data_service.dart';
|
||||
import 'package:em2rp/services/api_service.dart';
|
||||
|
||||
class AlertProvider extends ChangeNotifier {
|
||||
final DataService _dataService = DataService(FirebaseFunctionsApiService());
|
||||
|
||||
List<AlertModel> _alerts = [];
|
||||
bool _isLoading = false;
|
||||
|
||||
List<AlertModel> get alerts => _alerts;
|
||||
bool get isLoading => _isLoading;
|
||||
|
||||
/// Nombre d'alertes non lues
|
||||
int get unreadCount => _alerts.where((a) => !a.isRead).length;
|
||||
|
||||
/// Charger toutes les alertes via l'API
|
||||
Future<void> loadAlerts() async {
|
||||
_isLoading = true;
|
||||
notifyListeners();
|
||||
|
||||
try {
|
||||
final alertsData = await _dataService.getAlerts();
|
||||
|
||||
_alerts = alertsData.map((data) {
|
||||
return AlertModel.fromMap(data, data['id'] as String);
|
||||
}).toList();
|
||||
|
||||
_isLoading = false;
|
||||
notifyListeners();
|
||||
} catch (e) {
|
||||
print('Error loading alerts: $e');
|
||||
_isLoading = false;
|
||||
notifyListeners();
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
/// Recharger les alertes
|
||||
Future<void> refresh() async {
|
||||
await loadAlerts();
|
||||
}
|
||||
|
||||
/// Obtenir les alertes non lues
|
||||
List<AlertModel> get unreadAlerts {
|
||||
return _alerts.where((a) => !a.isRead).toList();
|
||||
}
|
||||
|
||||
/// Obtenir les alertes par type
|
||||
List<AlertModel> getByType(AlertType type) {
|
||||
return _alerts.where((a) => a.type == type).toList();
|
||||
}
|
||||
|
||||
/// Obtenir les alertes critiques (stock bas, équipement perdu)
|
||||
List<AlertModel> get criticalAlerts {
|
||||
return _alerts.where((a) =>
|
||||
a.type == AlertType.lowStock || a.type == AlertType.lost
|
||||
).toList();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ class ContainerProvider with ChangeNotifier {
|
||||
// Charger toutes les pages en boucle
|
||||
while (hasMore) {
|
||||
pageCount++;
|
||||
print('[ContainerProvider] Loading page $pageCount...');
|
||||
DebugLog.info('[ContainerProvider] Loading page $pageCount...');
|
||||
|
||||
final result = await _dataService.getContainersPaginated(
|
||||
limit: 100, // Charger 100 par page pour aller plus vite
|
||||
@@ -86,14 +86,14 @@ class ContainerProvider with ChangeNotifier {
|
||||
hasMore = result['hasMore'] as bool? ?? false;
|
||||
lastVisible = result['lastVisible'] as String?;
|
||||
|
||||
print('[ContainerProvider] Loaded ${containers.length} containers, total: ${_containers.length}, hasMore: $hasMore');
|
||||
DebugLog.info('[ContainerProvider] Loaded ${containers.length} containers, total: ${_containers.length}, hasMore: $hasMore');
|
||||
}
|
||||
|
||||
_isLoading = false;
|
||||
_isInitialized = true;
|
||||
notifyListeners();
|
||||
} catch (e) {
|
||||
print('Error loading containers: $e');
|
||||
DebugLog.error('[ContainerProvider] Error loading containers', e);
|
||||
_isLoading = false;
|
||||
notifyListeners();
|
||||
}
|
||||
@@ -292,7 +292,7 @@ class ContainerProvider with ChangeNotifier {
|
||||
Future<List<ContainerModel>> getContainersByIds(List<String> containerIds) async {
|
||||
if (containerIds.isEmpty) return [];
|
||||
|
||||
print('[ContainerProvider] Loading ${containerIds.length} containers by IDs...');
|
||||
DebugLog.info('[ContainerProvider] Loading ${containerIds.length} containers by IDs...');
|
||||
|
||||
try {
|
||||
// Vérifier d'abord le cache local
|
||||
@@ -320,7 +320,7 @@ class ContainerProvider with ChangeNotifier {
|
||||
}
|
||||
}
|
||||
|
||||
print('[ContainerProvider] Found ${cachedContainers.length} in cache, ${missingIds.length} missing');
|
||||
DebugLog.info('[ContainerProvider] Found ${cachedContainers.length} in cache, ${missingIds.length} missing');
|
||||
|
||||
// Si tous sont en cache, retourner directement
|
||||
if (missingIds.isEmpty) {
|
||||
@@ -341,12 +341,12 @@ class ContainerProvider with ChangeNotifier {
|
||||
}
|
||||
}
|
||||
|
||||
print('[ContainerProvider] Loaded ${loadedContainers.length} containers from API');
|
||||
DebugLog.info('[ContainerProvider] Loaded ${loadedContainers.length} containers from API');
|
||||
|
||||
// Retourner tous les conteneurs (cache + chargés)
|
||||
return [...cachedContainers, ...loadedContainers];
|
||||
} catch (e) {
|
||||
print('[ContainerProvider] Error loading containers by IDs: $e');
|
||||
DebugLog.error('[ContainerProvider] Error loading containers by IDs', e);
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,51 +0,0 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:em2rp/models/maintenance_model.dart';
|
||||
import 'package:em2rp/services/data_service.dart';
|
||||
import 'package:em2rp/services/api_service.dart';
|
||||
|
||||
class MaintenanceProvider extends ChangeNotifier {
|
||||
final DataService _dataService = DataService(FirebaseFunctionsApiService());
|
||||
|
||||
List<MaintenanceModel> _maintenances = [];
|
||||
bool _isLoading = false;
|
||||
|
||||
List<MaintenanceModel> get maintenances => _maintenances;
|
||||
bool get isLoading => _isLoading;
|
||||
|
||||
/// Charger toutes les maintenances via l'API
|
||||
Future<void> loadMaintenances({String? equipmentId}) async {
|
||||
_isLoading = true;
|
||||
notifyListeners();
|
||||
|
||||
try {
|
||||
final maintenancesData = await _dataService.getMaintenances(
|
||||
equipmentId: equipmentId,
|
||||
);
|
||||
|
||||
_maintenances = maintenancesData.map((data) {
|
||||
return MaintenanceModel.fromMap(data, data['id'] as String);
|
||||
}).toList();
|
||||
|
||||
_isLoading = false;
|
||||
notifyListeners();
|
||||
} catch (e) {
|
||||
print('Error loading maintenances: $e');
|
||||
_isLoading = false;
|
||||
notifyListeners();
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
/// Recharger les maintenances
|
||||
Future<void> refresh({String? equipmentId}) async {
|
||||
await loadMaintenances(equipmentId: equipmentId);
|
||||
}
|
||||
|
||||
/// Obtenir les maintenances pour un équipement spécifique
|
||||
List<MaintenanceModel> getForEquipment(String equipmentId) {
|
||||
return _maintenances.where((m) =>
|
||||
m.equipmentIds.contains(equipmentId)
|
||||
).toList();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user