2015-08-08 03:08:27 +08:00
|
|
|
import { setting } from 'discourse/lib/computed';
|
2015-11-21 09:27:06 +08:00
|
|
|
import AdminDashboard from 'admin/models/admin-dashboard';
|
2016-08-04 03:36:41 +08:00
|
|
|
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'];
|
2013-02-21 02:15:50 +08:00
|
|
|
|
2015-08-08 03:08:27 +08:00
|
|
|
// This controller supports the default interface when you enter the admin section.
|
2014-07-23 11:20:45 +08:00
|
|
|
export default Ember.Controller.extend({
|
2016-08-04 03:36:41 +08:00
|
|
|
loading: null,
|
2013-03-20 11:18:00 +08:00
|
|
|
versionCheck: null,
|
2016-08-04 03:36:41 +08:00
|
|
|
dashboardFetchedAt: null,
|
2015-08-08 03:08:27 +08:00
|
|
|
showVersionChecks: setting('version_checks'),
|
2014-09-12 04:30:47 +08:00
|
|
|
|
2016-08-04 03:36:41 +08:00
|
|
|
@computed('problems.length')
|
|
|
|
foundProblems(problemsLength) {
|
2016-08-09 00:32:43 +08:00
|
|
|
return this.currentUser.get('admin') && (problemsLength || 0) > 0;
|
2016-08-04 03:36:41 +08:00
|
|
|
},
|
2013-04-17 00:09:37 +08:00
|
|
|
|
2016-08-04 03:36:41 +08:00
|
|
|
@computed('foundProblems')
|
|
|
|
thereWereProblems(foundProblems) {
|
|
|
|
if (!this.currentUser.get('admin')) { return false; }
|
|
|
|
|
|
|
|
if (foundProblems) {
|
2013-04-17 00:09:37 +08:00
|
|
|
this.set('hadProblems', true);
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return this.get('hadProblems') || false;
|
|
|
|
}
|
2016-08-04 03:36:41 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
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);
|
|
|
|
});
|
|
|
|
}
|
2013-04-17 00:09:37 +08:00
|
|
|
|
2016-08-04 03:36:41 +08:00
|
|
|
if (!this.get('problemsFetchedAt') || moment().subtract(PROBLEMS_CHECK_MINUTES, 'minutes').toDate() > this.get('problemsFetchedAt')) {
|
|
|
|
this.loadProblems();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
loadProblems() {
|
2013-04-17 00:09:37 +08:00
|
|
|
this.set('loadingProblems', true);
|
|
|
|
this.set('problemsFetchedAt', new Date());
|
2016-08-04 03:36:41 +08:00
|
|
|
AdminDashboard.fetchProblems().then(d => {
|
|
|
|
this.set('problems', d.problems);
|
|
|
|
}).finally(() => {
|
|
|
|
this.set('loadingProblems', false);
|
2013-04-17 00:09:37 +08:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2016-08-04 03:36:41 +08:00
|
|
|
@computed('problemsFetchedAt')
|
|
|
|
problemsTimestamp(problemsFetchedAt) {
|
|
|
|
return moment(problemsFetchedAt).format('LLL');
|
|
|
|
},
|
2013-08-03 06:31:25 +08:00
|
|
|
|
2016-08-04 03:36:41 +08:00
|
|
|
@computed('updated_at')
|
|
|
|
updatedTimestamp(updatedAt) {
|
|
|
|
return moment(updatedAt).format('LLL');
|
|
|
|
},
|
2013-09-17 02:08:55 +08:00
|
|
|
|
|
|
|
actions: {
|
2016-08-04 03:36:41 +08:00
|
|
|
refreshProblems() {
|
2013-09-17 02:08:55 +08:00
|
|
|
this.loadProblems();
|
2015-02-06 11:39:04 +08:00
|
|
|
},
|
2016-08-04 03:36:41 +08:00
|
|
|
showTrafficReport() {
|
2015-02-06 11:39:04 +08:00
|
|
|
this.set("showTrafficReport", true);
|
2013-09-17 02:08:55 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-23 04:41:12 +08:00
|
|
|
});
|