Ajout de statu d'événement (bouton non indéxé sur le status pour le moment
This commit is contained in:
		| @@ -1,6 +1,36 @@ | ||||
| import 'package:cloud_firestore/cloud_firestore.dart'; | ||||
| import 'package:latlong2/latlong.dart'; | ||||
|  | ||||
| enum EventStatus { | ||||
|   confirmed, | ||||
|   canceled, | ||||
|   waitingForApproval, | ||||
| } | ||||
|  | ||||
| String eventStatusToString(EventStatus status) { | ||||
|   switch (status) { | ||||
|     case EventStatus.confirmed: | ||||
|       return 'CONFIRMED'; | ||||
|     case EventStatus.canceled: | ||||
|       return 'CANCELED'; | ||||
|     case EventStatus.waitingForApproval: | ||||
|     default: | ||||
|       return 'WAITING_FOR_APPROVAL'; | ||||
|   } | ||||
| } | ||||
|  | ||||
| EventStatus eventStatusFromString(String? status) { | ||||
|   switch (status) { | ||||
|     case 'CONFIRMED': | ||||
|       return EventStatus.confirmed; | ||||
|     case 'CANCELED': | ||||
|       return EventStatus.canceled; | ||||
|     case 'WAITING_FOR_APPROVAL': | ||||
|     default: | ||||
|       return EventStatus.waitingForApproval; | ||||
|   } | ||||
| } | ||||
|  | ||||
| class EventModel { | ||||
|   final String id; | ||||
|   final String name; | ||||
| @@ -18,6 +48,7 @@ class EventModel { | ||||
|   final List<DocumentReference> workforce; | ||||
|   final List<Map<String, String>> documents; | ||||
|   final List<Map<String, dynamic>> options; | ||||
|   final EventStatus status; | ||||
|  | ||||
|   EventModel({ | ||||
|     required this.id, | ||||
| @@ -36,6 +67,7 @@ class EventModel { | ||||
|     required this.workforce, | ||||
|     required this.documents, | ||||
|     this.options = const [], | ||||
|     this.status = EventStatus.waitingForApproval, | ||||
|   }); | ||||
|  | ||||
|   factory EventModel.fromMap(Map<String, dynamic> map, String id) { | ||||
| @@ -49,8 +81,9 @@ class EventModel { | ||||
|             if (e is Map) { | ||||
|               return Map<String, String>.from(e as Map); | ||||
|             } else if (e is String) { | ||||
|               final fileName = | ||||
|                   Uri.decodeComponent(e.split('/').last.split('?').first); | ||||
|               final fileName = Uri.decodeComponent( | ||||
|                 e.split('/').last.split('?').first, | ||||
|               ); | ||||
|               return {'name': fileName, 'url': e}; | ||||
|             } else { | ||||
|               return {}; | ||||
| @@ -89,6 +122,7 @@ class EventModel { | ||||
|       workforce: workforceRefs.whereType<DocumentReference>().toList(), | ||||
|       documents: docs, | ||||
|       options: options, | ||||
|       status: eventStatusFromString(map['status'] as String?), | ||||
|     ); | ||||
|   } | ||||
|  | ||||
| @@ -110,6 +144,7 @@ class EventModel { | ||||
|       'workforce': workforce, | ||||
|       'documents': documents, | ||||
|       'options': options, | ||||
|       'status': eventStatusToString(status), | ||||
|     }; | ||||
|   } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user