Skip to content

Commit

Permalink
feat: topics dashboard details subpage
Browse files Browse the repository at this point in the history
  • Loading branch information
julianlam committed Feb 24, 2021
1 parent c57c770 commit e1ed514
Show file tree
Hide file tree
Showing 7 changed files with 136 additions and 68 deletions.
7 changes: 6 additions & 1 deletion public/language/en-GB/admin/dashboard.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
20 changes: 19 additions & 1 deletion public/src/admin/dashboard/topics.js
Original file line number Diff line number Diff line change
@@ -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;
});
10 changes: 9 additions & 1 deletion src/controllers/admin/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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,
});
};
5 changes: 5 additions & 0 deletions src/views/admin/dashboard/logins.tpl
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
<div class="row dashboard">
<div class="col-xs-12">
<a class="btn btn-link" href="{config.relative_path}/admin/dashboard">
<i class="fa fa-chevron-left"></i>
[[admin/dashboard:back-to-dashboard]]
</a>

<!-- IMPORT admin/partials/dashboard/graph.tpl -->
<!-- IMPORT admin/partials/dashboard/stats.tpl -->
</div>
Expand Down
22 changes: 22 additions & 0 deletions src/views/admin/dashboard/topics.tpl
Original file line number Diff line number Diff line change
@@ -1,6 +1,28 @@
<div class="row dashboard">
<div class="col-xs-12">
<a class="btn btn-link" href="{config.relative_path}/admin/dashboard">
<i class="fa fa-chevron-left"></i>
[[admin/dashboard:back-to-dashboard]]
</a>

<!-- IMPORT admin/partials/dashboard/graph.tpl -->
<!-- IMPORT admin/partials/dashboard/stats.tpl -->

<table class="table table-striped topics-list">
<tbody>
{{{ if !topics.length}}}
<tr>
<td colspan=4" class="text-center"><em>[[admin/dashboard:details.no-topics]]</em></td>
</tr>
{{{ end }}}
{{{ each topics }}}
<tr>
<td><a href="{config.relative_path}/topics/{../slug}">{../title}</a></td>
<td>[[topic:posted_by, {../user.username}]]</td>
<td><span class="timeago" data-title="{../timestampISO}"></span></td>
</tr>
{{{ end }}}
</tbody>
</table>
</div>
</div>
52 changes: 32 additions & 20 deletions src/views/admin/dashboard/users.tpl
Original file line number Diff line number Diff line change
@@ -1,23 +1,35 @@
<div class="dashboard">
<!-- IMPORT admin/partials/dashboard/graph.tpl -->
<!-- IMPORT admin/partials/dashboard/stats.tpl -->
<div class="col-xs-12">
<a class="btn btn-link" href="{config.relative_path}/admin/dashboard">
<i class="fa fa-chevron-left"></i>
[[admin/dashboard:back-to-dashboard]]
</a>

<table class="table table-striped users-list">
<thead>
<th class="text-muted">[[admin/manage/users:users.uid]]</th>
<th class="text-muted">[[admin/manage/users:users.username]]</th>
<th class="text-muted">[[admin/manage/users:users.email]]</th>
<th data-sort="joindate">[[admin/manage/users:users.joined]]</th>
</thead>
<tbody>
{{{ each users }}}
<tr>
<td>{../uid}</td>
<td>{../username}</td>
<td>{../email}</td>
<td><span class="timeago" title="{../joindateISO}"></span></td>
</tr>
{{{ end }}}
</tbody>
</table>
<!-- IMPORT admin/partials/dashboard/graph.tpl -->
<!-- IMPORT admin/partials/dashboard/stats.tpl -->

<table class="table table-striped users-list">
<thead>
<th class="text-muted">[[admin/manage/users:users.uid]]</th>
<th class="text-muted">[[admin/manage/users:users.username]]</th>
<th class="text-muted">[[admin/manage/users:users.email]]</th>
<th data-sort="joindate">[[admin/manage/users:users.joined]]</th>
</thead>
<tbody>
{{{ if !users.length}}}
<tr>
<td colspan=4" class="text-center"><em>[[admin/dashboard:details.no-logins]]</em></td>
</tr>
{{{ end }}}
{{{ each users }}}
<tr>
<td>{../uid}</td>
<td>{../username}</td>
<td>{../email}</td>
<td><span class="timeago" title="{../joindateISO}"></span></td>
</tr>
{{{ end }}}
</tbody>
</table>
</div>
</div>
88 changes: 43 additions & 45 deletions src/views/admin/partials/dashboard/stats.tpl
Original file line number Diff line number Diff line change
@@ -1,49 +1,47 @@
<div class="row">
<div class="table-responsive">
<table class="table table-striped">
<thead>
<tr>
<th></th>
<th class="text-right">[[admin/dashboard:stats.yesterday]]</th>
<th class="text-right">[[admin/dashboard:stats.today]]</th>
<th></th>
<th class="text-right">[[admin/dashboard:stats.last-week]]</th>
<th class="text-right">[[admin/dashboard:stats.this-week]]</th>
<th></th>
<th class="text-right">[[admin/dashboard:stats.last-month]]</th>
<th class="text-right">[[admin/dashboard:stats.this-month]]</th>
<th></th>
<th class="text-right">[[admin/dashboard:stats.all]]</th>
</tr>
</thead>
<tbody>
<!-- BEGIN stats -->
<tr>
<td>
<strong>
{{{ if ../href }}}
<a href="{../href}">{../name}</a>
{{{ else }}}
{../name}
{{{ end }}}
</strong>
</td>
<td class="text-right formatted-number">{stats.yesterday}</td>
<td class="text-right formatted-number">{stats.today}</td>
<td class="{stats.dayTextClass}"><small>{stats.dayIncrease}%</small></td>
<div class="table-responsive">
<table class="table table-striped">
<thead>
<tr>
<th></th>
<th class="text-right">[[admin/dashboard:stats.yesterday]]</th>
<th class="text-right">[[admin/dashboard:stats.today]]</th>
<th></th>
<th class="text-right">[[admin/dashboard:stats.last-week]]</th>
<th class="text-right">[[admin/dashboard:stats.this-week]]</th>
<th></th>
<th class="text-right">[[admin/dashboard:stats.last-month]]</th>
<th class="text-right">[[admin/dashboard:stats.this-month]]</th>
<th></th>
<th class="text-right">[[admin/dashboard:stats.all]]</th>
</tr>
</thead>
<tbody>
<!-- BEGIN stats -->
<tr>
<td>
<strong>
{{{ if ../href }}}
<a href="{../href}">{../name}</a>
{{{ else }}}
{../name}
{{{ end }}}
</strong>
</td>
<td class="text-right formatted-number">{stats.yesterday}</td>
<td class="text-right formatted-number">{stats.today}</td>
<td class="{stats.dayTextClass}"><small>{stats.dayIncrease}%</small></td>

<td class="text-right formatted-number">{stats.lastweek}</td>
<td class="text-right formatted-number">{stats.thisweek}</td>
<td class="{stats.weekTextClass}"><small>{stats.weekIncrease}%</small></td>
<td class="text-right formatted-number">{stats.lastweek}</td>
<td class="text-right formatted-number">{stats.thisweek}</td>
<td class="{stats.weekTextClass}"><small>{stats.weekIncrease}%</small></td>

<td class="text-right formatted-number">{stats.lastmonth}</td>
<td class="text-right formatted-number">{stats.thismonth}</td>
<td class="{stats.monthTextClass}"><small>{stats.monthIncrease}%</small></td>
<td class="text-right formatted-number">{stats.lastmonth}</td>
<td class="text-right formatted-number">{stats.thismonth}</td>
<td class="{stats.monthTextClass}"><small>{stats.monthIncrease}%</small></td>

<td class="text-right formatted-number">{stats.alltime}</td>
</tr>
<!-- END stats -->
</tbody>
</table>
</div>
<td class="text-right formatted-number">{stats.alltime}</td>
</tr>
<!-- END stats -->
</tbody>
</table>
</div>

0 comments on commit e1ed514

Please sign in to comment.