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 */ /** @var ScheduleUrl $schedule */
$schedule = ScheduleUrl::findOrNew($scheduleId); $schedule = ScheduleUrl::findOrNew($scheduleId);
if ($request->request->has('delete')) {
return $this->delete($schedule);
}
$data = $this->validate($request, [ $data = $this->validate($request, [
'name' => 'required', 'name' => 'required',
'url' => 'required', 'url' => 'required',
@ -146,6 +150,34 @@ class ImportSchedule extends BaseController
return redirect('/admin/schedule/load/' . $schedule->id); 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 public function loadSchedule(Request $request): Response
{ {
try { try {

View File

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

View File

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

View File

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

View File

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

View File

@ -45,7 +45,13 @@
'value': schedule ? schedule.minutes_after : 15 '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> </div>
</form> </form>
{% endblock %} {% endblock %}

View File

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

View File

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