Added delete schedule and no schedule message

This commit is contained in:
Juan Gilsanz Polo 2024-01-26 21:23:37 +01:00
parent 283d4e5c41
commit 770366eae6
3 changed files with 36 additions and 9 deletions

View file

@ -745,5 +745,6 @@
"to": "To: {to}", "to": "To: {to}",
"selectStartTime": "Select start time", "selectStartTime": "Select start time",
"selectEndTime": "Select end time", "selectEndTime": "Select end time",
"startTimeBeforeEndTime": "Start time must be before end time." "startTimeBeforeEndTime": "Start time must be before end time.",
"noBlockingScheduleThisDevice": "There's no blocking schedule for this device."
} }

View file

@ -745,5 +745,6 @@
"to": "Hasta: {to}", "to": "Hasta: {to}",
"selectStartTime": "Seleccionar hora de inicio", "selectStartTime": "Seleccionar hora de inicio",
"selectEndTime": "Seleccionar hora de fin", "selectEndTime": "Seleccionar hora de fin",
"startTimeBeforeEndTime": "La hora de inicio debe ser anterior a la hora de fin." "startTimeBeforeEndTime": "La hora de inicio debe ser anterior a la hora de fin.",
"noBlockingScheduleThisDevice": "No hay programación de bloqueo para este dispositivo."
} }

View file

@ -69,6 +69,12 @@ class BlockingSchedule extends StatelessWidget {
); );
} }
void onDeleteSchedule(String weekday) {
final scheduleJson = blockedServicesSchedule.toJson();
scheduleJson[weekday] = null;
setBlockedServicesSchedule(BlockedServicesSchedule.fromJson(scheduleJson));
}
String formatTime(int time) { String formatTime(int time) {
final formatted = Duration(milliseconds: time); final formatted = Duration(milliseconds: time);
final hours = formatted.inHours; final hours = formatted.inHours;
@ -92,47 +98,66 @@ class BlockingSchedule extends StatelessWidget {
], ],
), ),
const SizedBox(height: 2), const SizedBox(height: 2),
if (
blockedServicesSchedule.mon == null &&
blockedServicesSchedule.tue == null &&
blockedServicesSchedule.wed == null &&
blockedServicesSchedule.thu == null &&
blockedServicesSchedule.fri == null &&
blockedServicesSchedule.sat == null &&
blockedServicesSchedule.sun == null
) Padding(
padding: const EdgeInsets.all(16),
child: Text(
AppLocalizations.of(context)!.noBlockingScheduleThisDevice,
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 18,
color: Theme.of(context).colorScheme.onSurfaceVariant
),
),
),
if (blockedServicesSchedule.mon != null) _ScheduleTile( if (blockedServicesSchedule.mon != null) _ScheduleTile(
weekday: AppLocalizations.of(context)!.monday, weekday: AppLocalizations.of(context)!.monday,
schedule: "${formatTime(blockedServicesSchedule.mon!.start!)} - ${formatTime(blockedServicesSchedule.mon!.end!)}", schedule: "${formatTime(blockedServicesSchedule.mon!.start!)} - ${formatTime(blockedServicesSchedule.mon!.end!)}",
onEdit: () => openEditScheduleModal("mon"), onEdit: () => openEditScheduleModal("mon"),
onDelete: () => {} onDelete: () => onDeleteSchedule("mon")
), ),
if (blockedServicesSchedule.tue != null) _ScheduleTile( if (blockedServicesSchedule.tue != null) _ScheduleTile(
weekday: AppLocalizations.of(context)!.tuesday, weekday: AppLocalizations.of(context)!.tuesday,
schedule: "${formatTime(blockedServicesSchedule.tue!.start!)} - ${formatTime(blockedServicesSchedule.tue!.end!)}", schedule: "${formatTime(blockedServicesSchedule.tue!.start!)} - ${formatTime(blockedServicesSchedule.tue!.end!)}",
onEdit: () => openEditScheduleModal("tue"), onEdit: () => openEditScheduleModal("tue"),
onDelete: () => {} onDelete: () => onDeleteSchedule("tue")
), ),
if (blockedServicesSchedule.wed != null) _ScheduleTile( if (blockedServicesSchedule.wed != null) _ScheduleTile(
weekday: AppLocalizations.of(context)!.wednesday, weekday: AppLocalizations.of(context)!.wednesday,
schedule: "${formatTime(blockedServicesSchedule.wed!.start!)} - ${formatTime(blockedServicesSchedule.wed!.end!)}", schedule: "${formatTime(blockedServicesSchedule.wed!.start!)} - ${formatTime(blockedServicesSchedule.wed!.end!)}",
onEdit: () => openEditScheduleModal("wed"), onEdit: () => openEditScheduleModal("wed"),
onDelete: () => {} onDelete: () => onDeleteSchedule("wed")
), ),
if (blockedServicesSchedule.thu != null) _ScheduleTile( if (blockedServicesSchedule.thu != null) _ScheduleTile(
weekday: AppLocalizations.of(context)!.thursday, weekday: AppLocalizations.of(context)!.thursday,
schedule: "${formatTime(blockedServicesSchedule.thu!.start!)} - ${formatTime(blockedServicesSchedule.thu!.end!)}", schedule: "${formatTime(blockedServicesSchedule.thu!.start!)} - ${formatTime(blockedServicesSchedule.thu!.end!)}",
onEdit: () => openEditScheduleModal("thu"), onEdit: () => openEditScheduleModal("thu"),
onDelete: () => {} onDelete: () => onDeleteSchedule("thu")
), ),
if (blockedServicesSchedule.fri != null) _ScheduleTile( if (blockedServicesSchedule.fri != null) _ScheduleTile(
weekday: AppLocalizations.of(context)!.friday, weekday: AppLocalizations.of(context)!.friday,
schedule: "${formatTime(blockedServicesSchedule.fri!.start!)} - ${formatTime(blockedServicesSchedule.fri!.end!)}", schedule: "${formatTime(blockedServicesSchedule.fri!.start!)} - ${formatTime(blockedServicesSchedule.fri!.end!)}",
onEdit: () => openEditScheduleModal("fri"), onEdit: () => openEditScheduleModal("fri"),
onDelete: () => {} onDelete: () => onDeleteSchedule("fri")
), ),
if (blockedServicesSchedule.sat != null) _ScheduleTile( if (blockedServicesSchedule.sat != null) _ScheduleTile(
weekday: AppLocalizations.of(context)!.saturday, weekday: AppLocalizations.of(context)!.saturday,
schedule: "${formatTime(blockedServicesSchedule.sat!.start!)} - ${formatTime(blockedServicesSchedule.sat!.end!)}", schedule: "${formatTime(blockedServicesSchedule.sat!.start!)} - ${formatTime(blockedServicesSchedule.sat!.end!)}",
onEdit: () => openEditScheduleModal("sat"), onEdit: () => openEditScheduleModal("sat"),
onDelete: () => {} onDelete: () => onDeleteSchedule("sat")
), ),
if (blockedServicesSchedule.sun != null) _ScheduleTile( if (blockedServicesSchedule.sun != null) _ScheduleTile(
weekday: AppLocalizations.of(context)!.sunday, weekday: AppLocalizations.of(context)!.sunday,
schedule: "${formatTime(blockedServicesSchedule.sun!.start!)} - ${formatTime(blockedServicesSchedule.sun!.end!)}", schedule: "${formatTime(blockedServicesSchedule.sun!.start!)} - ${formatTime(blockedServicesSchedule.sun!.end!)}",
onEdit: () => openEditScheduleModal("sun"), onEdit: () => openEditScheduleModal("sun"),
onDelete: () => {} onDelete: () => onDeleteSchedule("sun")
), ),
], ],
); );