From a464682b471ccd8d8f2eb195dc8495778f46e444 Mon Sep 17 00:00:00 2001 From: Igor Scheller Date: Sun, 26 Feb 2023 11:27:41 +0100 Subject: [PATCH] Reimplemented admin room pages --- config/routes.php | 11 + includes/controller/angeltypes_controller.php | 7 +- .../public_dashboard_controller.php | 3 +- includes/controller/rooms_controller.php | 4 +- includes/controller/shifts_controller.php | 2 +- includes/includes.php | 2 - includes/model/Room_model.php | 122 --------- includes/pages/admin_rooms.php | 238 ------------------ includes/pages/admin_shifts.php | 7 +- includes/pages/user_shifts.php | 2 +- includes/sys_menu.php | 7 +- includes/view/Rooms_view.php | 7 +- resources/assets/js/forms.js | 7 + resources/assets/themes/base.scss | 1 + resources/lang/de_DE/additional.po | 9 + resources/lang/de_DE/default.po | 33 +++ resources/lang/en_US/additional.po | 9 + resources/lang/en_US/default.po | 33 +++ resources/views/admin/rooms/edit.twig | 66 +++++ resources/views/admin/rooms/index.twig | 71 ++++++ resources/views/macros/base.twig | 6 + resources/views/macros/form.twig | 83 +++++- resources/views/pages/design.twig | 4 + src/Controllers/Admin/RoomsController.php | 174 +++++++++++++ src/Http/Response.php | 4 +- src/Http/Validation/Validator.php | 7 + src/Middleware/LegacyMiddleware.php | 4 - src/Renderer/Twig/Extensions/Session.php | 12 + .../Controllers/Admin/RoomsControllerTest.php | 220 ++++++++++++++++ tests/Unit/Http/ResponseTest.php | 4 +- tests/Unit/Http/Validation/ValidatorTest.php | 15 ++ tests/Unit/Middleware/ErrorHandlerTest.php | 4 +- .../Renderer/Twig/Extensions/SessionTest.php | 24 +- 33 files changed, 800 insertions(+), 402 deletions(-) delete mode 100644 includes/model/Room_model.php delete mode 100644 includes/pages/admin_rooms.php create mode 100644 resources/views/admin/rooms/edit.twig create mode 100644 resources/views/admin/rooms/index.twig create mode 100644 src/Controllers/Admin/RoomsController.php create mode 100644 tests/Unit/Controllers/Admin/RoomsControllerTest.php diff --git a/config/routes.php b/config/routes.php index a28e697d..771509dc 100644 --- a/config/routes.php +++ b/config/routes.php @@ -157,6 +157,17 @@ $route->addGroup( } ); + // Rooms + $route->addGroup( + '/rooms', + function (RouteCollector $route): void { + $route->get('', 'Admin\\RoomsController@index'); + $route->post('', 'Admin\\RoomsController@delete'); + $route->get('/edit[/{room_id:\d+}]', 'Admin\\RoomsController@edit'); + $route->post('/edit[/{room_id:\d+}]', 'Admin\\RoomsController@save'); + } + ); + // User $route->addGroup( '/user/{user_id:\d+}', diff --git a/includes/controller/angeltypes_controller.php b/includes/controller/angeltypes_controller.php index 0c8f15fb..bdc00572 100644 --- a/includes/controller/angeltypes_controller.php +++ b/includes/controller/angeltypes_controller.php @@ -2,6 +2,7 @@ use Engelsystem\Helpers\Carbon; use Engelsystem\Models\AngelType; +use Engelsystem\Models\Room; use Engelsystem\Models\UserAngelType; use Engelsystem\ShiftsFilter; use Engelsystem\ShiftsFilterRenderer; @@ -239,9 +240,13 @@ function angeltype_controller_shiftsFilterDays(AngelType $angeltype) function angeltype_controller_shiftsFilter(AngelType $angeltype, $days) { $request = request(); + $roomIds = Room::query() + ->select('id') + ->pluck('id') + ->toArray(); $shiftsFilter = new ShiftsFilter( auth()->can('user_shifts_admin'), - Room_ids(), + $roomIds, [$angeltype->id] ); $selected_day = date('Y-m-d'); diff --git a/includes/controller/public_dashboard_controller.php b/includes/controller/public_dashboard_controller.php index 47476262..d4f73434 100644 --- a/includes/controller/public_dashboard_controller.php +++ b/includes/controller/public_dashboard_controller.php @@ -2,6 +2,7 @@ use Engelsystem\Models\AngelType; use Engelsystem\Models\News; +use Engelsystem\Models\Room; use Engelsystem\Models\Shifts\Shift; use Engelsystem\ShiftsFilter; @@ -24,7 +25,7 @@ function public_dashboard_controller() } $angelTypes = collect(unrestricted_angeltypes()); - $rooms = $requestRooms ?: Rooms()->pluck('id')->toArray(); + $rooms = $requestRooms ?: Room::orderBy('name')->get()->pluck('id')->toArray(); $angelTypes = $requestAngelTypes ?: $angelTypes->pluck('id')->toArray(); $filterValues = [ 'userShiftsAdmin' => false, diff --git a/includes/controller/rooms_controller.php b/includes/controller/rooms_controller.php index 1a253c30..2136565a 100644 --- a/includes/controller/rooms_controller.php +++ b/includes/controller/rooms_controller.php @@ -73,8 +73,8 @@ function rooms_controller(): array return match ($action) { 'view' => room_controller(), - 'list' => throw_redirect(page_link_to('admin_rooms')), - default => throw_redirect(page_link_to('admin_rooms')), + 'list' => throw_redirect(page_link_to('admin/rooms')), + default => throw_redirect(page_link_to('admin/rooms')), }; } diff --git a/includes/controller/shifts_controller.php b/includes/controller/shifts_controller.php index b865673b..2899f39e 100644 --- a/includes/controller/shifts_controller.php +++ b/includes/controller/shifts_controller.php @@ -67,7 +67,7 @@ function shift_edit_controller() } $rooms = []; - foreach (Rooms() as $room) { + foreach (Room::orderBy('name')->get() as $room) { $rooms[$room->id] = $room->name; } $angeltypes = AngelType::all()->pluck('name', 'id')->toArray(); diff --git a/includes/includes.php b/includes/includes.php index 5317b4ca..e16c4170 100644 --- a/includes/includes.php +++ b/includes/includes.php @@ -12,7 +12,6 @@ $includeFiles = [ __DIR__ . '/../includes/sys_template.php', __DIR__ . '/../includes/model/NeededAngelTypes_model.php', - __DIR__ . '/../includes/model/Room_model.php', __DIR__ . '/../includes/model/ShiftEntry_model.php', __DIR__ . '/../includes/model/Shifts_model.php', __DIR__ . '/../includes/model/ShiftsFilter.php', @@ -61,7 +60,6 @@ $includeFiles = [ __DIR__ . '/../includes/pages/admin_arrive.php', __DIR__ . '/../includes/pages/admin_free.php', __DIR__ . '/../includes/pages/admin_groups.php', - __DIR__ . '/../includes/pages/admin_rooms.php', __DIR__ . '/../includes/pages/admin_shifts.php', __DIR__ . '/../includes/pages/admin_user.php', __DIR__ . '/../includes/pages/guest_login.php', diff --git a/includes/model/Room_model.php b/includes/model/Room_model.php deleted file mode 100644 index 28c8827b..00000000 --- a/includes/model/Room_model.php +++ /dev/null @@ -1,122 +0,0 @@ -where('name', $name) - ->where('id', '!=', $room_id) - ->count(); - if ($roomCount) { - $valid = false; - } - - return new ValidationResult($valid, $name); -} - -/** - * returns a list of rooms. - * - * @return Room[]|Collection - */ -function Rooms() -{ - return Room::orderBy('name')->get(); -} - -/** - * Returns Room id array - * - * @return int[] - */ -function Room_ids() -{ - return Room::query() - ->select('id') - ->pluck('id') - ->toArray(); -} - -/** - * Delete a room - * - * @param Room $room - */ -function Room_delete(Room $room) -{ - $room->delete(); - engelsystem_log('Room deleted: ' . $room->name); -} - -/** - * Create a new room - * - * @param string $name Name of the room - * @param string|null $map_url URL to a map tha can be displayed in an iframe - * @param string|null $description - * - * @return null|int - */ -function Room_create(string $name, string $map_url = null, string $description = null, string $dect = null) -{ - $room = new Room(); - $room->name = $name; - $room->description = $description; - $room->map_url = $map_url; - $room->dect = $dect; - $room->save(); - - engelsystem_log( - 'Room created: ' . $name - . ', dect: ' . $dect - . ', map_url: ' . $map_url - . ', description: ' . $description - ); - - return $room->id; -} - -/** - * Update a room - * - * @param int $room_id The rooms id - * @param string $name Name of the room - * @param string|null $map_url URL to a map tha can be displayed in an iframe - * @param string|null $description Markdown description - */ -function Room_update( - int $room_id, - string $name, - string $map_url = null, - string $description = null, - string $dect = null -) { - $room = Room::find($room_id); - $room->name = $name; - $room->description = $description ?: null; - $room->map_url = $map_url ?: null; - $room->dect = $dect ?: null; - $room->save(); - - engelsystem_log( - 'Room updated: ' . $name . - ', dect: ' . $dect . - ', map_url: ' . $map_url . - ', description: ' . $description - ); -} diff --git a/includes/pages/admin_rooms.php b/includes/pages/admin_rooms.php deleted file mode 100644 index 3113877b..00000000 --- a/includes/pages/admin_rooms.php +++ /dev/null @@ -1,238 +0,0 @@ - Room_name_render($room), - 'dect' => icon_bool($room->dect), - 'map_url' => icon_bool($room->map_url), - 'actions' => table_buttons([ - button( - page_link_to('admin_rooms', ['show' => 'edit', 'id' => $room->id]), - icon('pencil') . __('edit'), - 'btn-sm' - ), - button( - page_link_to('admin_rooms', ['show' => 'delete', 'id' => $room->id]), - icon('trash') . __('delete'), - 'btn-sm' - ), - ]), - ]; - } - - $room = null; - if ($request->has('show')) { - $msg = ''; - $name = ''; - $map_url = null; - $description = null; - $dect = null; - $room_id = 0; - - $angeltypes_source = AngelType::all(); - $angeltypes = []; - $angeltypes_count = []; - foreach ($angeltypes_source as $angeltype) { - $angeltypes[$angeltype->id] = $angeltype->name; - $angeltypes_count[$angeltype->id] = 0; - } - - if (test_request_int('id')) { - $room = Room::find($request->input('id')); - if (!$room) { - throw_redirect(page_link_to('admin_rooms')); - } - - $room_id = $room->id; - $name = $room->name; - $map_url = $room->map_url; - $description = $room->description; - $dect = $room->dect; - - $angeltypes_count = NeededAngelType::whereRoomId($room_id) - ->pluck('count', 'angel_type_id') - ->toArray() + $angeltypes_count; - } - if ($request->input('show') == 'edit') { - if ($request->hasPostData('submit')) { - $valid = true; - - if ($request->has('name') && strlen(strip_request_tags('name')) > 0) { - $result = Room_validate_name(strip_request_tags('name'), $room_id); - if (!$result->isValid()) { - $valid = false; - $msg .= error(__('This name is already in use.'), true); - } else { - $name = $result->getValue(); - } - } else { - $valid = false; - $msg .= error(__('Please enter a name.'), true); - } - - if ($request->has('map_url')) { - $map_url = strip_request_item('map_url'); - } - - if ($request->has('description')) { - $description = strip_request_item_nl('description'); - } - if ($request->has('dect')) { - $dect = strip_request_item_nl('dect'); - } - - foreach ($angeltypes as $angeltype_id => $angeltype) { - $angeltypes_count[$angeltype_id] = 0; - $queryKey = 'angeltype_count_' . $angeltype_id; - if (!$request->has($queryKey)) { - continue; - } - - if (preg_match('/^\d{1,4}$/', $request->input($queryKey))) { - $angeltypes_count[$angeltype_id] = $request->input($queryKey); - } else { - $valid = false; - $msg .= error(sprintf( - __('Please enter needed angels for type %s.'), - $angeltype - ), true); - } - } - - if ($valid) { - if (empty($room_id)) { - $room_id = Room_create($name, $map_url, $description, $dect); - } else { - Room_update($room_id, $name, $map_url, $description, $dect); - } - - NeededAngelType::whereRoomId($room_id)->delete(); - $needed_angeltype_info = []; - foreach ($angeltypes_count as $angeltype_id => $angeltype_count) { - $angeltype = AngelType::find($angeltype_id); - if (!empty($angeltype) && $angeltype_count > 0) { - $neededAngelType = new NeededAngelType(); - $neededAngelType->room_id = $room_id; - $neededAngelType->angelType()->associate($angeltype); - $neededAngelType->count = $angeltype_count; - $neededAngelType->save(); - - $needed_angeltype_info[] = $angeltype->name . ': ' . $angeltype_count; - } - } - - engelsystem_log( - 'Set needed angeltypes of room ' . $name - . ' to: ' . join(', ', $needed_angeltype_info) - ); - success(__('Room saved.')); - throw_redirect(page_link_to('admin_rooms')); - } - } - $angeltypes_count_form = []; - foreach ($angeltypes as $angeltype_id => $angeltypeName) { - $angeltypes_count_form[] = div('col-lg-4 col-md-6 col-xs-6', [ - form_spinner('angeltype_count_' . $angeltype_id, $angeltypeName, $angeltypes_count[$angeltype_id]), - ]); - } - - return page_with_title(admin_rooms_title(), [ - buttons([ - button(page_link_to('admin_rooms'), __('back'), 'back'), - ]), - $msg, - form([ - div('row', [ - div('col-md-6', [ - form_text('name', __('Name'), $name, false, 35), - form_text('dect', __('DECT'), $dect), - form_text('map_url', __('Map URL'), $map_url), - form_info('', __('The map url is used to display an iframe on the room page.')), - form_textarea('description', __('Description'), $description), - form_info('', __('Please use markdown for the description.')), - ]), - div('col-md-6', [ - div('row', [ - div('col-md-12', [ - form_info(__('Needed angels:')), - ]), - join($angeltypes_count_form), - ]), - ]), - ]), - form_submit('submit', __('Save')), - ]), - ], true); - } elseif ($request->input('show') == 'delete') { - if ($request->hasPostData('ack')) { - $room = Room::find($room_id); - $shifts = $room->shifts; - foreach ($shifts as $shift) { - $shift = Shift($shift); - foreach ($shift->shiftEntries as $entry) { - event('shift.entry.deleting', [ - 'user' => User::find($entry['user_id']), - 'start' => $shift->start, - 'end' => $shift->end, - 'name' => $shift->shiftType->name, - 'title' => $shift->title, - 'type' => $entry->angelType->name, - 'room' => $room, - 'freeloaded' => (bool) $entry['freeloaded'], - ]); - } - } - - Room_delete($room); - - success(sprintf(__('Room %s deleted.'), $name)); - throw_redirect(page_link_to('admin_rooms')); - } - - return page_with_title(admin_rooms_title(), [ - buttons([ - button(page_link_to('admin_rooms'), __('back'), 'back'), - ]), - sprintf(__('Do you want to delete room %s?'), $name), - form([ - form_submit('ack', __('Delete'), 'delete btn-danger'), - ], page_link_to('admin_rooms', ['show' => 'delete', 'id' => $room_id])), - ], true); - } - } - - return page_with_title(admin_rooms_title(), [ - buttons([ - button(page_link_to('admin_rooms', ['show' => 'edit']), __('add')), - ]), - msg(), - table([ - 'name' => __('Name'), - 'dect' => __('DECT'), - 'map_url' => __('Map'), - 'actions' => '', - ], $rooms), - ], true); -} diff --git a/includes/pages/admin_shifts.php b/includes/pages/admin_shifts.php index 339d76ce..7fa8299f 100644 --- a/includes/pages/admin_shifts.php +++ b/includes/pages/admin_shifts.php @@ -43,11 +43,8 @@ function admin_shifts() $shift_over_midnight = true; // Locations laden - $rooms = Rooms(); - $room_array = []; - foreach ($rooms as $room) { - $room_array[$room->id] = $room->name; - } + $rooms = Room::orderBy('name')->get(); + $room_array = $rooms->pluck('name', 'id')->toArray(); // Load angeltypes /** @var AngelType[] $types */ diff --git a/includes/pages/user_shifts.php b/includes/pages/user_shifts.php index 127f0270..15b5cd22 100644 --- a/includes/pages/user_shifts.php +++ b/includes/pages/user_shifts.php @@ -115,7 +115,7 @@ function update_ShiftsFilter(ShiftsFilter $shiftsFilter, $user_shifts_admin, $da */ function load_rooms() { - $rooms = Rooms(); + $rooms = Room::orderBy('name')->get(); if ($rooms->isEmpty()) { error(__('The administration has not configured any rooms yet.')); throw_redirect(page_link_to('/')); diff --git a/includes/sys_menu.php b/includes/sys_menu.php index 7dcb3c91..806694cc 100644 --- a/includes/sys_menu.php +++ b/includes/sys_menu.php @@ -1,6 +1,7 @@ ['Answer questions', 'question.edit'], 'shifttypes' => 'Shifttypes', 'admin_shifts' => 'Create shifts', - 'admin_rooms' => 'Rooms', + 'admin/rooms' => ['room.rooms', 'admin_rooms'], 'admin_groups' => 'Grouprights', 'admin/schedule' => ['schedule.import', 'schedule.import'], 'admin/logs' => ['log.log', 'admin_log'], @@ -152,10 +153,10 @@ function make_room_navigation($menu) } // Get a list of all rooms - $rooms = Rooms(); + $rooms = Room::orderBy('name')->get(); $room_menu = []; if (auth()->can('admin_rooms')) { - $room_menu[] = toolbar_dropdown_item(page_link_to('admin_rooms'), __('Manage rooms'), false, 'list'); + $room_menu[] = toolbar_dropdown_item(page_link_to('admin/rooms'), __('Manage rooms'), false, 'list'); } if (count($room_menu) > 0) { $room_menu[] = toolbar_dropdown_item_divider(); diff --git a/includes/view/Rooms_view.php b/includes/view/Rooms_view.php index c7cefde7..7832a854 100644 --- a/includes/view/Rooms_view.php +++ b/includes/view/Rooms_view.php @@ -61,15 +61,10 @@ function Room_view(Room $room, ShiftsFilterRenderer $shiftsFilterRenderer, Shift $assignNotice, auth()->can('admin_rooms') ? buttons([ button( - page_link_to('admin_rooms', ['show' => 'edit', 'id' => $room->id]), + page_link_to('admin/rooms/edit/' . $room->id), icon('pencil') . __('edit'), 'btn' ), - button( - page_link_to('admin_rooms', ['show' => 'delete', 'id' => $room->id]), - icon('trash') . __('delete'), - 'btn' - ), ]) : '', $dect, $description, diff --git a/resources/assets/js/forms.js b/resources/assets/js/forms.js index 3a7e46d7..e6e19196 100644 --- a/resources/assets/js/forms.js +++ b/resources/assets/js/forms.js @@ -254,6 +254,13 @@ ready(() => { document.querySelectorAll('[data-bs-toggle="popover"]').forEach((element) => new bootstrap.Popover(element)); }); +/** + * Init Bootstrap Tooltips + */ +ready(() => { + document.querySelectorAll('[data-bs-toggle="tooltip"]').forEach((element) => new bootstrap.Tooltip(element)); +}); + /** * Show oauth buttons on welcome title click */ diff --git a/resources/assets/themes/base.scss b/resources/assets/themes/base.scss index 2ab2ef87..6893e425 100644 --- a/resources/assets/themes/base.scss +++ b/resources/assets/themes/base.scss @@ -46,6 +46,7 @@ $form-label-font-weight: $font-weight-bold; @import '~bootstrap/scss/list-group'; @import '~bootstrap/scss/close'; @import '~bootstrap/scss/popover'; +@import '~bootstrap/scss/tooltip'; @import '~bootstrap/scss/helpers'; diff --git a/resources/lang/de_DE/additional.po b/resources/lang/de_DE/additional.po index 2ea82b44..aad375fb 100644 --- a/resources/lang/de_DE/additional.po +++ b/resources/lang/de_DE/additional.po @@ -209,3 +209,12 @@ msgstr "Arbeitseinsatz erfolgreich bearbeitet." msgid "worklog.delete.success" msgstr "Arbeitseinsatz erfolgreich gelöscht." + +msgid "room.edit.success" +msgstr "Raum erfolgreich bearbeitet." + +msgid "room.delete.success" +msgstr "Raum erfolgreich gelöscht." + +msgid "validation.name.exists" +msgstr "Der Name wird bereits verwendet." diff --git a/resources/lang/de_DE/default.po b/resources/lang/de_DE/default.po index 86466259..2499bf97 100644 --- a/resources/lang/de_DE/default.po +++ b/resources/lang/de_DE/default.po @@ -2812,6 +2812,12 @@ msgstr "Aktualisiert" msgid "form.cancel" msgstr "Abbrechen" +msgid "form.markdown" +msgstr "Du kannst hier Markdown verwenden" + +msgid "form.required" +msgstr "Pflichtfeld" + msgid "schedule.import" msgstr "Programm importieren" @@ -3189,3 +3195,30 @@ msgstr "E-Mail" msgid "registration.register" msgstr "Registrieren" + +msgid "room.rooms" +msgstr "Räume" + +msgid "room.name" +msgstr "Name" + +msgid "room.dect" +msgstr "DECT" + +msgid "room.map_url" +msgstr "Karte" + +msgid "room.description" +msgstr "Beschreibung" + +msgid "room.required_angels" +msgstr "Benötigte Engel" + +msgid "room.map_url.info" +msgstr "Die Karte wird auf der Raum-Seite als iframe eingebettet." + +msgid "room.create.title" +msgstr "Raum erstellen" + +msgid "room.edit.title" +msgstr "Raum bearbeiten" diff --git a/resources/lang/en_US/additional.po b/resources/lang/en_US/additional.po index 51a6f9c0..57f5f2dc 100644 --- a/resources/lang/en_US/additional.po +++ b/resources/lang/en_US/additional.po @@ -208,3 +208,12 @@ msgstr "Work log successfully updated." msgid "worklog.delete.success" msgstr "Work log successfully deleted." + +msgid "room.edit.success" +msgstr "Room edited successfully." + +msgid "room.delete.success" +msgstr "Room successfully deleted." + +msgid "validation.name.exists" +msgstr "The name is already used." diff --git a/resources/lang/en_US/default.po b/resources/lang/en_US/default.po index aaa353e5..5ab33542 100644 --- a/resources/lang/en_US/default.po +++ b/resources/lang/en_US/default.po @@ -79,6 +79,12 @@ msgstr "Updated" msgid "form.cancel" msgstr "Cancel" +msgid "form.required" +msgstr "Required" + +msgid "form.markdown" +msgstr "You can use Markdown here" + msgid "schedule.import" msgstr "Import schedule" @@ -452,3 +458,30 @@ msgstr "E-Mail" msgid "registration.register" msgstr "Register" + +msgid "room.rooms" +msgstr "Rooms" + +msgid "room.name" +msgstr "Name" + +msgid "room.dect" +msgstr "DECT" + +msgid "room.map_url" +msgstr "Map" + +msgid "room.description" +msgstr "Description" + +msgid "room.required_angels" +msgstr "Required angels" + +msgid "room.map_url.info" +msgstr "The map will be embedded on the room page as an iframe." + +msgid "room.create.title" +msgstr "Create room" + +msgid "room.edit.title" +msgstr "Edit room" diff --git a/resources/views/admin/rooms/edit.twig b/resources/views/admin/rooms/edit.twig new file mode 100644 index 00000000..43df6d23 --- /dev/null +++ b/resources/views/admin/rooms/edit.twig @@ -0,0 +1,66 @@ +{% extends 'admin/rooms/index.twig' %} +{% import 'macros/base.twig' as m %} +{% import 'macros/form.twig' as f %} + +{% block title %}{{ room ? __('room.edit.title') : __('room.create.title') }}{% endblock %} + +{% block row_content %} +
+ {{ csrf() }} + {{ f.hidden('id', room ? room.id : '') }} + +
+
+ {{ f.input( + 'name', + __('room.name'), + null, + {'required': true, 'entry_required_icon': true, 'value': f.formData('room', room ? room.name : '')} + ) }} + + {{ f.input('dect', __('room.dect'), null, {'value': f.formData('dect', room ? room.dect : '')}) }} + {{ f.input( + 'map_url', + __('room.map_url'), + 'url', + {'value': f.formData('map_url', room ? room.map_url : ''), 'info': __('room.map_url.info')} + ) }} + + {{ f.textarea( + 'description', + __('room.description'), + {'value': f.formData('description', room ? room.description : ''), 'rows': 5, 'info': __('form.markdown')} + ) }} +
+ +
+

{{ __('room.required_angels') }}

+ {% for types in angel_types.chunk(3) %} +
+ {% for angel_type in types %} + {% set needed = needed_angel_types ? needed_angel_types.where('angel_type_id', angel_type.id).first() : null %} + {% set name = 'angel_type_' ~ angel_type.id %} +
+ {{ f.number( + name, + angel_type.name, + {'value': f.formData(name, needed ? needed.count : 0), 'min': 0, 'step': 1} + ) }} +
+ {% endfor %} +
+ {% endfor %} +
+
+ +
+
+ {{ f.submit(__('form.save'), {'icon_left': 'save'}) }} + {% if room %} + {{ f.submit(__('form.delete'), {'name': 'delete', 'btn_type': 'danger', 'icon_left': 'trash'}) }} + {% endif %} +
+
+ +
+{% endblock %} diff --git a/resources/views/admin/rooms/index.twig b/resources/views/admin/rooms/index.twig new file mode 100644 index 00000000..ac439c08 --- /dev/null +++ b/resources/views/admin/rooms/index.twig @@ -0,0 +1,71 @@ +{% extends 'layouts/app.twig' %} +{% import 'macros/base.twig' as m %} +{% import 'macros/form.twig' as f %} + +{% block title %}{{ __('room.rooms') }}{% endblock %} + +{% block content %} +
+

+ {{ block('title') }} + + {% if is_index|default(false) %} + {{ m.button(m.icon('plus-lg'), url('/admin/rooms/edit'), 'secondary') }} + {% endif %} +

+ + {% include 'layouts/parts/messages.twig' %} + +
+ + {% block row_content %} +
+
+ + + + + + + + + + + + {% for room in rooms %} + + + + + + + + + + {% endfor %} + +
{{ __('room.name') }}{{ __('room.dect') }}{{ __('room.map_url') }}
+ {{ m.icon('pin-map-fill') }} + + {{ room.name }} + + {{ m.iconBool(room.dect) }}{{ m.iconBool(room.map_url) }} +
+ + {{ m.button(m.icon('pencil'), url('admin/rooms/edit/' ~ room.id), null, 'sm', __('form.edit')) }} + +
+ {{ csrf() }} + {{ f.hidden('id', room.id) }} + {{ f.button(m.icon('trash'), {'title': __('form.delete'), 'name': 'delete', 'type': 'submit', 'btn_type': 'danger', 'size': 'sm'}) }} +
+ +
+
+
+
+ {% endblock %} + +
+
+{% endblock %} diff --git a/resources/views/macros/base.twig b/resources/views/macros/base.twig index 2fc1ca2b..d7609451 100644 --- a/resources/views/macros/base.twig +++ b/resources/views/macros/base.twig @@ -6,6 +6,12 @@ {% endmacro %} +{% macro iconBool(value) %} + + {{ _self.icon(value ? 'check-lg' : 'x-lg') }} + +{% endmacro %} + {% macro alert(message, type, raw) %}