From aa1f6e072b1be5c8e5e480b31319ceb4a18ff0c5 Mon Sep 17 00:00:00 2001 From: b1ek Date: Mon, 27 Feb 2023 23:26:24 +1000 Subject: [PATCH] add articles panel --- models/article.js | 5 +++ models/user.js | 3 +- public/static/ui/control_panel.css | 9 +++++- routes/admin.js | 2 ++ view/admin/panel.pug | 50 +++++++++++++++++++++++------- 5 files changed, 55 insertions(+), 14 deletions(-) diff --git a/models/article.js b/models/article.js index 98eb933..9aac7ee 100644 --- a/models/article.js +++ b/models/article.js @@ -38,6 +38,11 @@ Article.structure = { gpgsign: { type: DataTypes.TEXT, allowNull: true + }, + hidden: { + type: DataTypes.BOOLEAN, + allowNull: false, + defaultValue: false } }; diff --git a/models/user.js b/models/user.js index d001c70..04af7df 100644 --- a/models/user.js +++ b/models/user.js @@ -73,7 +73,8 @@ class User extends Model { * @returns User */ static async bySession(session) { - if (!session.user.user_id) return; + if (session.user == undefined) return; + if (session.user.user_id == undefined) return; const user = await User.findOne({where: {id: session.user.user_id}}); if (!user) { return false; diff --git a/public/static/ui/control_panel.css b/public/static/ui/control_panel.css index 7689eee..fee5d1e 100644 --- a/public/static/ui/control_panel.css +++ b/public/static/ui/control_panel.css @@ -1,8 +1,15 @@ +.control_panel { + border-collapse: separate; + border-spacing: 5px; +} .cp_panel_panel { border: 1px solid #c2c4c2; - padding: 4px; + border-radius: 2px; + padding: 4px 8px; min-height: 300px; font-size: 9pt; + max-width: 386px; + box-shadow: 0 2px 1px #20202010; } .cp_panel_panel h5 { font-size: 1.1em; diff --git a/routes/admin.js b/routes/admin.js index f673dbe..e769906 100644 --- a/routes/admin.js +++ b/routes/admin.js @@ -39,6 +39,8 @@ async function panel(req, res) { order: [['id', 'DESC']] }); + const articles = await db.Article.findAll({where: {hidden: true}}); + res.send(await Helpers.ViewLoader.load('admin/panel.pug', { current_route: req.originalUrl, gb_records, diff --git a/view/admin/panel.pug b/view/admin/panel.pug index 7df37ca..dd0fc28 100644 --- a/view/admin/panel.pug +++ b/view/admin/panel.pug @@ -13,7 +13,7 @@ block content | Warning: Your access level is unkown, so everything is displayed and some funtions may not work. hr - access_level = 4 - table + table(class='control_panel') tr td(class='cp_panel_panel') h5 Guestbook panel @@ -25,19 +25,26 @@ block content a(href='/admin/panel/guestbook.csv') Download data (.CSV) br a(href='/admin/panel/guestbook.csv') Download data (SQL) - form(action='/admin/panel/gb_api') - h5 Import from file - label(for='filetype') File type: - select(name='filetype') - option(value='csv') .CSV - option(value='sql') SQL - br - input(type='file' name='file') - br - input(type='submit' name='import' value='Send') + if (access_level >= 4) + div(style='padding-left:4px') + form(action='/admin/panel/gb_api') + h5 Import from file + p + b WARNING: + | All the records will be removed and replaced with your values! + label(for='filetype') File type: + select(name='filetype') + option(value='csv') .CSV + option(value='sql') .TSV + br + input(type='file' name='file') + br + input(type='submit' name='import' value='Send') hr div(style='max-height:160px;overflow-y:scroll') table + if (!gb_records || gb_records.length == 0) + p Nothing to show. each record of gb_records tr(class='' + (record.hidden ? 'cp_gb_entry_hidden' : '')) form(action='/admin/panel/gb_api' method='POST') @@ -56,4 +63,23 @@ block content input(type='submit' name='hide' value='Hide') else input(type='submit' name='hide' value='Unhide') - \ No newline at end of file + td(class='cp_panel_panel') + h5 Articles + hr + p + a(href='/admin/article/new') Create new article + if (access_level >= 4) + br + a(href='/admin/articles.csv') Download data (.CSV) + br + a(href='/admin/articles.sql') Download data (SQL) + div(style='padding-left:4px') + form(action='/admin/panel/article_api' method='POST') + h5 Import from file + p + b WARNING: + | All the records will be removed and replaced with your values! + hr + if (!articles) + p Nothing to show. + \ No newline at end of file