From e1ed514b10e6d53586d03c93323734d49731e1ce Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Wed, 24 Feb 2021 10:01:54 -0500 Subject: [PATCH] feat: topics dashboard details subpage --- public/language/en-GB/admin/dashboard.json | 7 +- public/src/admin/dashboard/topics.js | 20 ++++- src/controllers/admin/dashboard.js | 10 ++- src/views/admin/dashboard/logins.tpl | 5 ++ src/views/admin/dashboard/topics.tpl | 22 +++++ src/views/admin/dashboard/users.tpl | 52 +++++++----- src/views/admin/partials/dashboard/stats.tpl | 88 ++++++++++---------- 7 files changed, 136 insertions(+), 68 deletions(-) diff --git a/public/language/en-GB/admin/dashboard.json b/public/language/en-GB/admin/dashboard.json index f2aaff8415..6406c8c985 100644 --- a/public/language/en-GB/admin/dashboard.json +++ b/public/language/en-GB/admin/dashboard.json @@ -76,5 +76,10 @@ "graphs.registered-users": "Registered Users", "graphs.anonymous-users": "Anonymous Users", "last-restarted-by": "Last restarted by", - "no-users-browsing": "No users browsing" + "no-users-browsing": "No users browsing", + + "back-to-dashboard": "Back to Dashboard", + "details.no-users": "No users have joined within the selected timeframe", + "details.no-topics": "No topics have been posted within the selected timeframe", + "details.no-logins": "No logins have been recorded within the selected timeframe" } diff --git a/public/src/admin/dashboard/topics.js b/public/src/admin/dashboard/topics.js index 6bf8cc65dc..91e0754779 100644 --- a/public/src/admin/dashboard/topics.js +++ b/public/src/admin/dashboard/topics.js @@ -1,14 +1,32 @@ 'use strict'; -define('admin/dashboard/topics', ['admin/modules/dashboard-line-graph'], (graph) => { +define('admin/dashboard/topics', ['admin/modules/dashboard-line-graph', 'hooks'], (graph, hooks) => { const ACP = {}; ACP.init = () => { graph.init({ set: 'topics', dataset: ajaxify.data.dataset, + }).then(() => { + hooks.onPage('action:admin.dashboard.updateGraph', ACP.updateTable); }); }; + ACP.updateTable = () => { + if (window.fetch) { + fetch(`${config.relative_path}/api${ajaxify.data.url}${window.location.search}`, { credentials: 'include' }).then((response) => { + if (response.ok) { + response.json().then(function (payload) { + app.parseAndTranslate(ajaxify.data.template.name, 'topics', payload, function (html) { + const tbodyEl = document.querySelector('.topics-list tbody'); + tbodyEl.innerHTML = ''; + tbodyEl.append(...html.map((idx, el) => el)); + }); + }); + } + }); + } + }; + return ACP; }); diff --git a/src/controllers/admin/dashboard.js b/src/controllers/admin/dashboard.js index 8ecff0b26e..d864706c41 100644 --- a/src/controllers/admin/dashboard.js +++ b/src/controllers/admin/dashboard.js @@ -11,6 +11,7 @@ const meta = require('../../meta'); const analytics = require('../../analytics'); const plugins = require('../../plugins'); const user = require('../../user'); +const topics = require('../../topics'); const utils = require('../../utils'); const dashboardController = module.exports; @@ -261,7 +262,7 @@ dashboardController.getUsers = async (req, res) => { month: stats[0].thismonth, }; - // List of recently registered users + // List of users registered within time frame const end = parseInt(req.query.until, 10) || Date.now(); const start = end - (1000 * 60 * 60 * (req.query.units === 'days' ? 24 : 1) * (req.query.count || (req.query.units === 'days' ? 30 : 24))); const uids = await db.getSortedSetRangeByScore('users:joindate', 0, 500, start, end); @@ -288,10 +289,17 @@ dashboardController.getTopics = async (req, res) => { month: stats[0].thismonth, }; + // List of topics created within time frame + const end = parseInt(req.query.until, 10) || Date.now(); + const start = end - (1000 * 60 * 60 * (req.query.units === 'days' ? 24 : 1) * (req.query.count || (req.query.units === 'days' ? 30 : 24))); + const tids = await db.getSortedSetRangeByScore('topics:tid', 0, 500, start, end); + const topicData = await topics.getTopicsByTids(tids); + res.render('admin/dashboard/topics', { set: 'topics', query: req.query, stats, summary, + topics: topicData, }); }; diff --git a/src/views/admin/dashboard/logins.tpl b/src/views/admin/dashboard/logins.tpl index 64e7c1cc61..ec9f431882 100644 --- a/src/views/admin/dashboard/logins.tpl +++ b/src/views/admin/dashboard/logins.tpl @@ -1,5 +1,10 @@
diff --git a/src/views/admin/dashboard/topics.tpl b/src/views/admin/dashboard/topics.tpl index 64e7c1cc61..98b86e5e8c 100644 --- a/src/views/admin/dashboard/topics.tpl +++ b/src/views/admin/dashboard/topics.tpl @@ -1,6 +1,28 @@
+ + + [[admin/dashboard:back-to-dashboard]] + + + + + + {{{ if !topics.length}}} + + + + {{{ end }}} + {{{ each topics }}} + + + + + + {{{ end }}} + +
[[admin/dashboard:details.no-topics]]
{../title}[[topic:posted_by, {../user.username}]]
\ No newline at end of file diff --git a/src/views/admin/dashboard/users.tpl b/src/views/admin/dashboard/users.tpl index e6851fa06a..7c6e249b49 100644 --- a/src/views/admin/dashboard/users.tpl +++ b/src/views/admin/dashboard/users.tpl @@ -1,23 +1,35 @@
- - +
+ + + [[admin/dashboard:back-to-dashboard]] + - - - - - - - - - {{{ each users }}} - - - - - - - {{{ end }}} - -
[[admin/manage/users:users.uid]][[admin/manage/users:users.username]][[admin/manage/users:users.email]][[admin/manage/users:users.joined]]
{../uid}{../username}{../email}
+ + + + + + + + + + + + {{{ if !users.length}}} + + + + {{{ end }}} + {{{ each users }}} + + + + + + + {{{ end }}} + +
[[admin/manage/users:users.uid]][[admin/manage/users:users.username]][[admin/manage/users:users.email]][[admin/manage/users:users.joined]]
[[admin/dashboard:details.no-logins]]
{../uid}{../username}{../email}
+
\ No newline at end of file diff --git a/src/views/admin/partials/dashboard/stats.tpl b/src/views/admin/partials/dashboard/stats.tpl index a77b01d355..d89fe04b0c 100644 --- a/src/views/admin/partials/dashboard/stats.tpl +++ b/src/views/admin/partials/dashboard/stats.tpl @@ -1,49 +1,47 @@ -
-
- - - - - - - - - - - - - - - - - - - - - - - +
+
[[admin/dashboard:stats.yesterday]][[admin/dashboard:stats.today]][[admin/dashboard:stats.last-week]][[admin/dashboard:stats.this-week]][[admin/dashboard:stats.last-month]][[admin/dashboard:stats.this-month]][[admin/dashboard:stats.all]]
- - {{{ if ../href }}} - {../name} - {{{ else }}} - {../name} - {{{ end }}} - - {stats.yesterday}{stats.today}{stats.dayIncrease}%
+ + + + + + + + + + + + + + + + + + + + + + - - - + + + - - - + + + - - - - -
[[admin/dashboard:stats.yesterday]][[admin/dashboard:stats.today]][[admin/dashboard:stats.last-week]][[admin/dashboard:stats.this-week]][[admin/dashboard:stats.last-month]][[admin/dashboard:stats.this-month]][[admin/dashboard:stats.all]]
+ + {{{ if ../href }}} + {../name} + {{{ else }}} + {../name} + {{{ end }}} + + {stats.yesterday}{stats.today}{stats.dayIncrease}%{stats.lastweek}{stats.thisweek}{stats.weekIncrease}%{stats.lastweek}{stats.thisweek}{stats.weekIncrease}%{stats.lastmonth}{stats.thismonth}{stats.monthIncrease}%{stats.lastmonth}{stats.thismonth}{stats.monthIncrease}%{stats.alltime}
-
+ {stats.alltime} + + + +
\ No newline at end of file