From 331135a88e5e9c1c47f7315b7323f732f3794fcf Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Wed, 3 Aug 2016 15:36:41 -0400 Subject: [PATCH] Deuglify the admin dashboard loading state. Also clean up the code --- .../admin/controllers/admin-dashboard.js.es6 | 95 +++-- .../admin/routes/admin-dashboard.js.es6 | 47 +-- .../javascripts/admin/templates/dashboard.hbs | 385 +++++++++--------- .../admin/templates/version-checks.hbs | 98 +++-- 4 files changed, 301 insertions(+), 324 deletions(-) diff --git a/app/assets/javascripts/admin/controllers/admin-dashboard.js.es6 b/app/assets/javascripts/admin/controllers/admin-dashboard.js.es6 index 0e0b33b51..82cedfee5 100644 --- a/app/assets/javascripts/admin/controllers/admin-dashboard.js.es6 +++ b/app/assets/javascripts/admin/controllers/admin-dashboard.js.es6 @@ -1,56 +1,95 @@ import { setting } from 'discourse/lib/computed'; import AdminDashboard from 'admin/models/admin-dashboard'; +import VersionCheck from 'admin/models/version-check'; +import Report from 'admin/models/report'; +import AdminUser from 'admin/models/admin-user'; +import computed from 'ember-addons/ember-computed-decorators'; + +const PROBLEMS_CHECK_MINUTES = 1; + +const ATTRIBUTES = [ 'disk_space','admins', 'moderators', 'blocked', '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']; // This controller supports the default interface when you enter the admin section. export default Ember.Controller.extend({ - loading: true, + loading: null, versionCheck: null, - problemsCheckMinutes: 1, - + dashboardFetchedAt: null, showVersionChecks: setting('version_checks'), - foundProblems: function() { - return(Discourse.User.currentProp('admin') && this.get('problems') && this.get('problems').length > 0); - }.property('problems'), + @computed('problems.length') + foundProblems(problemsLength) { + return this.currentUser.get('admin') && (problemsLength || 0) > 1; + }, - thereWereProblems: function() { - if(!Discourse.User.currentProp('admin')) { return false; } - if( this.get('foundProblems') ) { + @computed('foundProblems') + thereWereProblems(foundProblems) { + if (!this.currentUser.get('admin')) { return false; } + + if (foundProblems) { this.set('hadProblems', true); return true; } else { return this.get('hadProblems') || false; } - }.property('foundProblems'), + }, - loadProblems: function() { + fetchDashboard() { + if (!this.get('dashboardFetchedAt') || moment().subtract(30, 'minutes').toDate() > this.get('dashboardFetchedAt')) { + this.set('dashboardFetchedAt', new Date()); + this.set('loading', true); + const versionChecks = this.siteSettings.version_checks; + AdminDashboard.find().then(d => { + if (versionChecks) { + this.set('versionCheck', VersionCheck.create(d.version_check)); + } + + REPORTS.forEach(name => this.set(name, d[name].map(r => Report.create(r)))); + + 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); + } + + ATTRIBUTES.forEach(a => this.set(a, d[a])); + this.set('loading', false); + }); + } + + if (!this.get('problemsFetchedAt') || moment().subtract(PROBLEMS_CHECK_MINUTES, 'minutes').toDate() > this.get('problemsFetchedAt')) { + this.loadProblems(); + } + }, + + loadProblems() { this.set('loadingProblems', true); this.set('problemsFetchedAt', new Date()); - var c = this; - AdminDashboard.fetchProblems().then(function(d) { - c.set('problems', d.problems); - c.set('loadingProblems', false); - if( d.problems && d.problems.length > 0 ) { - c.problemsCheckInterval = 1; - } else { - c.problemsCheckInterval = 10; - } + AdminDashboard.fetchProblems().then(d => { + this.set('problems', d.problems); + }).finally(() => { + this.set('loadingProblems', false); }); }, - problemsTimestamp: function() { - return moment(this.get('problemsFetchedAt')).format('LLL'); - }.property('problemsFetchedAt'), + @computed('problemsFetchedAt') + problemsTimestamp(problemsFetchedAt) { + return moment(problemsFetchedAt).format('LLL'); + }, - updatedTimestamp: function() { - return moment(this.get('updated_at')).format('LLL'); - }.property('updated_at'), + @computed('updated_at') + updatedTimestamp(updatedAt) { + return moment(updatedAt).format('LLL'); + }, actions: { - refreshProblems: function() { + refreshProblems() { this.loadProblems(); }, - showTrafficReport: function() { + showTrafficReport() { this.set("showTrafficReport", true); } } diff --git a/app/assets/javascripts/admin/routes/admin-dashboard.js.es6 b/app/assets/javascripts/admin/routes/admin-dashboard.js.es6 index b080834d0..afb2eaaec 100644 --- a/app/assets/javascripts/admin/routes/admin-dashboard.js.es6 +++ b/app/assets/javascripts/admin/routes/admin-dashboard.js.es6 @@ -1,48 +1,5 @@ -import AdminDashboard from 'admin/models/admin-dashboard'; -import VersionCheck from 'admin/models/version-check'; -import Report from 'admin/models/report'; -import AdminUser from 'admin/models/admin-user'; - export default Discourse.Route.extend({ - - setupController: function(c) { - this.fetchDashboardData(c); - }, - - fetchDashboardData: function(c) { - if( !c.get('dashboardFetchedAt') || moment().subtract(30, 'minutes').toDate() > c.get('dashboardFetchedAt') ) { - c.set('dashboardFetchedAt', new Date()); - var versionChecks = this.siteSettings.version_checks; - AdminDashboard.find().then(function(d) { - if (versionChecks) { - c.set('versionCheck', VersionCheck.create(d.version_check)); - } - - ['global_reports', 'page_view_reports', 'private_message_reports', 'http_reports', 'user_reports', 'mobile_reports'].forEach(name => { - c.set(name, d[name].map(r => Report.create(r))); - }); - - var topReferrers = d.top_referrers; - if (topReferrers && topReferrers.data) { - d.top_referrers.data = topReferrers.data.map(function (user) { - return AdminUser.create(user); - }); - c.set('top_referrers', topReferrers); - } - - [ 'disk_space','admins', 'moderators', 'blocked', 'suspended', - 'top_traffic_sources', 'top_referred_topics', 'updated_at'].forEach(function(x) { - c.set(x, d[x]); - }); - - c.set('loading', false); - }); - } - - if( !c.get('problemsFetchedAt') || moment().subtract(c.problemsCheckMinutes, 'minutes').toDate() > c.get('problemsFetchedAt') ) { - c.set('problemsFetchedAt', new Date()); - c.loadProblems(); - } + setupController(controller) { + controller.fetchDashboard(); } }); - diff --git a/app/assets/javascripts/admin/templates/dashboard.hbs b/app/assets/javascripts/admin/templates/dashboard.hbs index 47a731d98..e02a5a925 100644 --- a/app/assets/javascripts/admin/templates/dashboard.hbs +++ b/app/assets/javascripts/admin/templates/dashboard.hbs @@ -1,161 +1,149 @@ {{plugin-outlet "admin-dashboard-top"}} -
- {{#if showVersionChecks}} - {{partial 'admin/templates/version-checks'}} - {{/if}} +{{#conditional-loading-spinner condition=loading}} +
+ {{#if showVersionChecks}} + {{partial 'admin/templates/version-checks'}} + {{/if}} -
- - - - - - - - - - - - - {{#unless loading}} +
+
 01234
+ + + + + + + + + + + {{#each user_reports as |r|}} {{admin-report-trust-level-counts report=r}} {{/each}} - {{/unless}} - -
 01234
-
+ + +
-
- - - - - - - - - - - - - -
{{fa-icon "shield"}} {{i18n 'admin.dashboard.admins'}}{{#link-to 'adminUsersList.show' 'admins'}}{{admins}}{{/link-to}}{{fa-icon "ban"}} {{i18n 'admin.dashboard.suspended'}}{{#link-to 'adminUsersList.show' 'suspended'}}{{suspended}}{{/link-to}}
{{fa-icon "shield"}} {{i18n 'admin.dashboard.moderators'}}{{#link-to 'adminUsersList.show' 'moderators'}}{{moderators}}{{/link-to}}{{fa-icon "ban"}} {{i18n 'admin.dashboard.blocked'}}{{#link-to 'adminUsersList.show' 'blocked'}}{{blocked}}{{/link-to}}
-
- -
- - +
+
- - - - - - + + + + - - - {{#unless loading}} + + + + + + +
 {{i18n 'admin.dashboard.reports.today'}}{{i18n 'admin.dashboard.reports.yesterday'}}{{i18n 'admin.dashboard.reports.last_7_days'}}{{i18n 'admin.dashboard.reports.last_30_days'}}{{i18n 'admin.dashboard.reports.all'}}{{fa-icon "shield"}} {{i18n 'admin.dashboard.admins'}}{{#link-to 'adminUsersList.show' 'admins'}}{{admins}}{{/link-to}}{{fa-icon "ban"}} {{i18n 'admin.dashboard.suspended'}}{{#link-to 'adminUsersList.show' 'suspended'}}{{suspended}}{{/link-to}}
{{fa-icon "shield"}} {{i18n 'admin.dashboard.moderators'}}{{#link-to 'adminUsersList.show' 'moderators'}}{{moderators}}{{/link-to}}{{fa-icon "ban"}} {{i18n 'admin.dashboard.blocked'}}{{#link-to 'adminUsersList.show' 'blocked'}}{{blocked}}{{/link-to}}
+
+ +
+ + + + + + + + + + + + {{#each global_reports as |r|}} {{admin-report-counts report=r}} {{/each}} - {{/unless}} - -
 {{i18n 'admin.dashboard.reports.today'}}{{i18n 'admin.dashboard.reports.yesterday'}}{{i18n 'admin.dashboard.reports.last_7_days'}}{{i18n 'admin.dashboard.reports.last_30_days'}}{{i18n 'admin.dashboard.reports.all'}}
-
+ + +
-
- - - - - - - - - - - - - {{#unless loading}} +
+
{{i18n 'admin.dashboard.page_views_short'}}{{i18n 'admin.dashboard.reports.today'}}{{i18n 'admin.dashboard.reports.yesterday'}}{{i18n 'admin.dashboard.reports.last_7_days'}}{{i18n 'admin.dashboard.reports.last_30_days'}}{{i18n 'admin.dashboard.reports.all'}}
+ + + + + + + + + + + {{#each page_view_reports as |r|}} {{admin-report-counts report=r}} {{/each}} - {{/unless}} - -
{{i18n 'admin.dashboard.page_views_short'}}{{i18n 'admin.dashboard.reports.today'}}{{i18n 'admin.dashboard.reports.yesterday'}}{{i18n 'admin.dashboard.reports.last_7_days'}}{{i18n 'admin.dashboard.reports.last_30_days'}}{{i18n 'admin.dashboard.reports.all'}}
-
+ + + -
- - - - - - - - - - - - - {{#unless loading}} +
+
{{fa-icon "envelope"}} {{i18n 'admin.dashboard.private_messages_short'}}{{i18n 'admin.dashboard.reports.today'}}{{i18n 'admin.dashboard.reports.yesterday'}}{{i18n 'admin.dashboard.reports.last_7_days'}}{{i18n 'admin.dashboard.reports.last_30_days'}}{{i18n 'admin.dashboard.reports.all'}}
+ + + + + + + + + + + {{#each private_message_reports as |r|}} {{admin-report-counts report=r}} {{/each}} - {{/unless}} - -
{{fa-icon "envelope"}} {{i18n 'admin.dashboard.private_messages_short'}}{{i18n 'admin.dashboard.reports.today'}}{{i18n 'admin.dashboard.reports.yesterday'}}{{i18n 'admin.dashboard.reports.last_7_days'}}{{i18n 'admin.dashboard.reports.last_30_days'}}{{i18n 'admin.dashboard.reports.all'}}
-
+ + + -
- - - - - - - - - - - - - {{#unless loading}} +
+
{{i18n 'admin.dashboard.mobile_title'}}{{i18n 'admin.dashboard.reports.today'}}{{i18n 'admin.dashboard.reports.yesterday'}}{{i18n 'admin.dashboard.reports.last_7_days'}}{{i18n 'admin.dashboard.reports.last_30_days'}}{{i18n 'admin.dashboard.reports.all'}}
+ + + + + + + + + + + {{#each mobile_reports as |r|}} {{admin-report-counts report=r}} {{/each}} - {{/unless}} - -
{{i18n 'admin.dashboard.mobile_title'}}{{i18n 'admin.dashboard.reports.today'}}{{i18n 'admin.dashboard.reports.yesterday'}}{{i18n 'admin.dashboard.reports.last_7_days'}}{{i18n 'admin.dashboard.reports.last_30_days'}}{{i18n 'admin.dashboard.reports.all'}}
-
+ + + -
- - - - - - - - - - - {{#unless loading}} +
+
 
+ + + + + + + + + - {{/unless}} - -
 
{{i18n 'admin.dashboard.uploads'}} {{disk_space.uploads_used}} ({{i18n 'admin.dashboard.space_free' size=disk_space.uploads_free}}) {{#if currentUser.admin}}{{i18n 'admin.dashboard.backups'}}{{/if}} {{disk_space.backups_used}} ({{i18n 'admin.dashboard.space_free' size=disk_space.backups_free}})
-
+ + + - {{#unless loading}} {{#if showTrafficReport}}
@@ -183,54 +171,53 @@ {{i18n 'admin.dashboard.show_traffic_report'}} {{/if}} - {{/unless}} - + -
- - {{#if foundProblems}} -
-
{{fa-icon "exclamation-triangle"}}
-
-

- {{i18n 'admin.dashboard.problems_found'}} -

    - {{#each problems as |problem|}} -
  • {{{problem}}}
  • - {{/each}} -
-

-

- {{i18n 'admin.dashboard.last_checked'}}: {{problemsTimestamp}} - {{d-button action="refreshProblems" class="btn-small" icon="refresh" label="admin.dashboard.refresh_problems"}} -

-
-
-
- {{else}} - {{#if thereWereProblems}} +
+ {{#if foundProblems}}
-
 
+
{{fa-icon "exclamation-triangle"}}
-

- {{i18n 'admin.dashboard.no_problems'}} - {{d-button action="refreshProblems" class="btn-small" icon="refresh" label="admin.dashboard.refresh_problems"}} -

+ {{#conditional-loading-spinner condition=loadingProblems}} +

+ {{i18n 'admin.dashboard.problems_found'}} +

    + {{#each problems as |problem|}} +
  • {{{problem}}}
  • + {{/each}} +
+

+

+ {{i18n 'admin.dashboard.last_checked'}}: {{problemsTimestamp}} + {{d-button action="refreshProblems" class="btn-small" icon="refresh" label="admin.dashboard.refresh_problems"}} +

+ {{/conditional-loading-spinner}}
+ {{else}} + {{#if thereWereProblems}} +
+
 
+
+

+ {{i18n 'admin.dashboard.no_problems'}} + {{d-button action="refreshProblems" class="btn-small" icon="refresh" label="admin.dashboard.refresh_problems"}} +

+
+
+
+ {{/if}} {{/if}} - {{/if}} -
-
- - - - - - - {{#unless loading}} +
+
{{top_referred_topics.title}} ({{i18n 'admin.dashboard.reports.last_30_days'}}){{top_referred_topics.ytitles.num_clicks}}
+ + + + + + {{#each top_referred_topics.data as |data|}} @@ -245,20 +232,18 @@ {{/each}} - {{/unless}} -
{{top_referred_topics.title}} ({{i18n 'admin.dashboard.reports.last_30_days'}}){{top_referred_topics.ytitles.num_clicks}}
-
+ + -
- - - - - - - - - {{#unless loading}} +
+
{{top_traffic_sources.title}} ({{i18n 'admin.dashboard.reports.last_30_days'}}){{top_traffic_sources.ytitles.num_clicks}}{{top_traffic_sources.ytitles.num_topics}}
+ + + + + + + {{#each top_traffic_sources.data as |s|}} @@ -268,20 +253,18 @@ {{/each}} - {{/unless}} -
{{top_traffic_sources.title}} ({{i18n 'admin.dashboard.reports.last_30_days'}}){{top_traffic_sources.ytitles.num_clicks}}{{top_traffic_sources.ytitles.num_topics}}
-
+ + -
- - - - - - - - - {{#unless loading}} +
+
{{top_referrers.title}} ({{i18n 'admin.dashboard.reports.last_30_days'}}){{top_referrers.ytitles.num_clicks}}{{top_referrers.ytitles.num_topics}}
+ + + + + + + {{#each top_referrers.data as |r|}} @@ -291,14 +274,14 @@ {{/each}} - {{/unless}} -
{{top_referrers.title}} ({{i18n 'admin.dashboard.reports.last_30_days'}}){{top_referrers.ytitles.num_clicks}}{{top_referrers.ytitles.num_topics}}
+ +
- -
- -
-
{{i18n 'admin.dashboard.last_updated'}} {{updatedTimestamp}}
-
-
+ +
+
{{i18n 'admin.dashboard.last_updated'}} {{updatedTimestamp}}
+
+
+
+{{/conditional-loading-spinner}} diff --git a/app/assets/javascripts/admin/templates/version-checks.hbs b/app/assets/javascripts/admin/templates/version-checks.hbs index 26617f3cc..542020d8e 100644 --- a/app/assets/javascripts/admin/templates/version-checks.hbs +++ b/app/assets/javascripts/admin/templates/version-checks.hbs @@ -8,65 +8,63 @@ {{i18n 'admin.dashboard.latest_version'}} - {{#unless loading}} - - {{i18n 'admin.dashboard.version'}} - {{dash-if-empty versionCheck.installed_describe}} + + {{i18n 'admin.dashboard.version'}} + {{dash-if-empty versionCheck.installed_describe}} - {{#if versionCheck.noCheckPerformed}} - — + {{#if versionCheck.noCheckPerformed}} + — + + {{fa-icon "frown-o"}} + + + {{i18n 'admin.dashboard.no_check_performed'}} + + {{else}} + {{#if versionCheck.staleData}} + {{#if versionCheck.version_check_pending}}{{dash-if-empty versionCheck.installed_version}}{{/if}} - {{fa-icon "frown-o"}} + {{#if versionCheck.version_check_pending}} + {{fa-icon "smile-o"}} + {{else}} + {{fa-icon "frown-o"}} + {{/if}} - {{i18n 'admin.dashboard.no_check_performed'}} + + {{#if versionCheck.version_check_pending}} + {{i18n 'admin.dashboard.version_check_pending'}} + {{else}} + {{i18n 'admin.dashboard.stale_data'}} + {{/if}} + {{else}} - {{#if versionCheck.staleData}} - {{#if versionCheck.version_check_pending}}{{dash-if-empty versionCheck.installed_version}}{{/if}} - - {{#if versionCheck.version_check_pending}} - {{fa-icon "smile-o"}} - {{else}} - {{fa-icon "frown-o"}} - {{/if}} - - - - {{#if versionCheck.version_check_pending}} - {{i18n 'admin.dashboard.version_check_pending'}} + {{dash-if-empty versionCheck.latest_version}} + + {{#if versionCheck.upToDate }} + {{fa-icon "smile-o"}} + {{else}} + + {{#if versionCheck.behindByOneVersion}} + {{fa-icon "meh-o"}} {{else}} - {{i18n 'admin.dashboard.stale_data'}} + {{fa-icon "frown-o"}} {{/if}} - - {{else}} - {{dash-if-empty versionCheck.latest_version}} - - {{#if versionCheck.upToDate }} - {{fa-icon "smile-o"}} - {{else}} - - {{#if versionCheck.behindByOneVersion}} - {{fa-icon "meh-o"}} - {{else}} - {{fa-icon "frown-o"}} - {{/if}} - - {{/if}} - - - {{#if versionCheck.upToDate }} - {{i18n 'admin.dashboard.up_to_date'}} - {{else}} - {{i18n 'admin.dashboard.critical_available'}} - {{i18n 'admin.dashboard.updates_available'}} - {{i18n 'admin.dashboard.please_upgrade'}} - {{/if}} - - {{/if}} + {{/if}} + + + {{#if versionCheck.upToDate }} + {{i18n 'admin.dashboard.up_to_date'}} + {{else}} + {{i18n 'admin.dashboard.critical_available'}} + {{i18n 'admin.dashboard.updates_available'}} + {{i18n 'admin.dashboard.please_upgrade'}} + {{/if}} + {{/if}} - - {{/unless}} + {{/if}} +