Skip to content

Commit

Permalink
DEV: removes old dashboard (#7295)
Browse files Browse the repository at this point in the history
  • Loading branch information
jjaffeux committed Apr 1, 2019
1 parent d81f3ee commit e986e96
Show file tree
Hide file tree
Showing 39 changed files with 323 additions and 919 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { setting } from "discourse/lib/computed";
import computed from "ember-addons/ember-computed-decorators";
import AdminDashboardNext from "admin/models/admin-dashboard-next";
import AdminDashboard from "admin/models/admin-dashboard";
import Report from "admin/models/report";
import PeriodComputationMixin from "admin/mixins/period-computation";

Expand Down Expand Up @@ -88,12 +88,12 @@ export default Ember.Controller.extend(PeriodComputationMixin, {
) {
this.set("isLoading", true);

AdminDashboardNext.fetchGeneral()
.then(adminDashboardNextModel => {
AdminDashboard.fetchGeneral()
.then(adminDashboardModel => {
this.setProperties({
dashboardFetchedAt: new Date(),
model: adminDashboardNextModel,
reports: Ember.makeArray(adminDashboardNextModel.reports).map(x =>
model: adminDashboardModel,
reports: Ember.makeArray(adminDashboardModel.reports).map(x =>
Report.create(x)
)
});
Expand Down

This file was deleted.

100 changes: 56 additions & 44 deletions app/assets/javascripts/admin/controllers/admin-dashboard.js.es6
Original file line number Diff line number Diff line change
@@ -1,78 +1,90 @@
import AdminDashboard from "admin/models/admin-dashboard";
import Report from "admin/models/report";
import AdminUser from "admin/models/admin-user";
import { setting } from "discourse/lib/computed";
import computed from "ember-addons/ember-computed-decorators";
import AdminDashboard from "admin/models/admin-dashboard";
import VersionCheck from "admin/models/version-check";

const ATTRIBUTES = [
"admins",
"moderators",
"silenced",
"suspended",
"top_traffic_sources",
"top_referred_topics",
"updated_at"
];

const REPORTS = [
"global_reports",
"page_view_reports",
"private_message_reports",
"http_reports",
"user_reports",
"mobile_reports"
];
const PROBLEMS_CHECK_MINUTES = 1;

// This controller supports the default interface when you enter the admin section.
export default Ember.Controller.extend({
loading: null,
versionCheck: null,
isLoading: false,
dashboardFetchedAt: null,
exceptionController: Ember.inject.controller("exception"),
showVersionChecks: setting("version_checks"),

@computed("problems.length")
foundProblems(problemsLength) {
return this.currentUser.get("admin") && (problemsLength || 0) > 0;
},

fetchProblems() {
if (this.get("isLoadingProblems")) return;

if (
!this.get("problemsFetchedAt") ||
moment()
.subtract(PROBLEMS_CHECK_MINUTES, "minutes")
.toDate() > this.get("problemsFetchedAt")
) {
this._loadProblems();
}
},

fetchDashboard() {
const versionChecks = this.siteSettings.version_checks;

if (this.get("isLoading") || !versionChecks) return;

if (
!this.get("dashboardFetchedAt") ||
moment()
.subtract(30, "minutes")
.toDate() > this.get("dashboardFetchedAt")
) {
this.set("loading", true);
AdminDashboard.find()
.then(d => {
this.set("dashboardFetchedAt", new Date());
this.set("isLoading", true);

REPORTS.forEach(name =>
this.set(name, d[name].map(r => Report.create(r)))
);
AdminDashboard.fetch()
.then(model => {
let properties = {
dashboardFetchedAt: new Date()
};

const topReferrers = d.top_referrers;
if (topReferrers && topReferrers.data) {
d.top_referrers.data = topReferrers.data.map(user =>
AdminUser.create(user)
);
this.set("top_referrers", topReferrers);
if (versionChecks) {
properties.versionCheck = VersionCheck.create(model.version_check);
}

ATTRIBUTES.forEach(a => this.set(a, d[a]));
this.setProperties(properties);
})
.catch(e => {
this.get("exceptionController").set("thrown", e.jqXHR);
this.replaceRoute("exception");
})
.finally(() => {
this.set("loading", false);
this.set("isLoading", false);
});
}
},

@computed("updated_at")
updatedTimestamp(updatedAt) {
return moment(updatedAt).format("LLL");
_loadProblems() {
this.setProperties({
loadingProblems: true,
problemsFetchedAt: new Date()
});

AdminDashboard.fetchProblems()
.then(model => this.set("problems", model.problems))
.finally(() => this.set("loadingProblems", false));
},

@computed("problemsFetchedAt")
problemsTimestamp(problemsFetchedAt) {
return moment(problemsFetchedAt)
.locale("en")
.format("LLL");
},

actions: {
showTrafficReport() {
this.set("showTrafficReport", true);
refreshProblems() {
this._loadProblems();
}
}
});
9 changes: 8 additions & 1 deletion app/assets/javascripts/admin/controllers/admin.js.es6
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default Ember.Controller.extend({

@computed("application.currentPath")
adminContentsClassName(currentPath) {
return currentPath
let cssClasses = currentPath
.split(".")
.filter(segment => {
return (
Expand All @@ -27,5 +27,12 @@ export default Ember.Controller.extend({
})
.map(Ember.String.dasherize)
.join(" ");

// this is done to avoid breaking css customizations
if (cssClasses.includes("dashboard")) {
cssClasses = `${cssClasses} dashboard-next`;
}

return cssClasses;
}
});
52 changes: 0 additions & 52 deletions app/assets/javascripts/admin/models/admin-dashboard-next.js.es6

This file was deleted.

40 changes: 30 additions & 10 deletions app/assets/javascripts/admin/models/admin-dashboard.js.es6
Original file line number Diff line number Diff line change
@@ -1,18 +1,38 @@
import { ajax } from "discourse/lib/ajax";

const GENERAL_ATTRIBUTES = ["updated_at"];

const AdminDashboard = Discourse.Model.extend({});

AdminDashboard.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.
@method find
@return {jqXHR} a jQuery Promise object
**/
find: function() {
return ajax("/admin/dashboard-old.json").then(function(json) {
var model = AdminDashboard.create(json);
fetch() {
return ajax("/admin/dashboard.json").then(json => {
const model = AdminDashboard.create();
model.set("version_check", json.version_check);
return model;
});
},

fetchGeneral() {
return ajax("/admin/dashboard/general.json").then(json => {
const model = AdminDashboard.create();

const attributes = {};
GENERAL_ATTRIBUTES.forEach(a => (attributes[a] = json[a]));

model.setProperties({
reports: json.reports,
attributes,
loaded: true
});

return model;
});
},

fetchProblems() {
return ajax("/admin/dashboard/problems.json").then(json => {
const model = AdminDashboard.create(json);
model.set("loaded", true);
return model;
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default Discourse.Route.extend({
activate() {
this.controllerFor("admin-dashboard-general").fetchDashboard();
}
});

This file was deleted.

This file was deleted.

Loading

0 comments on commit e986e96

Please sign in to comment.