2015-09-16 04:45:01 +08:00
|
|
|
import { exportEntity } from 'discourse/lib/export-csv';
|
|
|
|
import { outputExportResult } from 'discourse/lib/export-result';
|
2016-01-20 20:11:21 +08:00
|
|
|
import Report from 'admin/models/report';
|
2016-02-03 10:29:51 +08:00
|
|
|
import computed from 'ember-addons/ember-computed-decorators';
|
2015-09-16 04:45:01 +08:00
|
|
|
|
2015-08-12 00:27:07 +08:00
|
|
|
export default Ember.Controller.extend({
|
2016-04-14 13:46:01 +08:00
|
|
|
queryParams: ["mode", "start-date", "end-date", "category-id", "group-id"],
|
|
|
|
viewMode: 'graph',
|
2013-05-30 01:33:54 +08:00
|
|
|
viewingTable: Em.computed.equal('viewMode', 'table'),
|
2016-04-14 13:46:01 +08:00
|
|
|
viewingGraph: Em.computed.equal('viewMode', 'graph'),
|
2014-11-06 03:46:27 +08:00
|
|
|
startDate: null,
|
|
|
|
endDate: null,
|
2015-06-24 21:19:39 +08:00
|
|
|
categoryId: null,
|
2016-02-03 10:29:51 +08:00
|
|
|
groupId: null,
|
2014-11-06 03:46:27 +08:00
|
|
|
refreshing: false,
|
2013-03-18 03:02:36 +08:00
|
|
|
|
2016-02-03 10:29:51 +08:00
|
|
|
@computed()
|
|
|
|
categoryOptions() {
|
|
|
|
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() {
|
|
|
|
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-04-21 15:33:23 +08:00
|
|
|
@computed('model.type')
|
2016-04-21 17:22:41 +08:00
|
|
|
showCategoryOptions(modelType) {
|
2016-05-09 15:46:09 +08:00
|
|
|
return !modelType.match(/_private_messages$/) && !modelType.match(/^page_view_/);
|
2016-04-21 15:33:23 +08:00
|
|
|
},
|
|
|
|
|
2016-02-03 10:29:51 +08:00
|
|
|
@computed('model.type')
|
|
|
|
showGroupOptions(modelType) {
|
|
|
|
return modelType === "visits" || modelType === "signups" || modelType === "profile_views";
|
|
|
|
},
|
2015-07-04 00:58:13 +08:00
|
|
|
|
2013-09-17 02:08:55 +08:00
|
|
|
actions: {
|
2015-06-24 21:19:39 +08:00
|
|
|
refreshReport() {
|
2015-07-04 00:58:13 +08:00
|
|
|
var q;
|
2015-06-24 21:19:39 +08:00
|
|
|
this.set("refreshing", true);
|
2016-02-03 10:29:51 +08:00
|
|
|
|
2016-04-14 13:46:01 +08:00
|
|
|
this.setProperties({
|
|
|
|
'start-date': this.get('startDate'),
|
|
|
|
'end-date': this.get('endDate'),
|
|
|
|
'category-id': this.get('categoryId'),
|
|
|
|
});
|
|
|
|
|
|
|
|
if (this.get('groupId')){
|
|
|
|
this.set('group-id', this.get('groupId'));
|
|
|
|
}
|
|
|
|
|
2016-02-03 10:29:51 +08:00
|
|
|
q = Report.find(this.get("model.type"), this.get("startDate"), this.get("endDate"), this.get("categoryId"), this.get("groupId"));
|
2015-07-04 00:58:13 +08:00
|
|
|
q.then(m => this.set("model", m)).finally(() => this.set("refreshing", false));
|
2014-11-06 03:46:27 +08:00
|
|
|
},
|
|
|
|
|
2015-06-24 21:19:39 +08:00
|
|
|
viewAsTable() {
|
2013-09-17 02:08:55 +08:00
|
|
|
this.set('viewMode', 'table');
|
|
|
|
},
|
2013-03-18 03:02:36 +08:00
|
|
|
|
2016-04-14 13:46:01 +08:00
|
|
|
viewAsGraph() {
|
|
|
|
this.set('viewMode', 'graph');
|
2015-09-16 04:45:01 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
exportCsv() {
|
|
|
|
exportEntity('report', {
|
|
|
|
name: this.get("model.type"),
|
|
|
|
start_date: this.get('startDate'),
|
|
|
|
end_date: this.get('endDate'),
|
2016-02-03 10:29:51 +08:00
|
|
|
category_id: this.get('categoryId') === 'all' ? undefined : this.get('categoryId'),
|
|
|
|
group_id: this.get('groupId') === 'all' ? undefined : this.get('groupId')
|
2015-09-16 04:45:01 +08:00
|
|
|
}).then(outputExportResult);
|
2013-09-17 02:08:55 +08:00
|
|
|
}
|
2013-03-18 03:02:36 +08:00
|
|
|
}
|
2014-06-10 23:54:38 +08:00
|
|
|
});
|