mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-12-17 19:12:37 -05:00
Deuglify the admin dashboard loading state. Also clean up the code
This commit is contained in:
parent
19fa24d888
commit
331135a88e
4 changed files with 301 additions and 324 deletions
|
@ -1,56 +1,95 @@
|
||||||
import { setting } from 'discourse/lib/computed';
|
import { setting } from 'discourse/lib/computed';
|
||||||
import AdminDashboard from 'admin/models/admin-dashboard';
|
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.
|
// This controller supports the default interface when you enter the admin section.
|
||||||
export default Ember.Controller.extend({
|
export default Ember.Controller.extend({
|
||||||
loading: true,
|
loading: null,
|
||||||
versionCheck: null,
|
versionCheck: null,
|
||||||
problemsCheckMinutes: 1,
|
dashboardFetchedAt: null,
|
||||||
|
|
||||||
showVersionChecks: setting('version_checks'),
|
showVersionChecks: setting('version_checks'),
|
||||||
|
|
||||||
foundProblems: function() {
|
@computed('problems.length')
|
||||||
return(Discourse.User.currentProp('admin') && this.get('problems') && this.get('problems').length > 0);
|
foundProblems(problemsLength) {
|
||||||
}.property('problems'),
|
return this.currentUser.get('admin') && (problemsLength || 0) > 1;
|
||||||
|
},
|
||||||
|
|
||||||
thereWereProblems: function() {
|
@computed('foundProblems')
|
||||||
if(!Discourse.User.currentProp('admin')) { return false; }
|
thereWereProblems(foundProblems) {
|
||||||
if( this.get('foundProblems') ) {
|
if (!this.currentUser.get('admin')) { return false; }
|
||||||
|
|
||||||
|
if (foundProblems) {
|
||||||
this.set('hadProblems', true);
|
this.set('hadProblems', true);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return this.get('hadProblems') || false;
|
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('loadingProblems', true);
|
||||||
this.set('problemsFetchedAt', new Date());
|
this.set('problemsFetchedAt', new Date());
|
||||||
var c = this;
|
AdminDashboard.fetchProblems().then(d => {
|
||||||
AdminDashboard.fetchProblems().then(function(d) {
|
this.set('problems', d.problems);
|
||||||
c.set('problems', d.problems);
|
}).finally(() => {
|
||||||
c.set('loadingProblems', false);
|
this.set('loadingProblems', false);
|
||||||
if( d.problems && d.problems.length > 0 ) {
|
|
||||||
c.problemsCheckInterval = 1;
|
|
||||||
} else {
|
|
||||||
c.problemsCheckInterval = 10;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
problemsTimestamp: function() {
|
@computed('problemsFetchedAt')
|
||||||
return moment(this.get('problemsFetchedAt')).format('LLL');
|
problemsTimestamp(problemsFetchedAt) {
|
||||||
}.property('problemsFetchedAt'),
|
return moment(problemsFetchedAt).format('LLL');
|
||||||
|
},
|
||||||
|
|
||||||
updatedTimestamp: function() {
|
@computed('updated_at')
|
||||||
return moment(this.get('updated_at')).format('LLL');
|
updatedTimestamp(updatedAt) {
|
||||||
}.property('updated_at'),
|
return moment(updatedAt).format('LLL');
|
||||||
|
},
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
refreshProblems: function() {
|
refreshProblems() {
|
||||||
this.loadProblems();
|
this.loadProblems();
|
||||||
},
|
},
|
||||||
showTrafficReport: function() {
|
showTrafficReport() {
|
||||||
this.set("showTrafficReport", true);
|
this.set("showTrafficReport", true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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({
|
export default Discourse.Route.extend({
|
||||||
|
setupController(controller) {
|
||||||
setupController: function(c) {
|
controller.fetchDashboard();
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
{{plugin-outlet "admin-dashboard-top"}}
|
{{plugin-outlet "admin-dashboard-top"}}
|
||||||
|
|
||||||
|
{{#conditional-loading-spinner condition=loading}}
|
||||||
<div class="dashboard-left">
|
<div class="dashboard-left">
|
||||||
{{#if showVersionChecks}}
|
{{#if showVersionChecks}}
|
||||||
{{partial 'admin/templates/version-checks'}}
|
{{partial 'admin/templates/version-checks'}}
|
||||||
|
@ -18,11 +19,9 @@
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{{#unless loading}}
|
|
||||||
{{#each user_reports as |r|}}
|
{{#each user_reports as |r|}}
|
||||||
{{admin-report-trust-level-counts report=r}}
|
{{admin-report-trust-level-counts report=r}}
|
||||||
{{/each}}
|
{{/each}}
|
||||||
{{/unless}}
|
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
@ -57,11 +56,9 @@
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{{#unless loading}}
|
|
||||||
{{#each global_reports as |r|}}
|
{{#each global_reports as |r|}}
|
||||||
{{admin-report-counts report=r}}
|
{{admin-report-counts report=r}}
|
||||||
{{/each}}
|
{{/each}}
|
||||||
{{/unless}}
|
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
@ -79,11 +76,9 @@
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{{#unless loading}}
|
|
||||||
{{#each page_view_reports as |r|}}
|
{{#each page_view_reports as |r|}}
|
||||||
{{admin-report-counts report=r}}
|
{{admin-report-counts report=r}}
|
||||||
{{/each}}
|
{{/each}}
|
||||||
{{/unless}}
|
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
@ -101,11 +96,9 @@
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{{#unless loading}}
|
|
||||||
{{#each private_message_reports as |r|}}
|
{{#each private_message_reports as |r|}}
|
||||||
{{admin-report-counts report=r}}
|
{{admin-report-counts report=r}}
|
||||||
{{/each}}
|
{{/each}}
|
||||||
{{/unless}}
|
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
@ -123,11 +116,9 @@
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{{#unless loading}}
|
|
||||||
{{#each mobile_reports as |r|}}
|
{{#each mobile_reports as |r|}}
|
||||||
{{admin-report-counts report=r}}
|
{{admin-report-counts report=r}}
|
||||||
{{/each}}
|
{{/each}}
|
||||||
{{/unless}}
|
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
@ -143,19 +134,16 @@
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{{#unless loading}}
|
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{i18n 'admin.dashboard.uploads'}}</td>
|
<td>{{i18n 'admin.dashboard.uploads'}}</td>
|
||||||
<td>{{disk_space.uploads_used}} ({{i18n 'admin.dashboard.space_free' size=disk_space.uploads_free}})</td>
|
<td>{{disk_space.uploads_used}} ({{i18n 'admin.dashboard.space_free' size=disk_space.uploads_free}})</td>
|
||||||
<td>{{#if currentUser.admin}}<a href="/admin/backups">{{i18n 'admin.dashboard.backups'}}</a>{{/if}}</td>
|
<td>{{#if currentUser.admin}}<a href="/admin/backups">{{i18n 'admin.dashboard.backups'}}</a>{{/if}}</td>
|
||||||
<td>{{disk_space.backups_used}} ({{i18n 'admin.dashboard.space_free' size=disk_space.backups_free}})</td>
|
<td>{{disk_space.backups_used}} ({{i18n 'admin.dashboard.space_free' size=disk_space.backups_free}})</td>
|
||||||
</tr>
|
</tr>
|
||||||
{{/unless}}
|
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{{#unless loading}}
|
|
||||||
{{#if showTrafficReport}}
|
{{#if showTrafficReport}}
|
||||||
<div class="dashboard-stats">
|
<div class="dashboard-stats">
|
||||||
<table class="table table-condensed table-hover">
|
<table class="table table-condensed table-hover">
|
||||||
|
@ -183,16 +171,15 @@
|
||||||
<a href {{action 'showTrafficReport'}}>{{i18n 'admin.dashboard.show_traffic_report'}}</a>
|
<a href {{action 'showTrafficReport'}}>{{i18n 'admin.dashboard.show_traffic_report'}}</a>
|
||||||
</div>
|
</div>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
{{/unless}}
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="dashboard-right">
|
<div class="dashboard-right">
|
||||||
|
|
||||||
{{#if foundProblems}}
|
{{#if foundProblems}}
|
||||||
<div class="dashboard-stats detected-problems">
|
<div class="dashboard-stats detected-problems">
|
||||||
<div class="look-here">{{fa-icon "exclamation-triangle"}}</div>
|
<div class="look-here">{{fa-icon "exclamation-triangle"}}</div>
|
||||||
<div class="problem-messages">
|
<div class="problem-messages">
|
||||||
<p class="{{if loadingProblems 'invisible'}}">
|
{{#conditional-loading-spinner condition=loadingProblems}}
|
||||||
|
<p>
|
||||||
{{i18n 'admin.dashboard.problems_found'}}
|
{{i18n 'admin.dashboard.problems_found'}}
|
||||||
<ul class="{{if loadingProblems 'invisible'}}">
|
<ul class="{{if loadingProblems 'invisible'}}">
|
||||||
{{#each problems as |problem|}}
|
{{#each problems as |problem|}}
|
||||||
|
@ -204,6 +191,7 @@
|
||||||
<small>{{i18n 'admin.dashboard.last_checked'}}: {{problemsTimestamp}}</small>
|
<small>{{i18n 'admin.dashboard.last_checked'}}: {{problemsTimestamp}}</small>
|
||||||
{{d-button action="refreshProblems" class="btn-small" icon="refresh" label="admin.dashboard.refresh_problems"}}
|
{{d-button action="refreshProblems" class="btn-small" icon="refresh" label="admin.dashboard.refresh_problems"}}
|
||||||
</p>
|
</p>
|
||||||
|
{{/conditional-loading-spinner}}
|
||||||
</div>
|
</div>
|
||||||
<div class="clearfix"></div>
|
<div class="clearfix"></div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -230,7 +218,6 @@
|
||||||
<th>{{top_referred_topics.ytitles.num_clicks}}</th>
|
<th>{{top_referred_topics.ytitles.num_clicks}}</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
{{#unless loading}}
|
|
||||||
{{#each top_referred_topics.data as |data|}}
|
{{#each top_referred_topics.data as |data|}}
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr>
|
<tr>
|
||||||
|
@ -245,7 +232,6 @@
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
{{/each}}
|
{{/each}}
|
||||||
{{/unless}}
|
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -258,7 +244,6 @@
|
||||||
<th>{{top_traffic_sources.ytitles.num_topics}}</th>
|
<th>{{top_traffic_sources.ytitles.num_topics}}</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
{{#unless loading}}
|
|
||||||
{{#each top_traffic_sources.data as |s|}}
|
{{#each top_traffic_sources.data as |s|}}
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr>
|
<tr>
|
||||||
|
@ -268,7 +253,6 @@
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
{{/each}}
|
{{/each}}
|
||||||
{{/unless}}
|
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -281,7 +265,6 @@
|
||||||
<th>{{top_referrers.ytitles.num_topics}}</th>
|
<th>{{top_referrers.ytitles.num_topics}}</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
{{#unless loading}}
|
|
||||||
{{#each top_referrers.data as |r|}}
|
{{#each top_referrers.data as |r|}}
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr>
|
<tr>
|
||||||
|
@ -291,7 +274,6 @@
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
{{/each}}
|
{{/each}}
|
||||||
{{/unless}}
|
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -302,3 +284,4 @@
|
||||||
<div class='clearfix'></div>
|
<div class='clearfix'></div>
|
||||||
</div>
|
</div>
|
||||||
<div class='clearfix'></div>
|
<div class='clearfix'></div>
|
||||||
|
{{/conditional-loading-spinner}}
|
||||||
|
|
|
@ -8,7 +8,6 @@
|
||||||
<th colspan="3">{{i18n 'admin.dashboard.latest_version'}}</th>
|
<th colspan="3">{{i18n 'admin.dashboard.latest_version'}}</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
{{#unless loading}}
|
|
||||||
<tbody>
|
<tbody>
|
||||||
<td class="title">{{i18n 'admin.dashboard.version'}}</td>
|
<td class="title">{{i18n 'admin.dashboard.version'}}</td>
|
||||||
<td class="version-number"><a href={{versionCheck.gitLink}} target="_blank">{{dash-if-empty versionCheck.installed_describe}}</a></td>
|
<td class="version-number"><a href={{versionCheck.gitLink}} target="_blank">{{dash-if-empty versionCheck.installed_describe}}</a></td>
|
||||||
|
@ -67,6 +66,5 @@
|
||||||
{{/if}}
|
{{/if}}
|
||||||
{{/if}}
|
{{/if}}
|
||||||
</tbody>
|
</tbody>
|
||||||
{{/unless}}
|
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in a new issue