add guestbook panel with hide functionality

This commit is contained in:
b1ek 2023-02-27 18:04:10 +10:00
parent 24f680eb5c
commit 8e5cb9dfcc
Signed by: blek
GPG Key ID: 14546221E3595D0C
5 changed files with 97 additions and 2 deletions

View File

@ -61,7 +61,6 @@ a:visited {
.main_contents {
padding: 16px 12px;
}
.flag_hr {
background: linear-gradient(0,#5BCEFA 20%,#F5A9B8 20%,40%,#FFFFFF 40%,60%,#F5A9B8 60%,80%,#5BCEFA 80%);

View File

@ -0,0 +1,22 @@
.cp_panel_panel {
border: 1px solid #c2c4c2;
padding: 4px;
min-height: 300px;
font-size: 9pt;
}
.cp_panel_panel h5 {
font-size: 1.1em;
margin: 3px 0;
padding: 0;
}
.cp_panel_panel a {
text-decoration: underline;
color: blue;
font-size: 100%;
}
.cp_gb_entry_hidden {
filter: opacity(0.7)
}
input[type=submit] {
cursor: pointer;
}

View File

@ -27,12 +27,37 @@ async function apiLogin(req, res) {
}
async function panel(req, res) {
const gb_records = await db.Guestbook.findAll({
order: [['id', 'DESC']]
});
res.send(await Helpers.ViewLoader.load('admin/panel.pug', {
current_route: req.originalUrl
current_route: req.originalUrl,
gb_records
}));
return;
}
async function gb_api(req, res) {
let action = false;
const id = req.body.id;
if (req.body.hide) action = 'hide';
if (!action) {
res.redirect('/admin/panel');
return;
}
switch (action) {
case 'hide':
const response = await db.Guestbook.update({hidden: db.Sequelize.literal('NOT hidden')}, {where: {id}})
res.redirect('/admin/panel');
return;
}
}
module.exports = (router) => {
// login
@ -42,5 +67,6 @@ module.exports = (router) => {
// panel
router.get('/admin/panel', handler(panel));
router.post('/admin/panel/gb_api', handler(gb_api));
}

46
view/admin/panel.pug Normal file
View File

@ -0,0 +1,46 @@
extends ../layout/main.pug
block root
- var title = 'Admin panel'
block head
link(rel='stylesheet' href='/static/ui/control_panel.css')
block content
h2 Admin panel
hr
if !access_level
p(style='color:#a02020;font-weight:bold;font-size:1em')
| Warning: Your access level is unkown, so everything is displayed and some funtions may not work.
hr
- access_level = 4
table
tr
td(class='cp_panel_panel')
h5 Guestbook panel
hr
p
a(href='/admin/panel/guestbook.editor') Edit data
br
a(href='/admin/panel/guestbook.csv') Download data (.CSV)
br
a(href='/admin/panel/guestbook.csv') Download data (SQL)
hr
table
each record of gb_records
tr(class='' + (record.hidden ? 'cp_gb_entry_hidden' : ''))
form(action='/admin/panel/gb_api' method='POST')
input(type='hidden' name='id' value=record.id)
td
a(href='/guestbook#gb_entry_' + record.id)= record.id
| : #{record.name}
td
if (record.text.length > 40)
| #{record.text.substr(0, 40)}...
else
| #{record.text}
td
if (!record.hidden)
input(type='submit' name='hide' value='Hide')
else
input(type='submit' name='hide' value='Unhide')

2
view/ui/button.pug Normal file
View File

@ -0,0 +1,2 @@
mixin button(text)