From 985f46c65266fb7f6cdabb8f016675e3a0d29332 Mon Sep 17 00:00:00 2001 From: binaryDiv Date: Fri, 30 Jul 2021 03:46:43 +0200 Subject: [PATCH] Accounts: Fetch list of all accounts (optionally filtered by domain) --- public/static/style.css | 28 +++++++++++++ src/Dependencies.php | 7 ++++ src/Frontend/Accounts/AccountController.php | 18 ++++++++ src/Repositories/AccountRepository.php | 35 ++++++++++++++++ templates/accounts.html.twig | 46 ++++++++++++++++++++- templates/domains.html.twig | 20 +++++---- 6 files changed, 145 insertions(+), 9 deletions(-) create mode 100644 src/Repositories/AccountRepository.php diff --git a/public/static/style.css b/public/static/style.css index 0c69551..ab04854 100644 --- a/public/static/style.css +++ b/public/static/style.css @@ -112,6 +112,10 @@ a:hover, a:focus { padding: 1em; } +.gray { + color: gray; +} + button { padding: 0.2em 1em; } @@ -121,3 +125,27 @@ table, tr, td, th { border-collapse: collapse; padding: 0.25em 0.5em; } + +.inactive { + color: gray; +} + +/* --- Filter options --- */ +.filter_options { + border: 1px solid #999999; + padding: 1em; + margin: 1em 0; +} + +.filter_options h4 { + margin: 0 0 0.5em 0; +} + +/* --- Detail columns --- */ +input#show_details_checkbox { + margin-bottom: 1em; +} + +input#show_details_checkbox:not(:checked) ~ table .detail_column { + display: none; +} diff --git a/src/Dependencies.php b/src/Dependencies.php index e3cc9f7..f7f9742 100644 --- a/src/Dependencies.php +++ b/src/Dependencies.php @@ -9,6 +9,7 @@ use MailAccountAdmin\Frontend\Accounts\AccountController; use MailAccountAdmin\Frontend\Domains\DomainController; use MailAccountAdmin\Frontend\Login\LoginController; use MailAccountAdmin\Frontend\Dashboard\DashboardController; +use MailAccountAdmin\Repositories\AccountRepository; use MailAccountAdmin\Repositories\AdminUserRepository; use MailAccountAdmin\Repositories\DomainRepository; use PDO; @@ -64,6 +65,11 @@ class Dependencies $c->get(self::DATABASE), ); }); + $container->set(AccountRepository::class, function (ContainerInterface $c) { + return new AccountRepository( + $c->get(self::DATABASE), + ); + }); // Helper classes $container->set(UserHelper::class, function (ContainerInterface $c) { @@ -97,6 +103,7 @@ class Dependencies return new AccountController( $c->get(self::TWIG), $c->get(UserHelper::class), + $c->get(AccountRepository::class), ); }); diff --git a/src/Frontend/Accounts/AccountController.php b/src/Frontend/Accounts/AccountController.php index d948371..a93ed33 100644 --- a/src/Frontend/Accounts/AccountController.php +++ b/src/Frontend/Accounts/AccountController.php @@ -3,15 +3,33 @@ declare(strict_types=1); namespace MailAccountAdmin\Frontend\Accounts; +use MailAccountAdmin\Common\UserHelper; use MailAccountAdmin\Frontend\BaseController; +use MailAccountAdmin\Repositories\AccountRepository; use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ServerRequestInterface as Request; +use Slim\Views\Twig; class AccountController extends BaseController { + /** @var AccountRepository */ + private $accountRepository; + + public function __construct(Twig $view, UserHelper $userHelper, AccountRepository $accountRepository) + { + parent::__construct($view, $userHelper); + $this->accountRepository = $accountRepository; + } + public function showAccounts(Request $request, Response $response): Response { + // Parse query parameters for filters + $queryParams = $request->getQueryParams(); + $filterByDomain = $queryParams['domain'] ?? null; + $renderData = [ + 'filterDomain' => $filterByDomain, + 'accountList' => $this->accountRepository->fetchAccountList($filterByDomain), ]; return $this->view->render($response, 'accounts.html.twig', $renderData); diff --git a/src/Repositories/AccountRepository.php b/src/Repositories/AccountRepository.php new file mode 100644 index 0000000..a97e3cd --- /dev/null +++ b/src/Repositories/AccountRepository.php @@ -0,0 +1,35 @@ +pdo->prepare($query); + $statement->execute($queryParams); + return $statement->fetchAll(PDO::FETCH_ASSOC); + } +} diff --git a/templates/accounts.html.twig b/templates/accounts.html.twig index ecfaddd..b920b3b 100644 --- a/templates/accounts.html.twig +++ b/templates/accounts.html.twig @@ -5,6 +5,48 @@ {% block content %}

Accounts

-

List of accounts ... TODO

-

Test

+

List of all mail accounts.

+ +
+
+

Filter:

+ + + + +
+
+ + + + + + + + + + + + + + + {% if accountList %} + {% for account in accountList -%} + + + + + + + + + + + {% endfor %} + {% else %} + + + + {% endif %} +
UsernameDomainAliasesActiveHome directoryMemoCreatedLast modified
{{ account['username'] }}{{ account['domain'] }}{{ account['alias_count'] }}{{ account['is_active'] == 1 ? 'Yes' : 'No' }}vmail/{{ account['home_dir'] }}{{ account['memo'] }}{{ account['created_at'] }}{{ account['modified_at'] }}
No accounts found.
{% endblock %} diff --git a/templates/domains.html.twig b/templates/domains.html.twig index f1f5ef7..79d0044 100644 --- a/templates/domains.html.twig +++ b/templates/domains.html.twig @@ -13,12 +13,18 @@ Accounts Aliases - {% for domain, domainCounts in domainList -%} - - {{ domain }} - {{ domainCounts['accounts'] }} - {{ domainCounts['aliases'] }} - - {% endfor %} + {% if domainList %} + {% for domain, domainCounts in domainList -%} + + {{ domain }} + {{ domainCounts['accounts'] }} + {{ domainCounts['aliases'] }} + + {% endfor %} + {% else %} + + No domains found. + + {% endif %} {% endblock %}