discourse/app/assets/javascripts/admin/controllers/admin-reports-show.js.es6

109 lines
2.7 KiB
Plaintext
Raw Normal View History

2018-06-15 23:03:24 +08:00
import { exportEntity } from "discourse/lib/export-csv";
import { outputExportResult } from "discourse/lib/export-result";
import Report from "admin/models/report";
import computed from "ember-addons/ember-computed-decorators";
export default Ember.Controller.extend({
queryParams: ["mode", "start_date", "end_date", "category_id", "group_id"],
2018-06-15 23:03:24 +08:00
viewMode: "graph",
viewingTable: Em.computed.equal("viewMode", "table"),
viewingGraph: Em.computed.equal("viewMode", "graph"),
startDate: null,
endDate: null,
categoryId: null,
groupId: null,
refreshing: false,
@computed()
categoryOptions() {
2018-06-15 23:03:24 +08:00
const arr = [{ name: I18n.t("category.all"), value: "all" }];
return arr.concat(
Discourse.Site.currentProp("sortedCategories").map(i => {
return { name: i.get("name"), value: i.get("id") };
})
);
},
@computed()
groupOptions() {
2018-06-15 23:03:24 +08:00
const arr = [
{ name: I18n.t("admin.dashboard.reports.groups"), value: "all" }
];
return arr.concat(
this.site.groups.map(i => {
return { name: i["name"], value: i["id"] };
})
);
},
2018-06-15 23:03:24 +08:00
@computed("model.type")
showCategoryOptions(modelType) {
return [
2018-06-15 23:03:24 +08:00
"topics",
"posts",
"time_to_first_response_total",
"topics_with_no_response",
"flags",
"likes",
"bookmarks"
].includes(modelType);
},
2018-06-15 23:03:24 +08:00
@computed("model.type")
showGroupOptions(modelType) {
2018-06-15 23:03:24 +08:00
return (
modelType === "visits" ||
modelType === "signups" ||
modelType === "profile_views"
);
},
2013-09-17 02:08:55 +08:00
actions: {
refreshReport() {
var q;
this.set("refreshing", true);
this.setProperties({
2018-06-15 23:03:24 +08:00
start_date: this.get("startDate"),
end_date: this.get("endDate"),
category_id: this.get("categoryId")
});
2018-06-15 23:03:24 +08:00
if (this.get("groupId")) {
this.set("group_id", this.get("groupId"));
}
2018-06-15 23:03:24 +08:00
q = Report.find(
this.get("model.type"),
this.get("startDate"),
this.get("endDate"),
this.get("categoryId"),
this.get("groupId")
);
q.then(m => this.set("model", m)).finally(() =>
this.set("refreshing", false)
);
},
viewAsTable() {
2018-06-15 23:03:24 +08:00
this.set("viewMode", "table");
2013-09-17 02:08:55 +08:00
},
viewAsGraph() {
2018-06-15 23:03:24 +08:00
this.set("viewMode", "graph");
},
exportCsv() {
2018-06-15 23:03:24 +08:00
exportEntity("report", {
name: this.get("model.type"),
2018-06-15 23:03:24 +08:00
start_date: this.get("startDate"),
end_date: this.get("endDate"),
category_id:
this.get("categoryId") === "all" ? undefined : this.get("categoryId"),
group_id:
this.get("groupId") === "all" ? undefined : this.get("groupId")
}).then(outputExportResult);
2013-09-17 02:08:55 +08:00
}
}
});