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>
<div class="btn-group"> <form method="post" action="{{ url('/admin/schedule/edit/' ~ schedule.id) }}">
<a {{ csrf() }}
href="{{ url('/admin/schedule/load/' ~ schedule.id) }}" <div class="btn-group">
class="btn btn-sm btn-secondary"> {{ m.button(m.icon('box-arrow-in-down'), url('/admin/schedule/load/' ~ schedule.id), 'secondary', 'sm', __('form.import')) }}
{{ __('form.import') }} {{ m.button(m.icon('pencil'), url('/admin/schedule/edit/' ~ schedule.id), 'secondary', 'sm', __('form.edit')) }}
</a> {{ f.delete(null, {
<a 'title': __('form.delete'),
href="{{ url('/admin/schedule/edit/' ~ schedule.id) }}" 'confirm_button_text': __('form.delete'),
class="btn btn-sm btn-secondary"> 'confirm_title': __('schedule.delete.title', [schedule.shifts|length]),
{{ __('form.edit') }} 'size': 'sm'
</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',