From d8873b450c719c239e401c9605b2719e602ae301 Mon Sep 17 00:00:00 2001 From: fatchan Date: Thu, 5 Dec 2019 07:43:59 +0000 Subject: [PATCH] search account username or baord URI on globalmanage accounts, and improve appearance --- db/accounts.js | 12 ++-- models/pages/boardlist.js | 2 +- models/pages/globalmanage/accounts.js | 26 ++++++++- views/pages/globalmanageaccounts.pug | 79 ++++++++++++++++----------- 4 files changed, 78 insertions(+), 41 deletions(-) diff --git a/db/accounts.js b/db/accounts.js index a8eaad1f..76e5b61b 100644 --- a/db/accounts.js +++ b/db/accounts.js @@ -16,8 +16,12 @@ module.exports = { }); }, - count: () => { - return db.estimatedDocumentCount(); + count: (filter) => { + if (filter) { + return db.countDocuments(filter); + } else { + return db.estimatedDocumentCount(); + } }, findOne: (username) => { @@ -48,8 +52,8 @@ module.exports = { }); }, - find: (skip=0, limit=0) => { - return db.find({}, { + find: (filter, skip=0, limit=0) => { + return db.find(filter, { 'projection': { 'passwordHash': 0 } diff --git a/models/pages/boardlist.js b/models/pages/boardlist.js index f4bcfb25..b64b02c1 100644 --- a/models/pages/boardlist.js +++ b/models/pages/boardlist.js @@ -11,7 +11,7 @@ module.exports = async (req, res, next) => { const isGlobalStaff = res.locals.permLevel <= 1; const { page, offset, queryString } = pageQueryConverter(req.query, limit); const direction = req.query.direction && req.query.direction === 'asc' ? 1 : -1; - let sort + let sort; if (req.query.sort && req.query.sort === 'activity') { sort = { 'lastPostTimestamp': direction diff --git a/models/pages/globalmanage/accounts.js b/models/pages/globalmanage/accounts.js index a550e72b..aaa4b30a 100644 --- a/models/pages/globalmanage/accounts.js +++ b/models/pages/globalmanage/accounts.js @@ -6,13 +6,30 @@ const { Accounts } = require(__dirname+'/../../../db/') module.exports = async (req, res, next) => { - const { page, offset } = pageQueryConverter(req.query, limit); + const { page, offset, queryString } = pageQueryConverter(req.query, limit); + + let filter = {}; + const username = req.query.username; + if (username && !Array.isArray(username)) { + filter['_id'] = username; + } + const uri = req.query.uri; + if (uri && !Array.isArray(uri)) { + filter['$or'] = [ + { + 'ownedBoards': uri + }, + { + 'modBoards': uri + }, + ]; + } let accounts, maxPage; try { [accounts, maxPage] = await Promise.all([ - Accounts.find(offset, limit), - Accounts.count(), + Accounts.find(filter, offset, limit), + Accounts.count(filter), ]); maxPage = Math.ceil(maxPage/limit); } catch (err) { @@ -21,6 +38,9 @@ module.exports = async (req, res, next) => { res.render('globalmanageaccounts', { csrf: req.csrfToken(), + queryString, + username, + uri, accounts, page, maxPage, diff --git a/views/pages/globalmanageaccounts.pug b/views/pages/globalmanageaccounts.pug index c29fe2e9..f55df84b 100644 --- a/views/pages/globalmanageaccounts.pug +++ b/views/pages/globalmanageaccounts.pug @@ -10,44 +10,57 @@ block content br +globalmanagenav('accounts') hr(size=1) - h4.no-m-p Accounts: .form-wrapper.flexleft - form.form-post(action=`/forms/global/editaccounts` method='POST' enctype='application/x-www-form-urlencoded') - input(type='hidden' name='_csrf' value=csrf) - .table-container.flex-left - table - tr - th - th Username - th Auth Level - th Own Boards - th Mod Boards - for account in accounts + h4.no-m-p Search: + form.form-post.mv-5(action=`/globalmanage/accounts.html` method='GET') + input(type='hidden' value=page) + .row + .label Username + input(type='text' name='username' value=username) + .row + .label Board URI + input(type='text' name='uri' value=uri) + input(type='submit', value='Filter') + h4.no-m-p Accounts: + if accounts && accounts.length > 0 + form.form-post(action=`/forms/global/editaccounts` method='POST' enctype='application/x-www-form-urlencoded') + input(type='hidden' name='_csrf' value=csrf) + .table-container.flex-left + table tr - td: input(type='checkbox', name='checkedaccounts' value=account._id) - td #{account._id} - td #{account.authLevel} - td - if account.ownedBoards.length > 0 - for b in account.ownedBoards - a(href=`/${b}/index.html`) /#{b}/ - | - else - | - - td - if account.modBoards.length > 0 - for b in account.modBoards - a(href=`/${b}/index.html`) /#{b}/ - | - else - | - - .pages.mt-5 + th + th Username + th Auth Level + th Own Boards + th Mod Boards + for account in accounts + tr + td: input(type='checkbox', name='checkedaccounts' value=account._id) + td #{account._id} + td #{account.authLevel} + td + if account.ownedBoards.length > 0 + for b in account.ownedBoards + a(href=`/${b}/index.html`) /#{b}/ + | + else + | - + td + if account.modBoards.length > 0 + for b in account.modBoards + a(href=`/${b}/index.html`) /#{b}/ + | + else + | - + .pages.mv-5 include ../includes/pages.pug + .row + .label Set Auth Level + input(type='number' name='auth_level') .row .label Delete Accounts label.postform-style.ph-5 input(type='checkbox', name='delete_account', value='true') - .row - .label Set Auth Level - input(type='number' name='auth_level') input(type='submit', value='apply') + else + p No results.