Ajout de statu d'événement (bouton non indéxé sur le status pour le moment
This commit is contained in:
@ -8,6 +8,7 @@ import 'package:em2rp/providers/event_provider.dart';
|
||||
import 'package:latlong2/latlong.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
import 'package:path/path.dart' as p;
|
||||
import 'package:cloud_firestore/cloud_firestore.dart';
|
||||
|
||||
class EventDetails extends StatelessWidget {
|
||||
final EventModel event;
|
||||
@ -80,13 +81,34 @@ class EventDetails extends StatelessWidget {
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
SelectableText(
|
||||
event.name,
|
||||
style: Theme.of(context).textTheme.headlineMedium?.copyWith(
|
||||
color: AppColors.noir,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
SelectableText(
|
||||
event.name,
|
||||
style: Theme.of(context).textTheme.headlineMedium?.copyWith(
|
||||
color: AppColors.noir,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
_buildStatusIcon(event.status),
|
||||
],
|
||||
),
|
||||
if (Provider.of<LocalUserProvider>(context, listen: false)
|
||||
.hasPermission('change_event_status'))
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 12.0),
|
||||
child: _FirestoreStatusButton(
|
||||
eventId: event.id,
|
||||
currentStatus: event.status,
|
||||
onStatusChanged: (newStatus) async {
|
||||
await FirebaseFirestore.instance
|
||||
.collection('events')
|
||||
.doc(event.id)
|
||||
.update({'status': eventStatusToString(newStatus)});
|
||||
},
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Expanded(
|
||||
child: SingleChildScrollView(
|
||||
@ -333,6 +355,34 @@ class EventDetails extends StatelessWidget {
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildStatusIcon(EventStatus status) {
|
||||
Color color;
|
||||
IconData icon;
|
||||
String tooltip;
|
||||
switch (status) {
|
||||
case EventStatus.confirmed:
|
||||
color = Colors.green;
|
||||
icon = Icons.check_circle;
|
||||
tooltip = 'Confirmé';
|
||||
break;
|
||||
case EventStatus.canceled:
|
||||
color = Colors.red;
|
||||
icon = Icons.cancel;
|
||||
tooltip = 'Annulé';
|
||||
break;
|
||||
case EventStatus.waitingForApproval:
|
||||
default:
|
||||
color = Colors.amber;
|
||||
icon = Icons.hourglass_empty;
|
||||
tooltip = 'En attente de validation';
|
||||
break;
|
||||
}
|
||||
return Tooltip(
|
||||
message: tooltip,
|
||||
child: Icon(icon, color: color, size: 28),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class EventAddDialog extends StatefulWidget {
|
||||
@ -573,3 +623,134 @@ class _EventAddDialogState extends State<EventAddDialog> {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _FirestoreStatusButton extends StatefulWidget {
|
||||
final String eventId;
|
||||
final EventStatus currentStatus;
|
||||
final Future<void> Function(EventStatus) onStatusChanged;
|
||||
const _FirestoreStatusButton(
|
||||
{required this.eventId,
|
||||
required this.currentStatus,
|
||||
required this.onStatusChanged});
|
||||
|
||||
@override
|
||||
State<_FirestoreStatusButton> createState() => _FirestoreStatusButtonState();
|
||||
}
|
||||
|
||||
class _FirestoreStatusButtonState extends State<_FirestoreStatusButton> {
|
||||
late EventStatus _status;
|
||||
bool _loading = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_status = widget.currentStatus;
|
||||
}
|
||||
|
||||
Future<void> changerStatut(EventStatus nouveau) async {
|
||||
if (_status == nouveau) return;
|
||||
setState(() => _loading = true);
|
||||
await FirebaseFirestore.instance
|
||||
.collection('events')
|
||||
.doc(widget.eventId)
|
||||
.update({'status': eventStatusToString(nouveau)});
|
||||
setState(() {
|
||||
_status = nouveau;
|
||||
_loading = false;
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
String texte;
|
||||
Color couleurFond;
|
||||
List<Widget> enfants = [];
|
||||
switch (_status) {
|
||||
case EventStatus.waitingForApproval:
|
||||
texte = "En Attente";
|
||||
couleurFond = Colors.yellow.shade600;
|
||||
enfants = [
|
||||
_buildIconButton(Icons.close, Colors.red,
|
||||
() => changerStatut(EventStatus.canceled)),
|
||||
_buildLabel(texte, couleurFond),
|
||||
_buildIconButton(Icons.check, Colors.green,
|
||||
() => changerStatut(EventStatus.confirmed)),
|
||||
];
|
||||
break;
|
||||
case EventStatus.confirmed:
|
||||
texte = "Confirmé";
|
||||
couleurFond = Colors.green;
|
||||
enfants = [
|
||||
_buildIconButton(Icons.close, Colors.red,
|
||||
() => changerStatut(EventStatus.canceled)),
|
||||
_buildIconButton(Icons.hourglass_empty, Colors.yellow.shade700,
|
||||
() => changerStatut(EventStatus.waitingForApproval)),
|
||||
_buildLabel(texte, couleurFond),
|
||||
];
|
||||
break;
|
||||
case EventStatus.canceled:
|
||||
texte = "Annulé";
|
||||
couleurFond = Colors.red;
|
||||
enfants = [
|
||||
_buildLabel(texte, couleurFond),
|
||||
_buildIconButton(Icons.hourglass_empty, Colors.yellow.shade700,
|
||||
() => changerStatut(EventStatus.waitingForApproval)),
|
||||
_buildIconButton(Icons.check, Colors.green,
|
||||
() => changerStatut(EventStatus.confirmed)),
|
||||
];
|
||||
break;
|
||||
}
|
||||
return AnimatedContainer(
|
||||
duration: const Duration(milliseconds: 200),
|
||||
padding: const EdgeInsets.all(2),
|
||||
decoration: const BoxDecoration(
|
||||
color: Colors.transparent,
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: enfants,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildLabel(String texte, Color couleur) {
|
||||
return AnimatedContainer(
|
||||
duration: const Duration(milliseconds: 200),
|
||||
margin: const EdgeInsets.symmetric(horizontal: 2),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
|
||||
decoration: BoxDecoration(
|
||||
color: couleur,
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
),
|
||||
child: AnimatedSwitcher(
|
||||
duration: const Duration(milliseconds: 200),
|
||||
child: Text(
|
||||
texte,
|
||||
key: ValueKey(texte),
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.bold, color: Colors.white, fontSize: 13),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildIconButton(
|
||||
IconData icone, Color couleur, VoidCallback onPressed) {
|
||||
return AnimatedContainer(
|
||||
duration: const Duration(milliseconds: 200),
|
||||
margin: const EdgeInsets.symmetric(horizontal: 2),
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(color: couleur, width: 1.5),
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
),
|
||||
child: IconButton(
|
||||
icon: Icon(icone, color: couleur, size: 16),
|
||||
onPressed: _loading ? null : onPressed,
|
||||
splashRadius: 16,
|
||||
tooltip: 'Changer statut',
|
||||
padding: const EdgeInsets.all(4),
|
||||
constraints: const BoxConstraints(minWidth: 28, minHeight: 28),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -213,6 +213,27 @@ class MonthView extends StatelessWidget {
|
||||
|
||||
Widget _buildEventItem(
|
||||
EventModel event, bool isSelected, DateTime currentDay) {
|
||||
Color color;
|
||||
Color textColor;
|
||||
IconData icon;
|
||||
switch (event.status) {
|
||||
case EventStatus.confirmed:
|
||||
color = Colors.green;
|
||||
textColor = Colors.white;
|
||||
icon = Icons.check;
|
||||
break;
|
||||
case EventStatus.canceled:
|
||||
color = Colors.red;
|
||||
textColor = Colors.white;
|
||||
icon = Icons.close;
|
||||
break;
|
||||
case EventStatus.waitingForApproval:
|
||||
default:
|
||||
color = Colors.amber;
|
||||
textColor = Colors.black;
|
||||
icon = Icons.hourglass_empty;
|
||||
break;
|
||||
}
|
||||
return GestureDetector(
|
||||
onTap: () {
|
||||
onDaySelected(currentDay, currentDay);
|
||||
@ -222,33 +243,40 @@ class MonthView extends StatelessWidget {
|
||||
margin: const EdgeInsets.only(bottom: 2),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 4, vertical: 2),
|
||||
decoration: BoxDecoration(
|
||||
color: isSelected
|
||||
? Colors.white.withAlpha(51)
|
||||
: AppColors.rouge.withAlpha(26),
|
||||
color: isSelected ? color.withAlpha(220) : color.withOpacity(0.18),
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Text(
|
||||
event.name,
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: isSelected ? Colors.white : AppColors.rouge,
|
||||
fontWeight: FontWeight.bold,
|
||||
Icon(icon, color: textColor, size: 16),
|
||||
const SizedBox(width: 4),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
event.name,
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: textColor,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
if (CalendarUtils.isMultiDayEvent(event))
|
||||
Text(
|
||||
'Jour ${CalendarUtils.calculateDayNumber(event.startDateTime, currentDay)}/${CalendarUtils.calculateTotalDays(event)}',
|
||||
style: TextStyle(
|
||||
fontSize: 10,
|
||||
color: textColor,
|
||||
),
|
||||
maxLines: 1,
|
||||
),
|
||||
],
|
||||
),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
if (CalendarUtils.isMultiDayEvent(event))
|
||||
Text(
|
||||
'Jour ${CalendarUtils.calculateDayNumber(event.startDateTime, event.startDateTime)}/${CalendarUtils.calculateTotalDays(event)}',
|
||||
style: TextStyle(
|
||||
fontSize: 10,
|
||||
color: isSelected ? Colors.white : AppColors.rouge,
|
||||
),
|
||||
maxLines: 1,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
@ -272,36 +272,47 @@ class WeekView extends StatelessWidget {
|
||||
padding: const EdgeInsets.all(4),
|
||||
decoration: BoxDecoration(
|
||||
color: isSelected
|
||||
? AppColors.rouge.withAlpha(80)
|
||||
: AppColors.rouge.withAlpha(26),
|
||||
? _getStatusColor(e.event.status).withAlpha(220)
|
||||
: _getStatusColor(e.event.status).withOpacity(0.18),
|
||||
border: Border.all(
|
||||
color: AppColors.rouge,
|
||||
color: _getStatusColor(e.event.status),
|
||||
width: isSelected ? 3 : 1,
|
||||
),
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Text(
|
||||
e.event.name,
|
||||
style: const TextStyle(
|
||||
color: AppColors.rouge,
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.bold,
|
||||
Icon(_getStatusIcon(e.event.status),
|
||||
color: _getStatusTextColor(e.event.status),
|
||||
size: 16),
|
||||
const SizedBox(width: 4),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
e.event.name,
|
||||
style: TextStyle(
|
||||
color: _getStatusTextColor(e.event.status),
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
if (CalendarUtils.isMultiDayEvent(e.event))
|
||||
Text(
|
||||
'Jour ${CalendarUtils.calculateDayNumber(e.event.startDateTime, weekStart.add(Duration(days: dayIdx)))}/${CalendarUtils.calculateTotalDays(e.event)}',
|
||||
style: TextStyle(
|
||||
color: _getStatusTextColor(e.event.status),
|
||||
fontSize: 10,
|
||||
),
|
||||
maxLines: 1,
|
||||
),
|
||||
],
|
||||
),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
if (CalendarUtils.isMultiDayEvent(e.event))
|
||||
Text(
|
||||
'Jour ${CalendarUtils.calculateDayNumber(e.event.startDateTime, weekStart.add(Duration(days: dayIdx)))}/${CalendarUtils.calculateTotalDays(e.event)}',
|
||||
style: const TextStyle(
|
||||
color: AppColors.rouge,
|
||||
fontSize: 10,
|
||||
),
|
||||
maxLines: 1,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
@ -377,6 +388,41 @@ class WeekView extends StatelessWidget {
|
||||
bool _overlap(_PositionedEvent a, _PositionedEvent b) {
|
||||
return a.end.isAfter(b.start) && a.start.isBefore(b.end);
|
||||
}
|
||||
|
||||
Color _getStatusColor(EventStatus status) {
|
||||
switch (status) {
|
||||
case EventStatus.confirmed:
|
||||
return Colors.green;
|
||||
case EventStatus.canceled:
|
||||
return Colors.red;
|
||||
case EventStatus.waitingForApproval:
|
||||
default:
|
||||
return Colors.amber;
|
||||
}
|
||||
}
|
||||
|
||||
Color _getStatusTextColor(EventStatus status) {
|
||||
switch (status) {
|
||||
case EventStatus.confirmed:
|
||||
case EventStatus.canceled:
|
||||
return Colors.white;
|
||||
case EventStatus.waitingForApproval:
|
||||
default:
|
||||
return Colors.black;
|
||||
}
|
||||
}
|
||||
|
||||
IconData _getStatusIcon(EventStatus status) {
|
||||
switch (status) {
|
||||
case EventStatus.confirmed:
|
||||
return Icons.check;
|
||||
case EventStatus.canceled:
|
||||
return Icons.close;
|
||||
case EventStatus.waitingForApproval:
|
||||
default:
|
||||
return Icons.hourglass_empty;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class _PositionedEvent {
|
||||
|
Reference in New Issue
Block a user