mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 09:42:07 +08:00
49 lines
1.5 KiB
JavaScript
49 lines
1.5 KiB
JavaScript
import { exportEntity } from 'discourse/lib/export-csv';
|
|
import { outputExportResult } from 'discourse/lib/export-result';
|
|
import Report from 'admin/models/report';
|
|
|
|
export default Ember.Controller.extend({
|
|
viewMode: 'table',
|
|
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(),
|
|
|
|
actions: {
|
|
refreshReport() {
|
|
var q;
|
|
this.set("refreshing", true);
|
|
if (this.get('categoryId') === "all") {
|
|
q = Report.find(this.get("model.type"), this.get("startDate"), this.get("endDate"));
|
|
} else {
|
|
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() {
|
|
this.set('viewMode', 'table');
|
|
},
|
|
|
|
viewAsBarChart() {
|
|
this.set('viewMode', 'barChart');
|
|
},
|
|
|
|
exportCsv() {
|
|
exportEntity('report', {
|
|
name: this.get("model.type"),
|
|
start_date: this.get('startDate'),
|
|
end_date: this.get('endDate'),
|
|
category_id: this.get('categoryId') === 'all' ? undefined : this.get('categoryId')
|
|
}).then(outputExportResult);
|
|
}
|
|
}
|
|
});
|