mirror of https://gitgud.io/fatchan/jschan.git
merge-requests/208/head
parent
3e2b361607
commit
f2df1aea4b
9 changed files with 162 additions and 27 deletions
@ -0,0 +1,76 @@ |
||||
'use strict'; |
||||
|
||||
const { Boards } = require(__dirname+'/../../../db/') |
||||
, { relativeColor, relativeString } = require(__dirname+'/../../../helpers/timeutils.js') |
||||
, pageQueryConverter = require(__dirname+'/../../../helpers/pagequeryconverter.js') |
||||
, limit = 20; |
||||
|
||||
module.exports = async (req, res, next) => { |
||||
|
||||
const { page, offset, queryString } = pageQueryConverter(req.query, limit); |
||||
const direction = req.query.direction && req.query.direction === 'asc' ? 1 : -1; |
||||
const search = (typeof req.query.search === 'string' ? req.query.search : null); |
||||
let sort = req.query.sort && req.query.sort === 'activity' ? 'activity' : 'popularity'; |
||||
|
||||
if (sort === 'activity') { |
||||
sort = { |
||||
'lastPostTimestamp': direction |
||||
} |
||||
} else { |
||||
sort = { |
||||
'ips': direction, |
||||
'pph': direction, |
||||
'sequence_value': direction |
||||
}; |
||||
} |
||||
|
||||
let filter = {}; |
||||
if (req.query.search && search) { |
||||
filter = { |
||||
'search': search |
||||
} |
||||
} |
||||
|
||||
let localBoards, pages, maxPage; |
||||
try { |
||||
[ localBoards, pages ] = await Promise.all([ |
||||
Boards.boardSort(offset, limit, sort, filter, true), |
||||
Boards.count(filter, true), |
||||
]); |
||||
maxPage = Math.ceil(pages / limit); |
||||
} catch (err) { |
||||
return next(err); |
||||
} |
||||
|
||||
const now = new Date(); |
||||
if (localBoards) { |
||||
for (let i = 0; i < localBoards.length; i++) { |
||||
if (localBoards[i].lastPostTimestamp) { |
||||
const lastPostDate = new Date(localBoards[i].lastPostTimestamp); |
||||
localBoards[i].lastPostTimestamp = { |
||||
text: relativeString(now, lastPostDate), |
||||
color: relativeColor(now, lastPostDate) |
||||
} |
||||
} |
||||
} |
||||
} |
||||
res.set('Cache-Control', 'private, max-age=60'); |
||||
|
||||
if (req.path.endsWith('/boards.json')) { |
||||
res.json({ |
||||
localBoards, |
||||
page, |
||||
maxPage, |
||||
}); |
||||
} else { |
||||
res.render('globalmanageboardlist', { |
||||
localBoards, |
||||
page, |
||||
maxPage, |
||||
query: req.query, |
||||
search, |
||||
queryString, |
||||
}); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,57 @@ |
||||
extends ../layout.pug |
||||
include ../mixins/ban.pug |
||||
include ../mixins/globalmanagenav.pug |
||||
|
||||
block head |
||||
title Manage |
||||
|
||||
block content |
||||
h1.board-title Global Management |
||||
br |
||||
+globalmanagenav('boards') |
||||
hr(size=1) |
||||
h4.text-center.no-m-p Filter: |
||||
.flexcenter.mv-10 |
||||
form.form-post(action='/globalmanage/boards.html' method='GET') |
||||
input(type='hidden' value=page) |
||||
.row |
||||
.label Search |
||||
input(type='text' name='search' value=search placeholder='Uri or tags') |
||||
.row |
||||
.label Sort |
||||
select(name='sort') |
||||
option(value='popularity') Popularity |
||||
option(value='activity' selected=query.sort === 'activity') Latest Activity |
||||
.row |
||||
.label Order |
||||
select(name='direction') |
||||
option(value='desc') Descending |
||||
option(value='asc' selected=query.direction === 'asc') Ascending |
||||
input(type='submit', value='Filter') |
||||
if localBoards && localBoards.length > 0 |
||||
h4.text-center.mv-10 Board List: |
||||
include ../includes/webringboardtable.pug |
||||
each board in localBoards |
||||
tr |
||||
td |
||||
span.left |
||||
if board.settings.sfw === true |
||||
span.help(title='SFW') 💼 |
||||
| |
||||
if board.settings.unlistedLocal === true |
||||
span.help(title='Unlisted') 👁️ |
||||
| |
||||
if !board.owner && board.settings.moderators.length === 0 |
||||
span.help(title='Abandoned') 🏚️ |
||||
| |
||||
a(href=`/${board._id}/index.html`) /#{board._id}/ - #{board.settings.name} |
||||
td #{board.settings.description} |
||||
td #{board.pph} |
||||
td #{board.ips} |
||||
td #{board.sequence_value-1} |
||||
if board.lastPostTimestamp |
||||
td(style=`background-color: ${board.lastPostTimestamp.color}`) #{board.lastPostTimestamp.text} |
||||
else |
||||
td - |
||||
.pages.text-center.mt-5.mv-0 |
||||
include ../includes/pages.pug |
Loading…
Reference in new issue