Implemented schedule deletion
This commit is contained in:
parent
d89fe01ddd
commit
15a6ba1c52
|
@ -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 {
|
||||
|
|
|
@ -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"
|
||||
|
||||
|
|
|
@ -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"
|
||||
|
||||
|
|
|
@ -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"
|
||||
|
||||
|
|
|
@ -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"
|
||||
|
||||
|
|
|
@ -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 %}
|
||||
|
|
|
@ -37,18 +37,19 @@
|
|||
<td>{{ schedule.name }}</td>
|
||||
<td><a href="{{ schedule.url }}" target="_blank">{{ schedule.url }}</a></td>
|
||||
<td>
|
||||
<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>
|
||||
</div>
|
||||
<form method="post" action="{{ url('/admin/schedule/edit/' ~ schedule.id) }}">
|
||||
{{ csrf() }}
|
||||
<div class="btn-group">
|
||||
{{ 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 %}
|
||||
|
|
|
@ -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',
|
||||
|
|
Loading…
Reference in New Issue