diff --git a/app/assets/javascripts/admin/components/admin-report.js.es6 b/app/assets/javascripts/admin/components/admin-report.js.es6 index 7c77d56fbc2..1c65ff47a9f 100644 --- a/app/assets/javascripts/admin/components/admin-report.js.es6 +++ b/app/assets/javascripts/admin/components/admin-report.js.es6 @@ -1,3 +1,4 @@ +import Category from "discourse/models/category"; import { exportEntity } from "discourse/lib/export-csv"; import { outputExportResult } from "discourse/lib/export-result"; import { ajax } from "discourse/lib/ajax"; @@ -59,11 +60,10 @@ export default Ember.Component.extend({ showDatesOptions: Ember.computed.alias("model.dates_filtering"), showGroupOptions: Ember.computed.alias("model.group_filtering"), showExport: Ember.computed.not("model.onlyTable"), - hasFilteringActions: Ember.computed.or( + showRefresh: Ember.computed.or( "showCategoryOptions", "showDatesOptions", - "showGroupOptions", - "showExport" + "showGroupOptions" ), init() { @@ -75,6 +75,14 @@ export default Ember.Component.extend({ didReceiveAttrs() { this._super(...arguments); + const state = this.get("filteringState"); + this.setProperties({ + category: Category.findById(state.categoryId), + groupId: state.groupId, + startDate: state.startDate, + endDate: state.endDate + }); + if (this.get("report")) { this._renderReport( this.get("report"), @@ -133,16 +141,6 @@ export default Ember.Component.extend({ }); }, - @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 = [ @@ -207,6 +205,15 @@ export default Ember.Component.extend({ }, actions: { + refreshReport() { + this.attrs.onRefresh({ + categoryId: this.get("category.id"), + groupId: this.get("groupId"), + startDate: this.get("startDate"), + endDate: this.get("endDate") + }); + }, + exportCsv() { exportEntity("report", { name: this.get("model.type"), diff --git a/app/assets/javascripts/admin/controllers/admin-reports-show.js.es6 b/app/assets/javascripts/admin/controllers/admin-reports-show.js.es6 index 0288b3f7d0e..fdabfd896e3 100644 --- a/app/assets/javascripts/admin/controllers/admin-reports-show.js.es6 +++ b/app/assets/javascripts/admin/controllers/admin-reports-show.js.es6 @@ -2,8 +2,6 @@ import computed from "ember-addons/ember-computed-decorators"; export default Ember.Controller.extend({ queryParams: ["start_date", "end_date", "category_id", "group_id"], - categoryId: null, - groupId: null, @computed("model.type") reportOptions(type) { @@ -16,21 +14,24 @@ export default Ember.Controller.extend({ return options; }, + @computed("category_id", "group_id", "start_date", "end_date") + filteringState(categoryId, groupId, startDate, endDate) { + return { + categoryId, + groupId, + startDate, + endDate + }; + }, + actions: { - onSelectStartDate(startDate) { - this.set("start_date", startDate); - }, - - onSelectCategory(categoryId) { - this.set("category_id", categoryId); - }, - - onSelectGroup(groupId) { - this.set("group_id", groupId); - }, - - onSelectEndDate(endDate) { - this.set("end_date", endDate); + onParamsChange(params) { + this.setProperties({ + start_date: params.startDate, + category_id: params.categoryId, + group_id: params.groupId, + end_date: params.endDate + }); } } }); diff --git a/app/assets/javascripts/admin/templates/components/admin-report.hbs b/app/assets/javascripts/admin/templates/components/admin-report.hbs index 0c4c4ee24e0..4c387c9f099 100644 --- a/app/assets/javascripts/admin/templates/components/admin-report.hbs +++ b/app/assets/javascripts/admin/templates/components/admin-report.hbs @@ -73,7 +73,6 @@ {{/unless}} {{#if showFilteringUI}} - {{#if hasFilteringActions}}