diff --git a/app/assets/javascripts/admin/controllers/admin-dashboard-next-general.js.es6 b/app/assets/javascripts/admin/controllers/admin-dashboard-general.js.es6 similarity index 91% rename from app/assets/javascripts/admin/controllers/admin-dashboard-next-general.js.es6 rename to app/assets/javascripts/admin/controllers/admin-dashboard-general.js.es6 index 34528173c98..044ad687451 100644 --- a/app/assets/javascripts/admin/controllers/admin-dashboard-next-general.js.es6 +++ b/app/assets/javascripts/admin/controllers/admin-dashboard-general.js.es6 @@ -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"; @@ -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) ) }); diff --git a/app/assets/javascripts/admin/controllers/admin-dashboard-next-moderation.js.es6 b/app/assets/javascripts/admin/controllers/admin-dashboard-moderation.js.es6 similarity index 100% rename from app/assets/javascripts/admin/controllers/admin-dashboard-next-moderation.js.es6 rename to app/assets/javascripts/admin/controllers/admin-dashboard-moderation.js.es6 diff --git a/app/assets/javascripts/admin/controllers/admin-dashboard-next.js.es6 b/app/assets/javascripts/admin/controllers/admin-dashboard-next.js.es6 deleted file mode 100644 index 1be0a8a7fa1..00000000000 --- a/app/assets/javascripts/admin/controllers/admin-dashboard-next.js.es6 +++ /dev/null @@ -1,90 +0,0 @@ -import { setting } from "discourse/lib/computed"; -import computed from "ember-addons/ember-computed-decorators"; -import AdminDashboardNext from "admin/models/admin-dashboard-next"; -import VersionCheck from "admin/models/version-check"; - -const PROBLEMS_CHECK_MINUTES = 1; - -export default Ember.Controller.extend({ - 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("isLoading", true); - - AdminDashboardNext.fetch() - .then(model => { - let properties = { - dashboardFetchedAt: new Date() - }; - - if (versionChecks) { - properties.versionCheck = VersionCheck.create(model.version_check); - } - - this.setProperties(properties); - }) - .catch(e => { - this.get("exceptionController").set("thrown", e.jqXHR); - this.replaceRoute("exception"); - }) - .finally(() => { - this.set("isLoading", false); - }); - } - }, - - _loadProblems() { - this.setProperties({ - loadingProblems: true, - problemsFetchedAt: new Date() - }); - - AdminDashboardNext.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: { - refreshProblems() { - this._loadProblems(); - } - } -}); diff --git a/app/assets/javascripts/admin/controllers/admin-dashboard-next-reports.js.es6 b/app/assets/javascripts/admin/controllers/admin-dashboard-reports.js.es6 similarity index 100% rename from app/assets/javascripts/admin/controllers/admin-dashboard-next-reports.js.es6 rename to app/assets/javascripts/admin/controllers/admin-dashboard-reports.js.es6 diff --git a/app/assets/javascripts/admin/controllers/admin-dashboard.js.es6 b/app/assets/javascripts/admin/controllers/admin-dashboard.js.es6 index b0e3047023a..7d6c68ea098 100644 --- a/app/assets/javascripts/admin/controllers/admin-dashboard.js.es6 +++ b/app/assets/javascripts/admin/controllers/admin-dashboard.js.es6 @@ -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 PROBLEMS_CHECK_MINUTES = 1; -const REPORTS = [ - "global_reports", - "page_view_reports", - "private_message_reports", - "http_reports", - "user_reports", - "mobile_reports" -]; - -// 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(); } } }); diff --git a/app/assets/javascripts/admin/controllers/admin.js.es6 b/app/assets/javascripts/admin/controllers/admin.js.es6 index afc8b7c46b3..9823f0fa792 100644 --- a/app/assets/javascripts/admin/controllers/admin.js.es6 +++ b/app/assets/javascripts/admin/controllers/admin.js.es6 @@ -15,7 +15,7 @@ export default Ember.Controller.extend({ @computed("application.currentPath") adminContentsClassName(currentPath) { - return currentPath + let cssClasses = currentPath .split(".") .filter(segment => { return ( @@ -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; } }); diff --git a/app/assets/javascripts/admin/models/admin-dashboard-next.js.es6 b/app/assets/javascripts/admin/models/admin-dashboard-next.js.es6 deleted file mode 100644 index f4f3eecfe7a..00000000000 --- a/app/assets/javascripts/admin/models/admin-dashboard-next.js.es6 +++ /dev/null @@ -1,52 +0,0 @@ -import { ajax } from "discourse/lib/ajax"; - -const GENERAL_ATTRIBUTES = ["updated_at"]; - -const AdminDashboardNext = Discourse.Model.extend({}); - -AdminDashboardNext.reopenClass({ - fetch() { - return ajax("/admin/dashboard.json").then(json => { - const model = AdminDashboardNext.create(); - model.set("version_check", json.version_check); - return model; - }); - }, - - fetchGeneral() { - return ajax("/admin/dashboard/general.json").then(json => { - const model = AdminDashboardNext.create(); - - const attributes = {}; - GENERAL_ATTRIBUTES.forEach(a => (attributes[a] = json[a])); - - model.setProperties({ - reports: json.reports, - attributes, - loaded: true - }); - - return model; - }); - }, - - /** - Only fetch the list of problems that should be rendered on the dashboard. - The model will only have its "problems" attribute set. - - @method fetchProblems - @return {jqXHR} a jQuery Promise object - **/ - fetchProblems: function() { - return ajax("/admin/dashboard/problems.json", { - type: "GET", - dataType: "json" - }).then(function(json) { - var model = AdminDashboardNext.create(json); - model.set("loaded", true); - return model; - }); - } -}); - -export default AdminDashboardNext; diff --git a/app/assets/javascripts/admin/models/admin-dashboard.js.es6 b/app/assets/javascripts/admin/models/admin-dashboard.js.es6 index 9ce5a79e151..15a111445b1 100644 --- a/app/assets/javascripts/admin/models/admin-dashboard.js.es6 +++ b/app/assets/javascripts/admin/models/admin-dashboard.js.es6 @@ -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. + fetch() { + return ajax("/admin/dashboard.json").then(json => { + const model = AdminDashboard.create(); + model.set("version_check", json.version_check); + return model; + }); + }, - @method find - @return {jqXHR} a jQuery Promise object - **/ - find: function() { - return ajax("/admin/dashboard-old.json").then(function(json) { - var model = AdminDashboard.create(json); + 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; }); diff --git a/app/assets/javascripts/admin/routes/admin-dashboard-general.js.es6 b/app/assets/javascripts/admin/routes/admin-dashboard-general.js.es6 new file mode 100644 index 00000000000..ffd544b3dba --- /dev/null +++ b/app/assets/javascripts/admin/routes/admin-dashboard-general.js.es6 @@ -0,0 +1,5 @@ +export default Discourse.Route.extend({ + activate() { + this.controllerFor("admin-dashboard-general").fetchDashboard(); + } +}); diff --git a/app/assets/javascripts/admin/routes/admin-dashboard-next-general.js.es6 b/app/assets/javascripts/admin/routes/admin-dashboard-next-general.js.es6 deleted file mode 100644 index e73b7247f37..00000000000 --- a/app/assets/javascripts/admin/routes/admin-dashboard-next-general.js.es6 +++ /dev/null @@ -1,5 +0,0 @@ -export default Discourse.Route.extend({ - activate() { - this.controllerFor("admin-dashboard-next-general").fetchDashboard(); - } -}); diff --git a/app/assets/javascripts/admin/routes/admin-dashboard-next.js.es6 b/app/assets/javascripts/admin/routes/admin-dashboard-next.js.es6 deleted file mode 100644 index b2ace398fed..00000000000 --- a/app/assets/javascripts/admin/routes/admin-dashboard-next.js.es6 +++ /dev/null @@ -1,9 +0,0 @@ -import { scrollTop } from "discourse/mixins/scroll-top"; - -export default Discourse.Route.extend({ - activate() { - this.controllerFor("admin-dashboard-next").fetchProblems(); - this.controllerFor("admin-dashboard-next").fetchDashboard(); - scrollTop(); - } -}); diff --git a/app/assets/javascripts/admin/routes/admin-dashboard-next-reports.js.es6 b/app/assets/javascripts/admin/routes/admin-dashboard-reports.js.es6 similarity index 100% rename from app/assets/javascripts/admin/routes/admin-dashboard-next-reports.js.es6 rename to app/assets/javascripts/admin/routes/admin-dashboard-reports.js.es6 diff --git a/app/assets/javascripts/admin/routes/admin-dashboard.js.es6 b/app/assets/javascripts/admin/routes/admin-dashboard.js.es6 index afb2eaaec5f..a6ff3c215ee 100644 --- a/app/assets/javascripts/admin/routes/admin-dashboard.js.es6 +++ b/app/assets/javascripts/admin/routes/admin-dashboard.js.es6 @@ -1,5 +1,9 @@ +import { scrollTop } from "discourse/mixins/scroll-top"; + export default Discourse.Route.extend({ - setupController(controller) { - controller.fetchDashboard(); + activate() { + this.controllerFor("admin-dashboard").fetchProblems(); + this.controllerFor("admin-dashboard").fetchDashboard(); + scrollTop(); } }); diff --git a/app/assets/javascripts/admin/routes/admin-reports-index.js.es6 b/app/assets/javascripts/admin/routes/admin-reports-index.js.es6 index 240efaddda8..2d21467ae64 100644 --- a/app/assets/javascripts/admin/routes/admin-reports-index.js.es6 +++ b/app/assets/javascripts/admin/routes/admin-reports-index.js.es6 @@ -1,5 +1,5 @@ export default Discourse.Route.extend({ beforeModel() { - this.transitionTo("admin.dashboardNextReports"); + this.transitionTo("admin.dashboardReports"); } }); diff --git a/app/assets/javascripts/admin/routes/admin-route-map.js.es6 b/app/assets/javascripts/admin/routes/admin-route-map.js.es6 index 688091ec0da..9ae0063ffea 100644 --- a/app/assets/javascripts/admin/routes/admin-route-map.js.es6 +++ b/app/assets/javascripts/admin/routes/admin-route-map.js.es6 @@ -1,18 +1,16 @@ export default function() { this.route("admin", { resetNamespace: true }, function() { - this.route("dashboard", { path: "/dashboard-old" }); - - this.route("dashboardNext", { path: "/" }, function() { + this.route("dashboard", { path: "/" }, function() { this.route("general", { path: "/" }); - this.route("admin.dashboardNextModeration", { + this.route("admin.dashboardModeration", { path: "/dashboard/moderation", resetNamespace: true }); - this.route("admin.dashboardNextSecurity", { + this.route("admin.dashboardSecurity", { path: "/dashboard/security", resetNamespace: true }); - this.route("admin.dashboardNextReports", { + this.route("admin.dashboardReports", { path: "/dashboard/reports", resetNamespace: true }); diff --git a/app/assets/javascripts/admin/templates/admin.hbs b/app/assets/javascripts/admin/templates/admin.hbs index 4dc2dc3061a..aec3433a0b1 100644 --- a/app/assets/javascripts/admin/templates/admin.hbs +++ b/app/assets/javascripts/admin/templates/admin.hbs @@ -1,11 +1,11 @@ {{#admin-wrapper class="container"}}
-
+