FEATURE: uses category-chooser for report filtering (#6174)
This commit is contained in:
parent
fa6b7f6b8c
commit
01d1f850e9
|
@ -1,3 +1,4 @@
|
||||||
|
import Category from "discourse/models/category";
|
||||||
import { exportEntity } from "discourse/lib/export-csv";
|
import { exportEntity } from "discourse/lib/export-csv";
|
||||||
import { outputExportResult } from "discourse/lib/export-result";
|
import { outputExportResult } from "discourse/lib/export-result";
|
||||||
import { ajax } from "discourse/lib/ajax";
|
import { ajax } from "discourse/lib/ajax";
|
||||||
|
@ -59,11 +60,10 @@ export default Ember.Component.extend({
|
||||||
showDatesOptions: Ember.computed.alias("model.dates_filtering"),
|
showDatesOptions: Ember.computed.alias("model.dates_filtering"),
|
||||||
showGroupOptions: Ember.computed.alias("model.group_filtering"),
|
showGroupOptions: Ember.computed.alias("model.group_filtering"),
|
||||||
showExport: Ember.computed.not("model.onlyTable"),
|
showExport: Ember.computed.not("model.onlyTable"),
|
||||||
hasFilteringActions: Ember.computed.or(
|
showRefresh: Ember.computed.or(
|
||||||
"showCategoryOptions",
|
"showCategoryOptions",
|
||||||
"showDatesOptions",
|
"showDatesOptions",
|
||||||
"showGroupOptions",
|
"showGroupOptions"
|
||||||
"showExport"
|
|
||||||
),
|
),
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
|
@ -75,6 +75,14 @@ export default Ember.Component.extend({
|
||||||
didReceiveAttrs() {
|
didReceiveAttrs() {
|
||||||
this._super(...arguments);
|
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")) {
|
if (this.get("report")) {
|
||||||
this._renderReport(
|
this._renderReport(
|
||||||
this.get("report"),
|
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()
|
@computed()
|
||||||
groupOptions() {
|
groupOptions() {
|
||||||
const arr = [
|
const arr = [
|
||||||
|
@ -207,6 +205,15 @@ export default Ember.Component.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
|
refreshReport() {
|
||||||
|
this.attrs.onRefresh({
|
||||||
|
categoryId: this.get("category.id"),
|
||||||
|
groupId: this.get("groupId"),
|
||||||
|
startDate: this.get("startDate"),
|
||||||
|
endDate: this.get("endDate")
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
exportCsv() {
|
exportCsv() {
|
||||||
exportEntity("report", {
|
exportEntity("report", {
|
||||||
name: this.get("model.type"),
|
name: this.get("model.type"),
|
||||||
|
|
|
@ -2,8 +2,6 @@ import computed from "ember-addons/ember-computed-decorators";
|
||||||
|
|
||||||
export default Ember.Controller.extend({
|
export default Ember.Controller.extend({
|
||||||
queryParams: ["start_date", "end_date", "category_id", "group_id"],
|
queryParams: ["start_date", "end_date", "category_id", "group_id"],
|
||||||
categoryId: null,
|
|
||||||
groupId: null,
|
|
||||||
|
|
||||||
@computed("model.type")
|
@computed("model.type")
|
||||||
reportOptions(type) {
|
reportOptions(type) {
|
||||||
|
@ -16,21 +14,24 @@ export default Ember.Controller.extend({
|
||||||
return options;
|
return options;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@computed("category_id", "group_id", "start_date", "end_date")
|
||||||
|
filteringState(categoryId, groupId, startDate, endDate) {
|
||||||
|
return {
|
||||||
|
categoryId,
|
||||||
|
groupId,
|
||||||
|
startDate,
|
||||||
|
endDate
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
onSelectStartDate(startDate) {
|
onParamsChange(params) {
|
||||||
this.set("start_date", startDate);
|
this.setProperties({
|
||||||
},
|
start_date: params.startDate,
|
||||||
|
category_id: params.categoryId,
|
||||||
onSelectCategory(categoryId) {
|
group_id: params.groupId,
|
||||||
this.set("category_id", categoryId);
|
end_date: params.endDate
|
||||||
},
|
});
|
||||||
|
|
||||||
onSelectGroup(groupId) {
|
|
||||||
this.set("group_id", groupId);
|
|
||||||
},
|
|
||||||
|
|
||||||
onSelectEndDate(endDate) {
|
|
||||||
this.set("end_date", endDate);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -73,7 +73,6 @@
|
||||||
{{/unless}}
|
{{/unless}}
|
||||||
|
|
||||||
{{#if showFilteringUI}}
|
{{#if showFilteringUI}}
|
||||||
{{#if hasFilteringActions}}
|
|
||||||
<div class="report-filters">
|
<div class="report-filters">
|
||||||
{{#if showDatesOptions}}
|
{{#if showDatesOptions}}
|
||||||
<div class="filtering-control">
|
<div class="filtering-control">
|
||||||
|
@ -84,8 +83,7 @@
|
||||||
<div class="filtering-input">
|
<div class="filtering-input">
|
||||||
{{date-picker-past
|
{{date-picker-past
|
||||||
value=startDate
|
value=startDate
|
||||||
defaultDate=startDate
|
defaultDate=startDate}}
|
||||||
onSelect=onSelectStartDate}}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -97,8 +95,7 @@
|
||||||
<div class="filtering-input">
|
<div class="filtering-input">
|
||||||
{{date-picker-past
|
{{date-picker-past
|
||||||
value=endDate
|
value=endDate
|
||||||
defaultDate=endDate
|
defaultDate=endDate}}
|
||||||
onSelect=onSelectEndDate}}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
@ -106,13 +103,10 @@
|
||||||
{{#if showCategoryOptions}}
|
{{#if showCategoryOptions}}
|
||||||
<div class="filtering-control">
|
<div class="filtering-control">
|
||||||
<div class="filtering-input">
|
<div class="filtering-input">
|
||||||
{{combo-box
|
{{search-advanced-category-chooser
|
||||||
onSelect=onSelectCategory
|
|
||||||
filterable=true
|
filterable=true
|
||||||
valueAttribute="value"
|
value=category
|
||||||
content=categoryOptions
|
castInteger=true}}
|
||||||
castInteger=true
|
|
||||||
value=categoryId}}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
@ -121,7 +115,6 @@
|
||||||
<div class="filtering-control">
|
<div class="filtering-control">
|
||||||
<div class="filtering-input">
|
<div class="filtering-input">
|
||||||
{{combo-box
|
{{combo-box
|
||||||
onSelect=onSelectGroup
|
|
||||||
castInteger=true
|
castInteger=true
|
||||||
filterable=true
|
filterable=true
|
||||||
valueAttribute="value"
|
valueAttribute="value"
|
||||||
|
@ -134,13 +127,28 @@
|
||||||
{{#if showExport}}
|
{{#if showExport}}
|
||||||
<div class="filtering-control">
|
<div class="filtering-control">
|
||||||
<div class="filtering-input">
|
<div class="filtering-input">
|
||||||
{{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"}}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{{/if}}
|
||||||
|
|
||||||
|
{{#if showRefresh}}
|
||||||
|
<div class="filtering-control">
|
||||||
|
<div class="filtering-input">
|
||||||
|
{{d-button
|
||||||
|
class="refresh-report-btn btn-primary"
|
||||||
|
action="refreshReport"
|
||||||
|
label="admin.dashboard.reports.refresh_report"
|
||||||
|
icon="refresh"}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
</div>
|
</div>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
{{/if}}
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{{#if model.relatedReport}}
|
{{#if model.relatedReport}}
|
||||||
|
|
|
@ -3,14 +3,9 @@
|
||||||
{{admin-report
|
{{admin-report
|
||||||
showAllReportsLink=true
|
showAllReportsLink=true
|
||||||
dataSourceName=model.type
|
dataSourceName=model.type
|
||||||
categoryId=category_id
|
filteringState=filteringState
|
||||||
groupId=group_id
|
|
||||||
reportOptions=reportOptions
|
reportOptions=reportOptions
|
||||||
startDate=start_date
|
|
||||||
endDate=end_date
|
|
||||||
showFilteringUI=true
|
showFilteringUI=true
|
||||||
onSelectCategory=(action "onSelectCategory")
|
onRefresh=(action "onParamsChange")}}
|
||||||
onSelectStartDate=(action "onSelectStartDate")
|
|
||||||
onSelectEndDate=(action "onSelectEndDate")}}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -108,9 +108,12 @@
|
||||||
|
|
||||||
.date-picker-wrapper,
|
.date-picker-wrapper,
|
||||||
.combo-box,
|
.combo-box,
|
||||||
.export-btn {
|
.export-csv-btn,
|
||||||
|
.refresh-report-btn {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.date-picker-wrapper {
|
||||||
.date-picker {
|
.date-picker {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
|
|
Loading…
Reference in New Issue