Merge branch 'perf/cleanup'
This commit is contained in:
@@ -2,3 +2,4 @@ node_modules/
|
||||
*.local
|
||||
.env
|
||||
.env.local
|
||||
serviceAccountKey.json
|
||||
|
||||
+4
-3
@@ -1,5 +1,7 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
import 'package:em2rp/providers/users_provider.dart';
|
||||
import 'package:em2rp/providers/event_provider.dart';
|
||||
import 'package:em2rp/providers/equipment_provider.dart';
|
||||
@@ -7,7 +9,6 @@ import 'package:em2rp/providers/container_provider.dart';
|
||||
import 'package:em2rp/providers/maintenance_provider.dart';
|
||||
import 'package:em2rp/providers/alert_provider.dart';
|
||||
import 'package:em2rp/utils/auth_guard_widget.dart';
|
||||
import 'package:em2rp/utils/performance_monitor.dart';
|
||||
import 'package:em2rp/views/alerts_page.dart';
|
||||
import 'package:em2rp/views/calendar_page.dart';
|
||||
import 'package:em2rp/views/login_page.dart';
|
||||
@@ -111,7 +112,7 @@ class _MyAppState extends State<MyApp> {
|
||||
if (FirebaseAuth.instance.currentUser != null) {
|
||||
unawaited(
|
||||
localAuthProvider.loadUserData().catchError((e) {
|
||||
print('User data bootstrap failed: $e');
|
||||
if (kDebugMode) debugPrint('User data bootstrap failed: $e');
|
||||
}),
|
||||
);
|
||||
return;
|
||||
@@ -125,7 +126,7 @@ class _MyAppState extends State<MyApp> {
|
||||
);
|
||||
unawaited(
|
||||
localAuthProvider.loadUserData().catchError((e) {
|
||||
print('Dev user bootstrap failed: $e');
|
||||
if (kDebugMode) debugPrint('Dev user bootstrap failed: $e');
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:em2rp/models/event_model.dart';
|
||||
import 'package:em2rp/models/equipment_model.dart';
|
||||
import 'package:em2rp/models/container_model.dart';
|
||||
@@ -84,7 +85,7 @@ class EventAvailabilityService {
|
||||
final conflicts = <AvailabilityConflict>[];
|
||||
|
||||
try {
|
||||
print('[EventAvailabilityService] Checking availability for equipment $equipmentId ($equipmentName)');
|
||||
if (kDebugMode) debugPrint('[EventAvailabilityService] Checking availability for equipment $equipmentId ($equipmentName)');
|
||||
|
||||
// Utiliser la Cloud Function pour vérifier la disponibilité
|
||||
final result = await _dataService.checkEquipmentAvailability(
|
||||
@@ -94,14 +95,14 @@ class EventAvailabilityService {
|
||||
excludeEventId: excludeEventId,
|
||||
);
|
||||
|
||||
print('[EventAvailabilityService] Result for $equipmentId: $result');
|
||||
if (kDebugMode) debugPrint('[EventAvailabilityService] Result for $equipmentId: $result');
|
||||
|
||||
final available = result['available'] as bool? ?? true;
|
||||
print('[EventAvailabilityService] Equipment $equipmentId available: $available');
|
||||
if (kDebugMode) debugPrint('[EventAvailabilityService] Equipment $equipmentId available: $available');
|
||||
|
||||
if (!available) {
|
||||
final conflictsData = result['conflicts'] as List<dynamic>? ?? [];
|
||||
print('[EventAvailabilityService] Found ${conflictsData.length} conflicts for equipment $equipmentId');
|
||||
if (kDebugMode) debugPrint('[EventAvailabilityService] Found ${conflictsData.length} conflicts for equipment $equipmentId');
|
||||
|
||||
for (final conflictData in conflictsData) {
|
||||
final conflict = conflictData as Map<String, dynamic>;
|
||||
@@ -119,19 +120,19 @@ class EventAvailabilityService {
|
||||
conflictingEvent: event,
|
||||
overlapDays: conflict['overlapDays'] as int? ?? 0,
|
||||
));
|
||||
print('[EventAvailabilityService] Added conflict with event ${event.name}');
|
||||
if (kDebugMode) debugPrint('[EventAvailabilityService] Added conflict with event ${event.name}');
|
||||
} catch (e) {
|
||||
print('[EventAvailabilityService] Error creating EventModel: $e');
|
||||
print('[EventAvailabilityService] EventData: $eventData');
|
||||
if (kDebugMode) debugPrint('[EventAvailabilityService] Error creating EventModel: $e');
|
||||
if (kDebugMode) debugPrint('[EventAvailabilityService] EventData: $eventData');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
print('[EventAvailabilityService] Error checking availability: $e');
|
||||
if (kDebugMode) debugPrint('[EventAvailabilityService] Error checking availability: $e');
|
||||
}
|
||||
|
||||
print('[EventAvailabilityService] Returning ${conflicts.length} conflicts for equipment $equipmentId');
|
||||
if (kDebugMode) debugPrint('[EventAvailabilityService] Returning ${conflicts.length} conflicts for equipment $equipmentId');
|
||||
return conflicts;
|
||||
}
|
||||
|
||||
@@ -234,11 +235,11 @@ class EventAvailabilityService {
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
print('[EventAvailabilityService] Error processing event $eventId for quantity: $e');
|
||||
if (kDebugMode) debugPrint('[EventAvailabilityService] Error processing event $eventId for quantity: $e');
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
print('[EventAvailabilityService] Error getting available quantity: $e');
|
||||
if (kDebugMode) debugPrint('[EventAvailabilityService] Error getting available quantity: $e');
|
||||
}
|
||||
|
||||
return totalQuantity - reservedQuantity;
|
||||
@@ -298,7 +299,7 @@ class EventAvailabilityService {
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
print('[EventAvailabilityService] Error processing event $eventId: $e');
|
||||
if (kDebugMode) debugPrint('[EventAvailabilityService] Error processing event $eventId: $e');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -361,7 +362,7 @@ class EventAvailabilityService {
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
print('[EventAvailabilityService] Error processing event $eventId: $e');
|
||||
if (kDebugMode) debugPrint('[EventAvailabilityService] Error processing event $eventId: $e');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user