2019-10-22 09:46:10 -04:00
|
|
|
import DiscourseRoute from "discourse/routes/discourse";
|
|
|
|
|
|
|
|
export default DiscourseRoute.extend({
|
2019-04-26 06:17:10 -04:00
|
|
|
queryParams: {
|
|
|
|
start_date: { refreshModel: true },
|
|
|
|
end_date: { refreshModel: true },
|
2020-07-28 10:14:41 -04:00
|
|
|
filters: { refreshModel: true },
|
|
|
|
chart_grouping: { refreshModel: true }
|
2019-04-26 06:17:10 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
model(params) {
|
|
|
|
params.customFilters = params.filters;
|
|
|
|
delete params.filters;
|
|
|
|
|
|
|
|
params.startDate =
|
|
|
|
params.start_date ||
|
2020-04-22 16:17:53 -04:00
|
|
|
moment()
|
2019-04-26 06:17:10 -04:00
|
|
|
.subtract(1, "day")
|
|
|
|
.subtract(1, "month")
|
|
|
|
.startOf("day")
|
|
|
|
.format("YYYY-MM-DD");
|
|
|
|
delete params.start_date;
|
|
|
|
|
|
|
|
params.endDate =
|
|
|
|
params.end_date ||
|
2020-04-22 16:17:53 -04:00
|
|
|
moment()
|
2019-04-26 06:17:10 -04:00
|
|
|
.endOf("day")
|
|
|
|
.format("YYYY-MM-DD");
|
|
|
|
delete params.end_date;
|
|
|
|
|
2020-07-28 10:14:41 -04:00
|
|
|
params.chartGrouping = params.chart_grouping || "daily";
|
|
|
|
delete params.chart_grouping;
|
|
|
|
|
2019-04-26 06:17:10 -04:00
|
|
|
return params;
|
|
|
|
},
|
|
|
|
|
|
|
|
deserializeQueryParam(value, urlKey, defaultValueType) {
|
|
|
|
if (urlKey === "filters") {
|
|
|
|
return JSON.parse(decodeURIComponent(value));
|
2018-07-19 14:33:11 -04:00
|
|
|
}
|
2014-11-05 14:46:27 -05:00
|
|
|
|
2019-04-26 06:17:10 -04:00
|
|
|
return this._super(value, urlKey, defaultValueType);
|
|
|
|
},
|
|
|
|
|
|
|
|
serializeQueryParam(value, urlKey, defaultValueType) {
|
|
|
|
if (urlKey === "filters") {
|
|
|
|
if (value && Object.keys(value).length > 0) {
|
|
|
|
return JSON.stringify(value);
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return this._super(value, urlKey, defaultValueType);
|
|
|
|
},
|
|
|
|
|
|
|
|
actions: {
|
|
|
|
onParamsChange(params) {
|
|
|
|
const queryParams = {
|
|
|
|
type: params.type,
|
2020-04-22 16:17:53 -04:00
|
|
|
start_date: params.startDate
|
|
|
|
? params.startDate.toISOString(true).split("T")[0]
|
|
|
|
: null,
|
2020-07-28 10:14:41 -04:00
|
|
|
chart_grouping: params.chartGrouping,
|
2019-04-26 06:17:10 -04:00
|
|
|
filters: params.filters,
|
|
|
|
end_date: params.endDate
|
2020-04-22 16:17:53 -04:00
|
|
|
? params.endDate.toISOString(true).split("T")[0]
|
|
|
|
: null
|
2019-04-26 06:17:10 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
this.transitionTo("adminReports.show", { queryParams });
|
2018-07-19 14:33:11 -04:00
|
|
|
}
|
2013-02-27 22:39:42 -05:00
|
|
|
}
|
2014-06-10 11:54:38 -04:00
|
|
|
});
|