From 750429fc622a9a94358d0230d2b3d593142443c1 Mon Sep 17 00:00:00 2001 From: Ivan Reshetnikov Date: Sat, 31 Aug 2024 17:06:02 +0500 Subject: [PATCH] feat: fancy admin panel --- assets/css/admin.css | 52 ++++++++++++++++++- lib/comfycamp/accounts.ex | 8 +++ .../components/layouts/admin.html.heex | 11 ++-- .../controllers/admin_page_controller.ex | 10 +++- .../controllers/admin_page_html.ex | 26 +++++++++- .../controllers/notes_editor_html.ex | 7 +-- 6 files changed, 103 insertions(+), 11 deletions(-) diff --git a/assets/css/admin.css b/assets/css/admin.css index db85c68..1689f45 100644 --- a/assets/css/admin.css +++ b/assets/css/admin.css @@ -1,10 +1,58 @@ .admin-panel { display: flex; - gap: 16px; + gap: 32px; margin-top: 16px; } -.admin-panel ul { +.admin-panel .menu { padding: 0; margin: 0; + list-style-type: none; +} + +.admin-panel .menu li { + padding: 10px; + background-color: #20232f; +} + +.admin-panel .menu li:first-child { + border-radius: 8px 8px 0 0; +} + +.admin-panel .menu li:not(:first-child) { + border-top: 1px solid #353544; +} + +.admin-panel .menu li:last-child { + border-radius: 0 0 8px 8px; +} + +.admin-panel h3 { + margin-top: 0; +} + +.admin-panel .stats { + display: flex; + flex-wrap: wrap; + gap: 16px; +} + +.admin-panel .stat { + background-color: #20232f; + padding: 16px; + border-radius: 8px; + display: flex; + flex-direction: column; + gap: 8px; + align-items: center; + width: min-content; +} + +.admin-panel .stat .value { + font-size: 48px; + font-weight: bold; +} + +.admin-panel .stat .name { + text-align: center; } diff --git a/lib/comfycamp/accounts.ex b/lib/comfycamp/accounts.ex index 5cf653e..db4b61e 100644 --- a/lib/comfycamp/accounts.ex +++ b/lib/comfycamp/accounts.ex @@ -33,6 +33,14 @@ defmodule Comfycamp.Accounts do Repo.all(User) end + def count_users() do + Repo.one(from u in "users", select: count(u.id)) + end + + def count_unapproved_users() do + Repo.one(from u in "users", select: count(u.id), where: not u.is_approved) + end + @doc """ Gets a user by email and password. diff --git a/lib/comfycamp_web/components/layouts/admin.html.heex b/lib/comfycamp_web/components/layouts/admin.html.heex index 96fd2a6..427dfb8 100644 --- a/lib/comfycamp_web/components/layouts/admin.html.heex +++ b/lib/comfycamp_web/components/layouts/admin.html.heex @@ -2,12 +2,15 @@
- <.link href={~p"/"}> - Главная страница -

Панель администратора

+ <.back navigate={~p"/"}>Главная страница
-
    +