From a110f4450ddfc66b5e8a6d13631830d603653105 Mon Sep 17 00:00:00 2001 From: Aidan Date: Tue, 31 Dec 2024 01:41:07 -0500 Subject: [PATCH] implement new admin dashboard --- app.js | 17 +++++- public/js/admin.js | 40 ++++++++++++++ src/admin/dash.ejs | 102 +++++++++++++++++++----------------- src/admin/edit.ejs | 25 +++++++++ src/admin/shards/footer.ejs | 4 ++ src/admin/shards/header.ejs | 37 +++++++++++++ 6 files changed, 177 insertions(+), 48 deletions(-) create mode 100644 public/js/admin.js create mode 100644 src/admin/edit.ejs create mode 100644 src/admin/shards/footer.ejs create mode 100644 src/admin/shards/header.ejs diff --git a/app.js b/app.js index ce6cc29..0774168 100644 --- a/app.js +++ b/app.js @@ -158,7 +158,7 @@ app.post('/admin', (req, res) => { app.get('/admin/dashboard', checkAdminAuth, async (req, res) => { const requests = await Request.findAll(); - res.render('admin/dash', { requests, currentPage: 'admin' }); + res.render('admin/dash', { requests, currentPage: 'admin', user: process.env.ADMIN_USERNAME }); }); app.post('/admin/update-status', checkAdminAuth, async (req, res) => { @@ -173,6 +173,21 @@ app.post('/admin/delete-request', checkAdminAuth, async (req, res) => { res.redirect('/admin/dashboard'); }); +app.get('/admin/edit/:id', checkAdminAuth, async (req, res) => { + const { id } = req.params; + const request = await Request.findByPk(id); + if (!request) { + return res.status(404).render('error/404'); + } + res.render('admin/edit', { request, currentPage: 'admin' }); +}); + +app.post('/admin/edit', checkAdminAuth, async (req, res) => { + const { id, fullName, email, reason, telegram } = req.body; + await Request.update({ fullName, email, reason, telegram }, { where: { id } }); + res.redirect('/admin/dashboard'); +}); + // Start server on internal port defined in .env app.listen(process.env.INTERNAL_PORT, () => { console.log(`Server started on port ${process.env.INTERNAL_PORT}`); diff --git a/public/js/admin.js b/public/js/admin.js new file mode 100644 index 0000000..411103b --- /dev/null +++ b/public/js/admin.js @@ -0,0 +1,40 @@ +const body = document.body; +const modeSwitch = document.getElementById('modeSwitch'); +const iconSwitch = document.getElementById('iconSwitch'); +const nav = document.getElementById('nav'); + +function getCookie(name) { + const match = document.cookie.match(new RegExp('(^| )' + name + '=([^;]+)')); + return match ? match[2] : null; +} + +function setCookie(name, value, days) { + const d = new Date(); + d.setTime(d.getTime() + (days * 24 * 60 * 60 * 1000)); + document.cookie = `${name}=${value}; expires=${d.toUTCString()}; path=/`; +} + +function toggleTheme(theme) { + const isDark = theme === 'dark'; + body.classList.toggle('dark-mode', isDark); + body.classList.toggle('light-mode', !isDark); + iconSwitch.classList.toggle('bi-moon', isDark); + iconSwitch.classList.toggle('text-white', isDark); + iconSwitch.classList.toggle('bi-brightness-high', !isDark); + iconSwitch.classList.toggle('text-black', !isDark); + nav.classList.toggle('navbar-dark', isDark); + nav.classList.toggle('bg-dark', isDark); + nav.classList.toggle('navbar-light', !isDark); + nav.classList.toggle('bg-light', !isDark); +} + +document.addEventListener('DOMContentLoaded', () => { + const theme = getCookie('theme') || 'light'; + toggleTheme(theme); +}); + +modeSwitch.addEventListener('click', () => { + const newTheme = body.classList.contains('dark-mode') ? 'light' : 'dark'; + setCookie('theme', newTheme, 30); + toggleTheme(newTheme); +}); \ No newline at end of file diff --git a/src/admin/dash.ejs b/src/admin/dash.ejs index f24fde8..924c946 100644 --- a/src/admin/dash.ejs +++ b/src/admin/dash.ejs @@ -1,50 +1,58 @@ -<%- include('../shards/header', { title: 'Admin Dashboard - p0ntus mail' }) %> -
- <%- include('../shards/nav', { currentPage: 'admin' }) %> - Dashboard -
- - - - - - - - - - - - - - - <% requests.forEach(request => { %> +<%- include('shards/header', { title: 'Admin Dashboard - p0ntus mail' }) %> +
+
+

Welcome, <%= user %>!

+

You are at viewing all requests

+
+
+
IDFull NameEmailReasonTelegramStatusUpdate StatusDelete
+ - - - - - - - - + + + + + + + + - <% }); %> - -
<%= request.id %><%= request.fullName %><%= request.email %><%= request.reason %><%= request.telegram %><%= request.status %> -
- - - -
-
-
- - -
-
IDFull NameEmailReasonTelegramStatusUpdate StatusDelete
+ + + <% requests.forEach(request => { %> + + <%= request.id %> + <%= request.fullName %> + <%= request.email %> + <%= request.reason %> + <%= request.telegram %> + <%= request.status %> + +
+ + + +
+ + + + + +
+ + +
+ + + <% }); %> + + +
-<%- include('../shards/footer') %> \ No newline at end of file +<%- include('shards/footer') %> \ No newline at end of file diff --git a/src/admin/edit.ejs b/src/admin/edit.ejs new file mode 100644 index 0000000..c06a30b --- /dev/null +++ b/src/admin/edit.ejs @@ -0,0 +1,25 @@ +<%- include('shards/header', { title: 'Edit Request - p0ntus mail' }) %> +
+

Edit Request

+
+ +
+ + +
+
+ + +
+
+ + +
+
+ + +
+ +
+
+<%- include('shards/footer') %> \ No newline at end of file diff --git a/src/admin/shards/footer.ejs b/src/admin/shards/footer.ejs new file mode 100644 index 0000000..8db4976 --- /dev/null +++ b/src/admin/shards/footer.ejs @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/src/admin/shards/header.ejs b/src/admin/shards/header.ejs new file mode 100644 index 0000000..10d5cc8 --- /dev/null +++ b/src/admin/shards/header.ejs @@ -0,0 +1,37 @@ + + + + + <%= title %> + + + + + + \ No newline at end of file