dashboard next: activity metrics and new contributors

This commit also introduces a better grouping of data points.
This commit is contained in:
Joffrey JAFFEUX
2018-04-26 14:49:41 +02:00
committed by GitHub
parent b26e27bdab
commit 9fabf2543b
16 changed files with 260 additions and 128 deletions

View File

@@ -1,9 +1,13 @@
import { ajax } from 'discourse/lib/ajax';
import { ajax } from "discourse/lib/ajax";
import Report from "admin/models/report";
const ATTRIBUTES = [ "disk_space", "updated_at", "last_backup_taken_at"];
const REPORTS = [ "global_reports", "user_reports" ];
const AdminDashboardNext = Discourse.Model.extend({});
AdminDashboardNext.reopenClass({
/**
Fetch all dashboard data. This can be an expensive request when the cached data
has expired and the server must collect the data again.
@@ -11,13 +15,26 @@ AdminDashboardNext.reopenClass({
@method find
@return {jqXHR} a jQuery Promise object
**/
find: function() {
find() {
return ajax("/admin/dashboard-next.json").then(function(json) {
var model = AdminDashboardNext.create(json);
model.set('loaded', true);
var model = AdminDashboardNext.create();
const reports = {};
REPORTS.forEach(name => json[name].forEach(r => {
if (!reports[name]) reports[name] = {};
reports[name][r.type] = Report.create(r);
}));
model.set("reports", reports);
const attributes = {};
ATTRIBUTES.forEach(a => attributes[a] = json[a]);
model.set("attributes", attributes);
model.set("loaded", true);
return model;
});
},
}
});
export default AdminDashboardNext;

View File

@@ -60,12 +60,18 @@ const Report = Discourse.Model.extend({
sevenDayTrend() {
const currentPeriod = this.valueFor(1, 7);
const prevPeriod = this.valueFor(8, 14);
if (currentPeriod > prevPeriod) {
const change = ((currentPeriod - prevPeriod) / prevPeriod) * 100;
if (change > 50) {
return "high-trending-up";
} else if (change > 0) {
return "trending-up";
} else if (currentPeriod < prevPeriod) {
return "trending-down";
} else {
} else if (change === 0) {
return "no-change";
} else if (change < -50) {
return "high-trending-down";
} else if (change < 0) {
return "trending-down";
}
},