Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #275: Template refactoring #287

Merged
merged 3 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion config/autoload/app.global.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
$baseUrl = 'http://localhost:8080';

$app = [
'name' => 'DotKernel Admin V4',
'name' => 'Dotkernel Admin V5',
'url' => $baseUrl,
];

Expand Down
2 changes: 1 addition & 1 deletion config/autoload/cli.global.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion config/autoload/mail.local.php.dist
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ return [
// message configuration
'message_options' => [
'from' => '',
'from_name' => 'DotKernel',
'from_name' => 'Dotkernel',
'reply_to' => '',
'reply_to_name' => '',
'to' => [],
Expand Down
4 changes: 2 additions & 2 deletions config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
27 changes: 14 additions & 13 deletions src/Admin/src/Controller/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down Expand Up @@ -304,7 +302,7 @@ public function loginAction(): ResponseInterface

return new HtmlResponse(
$this->template->render('admin::login', [
'form' => $form,
'form' => $form->prepare(),
])
);
}
Expand All @@ -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);
Expand All @@ -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(),
])
);
}
Expand Down
4 changes: 4 additions & 0 deletions src/Admin/src/Form/AccountForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public function init(): void
],
'attributes' => [
'placeholder' => 'Identity...',
'class' => 'form-control',
],
], ['priority' => -9]);

Expand All @@ -47,6 +48,7 @@ public function init(): void
],
'attributes' => [
'placeholder' => 'First name...',
'class' => 'form-control',
],
], ['priority' => -10]);

Expand All @@ -58,6 +60,7 @@ public function init(): void
],
'attributes' => [
'placeholder' => 'Last name...',
'class' => 'form-control',
],
], ['priority' => -11]);

Expand All @@ -67,6 +70,7 @@ public function init(): void
'attributes' => [
'type' => 'submit',
'value' => 'Update account',
'class' => 'btn btn-primary btn-color',
],
], ['priority' => -100]);

Expand Down
2 changes: 2 additions & 0 deletions src/Admin/src/Form/AdminDeleteForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
4 changes: 4 additions & 0 deletions src/Admin/src/Form/ChangePasswordForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public function init(): void
],
'attributes' => [
'placeholder' => '',
'class' => 'form-control',
],
]);

Expand All @@ -47,6 +48,7 @@ public function init(): void
],
'attributes' => [
'placeholder' => '',
'class' => 'form-control',
],
]);

Expand All @@ -58,6 +60,7 @@ public function init(): void
],
'attributes' => [
'placeholder' => '',
'class' => 'form-control',
],
]);

Expand All @@ -67,6 +70,7 @@ public function init(): void
'attributes' => [
'type' => 'submit',
'value' => 'Change Password',
'class' => 'btn btn-primary btn-color',
],
], ['priority' => -100]);

Expand Down
28 changes: 7 additions & 21 deletions src/Admin/templates/admin/account.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -12,36 +12,29 @@
<div class="bgc-white p-20 bd">
<h6 class="c-grey-900">Update personal data</h6>
<div class="mT-30">
{{ form().openTag(accountForm)|raw }}

{% set dummy = form.prepare() %}
{{ form().openTag(form)|raw }}

{% set identity = form.getElements().identity %}
{% set identity = accountForm.get('identity') %}
<div class="mb-3 form-group {% if identity.getMessages() %}has-error{% endif %}">
{% set dummy = identity.setAttribute('class', 'form-control') %}
{{ formLabel(identity) }}
{{ formElement(identity) }}
</div>

{% set firstName = form.getElements().firstName %}
{% set firstName = accountForm.get('firstName') %}
<div class="mb-3 form-group {% if firstName.getMessages() %}has-error{% endif %}">
{% set dummy = firstName.setAttribute('class', 'form-control') %}
{{ formLabel(firstName) }}
{{ formElement(firstName) }}
</div>

{% set lastName = form.getElements().lastName %}
{% set lastName = accountForm.get('lastName') %}
<div class="mb-3 form-group {% if lastName.getMessages() %}has-error{% endif %}">
{% set dummy = lastName.setAttribute('class', 'form-control') %}
{{ formLabel(lastName) }}
{{ formElement(lastName) }}
</div>

{{ 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 }}
</div>
Expand All @@ -51,36 +44,29 @@
<div class="bgc-white p-20 bd">
<h6 class="c-grey-900">Change password</h6>
<div class="mT-30">
{% set dummy = changePasswordForm.prepare() %}
{% set dummy = changePasswordForm.setAttribute('action', path('admin', {action: 'change-password'})) %}
{{ form().openTag(changePasswordForm)|raw }}

{% set currentPassword = changePasswordForm.get('currentPassword') %}
<div class="mb-3 form-group {% if currentPassword.getMessages() %}has-error{% endif %}">
{% set dummy = currentPassword.setAttribute('class', 'form-control') %}
{{ formLabel(currentPassword) }}
{{ formElement(currentPassword) }}
</div>

{% set password = changePasswordForm.getElements().password %}
<div class="mb-3 form-group {% if password.getMessages() %}has-error{% endif %}">
{% set dummy = password.setAttribute('class', 'form-control') %}
{{ formLabel(password) }}
{{ formElement(password) }}
</div>

{% set passwordConfirm = changePasswordForm.getElements().passwordConfirm %}
<div class="mb-3 form-group {% if passwordConfirm.getMessages() %}has-error{% endif %}">
{% set dummy = passwordConfirm.setAttribute('class', 'form-control') %}
{{ formLabel(passwordConfirm) }}
{{ formElement(passwordConfirm) }}
</div>

{{ 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 }}
</div>
Expand Down
26 changes: 11 additions & 15 deletions src/Admin/templates/admin/login.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="apple-touch-icon" sizes="180x180" href="{{ asset('images/app/favicon/apple-touch-icon.png') }}">
<link rel="icon" type="image/png" sizes="32x32" href="{{ asset('images/app/favicon/favicon-32x32.png') }}">
<link rel="icon" type="image/png" sizes="16x16" href="{{ asset('images/app/favicon/favicon-16x16.png') }}">
<link rel="manifest" href="{{ asset('images/app/favicon/site.webmanifest') }}">
<meta name="msapplication-TileColor" content="#2d89ef">
<meta name="theme-color" content="#ffffff">
<title>Sign In</title>
<link href="{{ asset('css/app.css') }}" rel="stylesheet">
</head>
Expand All @@ -14,36 +21,25 @@
<div class="pos-a centerXY">
<div class="bgc-white bdrs-50p w-100">
<a href="{{ path('dashboard') }}">
<img class="pos-a centerXY logo-img" src="{{ asset('images/app/logo.svg') }}" alt="">
<img class="pos-a centerXY logo-img" src="{{ asset('images/app/logo.svg') }}" alt="Dotkernel logo" />
</a>
</div>
</div>
</div>
<div class="col-md-4">
{% set dummy = form.prepare() %}
{{ form().openTag(form)|raw }}
<h4 class="fw-300 c-grey-900 mB-20">Login</h4>
<div class="mb-3">
{% set username = form.get('username') %}
{% set elementTranslatePlaceholder = username.getAttribute('placeholder')|trans|raw %}
{% set dummy = username.setAttribute('placeholder', elementTranslatePlaceholder) %}
{{ formElement(username) }}
{{ formElement(form.get('username')) }}
</div>
<div class="mb-3">
{% set password = form.get('password') %}
{% set elementTranslatePlaceholder = password.getAttribute('placeholder')|trans|raw %}
{% set dummy = password.setAttribute('placeholder', elementTranslatePlaceholder) %}
{{ formElement(password) }}
{{ formElement(form.get('password')) }}
</div>
{% 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 }}
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/Admin/templates/admin/simple-logins.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
data-bs-placement="top"
data-bs-custom-class="custom-tooltip"
data-bs-title="Filter by login identity">
<option value="">Select identity</option>
<option value="">Select identity ({{ identities|length }})</option>
{% for identity in identities %}
<option value="{{ identity }}" {{ identity == params.identity ? 'selected' : '' }}>{{ identity }}</option>
{% endfor %}
Expand Down
10 changes: 5 additions & 5 deletions src/App/templates/layout/default.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
<meta name="msapplication-TileColor" content="#2d89ef">
<meta name="theme-color" content="#ffffff">

<title>{% block title %}{% endblock %} - DotKernel</title>
<title>{% block title %}{% endblock %} - Dotkernel</title>

<link href="{{ asset('css/app.css') }}" rel="stylesheet">

<!--[if lt IE 9]>
<script src="{{ asset('js/html5shiv.js') }}"></script>
<script src="{{ asset('js/respond.min.js') }}"></script>
<![endif]-->
<!--[if lt IE 9]>
<script src="{{ asset('js/html5shiv.js') }}"></script>
<script src="{{ asset('js/respond.min.js') }}"></script>
<![endif]-->
</head>
<body class="app">
{{ include('@partial/left-menu.html.twig') }}
Expand Down
2 changes: 1 addition & 1 deletion src/App/templates/layout/main.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<meta name="msapplication-TileColor" content="#2d89ef">
<meta name="theme-color" content="#ffffff">

<title>{% block title %}{% endblock %} - DotKernel</title>
<title>{% block title %}{% endblock %} - Dotkernel</title>

<link href="{{ asset('css/app.css') }}" rel="stylesheet">
</head>
Expand Down
4 changes: 2 additions & 2 deletions src/App/templates/partial/left-menu.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
<div class="peers ai-c fxw-nw">
<div class="peer">
<div class="logo d-flex align-items-center">
<img id="min-logo" src="{{ asset('images/app/min-logo.svg') }}" alt="DotKernel">
<img id="full-logo" src="{{ asset('images/app/logo.svg') }}" alt="DotKernel">
<img id="min-logo" src="{{ asset('images/app/min-logo.svg') }}" alt="Dotkernel logo">
<img id="full-logo" src="{{ asset('images/app/logo.svg') }}" alt="Dotkernel logo">
</div>
</div>
<div class="peer peer-greed">
Expand Down
Loading