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: { gpgsign: {
type: DataTypes.TEXT, type: DataTypes.TEXT,
allowNull: true allowNull: true
},
hidden: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: false
} }
}; };

View File

@ -73,7 +73,8 @@ class User extends Model {
* @returns User * @returns User
*/ */
static async bySession(session) { 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}}); const user = await User.findOne({where: {id: session.user.user_id}});
if (!user) { if (!user) {
return false; return false;

View File

@ -1,8 +1,15 @@
.control_panel {
border-collapse: separate;
border-spacing: 5px;
}
.cp_panel_panel { .cp_panel_panel {
border: 1px solid #c2c4c2; border: 1px solid #c2c4c2;
padding: 4px; border-radius: 2px;
padding: 4px 8px;
min-height: 300px; min-height: 300px;
font-size: 9pt; font-size: 9pt;
max-width: 386px;
box-shadow: 0 2px 1px #20202010;
} }
.cp_panel_panel h5 { .cp_panel_panel h5 {
font-size: 1.1em; font-size: 1.1em;

View File

@ -39,6 +39,8 @@ async function panel(req, res) {
order: [['id', 'DESC']] order: [['id', 'DESC']]
}); });
const articles = await db.Article.findAll({where: {hidden: true}});
res.send(await Helpers.ViewLoader.load('admin/panel.pug', { res.send(await Helpers.ViewLoader.load('admin/panel.pug', {
current_route: req.originalUrl, current_route: req.originalUrl,
gb_records, 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. | Warning: Your access level is unkown, so everything is displayed and some funtions may not work.
hr hr
- access_level = 4 - access_level = 4
table table(class='control_panel')
tr tr
td(class='cp_panel_panel') td(class='cp_panel_panel')
h5 Guestbook panel h5 Guestbook panel
@ -25,12 +25,17 @@ block content
a(href='/admin/panel/guestbook.csv') Download data (.CSV) a(href='/admin/panel/guestbook.csv') Download data (.CSV)
br br
a(href='/admin/panel/guestbook.csv') Download data (SQL) a(href='/admin/panel/guestbook.csv') Download data (SQL)
if (access_level >= 4)
div(style='padding-left:4px')
form(action='/admin/panel/gb_api') form(action='/admin/panel/gb_api')
h5 Import from file h5 Import from file
p
b WARNING:
| All the records will be removed and replaced with your values!
label(for='filetype') File type: label(for='filetype') File type:
select(name='filetype') select(name='filetype')
option(value='csv') .CSV option(value='csv') .CSV
option(value='sql') SQL option(value='sql') .TSV
br br
input(type='file' name='file') input(type='file' name='file')
br br
@ -38,6 +43,8 @@ block content
hr hr
div(style='max-height:160px;overflow-y:scroll') div(style='max-height:160px;overflow-y:scroll')
table table
if (!gb_records || gb_records.length == 0)
p Nothing to show.
each record of gb_records each record of gb_records
tr(class='' + (record.hidden ? 'cp_gb_entry_hidden' : '')) tr(class='' + (record.hidden ? 'cp_gb_entry_hidden' : ''))
form(action='/admin/panel/gb_api' method='POST') form(action='/admin/panel/gb_api' method='POST')
@ -56,4 +63,23 @@ block content
input(type='submit' name='hide' value='Hide') input(type='submit' name='hide' value='Hide')
else else
input(type='submit' name='hide' value='Unhide') 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.