From 2e0a01a422f2923aa9750a5e11dab3230c5aec8b Mon Sep 17 00:00:00 2001 From: alexmerlin Date: Thu, 26 Sep 2024 15:58:21 +0300 Subject: [PATCH 1/2] Issue #275: Template refactoring Signed-off-by: alexmerlin --- src/Admin/src/Controller/AdminController.php | 27 ++++++++++--------- src/Admin/src/Form/AccountForm.php | 4 +++ src/Admin/src/Form/AdminDeleteForm.php | 2 ++ src/Admin/src/Form/ChangePasswordForm.php | 4 +++ src/Admin/templates/admin/account.html.twig | 28 +++++--------------- src/Admin/templates/admin/login.html.twig | 19 +++---------- 6 files changed, 35 insertions(+), 49 deletions(-) diff --git a/src/Admin/src/Controller/AdminController.php b/src/Admin/src/Controller/AdminController.php index cde5f1f..094e814 100644 --- a/src/Admin/src/Controller/AdminController.php +++ b/src/Admin/src/Controller/AdminController.php @@ -180,8 +180,6 @@ public function deleteAction(): ResponseInterface assert($admin instanceof Admin); $form = new AdminDeleteForm(); - $form->setAttribute('id', 'deleteAdminForm'); - $form->setAttribute('method', RequestMethodInterface::METHOD_POST); $form->setAttribute( 'action', $this->router->generateUri('admin', ['action' => 'delete', 'uuid' => $uuid]) @@ -304,7 +302,7 @@ public function loginAction(): ResponseInterface return new HtmlResponse( $this->template->render('admin::login', [ - 'form' => $form, + 'form' => $form->prepare(), ]) ); } @@ -320,16 +318,19 @@ public function logoutAction(): ResponseInterface public function accountAction(): ResponseInterface { - $form = new AccountForm(); + $accountForm = new AccountForm(); $changePasswordForm = new ChangePasswordForm(); - $identity = $this->authenticationService->getIdentity(); - $admin = $this->adminService->getAdminRepository()->findOneBy(['uuid' => $identity->getUuid()]); + $changePasswordForm + ->setAttribute('action', $this->router->generateUri('admin', ['action' => 'change-password'])); + + $identity = $this->authenticationService->getIdentity(); + $admin = $this->adminService->getAdminRepository()->findOneBy(['uuid' => $identity->getUuid()]); if ($this->isPost()) { - $form->setData($this->getPostParams()); - if ($form->isValid()) { + $accountForm->setData($this->getPostParams()); + if ($accountForm->isValid()) { /** @var array $result */ - $result = $form->getData(); + $result = $accountForm->getData(); try { $this->adminService->updateAdmin($admin, $result); $this->messenger->addSuccess(Message::ACCOUNT_UPDATE_SUCCESSFULLY); @@ -341,17 +342,17 @@ public function accountAction(): ResponseInterface $this->messenger->addError(Message::AN_ERROR_OCCURRED); } } else { - $this->messenger->addError($this->forms->getMessagesAsString($form)); + $this->messenger->addError($this->forms->getMessagesAsString($accountForm)); } return new RedirectResponse($this->router->generateUri('admin', ['action' => 'account'])); } - $form->bind($admin); + $accountForm->bind($admin); return new HtmlResponse( $this->template->render('admin::account', [ - 'form' => $form, - 'changePasswordForm' => $changePasswordForm, + 'accountForm' => $accountForm->prepare(), + 'changePasswordForm' => $changePasswordForm->prepare(), ]) ); } diff --git a/src/Admin/src/Form/AccountForm.php b/src/Admin/src/Form/AccountForm.php index 45afbbd..ae557e7 100644 --- a/src/Admin/src/Form/AccountForm.php +++ b/src/Admin/src/Form/AccountForm.php @@ -36,6 +36,7 @@ public function init(): void ], 'attributes' => [ 'placeholder' => 'Identity...', + 'class' => 'form-control', ], ], ['priority' => -9]); @@ -47,6 +48,7 @@ public function init(): void ], 'attributes' => [ 'placeholder' => 'First name...', + 'class' => 'form-control', ], ], ['priority' => -10]); @@ -58,6 +60,7 @@ public function init(): void ], 'attributes' => [ 'placeholder' => 'Last name...', + 'class' => 'form-control', ], ], ['priority' => -11]); @@ -67,6 +70,7 @@ public function init(): void 'attributes' => [ 'type' => 'submit', 'value' => 'Update account', + 'class' => 'btn btn-primary btn-color', ], ], ['priority' => -100]); diff --git a/src/Admin/src/Form/AdminDeleteForm.php b/src/Admin/src/Form/AdminDeleteForm.php index afae14a..c379bde 100644 --- a/src/Admin/src/Form/AdminDeleteForm.php +++ b/src/Admin/src/Form/AdminDeleteForm.php @@ -22,6 +22,8 @@ public function __construct(?string $name = null, array $options = []) $this->init(); + $this->setAttribute('id', 'deleteAdminForm'); + $this->inputFilter = new AdminDeleteInputFilter(); $this->inputFilter->init(); } diff --git a/src/Admin/src/Form/ChangePasswordForm.php b/src/Admin/src/Form/ChangePasswordForm.php index d0cc719..3db85c0 100644 --- a/src/Admin/src/Form/ChangePasswordForm.php +++ b/src/Admin/src/Form/ChangePasswordForm.php @@ -36,6 +36,7 @@ public function init(): void ], 'attributes' => [ 'placeholder' => '', + 'class' => 'form-control', ], ]); @@ -47,6 +48,7 @@ public function init(): void ], 'attributes' => [ 'placeholder' => '', + 'class' => 'form-control', ], ]); @@ -58,6 +60,7 @@ public function init(): void ], 'attributes' => [ 'placeholder' => '', + 'class' => 'form-control', ], ]); @@ -67,6 +70,7 @@ public function init(): void 'attributes' => [ 'type' => 'submit', 'value' => 'Change Password', + 'class' => 'btn btn-primary btn-color', ], ], ['priority' => -100]); diff --git a/src/Admin/templates/admin/account.html.twig b/src/Admin/templates/admin/account.html.twig index 03e6bdf..3d45372 100644 --- a/src/Admin/templates/admin/account.html.twig +++ b/src/Admin/templates/admin/account.html.twig @@ -12,36 +12,29 @@
Update personal data
+ {{ form().openTag(accountForm)|raw }} - {% set dummy = form.prepare() %} - {{ form().openTag(form)|raw }} - - {% set identity = form.getElements().identity %} + {% set identity = accountForm.get('identity') %}
- {% set dummy = identity.setAttribute('class', 'form-control') %} {{ formLabel(identity) }} {{ formElement(identity) }}
- {% set firstName = form.getElements().firstName %} + {% set firstName = accountForm.get('firstName') %}
- {% set dummy = firstName.setAttribute('class', 'form-control') %} {{ formLabel(firstName) }} {{ formElement(firstName) }}
- {% set lastName = form.getElements().lastName %} + {% set lastName = accountForm.get('lastName') %}
- {% set dummy = lastName.setAttribute('class', 'form-control') %} {{ formLabel(lastName) }} {{ formElement(lastName) }}
- {{ formElement(form.get('accountCsrf')) }} + {{ formElement(accountForm.get('accountCsrf')) }} - {% set submit = form.get('submit') %} - {% set dummy = submit.setAttribute('class', 'btn btn-primary btn-color') %} - {{ formSubmit(submit) }} + {{ formSubmit(accountForm.get('submit')) }} {{ form().closeTag()|raw }}
@@ -51,36 +44,29 @@
Change password
- {% set dummy = changePasswordForm.prepare() %} - {% set dummy = changePasswordForm.setAttribute('action', path('admin', {action: 'change-password'})) %} {{ form().openTag(changePasswordForm)|raw }} {% set currentPassword = changePasswordForm.get('currentPassword') %}
- {% set dummy = currentPassword.setAttribute('class', 'form-control') %} {{ formLabel(currentPassword) }} {{ formElement(currentPassword) }}
{% set password = changePasswordForm.getElements().password %}
- {% set dummy = password.setAttribute('class', 'form-control') %} {{ formLabel(password) }} {{ formElement(password) }}
{% set passwordConfirm = changePasswordForm.getElements().passwordConfirm %}
- {% set dummy = passwordConfirm.setAttribute('class', 'form-control') %} {{ formLabel(passwordConfirm) }} {{ formElement(passwordConfirm) }}
{{ formElement(changePasswordForm.get('changePasswordCsrf')) }} - {% set submit = changePasswordForm.get('submit') %} - {% set dummy = submit.setAttribute('class', 'btn btn-primary btn-color') %} - {{ formSubmit(submit) }} + {{ formSubmit(changePasswordForm.get('submit')) }} {{ form().closeTag()|raw }}
diff --git a/src/Admin/templates/admin/login.html.twig b/src/Admin/templates/admin/login.html.twig index 45d8746..038da12 100644 --- a/src/Admin/templates/admin/login.html.twig +++ b/src/Admin/templates/admin/login.html.twig @@ -14,36 +14,25 @@
- {% set dummy = form.prepare() %} {{ form().openTag(form)|raw }}

Login

- {% set username = form.get('username') %} - {% set elementTranslatePlaceholder = username.getAttribute('placeholder')|trans|raw %} - {% set dummy = username.setAttribute('placeholder', elementTranslatePlaceholder) %} - {{ formElement(username) }} + {{ formElement(form.get('username')) }}
- {% set password = form.get('password') %} - {% set elementTranslatePlaceholder = password.getAttribute('placeholder')|trans|raw %} - {% set dummy = password.setAttribute('placeholder', elementTranslatePlaceholder) %} - {{ formElement(password) }} + {{ formElement(form.get('password')) }}
- {% set submit = form.get('submit') %} - {% set submitValue = submit.getValue|trans|raw %} - {% set dummy = submit.setAttribute('value', submitValue) %} - {{ messagesPartial('partial::alerts', {}, null, 'user-login') }} {{ formElement(form.get('loginCsrf')) }} - {{ formSubmit(submit) }} + {{ formSubmit(form.get('submit')) }} {{ form().closeTag()|raw }}
From d852bbdb14b9049c4e33700075d4e91330e1fbf0 Mon Sep 17 00:00:00 2001 From: alexmerlin Date: Thu, 26 Sep 2024 17:12:04 +0300 Subject: [PATCH 2/2] Minor tweaks Signed-off-by: alexmerlin --- CHANGELOG.md | 4 ++-- config/autoload/app.global.php | 2 +- config/autoload/cli.global.php | 2 +- config/autoload/mail.local.php.dist | 2 +- config/config.php | 4 ++-- src/Admin/templates/admin/login.html.twig | 7 +++++++ src/Admin/templates/admin/simple-logins.html.twig | 2 +- src/App/templates/layout/default.html.twig | 10 +++++----- src/App/templates/layout/main.html.twig | 2 +- src/App/templates/partial/left-menu.html.twig | 4 ++-- 10 files changed, 23 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5dbb6ea..4530bb6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,8 +8,8 @@ ### Added -* Issue [#284](https://github.com/dotkernel/admin/issues/284): Created file `CHANGELOG.md` by @alexmerlin in [#285](https://github.com/dotkernel/admin/pull/285) -* Issue [#282](https://github.com/dotkernel/admin/issues/282): Show current page as active/open in left menu by @alexmerlin in [#286](https://github.com/dotkernel/admin/pull/286) +* Issue [#284](https://github.com/dotkernel/admin/issues/284): Created file `CHANGELOG.md` by [@alexmerlin](https://github.com/alexmerlin) in [#285](https://github.com/dotkernel/admin/pull/285) +* Issue [#282](https://github.com/dotkernel/admin/issues/282): Show current page as active/open in left menu by [@alexmerlin](https://github.com/alexmerlin) in [#286](https://github.com/dotkernel/admin/pull/286) ### Deprecated diff --git a/config/autoload/app.global.php b/config/autoload/app.global.php index f08b70d..97434f2 100644 --- a/config/autoload/app.global.php +++ b/config/autoload/app.global.php @@ -5,7 +5,7 @@ $baseUrl = 'http://localhost:8080'; $app = [ - 'name' => 'DotKernel Admin V4', + 'name' => 'Dotkernel Admin V5', 'url' => $baseUrl, ]; diff --git a/config/autoload/cli.global.php b/config/autoload/cli.global.php index 69700f7..ecde79e 100644 --- a/config/autoload/cli.global.php +++ b/config/autoload/cli.global.php @@ -11,7 +11,7 @@ */ 'dot_cli' => [ 'version' => '1.0.0', - 'name' => 'DotKernel CLI', + 'name' => 'Dotkernel CLI', 'commands' => [ DemoCommand::getDefaultName() => DemoCommand::class, Dot\GeoIP\Command\GeoIpCommand::getDefaultName() => Dot\GeoIP\Command\GeoIpCommand::class, diff --git a/config/autoload/mail.local.php.dist b/config/autoload/mail.local.php.dist index 5de326c..79bad53 100644 --- a/config/autoload/mail.local.php.dist +++ b/config/autoload/mail.local.php.dist @@ -33,7 +33,7 @@ return [ // message configuration 'message_options' => [ 'from' => '', - 'from_name' => 'DotKernel', + 'from_name' => 'Dotkernel', 'reply_to' => '', 'reply_to_name' => '', 'to' => [], diff --git a/config/config.php b/config/config.php index f3efa4c..29772f6 100644 --- a/config/config.php +++ b/config/config.php @@ -27,7 +27,7 @@ Mezzio\Router\FastRouteRouter\ConfigProvider::class, Mezzio\Twig\ConfigProvider::class, - // DotKernel packages + // Dotkernel packages Dot\Cli\ConfigProvider::class, Dot\DataFixtures\ConfigProvider::class, Dot\DependencyInjection\ConfigProvider::class, @@ -47,7 +47,7 @@ // Include cache configuration new ArrayProvider($cacheConfig), - // DotKernel modules + // Dotkernel modules Admin\App\ConfigProvider::class, Admin\Admin\ConfigProvider::class, Admin\Setting\ConfigProvider::class, diff --git a/src/Admin/templates/admin/login.html.twig b/src/Admin/templates/admin/login.html.twig index 038da12..df8e1f2 100644 --- a/src/Admin/templates/admin/login.html.twig +++ b/src/Admin/templates/admin/login.html.twig @@ -2,7 +2,14 @@ + + + + + + + Sign In diff --git a/src/Admin/templates/admin/simple-logins.html.twig b/src/Admin/templates/admin/simple-logins.html.twig index 2c0beb0..4365ac6 100644 --- a/src/Admin/templates/admin/simple-logins.html.twig +++ b/src/Admin/templates/admin/simple-logins.html.twig @@ -24,7 +24,7 @@ data-bs-placement="top" data-bs-custom-class="custom-tooltip" data-bs-title="Filter by login identity"> - + {% for identity in identities %} {% endfor %} diff --git a/src/App/templates/layout/default.html.twig b/src/App/templates/layout/default.html.twig index 3a2aea3..945face 100644 --- a/src/App/templates/layout/default.html.twig +++ b/src/App/templates/layout/default.html.twig @@ -11,14 +11,14 @@ - {% block title %}{% endblock %} - DotKernel + {% block title %}{% endblock %} - Dotkernel - + {{ include('@partial/left-menu.html.twig') }} diff --git a/src/App/templates/layout/main.html.twig b/src/App/templates/layout/main.html.twig index 484c325..1dd7553 100644 --- a/src/App/templates/layout/main.html.twig +++ b/src/App/templates/layout/main.html.twig @@ -11,7 +11,7 @@ - {% block title %}{% endblock %} - DotKernel + {% block title %}{% endblock %} - Dotkernel diff --git a/src/App/templates/partial/left-menu.html.twig b/src/App/templates/partial/left-menu.html.twig index 5dafd6e..d7dd5e3 100644 --- a/src/App/templates/partial/left-menu.html.twig +++ b/src/App/templates/partial/left-menu.html.twig @@ -8,8 +8,8 @@