add articles panel

This commit is contained in:
b1ek 2023-02-27 23:26:24 +10:00
parent 3a1b0d9dbc
commit aa1f6e072b
Signed by: blek
GPG Key ID: 14546221E3595D0C
5 changed files with 55 additions and 14 deletions

View File

@ -38,6 +38,11 @@ Article.structure = {
gpgsign: {
type: DataTypes.TEXT,
allowNull: true
},
hidden: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: false
}
};

View File

@ -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;

View File

@ -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;

View File

@ -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,

View File

@ -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')
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.