feat: Add dashboard layout with sidebar and main content area
- Implemented AppFooter widget for mobile and desktop views. - Created ChildrenSidebar widget to display children's information. - Developed AppLayout to manage app structure with optional footer. - Added ChildrenSidebar for selecting children and displaying their status. - Introduced DashboardAppBar for navigation and user actions. - Built WMainContentArea for displaying assistant details and calendar. - Created MainContentArea to manage contracts and events display. - Implemented MessagingSidebar for messaging functionality. - Updated widget tests to reflect new structure and imports.
This commit is contained in:
@@ -0,0 +1,138 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:p_tits_pas/models/m_dashbord/assistant_model.dart';
|
||||
import 'package:p_tits_pas/models/m_dashbord/child_model.dart';
|
||||
import 'package:p_tits_pas/models/m_dashbord/contract_model.dart';
|
||||
import 'package:p_tits_pas/models/m_dashbord/conversation_model.dart';
|
||||
import 'package:p_tits_pas/models/m_dashbord/event_model.dart';
|
||||
import 'package:p_tits_pas/models/m_dashbord/notification_model.dart';
|
||||
import 'package:p_tits_pas/services/dashboardService.dart';
|
||||
|
||||
class ParentDashboardController extends ChangeNotifier {
|
||||
final DashboardService _dashboardService;
|
||||
|
||||
ParentDashboardController(this._dashboardService);
|
||||
|
||||
// État des données
|
||||
List<ChildModel> _children = [];
|
||||
String? _selectedChildId;
|
||||
AssistantModel? _selectedAssistant;
|
||||
List<EventModel> _upcomingEvents = [];
|
||||
List<ContractModel> _contracts = [];
|
||||
List<ConversationModel> _conversations = [];
|
||||
List<NotificationModel> _notifications = [];
|
||||
|
||||
// État de chargement
|
||||
bool _isLoading = false;
|
||||
String? _error;
|
||||
|
||||
// Getters
|
||||
List<ChildModel> get children => _children;
|
||||
String? get selectedChildId => _selectedChildId;
|
||||
ChildModel? get selectedChild => _children.where((c) => c.id == _selectedChildId).firstOrNull;
|
||||
AssistantModel? get selectedAssistant => _selectedAssistant;
|
||||
List<EventModel> get upcomingEvents => _upcomingEvents;
|
||||
List<ContractModel> get contracts => _contracts;
|
||||
List<ConversationModel> get conversations => _conversations;
|
||||
List<NotificationModel> get notifications => _notifications;
|
||||
bool get isLoading => _isLoading;
|
||||
String? get error => _error;
|
||||
|
||||
// Initialisation du dashboard
|
||||
Future<void> initDashboard() async {
|
||||
_isLoading = true;
|
||||
_error = null;
|
||||
notifyListeners();
|
||||
|
||||
try {
|
||||
await Future.wait([
|
||||
_loadChildren(),
|
||||
_loadUpcomingEvents(),
|
||||
_loadContracts(),
|
||||
_loadConversations(),
|
||||
_loadNotifications(),
|
||||
]);
|
||||
|
||||
// Sélectionner le premier enfant par défaut
|
||||
if (_children.isNotEmpty && _selectedChildId == null) {
|
||||
await selectChild(_children.first.id);
|
||||
}
|
||||
} catch (e) {
|
||||
_error = 'Erreur lors du chargement du tableau de bord: $e';
|
||||
} finally {
|
||||
_isLoading = false;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
// Sélection d'un enfant
|
||||
Future<void> selectChild(String childId) async {
|
||||
_selectedChildId = childId;
|
||||
notifyListeners();
|
||||
|
||||
// Charger les données spécifiques à cet enfant
|
||||
await _loadChildSpecificData(childId);
|
||||
}
|
||||
|
||||
// Afficher le modal d'ajout d'enfant
|
||||
void showAddChildModal() {
|
||||
// Logique pour ouvrir le modal d'ajout d'enfant
|
||||
// Sera implémentée dans le ticket FRONT-09
|
||||
}
|
||||
|
||||
// Méthodes privées de chargement des données
|
||||
Future<void> _loadChildren() async {
|
||||
_children = await _dashboardService.getChildren();
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<void> _loadChildSpecificData(String childId) async {
|
||||
try {
|
||||
// Charger l'assistante maternelle associée à cet enfant
|
||||
_selectedAssistant = await _dashboardService.getAssistantForChild(childId);
|
||||
|
||||
// Filtrer les événements et contrats pour cet enfant
|
||||
_upcomingEvents = await _dashboardService.getEventsForChild(childId);
|
||||
_contracts = await _dashboardService.getContractsForChild(childId);
|
||||
|
||||
notifyListeners();
|
||||
} catch (e) {
|
||||
_error = 'Erreur lors du chargement des données pour l\'enfant: $e';
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _loadUpcomingEvents() async {
|
||||
_upcomingEvents = await _dashboardService.getUpcomingEvents();
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<void> _loadContracts() async {
|
||||
_contracts = await _dashboardService.getContracts();
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<void> _loadConversations() async {
|
||||
_conversations = await _dashboardService.getConversations();
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<void> _loadNotifications() async {
|
||||
_notifications = await _dashboardService.getNotifications();
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
// Méthodes d'action
|
||||
Future<void> markNotificationAsRead(String notificationId) async {
|
||||
try {
|
||||
await _dashboardService.markNotificationAsRead(notificationId);
|
||||
await _loadNotifications(); // Recharger les notifications
|
||||
} catch (e) {
|
||||
_error = 'Erreur lors du marquage de la notification: $e';
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> refreshDashboard() async {
|
||||
await initDashboard();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user