Alignement design systeme OK
This commit is contained in:
@@ -15,7 +15,7 @@ import 'keycloak_webview_auth_service.dart';
|
||||
/// Configuration Keycloak pour votre instance
|
||||
class KeycloakConfig {
|
||||
/// URL de base de votre Keycloak
|
||||
static const String baseUrl = 'http://192.168.1.145:8180';
|
||||
static const String baseUrl = 'http://192.168.1.11:8180';
|
||||
|
||||
/// Realm UnionFlow
|
||||
static const String realm = 'unionflow';
|
||||
@@ -193,9 +193,9 @@ class KeycloakAuthService {
|
||||
lastName: lastName,
|
||||
|
||||
primaryRole: primaryRole,
|
||||
organizationContexts: [], // À implémenter selon vos besoins
|
||||
organizationContexts: const [], // À implémenter selon vos besoins
|
||||
additionalPermissions: permissions,
|
||||
revokedPermissions: [],
|
||||
revokedPermissions: const [],
|
||||
preferences: const UserPreferences(),
|
||||
lastLoginAt: DateTime.now(),
|
||||
createdAt: DateTime.now(), // À récupérer depuis Keycloak si disponible
|
||||
|
||||
@@ -27,7 +27,7 @@ import 'keycloak_role_mapper.dart';
|
||||
/// Configuration Keycloak pour l'authentification WebView
|
||||
class KeycloakWebViewConfig {
|
||||
/// URL de base de l'instance Keycloak
|
||||
static const String baseUrl = 'http://192.168.1.145:8180';
|
||||
static const String baseUrl = 'http://192.168.1.11:8180';
|
||||
|
||||
/// Realm UnionFlow
|
||||
static const String realm = 'unionflow';
|
||||
@@ -273,7 +273,7 @@ class KeycloakWebViewAuthService {
|
||||
},
|
||||
body: body,
|
||||
)
|
||||
.timeout(Duration(seconds: KeycloakWebViewConfig.httpTimeoutSeconds));
|
||||
.timeout(const Duration(seconds: KeycloakWebViewConfig.httpTimeoutSeconds));
|
||||
|
||||
debugPrint('📡 Réponse token endpoint: ${response.statusCode}');
|
||||
|
||||
@@ -371,7 +371,7 @@ class KeycloakWebViewAuthService {
|
||||
}
|
||||
|
||||
// Vérifier l'issuer
|
||||
final String expectedIssuer = '${KeycloakWebViewConfig.baseUrl}/realms/${KeycloakWebViewConfig.realm}';
|
||||
const String expectedIssuer = '${KeycloakWebViewConfig.baseUrl}/realms/${KeycloakWebViewConfig.realm}';
|
||||
if (payload['iss'] != expectedIssuer) {
|
||||
throw KeycloakWebViewAuthException(
|
||||
'Token JWT invalide: issuer incorrect (attendu: $expectedIssuer, reçu: ${payload['iss']})',
|
||||
|
||||
@@ -0,0 +1,328 @@
|
||||
/// Modèle pour les critères de recherche avancée des membres
|
||||
/// Correspond au DTO Java MembreSearchCriteria
|
||||
class MembreSearchCriteria {
|
||||
/// Terme de recherche général (nom, prénom, email)
|
||||
final String? query;
|
||||
|
||||
/// Recherche par nom exact ou partiel
|
||||
final String? nom;
|
||||
|
||||
/// Recherche par prénom exact ou partiel
|
||||
final String? prenom;
|
||||
|
||||
/// Recherche par email exact ou partiel
|
||||
final String? email;
|
||||
|
||||
/// Filtre par numéro de téléphone
|
||||
final String? telephone;
|
||||
|
||||
/// Liste des IDs d'organisations
|
||||
final List<String>? organisationIds;
|
||||
|
||||
/// Liste des rôles à rechercher
|
||||
final List<String>? roles;
|
||||
|
||||
/// Filtre par statut d'activité
|
||||
final String? statut;
|
||||
|
||||
/// Date d'adhésion minimum (format ISO 8601)
|
||||
final String? dateAdhesionMin;
|
||||
|
||||
/// Date d'adhésion maximum (format ISO 8601)
|
||||
final String? dateAdhesionMax;
|
||||
|
||||
/// Âge minimum
|
||||
final int? ageMin;
|
||||
|
||||
/// Âge maximum
|
||||
final int? ageMax;
|
||||
|
||||
/// Filtre par région
|
||||
final String? region;
|
||||
|
||||
/// Filtre par ville
|
||||
final String? ville;
|
||||
|
||||
/// Filtre par profession
|
||||
final String? profession;
|
||||
|
||||
/// Filtre par nationalité
|
||||
final String? nationalite;
|
||||
|
||||
/// Filtre membres du bureau uniquement
|
||||
final bool? membreBureau;
|
||||
|
||||
/// Filtre responsables uniquement
|
||||
final bool? responsable;
|
||||
|
||||
/// Inclure les membres inactifs dans la recherche
|
||||
final bool includeInactifs;
|
||||
|
||||
const MembreSearchCriteria({
|
||||
this.query,
|
||||
this.nom,
|
||||
this.prenom,
|
||||
this.email,
|
||||
this.telephone,
|
||||
this.organisationIds,
|
||||
this.roles,
|
||||
this.statut,
|
||||
this.dateAdhesionMin,
|
||||
this.dateAdhesionMax,
|
||||
this.ageMin,
|
||||
this.ageMax,
|
||||
this.region,
|
||||
this.ville,
|
||||
this.profession,
|
||||
this.nationalite,
|
||||
this.membreBureau,
|
||||
this.responsable,
|
||||
this.includeInactifs = false,
|
||||
});
|
||||
|
||||
/// Factory constructor pour créer depuis JSON
|
||||
factory MembreSearchCriteria.fromJson(Map<String, dynamic> json) {
|
||||
return MembreSearchCriteria(
|
||||
query: json['query'] as String?,
|
||||
nom: json['nom'] as String?,
|
||||
prenom: json['prenom'] as String?,
|
||||
email: json['email'] as String?,
|
||||
telephone: json['telephone'] as String?,
|
||||
organisationIds: (json['organisationIds'] as List<dynamic>?)?.cast<String>(),
|
||||
roles: (json['roles'] as List<dynamic>?)?.cast<String>(),
|
||||
statut: json['statut'] as String?,
|
||||
dateAdhesionMin: json['dateAdhesionMin'] as String?,
|
||||
dateAdhesionMax: json['dateAdhesionMax'] as String?,
|
||||
ageMin: json['ageMin'] as int?,
|
||||
ageMax: json['ageMax'] as int?,
|
||||
region: json['region'] as String?,
|
||||
ville: json['ville'] as String?,
|
||||
profession: json['profession'] as String?,
|
||||
nationalite: json['nationalite'] as String?,
|
||||
membreBureau: json['membreBureau'] as bool?,
|
||||
responsable: json['responsable'] as bool?,
|
||||
includeInactifs: json['includeInactifs'] as bool? ?? false,
|
||||
);
|
||||
}
|
||||
|
||||
/// Convertit vers JSON
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'query': query,
|
||||
'nom': nom,
|
||||
'prenom': prenom,
|
||||
'email': email,
|
||||
'telephone': telephone,
|
||||
'organisationIds': organisationIds,
|
||||
'roles': roles,
|
||||
'statut': statut,
|
||||
'dateAdhesionMin': dateAdhesionMin,
|
||||
'dateAdhesionMax': dateAdhesionMax,
|
||||
'ageMin': ageMin,
|
||||
'ageMax': ageMax,
|
||||
'region': region,
|
||||
'ville': ville,
|
||||
'profession': profession,
|
||||
'nationalite': nationalite,
|
||||
'membreBureau': membreBureau,
|
||||
'responsable': responsable,
|
||||
'includeInactifs': includeInactifs,
|
||||
};
|
||||
}
|
||||
|
||||
/// Vérifie si au moins un critère de recherche est défini
|
||||
bool get hasAnyCriteria {
|
||||
return query?.isNotEmpty == true ||
|
||||
nom?.isNotEmpty == true ||
|
||||
prenom?.isNotEmpty == true ||
|
||||
email?.isNotEmpty == true ||
|
||||
telephone?.isNotEmpty == true ||
|
||||
organisationIds?.isNotEmpty == true ||
|
||||
roles?.isNotEmpty == true ||
|
||||
statut?.isNotEmpty == true ||
|
||||
dateAdhesionMin?.isNotEmpty == true ||
|
||||
dateAdhesionMax?.isNotEmpty == true ||
|
||||
ageMin != null ||
|
||||
ageMax != null ||
|
||||
region?.isNotEmpty == true ||
|
||||
ville?.isNotEmpty == true ||
|
||||
profession?.isNotEmpty == true ||
|
||||
nationalite?.isNotEmpty == true ||
|
||||
membreBureau != null ||
|
||||
responsable != null;
|
||||
}
|
||||
|
||||
/// Valide la cohérence des critères de recherche
|
||||
bool get isValid {
|
||||
// Validation des âges
|
||||
if (ageMin != null && ageMax != null) {
|
||||
if (ageMin! > ageMax!) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Validation des dates (si implémentée)
|
||||
if (dateAdhesionMin != null && dateAdhesionMax != null) {
|
||||
try {
|
||||
final dateMin = DateTime.parse(dateAdhesionMin!);
|
||||
final dateMax = DateTime.parse(dateAdhesionMax!);
|
||||
if (dateMin.isAfter(dateMax)) {
|
||||
return false;
|
||||
}
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// Retourne une description textuelle des critères actifs
|
||||
String get description {
|
||||
final parts = <String>[];
|
||||
|
||||
if (query?.isNotEmpty == true) parts.add("Recherche: '$query'");
|
||||
if (nom?.isNotEmpty == true) parts.add("Nom: '$nom'");
|
||||
if (prenom?.isNotEmpty == true) parts.add("Prénom: '$prenom'");
|
||||
if (email?.isNotEmpty == true) parts.add("Email: '$email'");
|
||||
if (statut?.isNotEmpty == true) parts.add("Statut: $statut");
|
||||
if (organisationIds?.isNotEmpty == true) {
|
||||
parts.add("Organisations: ${organisationIds!.length}");
|
||||
}
|
||||
if (roles?.isNotEmpty == true) {
|
||||
parts.add("Rôles: ${roles!.join(', ')}");
|
||||
}
|
||||
if (dateAdhesionMin?.isNotEmpty == true) {
|
||||
parts.add("Adhésion >= $dateAdhesionMin");
|
||||
}
|
||||
if (dateAdhesionMax?.isNotEmpty == true) {
|
||||
parts.add("Adhésion <= $dateAdhesionMax");
|
||||
}
|
||||
if (ageMin != null) parts.add("Âge >= $ageMin");
|
||||
if (ageMax != null) parts.add("Âge <= $ageMax");
|
||||
if (region?.isNotEmpty == true) parts.add("Région: '$region'");
|
||||
if (ville?.isNotEmpty == true) parts.add("Ville: '$ville'");
|
||||
if (profession?.isNotEmpty == true) parts.add("Profession: '$profession'");
|
||||
if (nationalite?.isNotEmpty == true) parts.add("Nationalité: '$nationalite'");
|
||||
if (membreBureau == true) parts.add("Membre bureau");
|
||||
if (responsable == true) parts.add("Responsable");
|
||||
|
||||
return parts.join(' • ');
|
||||
}
|
||||
|
||||
/// Crée une copie avec des modifications
|
||||
MembreSearchCriteria copyWith({
|
||||
String? query,
|
||||
String? nom,
|
||||
String? prenom,
|
||||
String? email,
|
||||
String? telephone,
|
||||
List<String>? organisationIds,
|
||||
List<String>? roles,
|
||||
String? statut,
|
||||
String? dateAdhesionMin,
|
||||
String? dateAdhesionMax,
|
||||
int? ageMin,
|
||||
int? ageMax,
|
||||
String? region,
|
||||
String? ville,
|
||||
String? profession,
|
||||
String? nationalite,
|
||||
bool? membreBureau,
|
||||
bool? responsable,
|
||||
bool? includeInactifs,
|
||||
}) {
|
||||
return MembreSearchCriteria(
|
||||
query: query ?? this.query,
|
||||
nom: nom ?? this.nom,
|
||||
prenom: prenom ?? this.prenom,
|
||||
email: email ?? this.email,
|
||||
telephone: telephone ?? this.telephone,
|
||||
organisationIds: organisationIds ?? this.organisationIds,
|
||||
roles: roles ?? this.roles,
|
||||
statut: statut ?? this.statut,
|
||||
dateAdhesionMin: dateAdhesionMin ?? this.dateAdhesionMin,
|
||||
dateAdhesionMax: dateAdhesionMax ?? this.dateAdhesionMax,
|
||||
ageMin: ageMin ?? this.ageMin,
|
||||
ageMax: ageMax ?? this.ageMax,
|
||||
region: region ?? this.region,
|
||||
ville: ville ?? this.ville,
|
||||
profession: profession ?? this.profession,
|
||||
nationalite: nationalite ?? this.nationalite,
|
||||
membreBureau: membreBureau ?? this.membreBureau,
|
||||
responsable: responsable ?? this.responsable,
|
||||
includeInactifs: includeInactifs ?? this.includeInactifs,
|
||||
);
|
||||
}
|
||||
|
||||
/// Critères vides
|
||||
static const empty = MembreSearchCriteria();
|
||||
|
||||
/// Critères pour recherche rapide par nom/prénom
|
||||
static MembreSearchCriteria quickSearch(String query) {
|
||||
return MembreSearchCriteria(query: query);
|
||||
}
|
||||
|
||||
/// Critères pour membres actifs uniquement
|
||||
static const activeMembers = MembreSearchCriteria(
|
||||
statut: 'ACTIF',
|
||||
includeInactifs: false,
|
||||
);
|
||||
|
||||
/// Critères pour membres du bureau
|
||||
static const bureauMembers = MembreSearchCriteria(
|
||||
membreBureau: true,
|
||||
statut: 'ACTIF',
|
||||
);
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) =>
|
||||
identical(this, other) ||
|
||||
other is MembreSearchCriteria &&
|
||||
runtimeType == other.runtimeType &&
|
||||
query == other.query &&
|
||||
nom == other.nom &&
|
||||
prenom == other.prenom &&
|
||||
email == other.email &&
|
||||
telephone == other.telephone &&
|
||||
organisationIds == other.organisationIds &&
|
||||
roles == other.roles &&
|
||||
statut == other.statut &&
|
||||
dateAdhesionMin == other.dateAdhesionMin &&
|
||||
dateAdhesionMax == other.dateAdhesionMax &&
|
||||
ageMin == other.ageMin &&
|
||||
ageMax == other.ageMax &&
|
||||
region == other.region &&
|
||||
ville == other.ville &&
|
||||
profession == other.profession &&
|
||||
nationalite == other.nationalite &&
|
||||
membreBureau == other.membreBureau &&
|
||||
responsable == other.responsable &&
|
||||
includeInactifs == other.includeInactifs;
|
||||
|
||||
@override
|
||||
int get hashCode => Object.hashAll([
|
||||
query,
|
||||
nom,
|
||||
prenom,
|
||||
email,
|
||||
telephone,
|
||||
organisationIds,
|
||||
roles,
|
||||
statut,
|
||||
dateAdhesionMin,
|
||||
dateAdhesionMax,
|
||||
ageMin,
|
||||
ageMax,
|
||||
region,
|
||||
ville,
|
||||
profession,
|
||||
nationalite,
|
||||
membreBureau,
|
||||
responsable,
|
||||
includeInactifs,
|
||||
]);
|
||||
|
||||
@override
|
||||
String toString() => 'MembreSearchCriteria(${description.isNotEmpty ? description : 'empty'})';
|
||||
}
|
||||
269
unionflow-mobile-apps/lib/core/models/membre_search_result.dart
Normal file
269
unionflow-mobile-apps/lib/core/models/membre_search_result.dart
Normal file
@@ -0,0 +1,269 @@
|
||||
import 'membre_search_criteria.dart';
|
||||
import '../../features/members/data/models/membre_model.dart';
|
||||
|
||||
/// Modèle pour les résultats de recherche avancée des membres
|
||||
/// Correspond au DTO Java MembreSearchResultDTO
|
||||
class MembreSearchResult {
|
||||
/// Liste des membres trouvés
|
||||
final List<MembreModel> membres;
|
||||
|
||||
/// Nombre total de résultats (toutes pages confondues)
|
||||
final int totalElements;
|
||||
|
||||
/// Nombre total de pages
|
||||
final int totalPages;
|
||||
|
||||
/// Numéro de la page actuelle (0-based)
|
||||
final int currentPage;
|
||||
|
||||
/// Taille de la page
|
||||
final int pageSize;
|
||||
|
||||
/// Nombre d'éléments sur la page actuelle
|
||||
final int numberOfElements;
|
||||
|
||||
/// Indique s'il y a une page suivante
|
||||
final bool hasNext;
|
||||
|
||||
/// Indique s'il y a une page précédente
|
||||
final bool hasPrevious;
|
||||
|
||||
/// Indique si c'est la première page
|
||||
final bool isFirst;
|
||||
|
||||
/// Indique si c'est la dernière page
|
||||
final bool isLast;
|
||||
|
||||
/// Critères de recherche utilisés
|
||||
final MembreSearchCriteria criteria;
|
||||
|
||||
/// Temps d'exécution de la recherche en millisecondes
|
||||
final int executionTimeMs;
|
||||
|
||||
/// Statistiques de recherche
|
||||
final SearchStatistics? statistics;
|
||||
|
||||
const MembreSearchResult({
|
||||
required this.membres,
|
||||
required this.totalElements,
|
||||
required this.totalPages,
|
||||
required this.currentPage,
|
||||
required this.pageSize,
|
||||
required this.numberOfElements,
|
||||
required this.hasNext,
|
||||
required this.hasPrevious,
|
||||
required this.isFirst,
|
||||
required this.isLast,
|
||||
required this.criteria,
|
||||
required this.executionTimeMs,
|
||||
this.statistics,
|
||||
});
|
||||
|
||||
/// Factory constructor pour créer depuis JSON
|
||||
factory MembreSearchResult.fromJson(Map<String, dynamic> json) {
|
||||
return MembreSearchResult(
|
||||
membres: (json['membres'] as List<dynamic>?)
|
||||
?.map((e) => MembreModel.fromJson(e as Map<String, dynamic>))
|
||||
.toList() ?? [],
|
||||
totalElements: json['totalElements'] as int? ?? 0,
|
||||
totalPages: json['totalPages'] as int? ?? 0,
|
||||
currentPage: json['currentPage'] as int? ?? 0,
|
||||
pageSize: json['pageSize'] as int? ?? 20,
|
||||
numberOfElements: json['numberOfElements'] as int? ?? 0,
|
||||
hasNext: json['hasNext'] as bool? ?? false,
|
||||
hasPrevious: json['hasPrevious'] as bool? ?? false,
|
||||
isFirst: json['isFirst'] as bool? ?? true,
|
||||
isLast: json['isLast'] as bool? ?? true,
|
||||
criteria: MembreSearchCriteria.fromJson(json['criteria'] as Map<String, dynamic>? ?? {}),
|
||||
executionTimeMs: json['executionTimeMs'] as int? ?? 0,
|
||||
statistics: json['statistics'] != null
|
||||
? SearchStatistics.fromJson(json['statistics'] as Map<String, dynamic>)
|
||||
: null,
|
||||
);
|
||||
}
|
||||
|
||||
/// Convertit vers JSON
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'membres': membres.map((e) => e.toJson()).toList(),
|
||||
'totalElements': totalElements,
|
||||
'totalPages': totalPages,
|
||||
'currentPage': currentPage,
|
||||
'pageSize': pageSize,
|
||||
'numberOfElements': numberOfElements,
|
||||
'hasNext': hasNext,
|
||||
'hasPrevious': hasPrevious,
|
||||
'isFirst': isFirst,
|
||||
'isLast': isLast,
|
||||
'criteria': criteria.toJson(),
|
||||
'executionTimeMs': executionTimeMs,
|
||||
'statistics': statistics?.toJson(),
|
||||
};
|
||||
}
|
||||
|
||||
/// Vérifie si les résultats sont vides
|
||||
bool get isEmpty => membres.isEmpty;
|
||||
|
||||
/// Vérifie si les résultats ne sont pas vides
|
||||
bool get isNotEmpty => membres.isNotEmpty;
|
||||
|
||||
/// Retourne le numéro de la page suivante (1-based pour affichage)
|
||||
int get nextPageNumber => hasNext ? currentPage + 2 : -1;
|
||||
|
||||
/// Retourne le numéro de la page précédente (1-based pour affichage)
|
||||
int get previousPageNumber => hasPrevious ? currentPage : -1;
|
||||
|
||||
/// Retourne une description textuelle des résultats
|
||||
String get resultDescription {
|
||||
if (isEmpty) {
|
||||
return 'Aucun membre trouvé';
|
||||
}
|
||||
|
||||
if (totalElements == 1) {
|
||||
return '1 membre trouvé';
|
||||
}
|
||||
|
||||
if (totalPages == 1) {
|
||||
return '$totalElements membres trouvés';
|
||||
}
|
||||
|
||||
final startElement = currentPage * pageSize + 1;
|
||||
final endElement = (startElement + numberOfElements - 1).clamp(1, totalElements);
|
||||
|
||||
return 'Membres $startElement-$endElement sur $totalElements (page ${currentPage + 1}/$totalPages)';
|
||||
}
|
||||
|
||||
/// Résultat vide
|
||||
static MembreSearchResult empty(MembreSearchCriteria criteria) {
|
||||
return MembreSearchResult(
|
||||
membres: const [],
|
||||
totalElements: 0,
|
||||
totalPages: 0,
|
||||
currentPage: 0,
|
||||
pageSize: 20,
|
||||
numberOfElements: 0,
|
||||
hasNext: false,
|
||||
hasPrevious: false,
|
||||
isFirst: true,
|
||||
isLast: true,
|
||||
criteria: criteria,
|
||||
executionTimeMs: 0,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() => 'MembreSearchResult($resultDescription, ${executionTimeMs}ms)';
|
||||
}
|
||||
|
||||
/// Statistiques sur les résultats de recherche
|
||||
class SearchStatistics {
|
||||
/// Nombre de membres actifs dans les résultats
|
||||
final int membresActifs;
|
||||
|
||||
/// Nombre de membres inactifs dans les résultats
|
||||
final int membresInactifs;
|
||||
|
||||
/// Âge moyen des membres trouvés
|
||||
final double ageMoyen;
|
||||
|
||||
/// Âge minimum des membres trouvés
|
||||
final int ageMin;
|
||||
|
||||
/// Âge maximum des membres trouvés
|
||||
final int ageMax;
|
||||
|
||||
/// Nombre d'organisations représentées
|
||||
final int nombreOrganisations;
|
||||
|
||||
/// Nombre de régions représentées
|
||||
final int nombreRegions;
|
||||
|
||||
/// Ancienneté moyenne en années
|
||||
final double ancienneteMoyenne;
|
||||
|
||||
const SearchStatistics({
|
||||
required this.membresActifs,
|
||||
required this.membresInactifs,
|
||||
required this.ageMoyen,
|
||||
required this.ageMin,
|
||||
required this.ageMax,
|
||||
required this.nombreOrganisations,
|
||||
required this.nombreRegions,
|
||||
required this.ancienneteMoyenne,
|
||||
});
|
||||
|
||||
/// Factory constructor pour créer depuis JSON
|
||||
factory SearchStatistics.fromJson(Map<String, dynamic> json) {
|
||||
return SearchStatistics(
|
||||
membresActifs: json['membresActifs'] as int? ?? 0,
|
||||
membresInactifs: json['membresInactifs'] as int? ?? 0,
|
||||
ageMoyen: (json['ageMoyen'] as num?)?.toDouble() ?? 0.0,
|
||||
ageMin: json['ageMin'] as int? ?? 0,
|
||||
ageMax: json['ageMax'] as int? ?? 0,
|
||||
nombreOrganisations: json['nombreOrganisations'] as int? ?? 0,
|
||||
nombreRegions: json['nombreRegions'] as int? ?? 0,
|
||||
ancienneteMoyenne: (json['ancienneteMoyenne'] as num?)?.toDouble() ?? 0.0,
|
||||
);
|
||||
}
|
||||
|
||||
/// Convertit vers JSON
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'membresActifs': membresActifs,
|
||||
'membresInactifs': membresInactifs,
|
||||
'ageMoyen': ageMoyen,
|
||||
'ageMin': ageMin,
|
||||
'ageMax': ageMax,
|
||||
'nombreOrganisations': nombreOrganisations,
|
||||
'nombreRegions': nombreRegions,
|
||||
'ancienneteMoyenne': ancienneteMoyenne,
|
||||
};
|
||||
}
|
||||
|
||||
/// Nombre total de membres
|
||||
int get totalMembres => membresActifs + membresInactifs;
|
||||
|
||||
/// Pourcentage de membres actifs
|
||||
double get pourcentageActifs {
|
||||
if (totalMembres == 0) return 0.0;
|
||||
return (membresActifs / totalMembres) * 100;
|
||||
}
|
||||
|
||||
/// Pourcentage de membres inactifs
|
||||
double get pourcentageInactifs {
|
||||
if (totalMembres == 0) return 0.0;
|
||||
return (membresInactifs / totalMembres) * 100;
|
||||
}
|
||||
|
||||
/// Tranche d'âge
|
||||
String get trancheAge {
|
||||
if (ageMin == ageMax) return '$ageMin ans';
|
||||
return '$ageMin-$ageMax ans';
|
||||
}
|
||||
|
||||
/// Description textuelle des statistiques
|
||||
String get description {
|
||||
final parts = <String>[];
|
||||
|
||||
if (totalMembres > 0) {
|
||||
parts.add('$totalMembres membres');
|
||||
if (membresActifs > 0) {
|
||||
parts.add('${pourcentageActifs.toStringAsFixed(1)}% actifs');
|
||||
}
|
||||
if (ageMoyen > 0) {
|
||||
parts.add('âge moyen: ${ageMoyen.toStringAsFixed(1)} ans');
|
||||
}
|
||||
if (nombreOrganisations > 0) {
|
||||
parts.add('$nombreOrganisations organisations');
|
||||
}
|
||||
if (ancienneteMoyenne > 0) {
|
||||
parts.add('ancienneté: ${ancienneteMoyenne.toStringAsFixed(1)} ans');
|
||||
}
|
||||
}
|
||||
|
||||
return parts.join(' • ');
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() => 'SearchStatistics($description)';
|
||||
}
|
||||
43
unionflow-mobile-apps/lib/core/navigation/app_router.dart
Normal file
43
unionflow-mobile-apps/lib/core/navigation/app_router.dart
Normal file
@@ -0,0 +1,43 @@
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
|
||||
import '../auth/bloc/auth_bloc.dart';
|
||||
import '../../features/auth/presentation/pages/login_page.dart';
|
||||
import 'main_navigation_layout.dart';
|
||||
|
||||
/// Configuration du routeur principal de l'application
|
||||
class AppRouter {
|
||||
static final GoRouter router = GoRouter(
|
||||
initialLocation: '/',
|
||||
redirect: (context, state) {
|
||||
final authState = context.read<AuthBloc>().state;
|
||||
final isAuthenticated = authState is AuthAuthenticated;
|
||||
final isOnLoginPage = state.matchedLocation == '/login';
|
||||
|
||||
// Si pas authentifié et pas sur la page de login, rediriger vers login
|
||||
if (!isAuthenticated && !isOnLoginPage) {
|
||||
return '/login';
|
||||
}
|
||||
|
||||
// Si authentifié et sur la page de login, rediriger vers dashboard
|
||||
if (isAuthenticated && isOnLoginPage) {
|
||||
return '/';
|
||||
}
|
||||
|
||||
return null; // Pas de redirection
|
||||
},
|
||||
routes: [
|
||||
GoRoute(
|
||||
path: '/login',
|
||||
name: 'login',
|
||||
builder: (context, state) => const LoginPage(),
|
||||
),
|
||||
GoRoute(
|
||||
path: '/',
|
||||
name: 'main',
|
||||
builder: (context, state) => const MainNavigationLayout(),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,419 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
|
||||
import '../auth/bloc/auth_bloc.dart';
|
||||
import '../auth/models/user_role.dart';
|
||||
|
||||
import '../design_system/tokens/tokens.dart';
|
||||
import '../../features/dashboard/presentation/pages/role_dashboards/role_dashboards.dart';
|
||||
import '../../features/members/presentation/pages/members_page.dart';
|
||||
import '../../features/events/presentation/pages/events_page.dart';
|
||||
|
||||
/// Layout principal avec navigation hybride
|
||||
/// Bottom Navigation pour les sections principales + Drawer pour fonctions avancées
|
||||
class MainNavigationLayout extends StatefulWidget {
|
||||
const MainNavigationLayout({super.key});
|
||||
|
||||
@override
|
||||
State<MainNavigationLayout> createState() => _MainNavigationLayoutState();
|
||||
}
|
||||
|
||||
class _MainNavigationLayoutState extends State<MainNavigationLayout> {
|
||||
int _selectedIndex = 0;
|
||||
|
||||
/// Obtient le dashboard approprié selon le rôle de l'utilisateur
|
||||
Widget _getDashboardForRole(UserRole role) {
|
||||
switch (role) {
|
||||
case UserRole.superAdmin:
|
||||
return const SuperAdminDashboard();
|
||||
case UserRole.orgAdmin:
|
||||
return const OrgAdminDashboard();
|
||||
case UserRole.moderator:
|
||||
return const ModeratorDashboard();
|
||||
case UserRole.activeMember:
|
||||
return const ActiveMemberDashboard();
|
||||
case UserRole.simpleMember:
|
||||
return const SimpleMemberDashboard();
|
||||
case UserRole.visitor:
|
||||
return const VisitorDashboard();
|
||||
}
|
||||
}
|
||||
|
||||
List<Widget> _getPages(UserRole role) {
|
||||
return [
|
||||
_getDashboardForRole(role),
|
||||
const MembersPage(),
|
||||
const EventsPage(),
|
||||
const MorePage(), // Page "Plus" qui affiche les options avancées
|
||||
];
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocBuilder<AuthBloc, AuthState>(
|
||||
builder: (context, state) {
|
||||
if (state is! AuthAuthenticated) {
|
||||
return const Scaffold(
|
||||
body: Center(child: CircularProgressIndicator()),
|
||||
);
|
||||
}
|
||||
|
||||
return Scaffold(
|
||||
body: IndexedStack(
|
||||
index: _selectedIndex,
|
||||
children: _getPages(state.effectiveRole),
|
||||
),
|
||||
bottomNavigationBar: BottomNavigationBar(
|
||||
type: BottomNavigationBarType.fixed,
|
||||
currentIndex: _selectedIndex,
|
||||
onTap: (index) {
|
||||
setState(() {
|
||||
_selectedIndex = index;
|
||||
});
|
||||
},
|
||||
selectedItemColor: ColorTokens.primary,
|
||||
unselectedItemColor: Colors.grey,
|
||||
items: const [
|
||||
BottomNavigationBarItem(
|
||||
icon: Icon(Icons.dashboard),
|
||||
label: 'Dashboard',
|
||||
),
|
||||
BottomNavigationBarItem(
|
||||
icon: Icon(Icons.people),
|
||||
label: 'Membres',
|
||||
),
|
||||
BottomNavigationBarItem(
|
||||
icon: Icon(Icons.event),
|
||||
label: 'Événements',
|
||||
),
|
||||
BottomNavigationBarItem(
|
||||
icon: Icon(Icons.more_horiz),
|
||||
label: 'Plus',
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Page "Plus" avec les fonctions avancées selon le rôle
|
||||
class MorePage extends StatelessWidget {
|
||||
const MorePage({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocBuilder<AuthBloc, AuthState>(
|
||||
builder: (context, state) {
|
||||
if (state is! AuthAuthenticated) {
|
||||
return Container(
|
||||
color: const Color(0xFFF8F9FA),
|
||||
child: const Center(child: CircularProgressIndicator()),
|
||||
);
|
||||
}
|
||||
|
||||
return Container(
|
||||
color: const Color(0xFFF8F9FA),
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(12),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// Titre de la section
|
||||
const Text(
|
||||
'Plus d\'Options',
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Color(0xFF6C5CE7),
|
||||
fontSize: 20,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
|
||||
// Profil utilisateur
|
||||
_buildUserProfile(state),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// Options selon le rôle
|
||||
..._buildRoleBasedOptions(state),
|
||||
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// Options communes
|
||||
..._buildCommonOptions(context),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildUserProfile(AuthAuthenticated state) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(12),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withOpacity(0.05),
|
||||
blurRadius: 4,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 50,
|
||||
height: 50,
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFF6C5CE7),
|
||||
borderRadius: BorderRadius.circular(25),
|
||||
),
|
||||
child: Center(
|
||||
child: Text(
|
||||
state.user.firstName.isNotEmpty ? state.user.firstName[0].toUpperCase() : 'U',
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'${state.user.firstName} ${state.user.lastName}',
|
||||
style: const TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Color(0xFF374151),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
state.effectiveRole.displayName,
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
color: Color(0xFF6C5CE7),
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
state.user.email,
|
||||
style: const TextStyle(
|
||||
fontSize: 12,
|
||||
color: Color(0xFF6B7280),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
List<Widget> _buildRoleBasedOptions(AuthAuthenticated state) {
|
||||
final options = <Widget>[];
|
||||
|
||||
// Options Super Admin
|
||||
if (state.effectiveRole == UserRole.superAdmin) {
|
||||
options.addAll([
|
||||
_buildSectionTitle('Administration Système'),
|
||||
_buildOptionTile(
|
||||
icon: Icons.settings,
|
||||
title: 'Paramètres Système',
|
||||
subtitle: 'Configuration globale',
|
||||
onTap: () {},
|
||||
),
|
||||
_buildOptionTile(
|
||||
icon: Icons.backup,
|
||||
title: 'Sauvegarde',
|
||||
subtitle: 'Gestion des sauvegardes',
|
||||
onTap: () {},
|
||||
),
|
||||
_buildOptionTile(
|
||||
icon: Icons.analytics,
|
||||
title: 'Logs Système',
|
||||
subtitle: 'Surveillance et logs',
|
||||
onTap: () {},
|
||||
),
|
||||
]);
|
||||
}
|
||||
|
||||
// Options Admin Organisation
|
||||
if (state.effectiveRole == UserRole.orgAdmin || state.effectiveRole == UserRole.superAdmin) {
|
||||
options.addAll([
|
||||
_buildSectionTitle('Administration'),
|
||||
_buildOptionTile(
|
||||
icon: Icons.business,
|
||||
title: 'Gestion Organisation',
|
||||
subtitle: 'Paramètres organisation',
|
||||
onTap: () {},
|
||||
),
|
||||
_buildOptionTile(
|
||||
icon: Icons.assessment,
|
||||
title: 'Rapports',
|
||||
subtitle: 'Rapports et statistiques',
|
||||
onTap: () {},
|
||||
),
|
||||
]);
|
||||
}
|
||||
|
||||
// Options RH
|
||||
if (state.effectiveRole == UserRole.moderator || state.effectiveRole == UserRole.superAdmin) {
|
||||
options.addAll([
|
||||
_buildSectionTitle('Ressources Humaines'),
|
||||
_buildOptionTile(
|
||||
icon: Icons.people_alt,
|
||||
title: 'Gestion RH',
|
||||
subtitle: 'Outils RH avancés',
|
||||
onTap: () {},
|
||||
),
|
||||
]);
|
||||
}
|
||||
|
||||
return options;
|
||||
}
|
||||
|
||||
List<Widget> _buildCommonOptions(BuildContext context) {
|
||||
return [
|
||||
_buildSectionTitle('Général'),
|
||||
_buildOptionTile(
|
||||
icon: Icons.person,
|
||||
title: 'Mon Profil',
|
||||
subtitle: 'Modifier mes informations',
|
||||
onTap: () {},
|
||||
),
|
||||
_buildOptionTile(
|
||||
icon: Icons.notifications,
|
||||
title: 'Notifications',
|
||||
subtitle: 'Gérer les notifications',
|
||||
onTap: () {},
|
||||
),
|
||||
_buildOptionTile(
|
||||
icon: Icons.help,
|
||||
title: 'Aide & Support',
|
||||
subtitle: 'Documentation et support',
|
||||
onTap: () {},
|
||||
),
|
||||
_buildOptionTile(
|
||||
icon: Icons.info,
|
||||
title: 'À propos',
|
||||
subtitle: 'Version et informations',
|
||||
onTap: () {},
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_buildOptionTile(
|
||||
icon: Icons.logout,
|
||||
title: 'Déconnexion',
|
||||
subtitle: 'Se déconnecter de l\'application',
|
||||
color: Colors.red,
|
||||
onTap: () {
|
||||
context.read<AuthBloc>().add(AuthLogoutRequested());
|
||||
},
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
Widget _buildSectionTitle(String title) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(
|
||||
top: 16,
|
||||
bottom: 8,
|
||||
),
|
||||
child: Text(
|
||||
title,
|
||||
style: const TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Color(0xFF6C5CE7),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildOptionTile({
|
||||
required IconData icon,
|
||||
required String title,
|
||||
required String subtitle,
|
||||
required VoidCallback onTap,
|
||||
Color? color,
|
||||
}) {
|
||||
return Container(
|
||||
margin: const EdgeInsets.only(bottom: 8),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withOpacity(0.05),
|
||||
blurRadius: 4,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: InkWell(
|
||||
onTap: onTap,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(12),
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.all(8),
|
||||
decoration: BoxDecoration(
|
||||
color: (color ?? const Color(0xFF6C5CE7)).withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
),
|
||||
child: Icon(
|
||||
icon,
|
||||
color: color ?? const Color(0xFF6C5CE7),
|
||||
size: 20,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
title,
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: color ?? const Color(0xFF374151),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
subtitle,
|
||||
style: const TextStyle(
|
||||
fontSize: 12,
|
||||
color: Color(0xFF6B7280),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const Icon(
|
||||
Icons.chevron_right,
|
||||
color: Color(0xFF6B7280),
|
||||
size: 16,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user