2018-06-15 17:03:24 +02: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";
|
2015-09-15 16:45:01 -04:00
|
|
|
|
2015-08-11 12:27:07 -04:00
|
|
|
export default Ember.Controller.extend({
|
2017-04-13 17:10:55 +08:00
|
|
|
queryParams: ["mode", "start_date", "end_date", "category_id", "group_id"],
|
2018-06-15 17:03:24 +02:00
|
|
|
viewMode: "graph",
|
|
|
|
viewingTable: Em.computed.equal("viewMode", "table"),
|
|
|
|
viewingGraph: Em.computed.equal("viewMode", "graph"),
|
2014-11-05 14:46:27 -05:00
|
|
|
startDate: null,
|
|
|
|
endDate: null,
|
2015-06-24 15:19:39 +02:00
|
|
|
categoryId: null,
|
2016-02-03 07:59:51 +05:30
|
|
|
groupId: null,
|
2014-11-05 14:46:27 -05:00
|
|
|
refreshing: false,
|
2013-03-17 15:02:36 -04:00
|
|
|
|
2016-02-03 07:59:51 +05:30
|
|
|
@computed()
|
|
|
|
categoryOptions() {
|
2018-06-15 17:03:24 +02: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") };
|
|
|
|
})
|
|
|
|
);
|
2016-02-03 07:59:51 +05:30
|
|
|
},
|
|
|
|
|
|
|
|
@computed()
|
|
|
|
groupOptions() {
|
2018-06-15 17:03:24 +02: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"] };
|
|
|
|
})
|
|
|
|
);
|
2016-02-03 07:59:51 +05:30
|
|
|
},
|
|
|
|
|
2018-06-15 17:03:24 +02:00
|
|
|
@computed("model.type")
|
2016-04-21 14:52:41 +05:30
|
|
|
showCategoryOptions(modelType) {
|
2017-04-13 17:10:55 +08:00
|
|
|
return [
|
2018-06-15 17:03:24 +02:00
|
|
|
"topics",
|
|
|
|
"posts",
|
|
|
|
"time_to_first_response_total",
|
|
|
|
"topics_with_no_response",
|
|
|
|
"flags",
|
|
|
|
"likes",
|
|
|
|
"bookmarks"
|
2017-04-13 17:10:55 +08:00
|
|
|
].includes(modelType);
|
2016-04-21 13:03:23 +05:30
|
|
|
},
|
|
|
|
|
2018-06-15 17:03:24 +02:00
|
|
|
@computed("model.type")
|
2016-02-03 07:59:51 +05:30
|
|
|
showGroupOptions(modelType) {
|
2018-06-15 17:03:24 +02:00
|
|
|
return (
|
|
|
|
modelType === "visits" ||
|
|
|
|
modelType === "signups" ||
|
|
|
|
modelType === "profile_views"
|
|
|
|
);
|
2016-02-03 07:59:51 +05:30
|
|
|
},
|
2015-07-03 12:58:13 -04:00
|
|
|
|
2013-09-16 14:08:55 -04:00
|
|
|
actions: {
|
2015-06-24 15:19:39 +02:00
|
|
|
refreshReport() {
|
2015-07-03 12:58:13 -04:00
|
|
|
var q;
|
2015-06-24 15:19:39 +02:00
|
|
|
this.set("refreshing", true);
|
2016-02-03 07:59:51 +05:30
|
|
|
|
2016-04-14 15:46:01 +10:00
|
|
|
this.setProperties({
|
2018-06-15 17:03:24 +02:00
|
|
|
start_date: this.get("startDate"),
|
|
|
|
end_date: this.get("endDate"),
|
|
|
|
category_id: this.get("categoryId")
|
2016-04-14 15:46:01 +10:00
|
|
|
});
|
|
|
|
|
2018-06-15 17:03:24 +02:00
|
|
|
if (this.get("groupId")) {
|
|
|
|
this.set("group_id", this.get("groupId"));
|
2016-04-14 15:46:01 +10:00
|
|
|
}
|
|
|
|
|
2018-06-15 17:03:24 +02: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)
|
|
|
|
);
|
2014-11-05 14:46:27 -05:00
|
|
|
},
|
|
|
|
|
2015-06-24 15:19:39 +02:00
|
|
|
viewAsTable() {
|
2018-06-15 17:03:24 +02:00
|
|
|
this.set("viewMode", "table");
|
2013-09-16 14:08:55 -04:00
|
|
|
},
|
2013-03-17 15:02:36 -04:00
|
|
|
|
2016-04-14 15:46:01 +10:00
|
|
|
viewAsGraph() {
|
2018-06-15 17:03:24 +02:00
|
|
|
this.set("viewMode", "graph");
|
2015-09-15 16:45:01 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
exportCsv() {
|
2018-06-15 17:03:24 +02:00
|
|
|
exportEntity("report", {
|
2015-09-15 16:45:01 -04:00
|
|
|
name: this.get("model.type"),
|
2018-06-15 17:03:24 +02: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")
|
2015-09-15 16:45:01 -04:00
|
|
|
}).then(outputExportResult);
|
2013-09-16 14:08:55 -04:00
|
|
|
}
|
2013-03-17 15:02:36 -04:00
|
|
|
}
|
2014-06-10 11:54:38 -04:00
|
|
|
});
|