Implemented schedule deletion

This commit is contained in:
Igor Scheller 2023-12-08 21:25:24 +01:00 committed by Michael Weimann
parent d89fe01ddd
commit 15a6ba1c52
8 changed files with 71 additions and 13 deletions

View File

@ -110,6 +110,10 @@ class ImportSchedule extends BaseController
/** @var ScheduleUrl $schedule */
$schedule = ScheduleUrl::findOrNew($scheduleId);
if ($request->request->has('delete')) {
return $this->delete($schedule);
}
$data = $this->validate($request, [
'name' => 'required',
'url' => 'required',
@ -146,6 +150,34 @@ class ImportSchedule extends BaseController
return redirect('/admin/schedule/load/' . $schedule->id);
}
protected function delete(ScheduleUrl $schedule): Response
{
foreach ($schedule->scheduleShifts as $scheduleShift) {
// Only guid is needed here
$event = new Event(
$scheduleShift->guid,
0,
new Room(''),
'',
'',
'',
Carbon::now(),
'',
'',
'',
'',
''
);
$this->fireDeleteShiftEntryEvents($event);
$this->deleteEvent($event);
}
$schedule->delete();
$this->addNotification('schedule.delete.success');
return redirect('/admin/schedule');
}
public function loadSchedule(Request $request): Response
{
try {

View File

@ -94,6 +94,9 @@ msgstr "Der Schichttyp konnte nicht gefunden werden."
msgid "schedule.import.success"
msgstr "Das Programm wurde erfolgreich importiert."
msgid "schedule.delete.success"
msgstr "Das Programm wurde erfolgreich gelöscht."
msgid "shifts.filter.toggle"
msgstr "Filter verstecken/anzeigen"

View File

@ -1431,6 +1431,9 @@ msgstr "Programm importieren"
msgid "schedule.edit.title"
msgstr "Programm bearbeiten"
msgid "schedule.delete.title"
msgstr "Programm mit %u Schichten löschen"
msgid "schedule.import.title"
msgstr "Programm importieren"

View File

@ -92,6 +92,9 @@ msgstr "The shift type can't not be found."
msgid "schedule.import.success"
msgstr "Schedule import successful."
msgid "schedule.delete.success"
msgstr "Schedule deletion successful."
msgid "shifts.filter.toggle"
msgstr "collapse/show filters"

View File

@ -121,6 +121,9 @@ msgstr "Import schedule"
msgid "schedule.edit.title"
msgstr "Edit schedule"
msgid "schedule.delete.title"
msgstr "Delete schedule with %u shifts"
msgid "schedule.import.title"
msgstr "Import schedule"

View File

@ -45,7 +45,13 @@
'value': schedule ? schedule.minutes_after : 15
}) }}
{{ f.submit(__('form.save')) }}
{{ f.save(__('form.save')) }}
{% if schedule %}
{{ f.delete(__('form.delete'), {
'confirm_title': __('schedule.delete.title', [schedule.shifts|length])
}) }}
{% endif %}
</div>
</form>
{% endblock %}

View File

@ -37,18 +37,19 @@
<td>{{ schedule.name }}</td>
<td><a href="{{ schedule.url }}" target="_blank">{{ schedule.url }}</a></td>
<td>
<form method="post" action="{{ url('/admin/schedule/edit/' ~ schedule.id) }}">
{{ csrf() }}
<div class="btn-group">
<a
href="{{ url('/admin/schedule/load/' ~ schedule.id) }}"
class="btn btn-sm btn-secondary">
{{ __('form.import') }}
</a>
<a
href="{{ url('/admin/schedule/edit/' ~ schedule.id) }}"
class="btn btn-sm btn-secondary">
{{ __('form.edit') }}
</a>
{{ m.button(m.icon('box-arrow-in-down'), url('/admin/schedule/load/' ~ schedule.id), 'secondary', 'sm', __('form.import')) }}
{{ m.button(m.icon('pencil'), url('/admin/schedule/edit/' ~ schedule.id), 'secondary', 'sm', __('form.edit')) }}
{{ f.delete(null, {
'title': __('form.delete'),
'confirm_button_text': __('form.delete'),
'confirm_title': __('schedule.delete.title', [schedule.shifts|length]),
'size': 'sm'
}) }}
</div>
</form>
</td>
</tr>
{% endfor %}

View File

@ -280,6 +280,13 @@ Renders a button.
{{ _self.button(label|default(__('form.submit')), {'type': 'submit', 'btn_type': 'primary'}|merge(opt|default({}))) }}
{%- endmacro %}
{% macro save(label, opt) %}
{{ _self.submit(label|default(' '), {
'icon_left': 'save',
'title': __('form.save'),
}|merge(opt|default({}))) }}
{%- endmacro %}
{% macro delete(label, opt) %}
{{ _self.submit(label|default(' '), {
'icon_left': 'trash',