-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
39 changed files
with
323 additions
and
919 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
90 changes: 0 additions & 90 deletions
90
app/assets/javascripts/admin/controllers/admin-dashboard-next.js.es6
This file was deleted.
Oops, something went wrong.
File renamed without changes.
100 changes: 56 additions & 44 deletions
100
app/assets/javascripts/admin/controllers/admin-dashboard.js.es6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 0 additions & 52 deletions
52
app/assets/javascripts/admin/models/admin-dashboard-next.js.es6
This file was deleted.
Oops, something went wrong.
40 changes: 30 additions & 10 deletions
40
app/assets/javascripts/admin/models/admin-dashboard.js.es6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
app/assets/javascripts/admin/routes/admin-dashboard-general.js.es6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
}); |
5 changes: 0 additions & 5 deletions
5
app/assets/javascripts/admin/routes/admin-dashboard-next-general.js.es6
This file was deleted.
Oops, something went wrong.
9 changes: 0 additions & 9 deletions
9
app/assets/javascripts/admin/routes/admin-dashboard-next.js.es6
This file was deleted.
Oops, something went wrong.
File renamed without changes.
Oops, something went wrong.