mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
dashboard next: activity metrics and new contributors
This commit also introduces a better grouping of data points.
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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";
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user