diff --git a/src/App/assets/js/components/_table_settings.js b/src/App/assets/js/components/_table_settings.js
index 4771a3cb..684b7e5c 100644
--- a/src/App/assets/js/components/_table_settings.js
+++ b/src/App/assets/js/components/_table_settings.js
@@ -4,8 +4,8 @@ $(function() {
return;
}
- if (! columnsSettings) {
- console.error("Invalid or no column settings provided.")
+ if (! getSettingsUrl) {
+ console.error("Invalid or no getSettingsUrl provided.")
return;
}
@@ -14,12 +14,19 @@ $(function() {
return;
}
+ const getSettings = () => {
+ return fetch(getSettingsUrl, {
+ method: 'GET',
+ });
+ };
+
const hideColumns = (tableId, visibleColumns) => {
const table = $(tableId);
if (visibleColumns.length === 0) {
table.show();
return;
}
+
$('.table-column').each((_, element) => {
const column = $(element).data('column');
toggleColumnVisibility(column, visibleColumns.includes(column));
@@ -92,9 +99,6 @@ $(function() {
}
}
- populateColumnSelector('#column-selector', columnsSettings);
- hideColumns(tableId, columnsSettings);
-
$(document).on('change', '.toggle-column-checkbox', function () {
const table = $(tableId);
if (! table) {
@@ -124,4 +128,17 @@ $(function() {
$(document).on('click', '.ui-checkbox', function (e) {
$(e.currentTarget).prop('checked', !$(e.currentTarget).prop('checked'));
});
+
+ getSettings()
+ .then((response) => response.json())
+ .then(settings => {
+ if (settings.data) {
+ populateColumnSelector('#column-selector', settings.data.value);
+ hideColumns(tableId, settings.data.value);
+ } else {
+ populateColumnSelector('#column-selector', []);
+ hideColumns(tableId, []);
+ }
+ })
+ .catch(error => console.error('Error: ', error));
});
diff --git a/src/App/assets/scss/components/_general.scss b/src/App/assets/scss/components/_general.scss
index 54ea7c96..cc598b46 100644
--- a/src/App/assets/scss/components/_general.scss
+++ b/src/App/assets/scss/components/_general.scss
@@ -944,7 +944,7 @@ h1.page-header {
}
/*
-DotKernel Template
+Dotkernel Template
Version 3.0
*/
diff --git a/src/App/src/Common/ServerRequestAwareInterface.php b/src/App/src/Common/ServerRequestAwareInterface.php
index 7091a539..0bff31e0 100644
--- a/src/App/src/Common/ServerRequestAwareInterface.php
+++ b/src/App/src/Common/ServerRequestAwareInterface.php
@@ -4,43 +4,75 @@
namespace Admin\App\Common;
+use Psr\Http\Message\ServerRequestInterface;
+
interface ServerRequestAwareInterface
{
- public function isDelete(): bool;
+ public function isDelete(ServerRequestInterface $request): bool;
- public function isGet(): bool;
+ public function isGet(ServerRequestInterface $request): bool;
- public function isPatch(): bool;
+ public function isPatch(ServerRequestInterface $request): bool;
- public function isPost(): bool;
+ public function isPost(ServerRequestInterface $request): bool;
- public function isPut(): bool;
+ public function isPut(ServerRequestInterface $request): bool;
- public function getPostParams(?callable $callback = null): array|null|object;
+ public function getPostParams(ServerRequestInterface $request, ?callable $callback = null): array|null|object;
- public function getPostParam(string $name, mixed $default = null, ?string $cast = null): mixed;
+ public function getPostParam(
+ ServerRequestInterface $request,
+ string $name,
+ mixed $default = null,
+ ?string $cast = null
+ ): mixed;
- public function getUploadedFiles(?callable $callback = null): array;
+ public function getUploadedFiles(ServerRequestInterface $request, ?callable $callback = null): array;
- public function getUploadedFile(string $name, ?callable $callback = null): mixed;
+ public function getUploadedFile(ServerRequestInterface $request, string $name, ?callable $callback = null): mixed;
- public function getQueryParams(?callable $callback = null): array;
+ public function getQueryParams(ServerRequestInterface $request, ?callable $callback = null): array;
- public function getQueryParam(string $name, mixed $default = null, ?string $cast = null): mixed;
+ public function getQueryParam(
+ ServerRequestInterface $request,
+ string $name,
+ mixed $default = null,
+ ?string $cast = null
+ ): mixed;
- public function getCookieParams(?callable $callback = null): array;
+ public function getCookieParams(ServerRequestInterface $request, ?callable $callback = null): array;
- public function getCookieParam(string $name, mixed $default = null, ?string $cast = null): mixed;
+ public function getCookieParam(
+ ServerRequestInterface $request,
+ string $name,
+ mixed $default = null,
+ ?string $cast = null
+ ): mixed;
- public function getServerParams(?callable $callback = null): array;
+ public function getServerParams(ServerRequestInterface $request, ?callable $callback = null): array;
- public function getServerParam(string $name, mixed $default = null, ?string $cast = null): mixed;
+ public function getServerParam(
+ ServerRequestInterface $request,
+ string $name,
+ mixed $default = null,
+ ?string $cast = null
+ ): mixed;
- public function getHeaders(?callable $callback = null): array;
+ public function getHeaders(ServerRequestInterface $request, ?callable $callback = null): array;
- public function getHeader(string $name, mixed $default = null, ?string $cast = null): mixed;
+ public function getHeader(
+ ServerRequestInterface $request,
+ string $name,
+ mixed $default = null,
+ ?string $cast = null
+ ): mixed;
- public function getAttributes(?callable $callback = null): array;
+ public function getAttributes(ServerRequestInterface $request, ?callable $callback = null): array;
- public function getAttribute(string $name, mixed $default = null, ?string $cast = null): mixed;
+ public function getAttribute(
+ ServerRequestInterface $request,
+ string $name,
+ mixed $default = null,
+ ?string $cast = null
+ ): mixed;
}
diff --git a/src/App/src/Common/ServerRequestAwareTrait.php b/src/App/src/Common/ServerRequestAwareTrait.php
index 587dfadb..d3b85712 100644
--- a/src/App/src/Common/ServerRequestAwareTrait.php
+++ b/src/App/src/Common/ServerRequestAwareTrait.php
@@ -6,6 +6,7 @@
use Exception;
use Fig\Http\Message\RequestMethodInterface;
+use Psr\Http\Message\ServerRequestInterface;
use function array_key_exists;
use function array_map;
@@ -14,34 +15,36 @@
trait ServerRequestAwareTrait
{
- public function isDelete(): bool
+ public function isDelete(ServerRequestInterface $request): bool
{
- return $this->request->getMethod() === RequestMethodInterface::METHOD_DELETE;
+ return $request->getMethod() === RequestMethodInterface::METHOD_DELETE;
}
- public function isGet(): bool
+ public function isGet(ServerRequestInterface $request): bool
{
- return $this->request->getMethod() === RequestMethodInterface::METHOD_GET;
+ return $request->getMethod() === RequestMethodInterface::METHOD_GET;
}
- public function isPatch(): bool
+ public function isPatch(ServerRequestInterface $request): bool
{
- return $this->request->getMethod() === RequestMethodInterface::METHOD_PATCH;
+ return $request->getMethod() === RequestMethodInterface::METHOD_PATCH;
}
- public function isPost(): bool
+ public function isPost(ServerRequestInterface $request): bool
{
- return $this->request->getMethod() === RequestMethodInterface::METHOD_POST;
+ return $request->getMethod() === RequestMethodInterface::METHOD_POST;
}
- public function isPut(): bool
+ public function isPut(ServerRequestInterface $request): bool
{
- return $this->request->getMethod() === RequestMethodInterface::METHOD_PUT;
+ return $request->getMethod() === RequestMethodInterface::METHOD_PUT;
}
- public function getPostParams(?callable $callback = null): array|null|object
- {
- $body = $this->request->getParsedBody();
+ public function getPostParams(
+ ServerRequestInterface $request,
+ ?callable $callback = null
+ ): array|null|object {
+ $body = $request->getParsedBody();
if (is_array($body)) {
return $callback ? array_map($callback, $body) : $body;
}
@@ -49,127 +52,151 @@ public function getPostParams(?callable $callback = null): array|null|object
return $body;
}
- public function getPostParam(string $name, mixed $default = null, ?string $cast = null): mixed
- {
- if (array_key_exists($name, $this->request->getParsedBody())) {
- return $this->cast($this->request->getParsedBody()[$name], $cast);
+ public function getPostParam(
+ ServerRequestInterface $request,
+ string $name,
+ mixed $default = null,
+ ?string $cast = null
+ ): mixed {
+ if (array_key_exists($name, $request->getParsedBody())) {
+ return $this->cast($request->getParsedBody()[$name], $cast);
}
return $this->cast($default, $cast);
}
- public function getUploadedFiles(?callable $callback = null): array
+ public function getUploadedFiles(ServerRequestInterface $request, ?callable $callback = null): array
{
if ($callback) {
- return array_map($callback, $this->request->getUploadedFiles());
+ return array_map($callback, $request->getUploadedFiles());
}
- return $this->request->getUploadedFiles();
+ return $request->getUploadedFiles();
}
/**
* @throws Exception
*/
- public function getUploadedFile(string $name, ?callable $callback = null): mixed
+ public function getUploadedFile(ServerRequestInterface $request, string $name, ?callable $callback = null): mixed
{
- if (! array_key_exists($name, $this->request->getUploadedFiles())) {
+ if (! array_key_exists($name, $request->getUploadedFiles())) {
throw new Exception(
sprintf('There is no file uploaded under the name: %s', $name)
);
}
if ($callback) {
- return $callback($this->request->getUploadedFiles()[$name]);
+ return $callback($request->getUploadedFiles()[$name]);
}
- return $this->request->getUploadedFiles()[$name];
+ return $request->getUploadedFiles()[$name];
}
- public function getQueryParams(?callable $callback = null): array
+ public function getQueryParams(ServerRequestInterface $request, ?callable $callback = null): array
{
if ($callback) {
- return array_map($callback, $this->request->getQueryParams());
+ return array_map($callback, $request->getQueryParams());
}
- return $this->request->getQueryParams();
+ return $request->getQueryParams();
}
- public function getQueryParam(string $name, mixed $default = null, ?string $cast = null): mixed
- {
- if (array_key_exists($name, $this->request->getQueryParams())) {
- return $this->cast($this->request->getQueryParams()[$name], $cast);
+ public function getQueryParam(
+ ServerRequestInterface $request,
+ string $name,
+ mixed $default = null,
+ ?string $cast = null
+ ): mixed {
+ if (array_key_exists($name, $request->getQueryParams())) {
+ return $this->cast($request->getQueryParams()[$name], $cast);
}
return $this->cast($default, $cast);
}
- public function getCookieParams(?callable $callback = null): array
+ public function getCookieParams(ServerRequestInterface $request, ?callable $callback = null): array
{
if ($callback) {
- return array_map($callback, $this->request->getCookieParams());
+ return array_map($callback, $request->getCookieParams());
}
- return $this->request->getCookieParams();
+ return $request->getCookieParams();
}
- public function getCookieParam(string $name, mixed $default = null, ?string $cast = null): mixed
- {
- if (array_key_exists($name, $this->request->getCookieParams())) {
- return $this->cast($this->request->getCookieParams()[$name], $cast);
+ public function getCookieParam(
+ ServerRequestInterface $request,
+ string $name,
+ mixed $default = null,
+ ?string $cast = null
+ ): mixed {
+ if (array_key_exists($name, $request->getCookieParams())) {
+ return $this->cast($request->getCookieParams()[$name], $cast);
}
return $this->cast($default, $cast);
}
- public function getServerParams(?callable $callback = null): array
+ public function getServerParams(ServerRequestInterface $request, ?callable $callback = null): array
{
if ($callback) {
- return array_map($callback, $this->request->getServerParams());
+ return array_map($callback, $request->getServerParams());
}
- return $this->request->getServerParams();
+ return $request->getServerParams();
}
- public function getServerParam(string $name, mixed $default = null, ?string $cast = null): mixed
- {
- if (array_key_exists($name, $this->request->getServerParams())) {
- return $this->cast($this->request->getServerParams()[$name], $cast);
+ public function getServerParam(
+ ServerRequestInterface $request,
+ string $name,
+ mixed $default = null,
+ ?string $cast = null
+ ): mixed {
+ if (array_key_exists($name, $request->getServerParams())) {
+ return $this->cast($request->getServerParams()[$name], $cast);
}
return $this->cast($default, $cast);
}
- public function getHeaders(?callable $callback = null): array
+ public function getHeaders(ServerRequestInterface $request, ?callable $callback = null): array
{
if ($callback) {
- return array_map($callback, $this->request->getHeaders());
+ return array_map($callback, $request->getHeaders());
}
- return $this->request->getHeaders();
+ return $request->getHeaders();
}
- public function getHeader(string $name, mixed $default = null, ?string $cast = null): mixed
- {
- if (array_key_exists($name, $this->request->getHeaders())) {
- return $this->cast($this->request->getHeaderLine($name), $cast);
+ public function getHeader(
+ ServerRequestInterface $request,
+ string $name,
+ mixed $default = null,
+ ?string $cast = null
+ ): mixed {
+ if (array_key_exists($name, $request->getHeaders())) {
+ return $this->cast($request->getHeaderLine($name), $cast);
}
return $this->cast($default, $cast);
}
- public function getAttributes(?callable $callback = null): array
+ public function getAttributes(ServerRequestInterface $request, ?callable $callback = null): array
{
if ($callback) {
- return array_map($callback, $this->request->getAttributes());
+ return array_map($callback, $request->getAttributes());
}
- return $this->request->getAttributes();
+ return $request->getAttributes();
}
- public function getAttribute(string $name, mixed $default = null, ?string $cast = null): mixed
- {
- if (array_key_exists($name, $this->request->getAttributes())) {
- return $this->cast($this->request->getAttributes()[$name], $cast);
+ public function getAttribute(
+ ServerRequestInterface $request,
+ string $name,
+ mixed $default = null,
+ ?string $cast = null
+ ): mixed {
+ if (array_key_exists($name, $request->getAttributes())) {
+ return $this->cast($request->getAttributes()[$name], $cast);
}
return $this->cast($default, $cast);
diff --git a/src/App/src/ConfigProvider.php b/src/App/src/ConfigProvider.php
index 3ccc5975..8d480b5c 100644
--- a/src/App/src/ConfigProvider.php
+++ b/src/App/src/ConfigProvider.php
@@ -4,10 +4,9 @@
namespace Admin\App;
-use Admin\App\Controller\DashboardController;
-use Admin\App\Controller\PageController;
use Admin\App\Factory\EntityListenerResolverFactory;
use Admin\App\Factory\FormsPluginFactory;
+use Admin\App\Handler\GetIndexRedirectHandler;
use Admin\App\Plugin\FormsPlugin;
use Admin\App\Resolver\EntityListenerResolver;
use Admin\App\Twig\Extension\RouteExtension;
@@ -41,8 +40,7 @@ public function getDependencies(): array
'factories' => [
'doctrine.entity_manager.orm_default' => EntityManagerFactory::class,
EntityListenerResolver::class => EntityListenerResolverFactory::class,
- DashboardController::class => AttributedServiceFactory::class,
- PageController::class => AttributedServiceFactory::class,
+ GetIndexRedirectHandler::class => AttributedServiceFactory::class,
PluginManager::class => PluginManagerFactory::class,
FormsPlugin::class => FormsPluginFactory::class,
RouteExtension::class => AttributedServiceFactory::class,
@@ -76,7 +74,6 @@ public function getTemplates(): array
{
return [
'paths' => [
- 'app' => [__DIR__ . '/../templates/app'],
'error' => [__DIR__ . '/../templates/error'],
'layout' => [__DIR__ . '/../templates/layout'],
'partial' => [__DIR__ . '/../templates/partial'],
diff --git a/src/App/src/Controller/DashboardController.php b/src/App/src/Controller/DashboardController.php
deleted file mode 100644
index 3a028e63..00000000
--- a/src/App/src/Controller/DashboardController.php
+++ /dev/null
@@ -1,36 +0,0 @@
-template->render('app::dashboard'));
- }
-}
diff --git a/src/App/src/Controller/PageController.php b/src/App/src/Controller/PageController.php
deleted file mode 100644
index d263f283..00000000
--- a/src/App/src/Controller/PageController.php
+++ /dev/null
@@ -1,31 +0,0 @@
-template->render('app::components'));
- }
-}
diff --git a/src/App/src/Handler/GetIndexRedirectHandler.php b/src/App/src/Handler/GetIndexRedirectHandler.php
new file mode 100644
index 00000000..3a97c249
--- /dev/null
+++ b/src/App/src/Handler/GetIndexRedirectHandler.php
@@ -0,0 +1,35 @@
+authenticationService->hasIdentity()) {
+ return new RedirectResponse($this->router->generateUri('dashboard::dashboard-view'));
+ }
+
+ return new RedirectResponse($this->router->generateUri('admin::admin-login-form'));
+ }
+}
diff --git a/src/App/src/Message.php b/src/App/src/Message.php
index 498a362e..8ee11ca0 100644
--- a/src/App/src/Message.php
+++ b/src/App/src/Message.php
@@ -15,11 +15,14 @@ class Message
public const ADMIN_UPDATED_SUCCESSFULLY = "Admin updated successfully";
public const ADMIN_IDENTITY_EXISTS = "An account with this identity already exists";
public const ADMIN_CREATED_SUCCESSFULLY = "Admin created successfully";
- public const ADMIN_DELETED_SUCCESSFULLY = "Admin deleted successfully";
- public const ACCOUNT_UPDATE_SUCCESSFULLY = "Your account was updated successfully";
- public const CURRENT_PASSWORD_INCORRECT = "Current password is incorrect";
- public const CREATE_ADMIN = "Create admin";
- public const UPDATE_ADMIN = "Update admin";
- public const DELETE_ADMIN = "Delete admin";
- public const CHANGE_PASSWORD = "Change password";
+
+ public const ADMIN_INACTIVE = "Admin is inactive";
+ public const ADMIN_DELETED_SUCCESSFULLY = "Admin deleted successfully";
+ public const ACCOUNT_UPDATE_SUCCESSFULLY = "Your account was updated successfully";
+ public const CURRENT_PASSWORD_INCORRECT = "Current password is incorrect";
+ public const CREATE_ADMIN = "Create admin";
+ public const UPDATE_ADMIN = "Update admin";
+ public const DELETE_ADMIN = "Delete admin";
+ public const CHANGE_PASSWORD = "Change password";
+ public const LOGIN_FAILED = "Login failed";
}
diff --git a/src/App/src/Middleware/AuthMiddleware.php b/src/App/src/Middleware/AuthMiddleware.php
index 8ec2f8e7..5928f6c0 100644
--- a/src/App/src/Middleware/AuthMiddleware.php
+++ b/src/App/src/Middleware/AuthMiddleware.php
@@ -54,7 +54,7 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
'user-login'
);
- return new RedirectResponse($this->router->generateUri("admin", ['action' => 'login']));
+ return new RedirectResponse($this->router->generateUri("admin::get-login-form"));
}
return $handler->handle($request);
diff --git a/src/App/src/RoutesDelegator.php b/src/App/src/RoutesDelegator.php
index 38b1bf9b..33bd96c9 100644
--- a/src/App/src/RoutesDelegator.php
+++ b/src/App/src/RoutesDelegator.php
@@ -4,20 +4,26 @@
namespace Admin\App;
-use Admin\App\Controller\DashboardController;
-use Admin\App\Controller\PageController;
+use Admin\App\Handler\GetIndexRedirectHandler;
use Mezzio\Application;
+use Psr\Container\ContainerExceptionInterface;
use Psr\Container\ContainerInterface;
+use Psr\Container\NotFoundExceptionInterface;
+
+use function assert;
class RoutesDelegator
{
+ /**
+ * @throws ContainerExceptionInterface
+ * @throws NotFoundExceptionInterface
+ */
public function __invoke(ContainerInterface $container, string $serviceName, callable $callback): Application
{
- /** @var Application $app */
$app = $callback();
+ assert($app instanceof Application);
- $app->get('/', DashboardController::class, 'dashboard');
- $app->get('/page[/{action}]', PageController::class, 'page');
+ $app->get('/', GetIndexRedirectHandler::class, 'app::index-redirect');
return $app;
}
diff --git a/src/App/src/Twig/Extension/RouteExtension.php b/src/App/src/Twig/Extension/RouteExtension.php
index 14057ff9..2f213031 100644
--- a/src/App/src/Twig/Extension/RouteExtension.php
+++ b/src/App/src/Twig/Extension/RouteExtension.php
@@ -6,6 +6,7 @@
use Dot\DependencyInjection\Attribute\Inject;
use Mezzio\Helper\UrlHelper;
+use Mezzio\Router\RouteResult;
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;
@@ -25,22 +26,21 @@ public function getFunctions(): array
];
}
- public function getCurrentRoute(): ?string
+ public function getCurrentRoute(): ?RouteResult
{
- return $this->urlHelper->getRequest()?->getUri()?->getPath();
+ return $this->urlHelper->getRouteResult();
}
- public function isRoute(?string $route): bool
+ public function isRoute(?string $routeName): bool
{
- if (null === $route) {
+ if (null === $routeName) {
return false;
}
- $currentRoute = $this->getCurrentRoute();
- if (null === $currentRoute) {
+ if (null === $this->getCurrentRoute()) {
return false;
}
- return $currentRoute === $route;
+ return $this->getCurrentRoute()->getMatchedRouteName() === $routeName;
}
}
diff --git a/src/App/templates/app/home-page.html.twig b/src/App/templates/app/home-page.html.twig
deleted file mode 100644
index 4e7f9f6c..00000000
--- a/src/App/templates/app/home-page.html.twig
+++ /dev/null
@@ -1,120 +0,0 @@
-{% extends '@layout/default.html.twig' %}
-
-{% block title %}Home{% endblock %}
-
-{% block content %}
-
-
Welcome to mezzio
-
- Congratulations! You have successfully installed the
- mezzio skeleton application.
- This skeleton can serve as a simple starting point for you to begin building your application.
-
-
- Mezzio builds on laminas-stratigility to provide a minimalist PSR-7 middleware framework for PHP.
-
-
-
-
-
-
-
- Mezzio is fast, small and perfect for rapid application development, prototyping and api's.
- You decide how you extend it and choose the best packages from major framework or standalone projects.
-
-
-
-
-
-
- HTTP messages are the foundation of web development. Web browsers and HTTP clients such as cURL create
- HTTP request messages that are sent to a web server, which provides an HTTP response message.
- Server-side code receives an HTTP request message, and returns an HTTP response message.
-
-
-
-
-
-
- Middleware is code that exists between the request and response, and which can take the incoming
- request, perform actions based on it, and either complete the response or pass delegation on to the
- next middleware in the queue. Your application is easily extended with custom middleware created by
- yourself or others.
-
-
-
-
-
-
-
-
- Mezzio promotes and advocates the usage of Dependency Injection/Inversion of Control containers
- when writing your applications. Mezzio supports multiple containers which typehints against
- PSR Container.
-
- {% if containerName is defined %}
-
-
- Get started with {{ containerName }}.
-
-
- {% endif %}
-
-
-
-
-
- One fundamental feature of mezzio is that it provides mechanisms for implementing dynamic
- routing, a feature required in most modern web applications. Mezzio ships with multiple adapters.
-
- {% if routerName is defined %}
-
-
- Get started with {{ routerName }}.
-
-
- {% endif %}
-
-
-
-
-
- By default, no middleware in Mezzio is templated. We do not even provide a default templating
- engine, as the choice of templating engine is often very specific to the project and/or organization.
- However, Mezzio does provide abstraction for templating, which allows you to write middleware that
- is engine-agnostic.
-
- {% if templateName is defined %}
-
-
- Get started with {{ templateName }}.
-
-
- {% endif %}
-
-
-{% endblock %}
diff --git a/src/App/templates/error/403.html.twig b/src/App/templates/error/403.html.twig
index ceb1fab3..69e96ab3 100644
--- a/src/App/templates/error/403.html.twig
+++ b/src/App/templates/error/403.html.twig
@@ -10,7 +10,7 @@
You don't have enough permissions to access the requested content!
You are looking for something that doesn't exist or may have moved. Check out one of the links on this page
- or head back to Dashboard.
+ or head back to Dashboard.