FEATURE: filter admin reports via user group
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
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';
|
||||
|
||||
export default Ember.Controller.extend({
|
||||
viewMode: 'table',
|
||||
@@ -9,22 +10,32 @@ export default Ember.Controller.extend({
|
||||
startDate: null,
|
||||
endDate: null,
|
||||
categoryId: null,
|
||||
groupId: 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(),
|
||||
@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']};}));
|
||||
},
|
||||
|
||||
@computed('model.type')
|
||||
showGroupOptions(modelType) {
|
||||
return modelType === "visits" || modelType === "signups" || modelType === "profile_views";
|
||||
},
|
||||
|
||||
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 = 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));
|
||||
},
|
||||
|
||||
@@ -41,7 +52,8 @@ export default Ember.Controller.extend({
|
||||
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')
|
||||
category_id: this.get('categoryId') === 'all' ? undefined : this.get('categoryId'),
|
||||
group_id: this.get('groupId') === 'all' ? undefined : this.get('groupId')
|
||||
}).then(outputExportResult);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -131,12 +131,13 @@ const Report = Discourse.Model.extend({
|
||||
|
||||
Report.reopenClass({
|
||||
|
||||
find(type, startDate, endDate, categoryId) {
|
||||
find(type, startDate, endDate, categoryId, groupId) {
|
||||
return Discourse.ajax("/admin/reports/" + type, {
|
||||
data: {
|
||||
start_date: startDate,
|
||||
end_date: endDate,
|
||||
category_id: categoryId
|
||||
category_id: categoryId,
|
||||
group_id: groupId
|
||||
}
|
||||
}).then(json => {
|
||||
// Add a percent field to each tuple
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
<h3>{{model.title}}</h3>
|
||||
|
||||
<div>
|
||||
<div class="admin-reports-filter">
|
||||
{{i18n 'admin.dashboard.reports.start_date'}} {{input type="date" value=startDate}}
|
||||
{{i18n 'admin.dashboard.reports.end_date'}} {{input type="date" value=endDate}}
|
||||
{{combo-box valueAttribute="value" content=categoryOptions value=categoryId}}
|
||||
{{#if showGroupOptions}}
|
||||
{{combo-box valueAttribute="value" content=groupOptions value=groupId}}
|
||||
{{/if}}
|
||||
{{d-button action="refreshReport" class="btn-primary" label="admin.dashboard.reports.refresh_report" icon="refresh"}}
|
||||
{{d-button action="exportCsv" label="admin.export_csv.button_text" icon="download"}}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user