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

49 lines
1.5 KiB
Plaintext
Raw Normal View History

import { exportEntity } from 'discourse/lib/export-csv';
import { outputExportResult } from 'discourse/lib/export-result';
2016-01-20 07:11:21 -05:00
import Report from 'admin/models/report';
export default Ember.Controller.extend({
viewMode: 'table',
2013-05-29 13:33:54 -04:00
viewingTable: Em.computed.equal('viewMode', 'table'),
viewingBarChart: Em.computed.equal('viewMode', 'barChart'),
startDate: null,
endDate: null,
categoryId: null,
refreshing: false,
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-16 14:08:55 -04:00
actions: {
refreshReport() {
var q;
this.set("refreshing", true);
if (this.get('categoryId') === "all") {
2016-01-20 07:11:21 -05:00
q = Report.find(this.get("model.type"), this.get("startDate"), this.get("endDate"));
} else {
2016-01-20 07:11:21 -05:00
q = 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));
},
viewAsTable() {
2013-09-16 14:08:55 -04:00
this.set('viewMode', 'table');
},
viewAsBarChart() {
2013-09-16 14:08:55 -04:00
this.set('viewMode', 'barChart');
},
exportCsv() {
exportEntity('report', {
name: this.get("model.type"),
start_date: this.get('startDate'),
end_date: this.get('endDate'),
2015-09-15 16:57:57 -04:00
category_id: this.get('categoryId') === 'all' ? undefined : this.get('categoryId')
}).then(outputExportResult);
2013-09-16 14:08:55 -04:00
}
}
});