From 01d1f850e979b485625c6ac93095f5c19159c4d7 Mon Sep 17 00:00:00 2001 From: Joffrey JAFFEUX Date: Wed, 25 Jul 2018 13:16:35 -0400 Subject: [PATCH] FEATURE: uses category-chooser for report filtering (#6174) --- .../admin/components/admin-report.js.es6 | 33 ++++++++++------- .../controllers/admin-reports-show.js.es6 | 33 ++++++++--------- .../templates/components/admin-report.hbs | 36 +++++++++++-------- .../admin/templates/reports-show.hbs | 9 ++--- .../common/admin/admin_report.scss | 5 ++- 5 files changed, 65 insertions(+), 51 deletions(-) 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}}
{{#if showDatesOptions}}
@@ -84,8 +83,7 @@
{{date-picker-past value=startDate - defaultDate=startDate - onSelect=onSelectStartDate}} + defaultDate=startDate}}
@@ -97,8 +95,7 @@
{{date-picker-past value=endDate - defaultDate=endDate - onSelect=onSelectEndDate}} + defaultDate=endDate}}
{{/if}} @@ -106,13 +103,10 @@ {{#if showCategoryOptions}}
- {{combo-box - onSelect=onSelectCategory + {{search-advanced-category-chooser filterable=true - valueAttribute="value" - content=categoryOptions - castInteger=true - value=categoryId}} + value=category + castInteger=true}}
{{/if}} @@ -121,7 +115,6 @@
{{combo-box - onSelect=onSelectGroup castInteger=true filterable=true valueAttribute="value" @@ -134,13 +127,28 @@ {{#if showExport}}
- {{d-button class="export-btn" action="exportCsv" label="admin.export_csv.button_text" icon="download"}} + {{d-button + class="export-csv-btn" + action="exportCsv" + label="admin.export_csv.button_text" + icon="download"}} +
+
+ {{/if}} + + {{#if showRefresh}} +
+
+ {{d-button + class="refresh-report-btn btn-primary" + action="refreshReport" + label="admin.dashboard.reports.refresh_report" + icon="refresh"}}
{{/if}}
{{/if}} - {{/if}}
{{#if model.relatedReport}} diff --git a/app/assets/javascripts/admin/templates/reports-show.hbs b/app/assets/javascripts/admin/templates/reports-show.hbs index 6be7401f8b8..8649abe5db1 100644 --- a/app/assets/javascripts/admin/templates/reports-show.hbs +++ b/app/assets/javascripts/admin/templates/reports-show.hbs @@ -3,14 +3,9 @@ {{admin-report showAllReportsLink=true dataSourceName=model.type - categoryId=category_id - groupId=group_id + filteringState=filteringState reportOptions=reportOptions - startDate=start_date - endDate=end_date showFilteringUI=true - onSelectCategory=(action "onSelectCategory") - onSelectStartDate=(action "onSelectStartDate") - onSelectEndDate=(action "onSelectEndDate")}} + onRefresh=(action "onParamsChange")}} diff --git a/app/assets/stylesheets/common/admin/admin_report.scss b/app/assets/stylesheets/common/admin/admin_report.scss index 520bc2a348f..8382d381160 100644 --- a/app/assets/stylesheets/common/admin/admin_report.scss +++ b/app/assets/stylesheets/common/admin/admin_report.scss @@ -108,9 +108,12 @@ .date-picker-wrapper, .combo-box, - .export-btn { + .export-csv-btn, + .refresh-report-btn { width: 100%; + } + .date-picker-wrapper { .date-picker { width: 100%; box-sizing: border-box;