2015-09-16 04:45:01 +08:00
|
|
|
import { exportEntity } from 'discourse/lib/export-csv';
|
|
|
|
import { outputExportResult } from 'discourse/lib/export-result';
|
|
|
|
|
2015-08-12 00:27:07 +08:00
|
|
|
export default Ember.Controller.extend({
|
2013-03-18 03:02:36 +08:00
|
|
|
viewMode: 'table',
|
2013-05-30 01:33:54 +08:00
|
|
|
viewingTable: Em.computed.equal('viewMode', 'table'),
|
|
|
|
viewingBarChart: Em.computed.equal('viewMode', 'barChart'),
|
2014-11-06 03:46:27 +08:00
|
|
|
startDate: null,
|
|
|
|
endDate: null,
|
2015-06-24 21:19:39 +08:00
|
|
|
categoryId: null,
|
2014-11-06 03:46:27 +08:00
|
|
|
refreshing: false,
|
2013-03-18 03:02:36 +08:00
|
|
|
|
2015-07-04 00:58:13 +08:00
|
|
|
categoryOptions: function() {
|
|
|
|
var arr = [{name: I18n.t('category.all'), value: 'all'}];
|
|
|
|
return arr.concat( Discourse.Site.currentProp('sortedCategories').map(function(i) { return {name: i.get('name'), value: i.get('id') }; }) );
|
|
|
|
}.property(),
|
|
|
|
|
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);
|
2015-07-04 00:58:13 +08:00
|
|
|
if (this.get('categoryId') === "all") {
|
|
|
|
q = Discourse.Report.find(this.get("model.type"), this.get("startDate"), this.get("endDate"));
|
|
|
|
} else {
|
|
|
|
q = Discourse.Report.find(this.get("model.type"), this.get("startDate"), this.get("endDate"), this.get("categoryId"));
|
|
|
|
}
|
|
|
|
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
|
|
|
|
2015-06-24 21:19:39 +08:00
|
|
|
viewAsBarChart() {
|
2013-09-17 02:08:55 +08:00
|
|
|
this.set('viewMode', 'barChart');
|
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'),
|
2015-09-16 04:57:57 +08:00
|
|
|
category_id: this.get('categoryId') === 'all' ? undefined : this.get('categoryId')
|
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
|
|
|
});
|