From e992db8e0cc24d41c7c5fc4ab121dce8584c1e7a Mon Sep 17 00:00:00 2001 From: Daniel Wilkowski Date: Fri, 18 Oct 2024 16:52:33 +0200 Subject: [PATCH] Add icon editor --- app/Domain/Icon/Icons.php | 7 +- app/Http/Controllers/Adm/BaseController.php | 1 + app/Http/Controllers/Adm/IconsController.php | 53 +++++++++ resources/views/adm/icons.twig | 110 +++++++++++++++++++ routes/adm.php | 3 + 5 files changed, 172 insertions(+), 2 deletions(-) create mode 100644 app/Http/Controllers/Adm/IconsController.php create mode 100644 resources/views/adm/icons.twig diff --git a/app/Domain/Icon/Icons.php b/app/Domain/Icon/Icons.php index 64165cc47e..13ee9d993b 100644 --- a/app/Domain/Icon/Icons.php +++ b/app/Domain/Icon/Icons.php @@ -3,6 +3,7 @@ use Coyote\Domain\Html; use Coyote\Domain\StringHtml; +use Illuminate\Support\Facades\Session; readonly class Icons { @@ -36,7 +37,7 @@ private function iconTag(string $class, string $iconName): Html private function iconClass(string $iconName): string { - $icons = $this->fa->icons(); + $icons = $this->icons(); if (\array_key_exists($iconName, $icons)) { return $icons[$iconName]; } @@ -45,6 +46,8 @@ private function iconClass(string $iconName): string public function icons(): array { - return $this->fa->icons(); + $defaultIcons = $this->fa->icons(); + $currentIcons = \array_filter(Session::get('icons', [])); + return \array_merge($defaultIcons, $currentIcons); } } diff --git a/app/Http/Controllers/Adm/BaseController.php b/app/Http/Controllers/Adm/BaseController.php index 43bfd3272e..3a7d3e1029 100644 --- a/app/Http/Controllers/Adm/BaseController.php +++ b/app/Http/Controllers/Adm/BaseController.php @@ -60,6 +60,7 @@ private function buildMenu(Menu $menu): Builder $menu->add('Bloki statyczne', ['route' => 'adm.blocks'])->prepend($fa('far fa-file-code fa-fw')); $menu->add('Faktury i płatności', ['route' => 'adm.payments'])->prepend($fa('fa-cart-shopping fa-fw'))->data('permission', 'adm-payment'); $menu->add('Eksperymenty', ['route' => 'adm.experiments'])->prepend($fa('fa-solid fa-flask fa-fw')); + $menu->add('Ikony', ['route' => 'adm.icons'])->prepend($fa('fa-solid fa-icons fa-fw')); }) ->filter(function (Item $item): bool { if ($item->data('permission')) { diff --git a/app/Http/Controllers/Adm/IconsController.php b/app/Http/Controllers/Adm/IconsController.php new file mode 100644 index 0000000000..6932c156c3 --- /dev/null +++ b/app/Http/Controllers/Adm/IconsController.php @@ -0,0 +1,53 @@ +breadcrumb->push('Ikony', route('adm.icons')); + } + + public function index(FontAwesomePro $icons, Connection $connection): View + { + return $this->view('adm.icons', [ + 'editorIcons' => $this->editorIcons(\array_filter($icons->icons()), $connection), + ]); + } + + private function editorIcons(array $icons, Connection $connection): array + { + $record = $connection->table('settings_key_value')->where('key', 'currentIcons')->first(); + if ($record) { + $sessionIcons = \json_decode($record->value, true); + } else { + $sessionIcons = []; + } + $editorIcons = []; + foreach ($icons as $iconName => $defaultIcon) { + $editorIcons[$iconName] = [$defaultIcon, $sessionIcons[$iconName] ?? '']; + } + return $editorIcons; + } + + public function save(Connection $connection): RedirectResponse + { + $currentIcons = $this->request->get('icons'); + Session::put('icons', $currentIcons); + $connection->table('settings_key_value')->insert([ + 'key' => date('Y-m-d H:i:s'), + 'value' => json_encode($currentIcons), + ]); + $connection->table('settings_key_value')->updateOrInsert( + ['key' => 'currentIcons'], + ['value' => json_encode($currentIcons)]); + return response()->redirectToRoute('adm.icons'); + } +} diff --git a/resources/views/adm/icons.twig b/resources/views/adm/icons.twig new file mode 100644 index 0000000000..d676a94849 --- /dev/null +++ b/resources/views/adm/icons.twig @@ -0,0 +1,110 @@ +{% extends 'adm.base' %} +{% block title %}Ikony {{ parent() }}{% endblock %} + +{% block card %} + {{ form_open({url: route('adm.icons.save'), method: 'post', id: 'app'}) }} +
+

+ +

+
+ + + + + + +
+ + + + +
+ +
+
+ + + + + + + + + + + +
Umiejscowienieikona font-awesome
+
+ + + +
+
+ + +
+ {{ form_close() }} +{% endblock %} + +{% block body %} + {{ parent() }} + + +{% endblock %} diff --git a/routes/adm.php b/routes/adm.php index d59f0fe19c..b32d3f55c3 100644 --- a/routes/adm.php +++ b/routes/adm.php @@ -148,5 +148,8 @@ function () { $this->get('Experiments/{survey}', ['uses' => 'ExperimentsController@show'])->name('experiments.show'); $this->post('Experiments/Save', ['uses' => 'ExperimentsController@create'])->name('experiments.create'); $this->post('Experiments/{survey}/Members', ['uses' => 'ExperimentsController@updateMembers'])->name('experiments.updateMembers'); + + $this->get('Icons', ['uses' => 'IconsController@index'])->name('icons'); + $this->post('Icons', ['uses' => 'IconsController@save'])->name('icons.save'); }, );