2019-10-22 21:46:10 +08:00
|
|
|
import DiscourseRoute from "discourse/routes/discourse";
|
|
|
|
|
|
|
|
export default DiscourseRoute.extend({
|
2019-04-26 18:17:10 +08:00
|
|
|
queryParams: {
|
|
|
|
start_date: { refreshModel: true },
|
|
|
|
end_date: { refreshModel: true },
|
|
|
|
filters: { refreshModel: true }
|
|
|
|
},
|
|
|
|
|
|
|
|
model(params) {
|
|
|
|
params.customFilters = params.filters;
|
|
|
|
delete params.filters;
|
|
|
|
|
|
|
|
params.startDate =
|
|
|
|
params.start_date ||
|
|
|
|
moment
|
|
|
|
.utc()
|
|
|
|
.subtract(1, "day")
|
|
|
|
.subtract(1, "month")
|
|
|
|
.startOf("day")
|
|
|
|
.format("YYYY-MM-DD");
|
|
|
|
delete params.start_date;
|
|
|
|
|
|
|
|
params.endDate =
|
|
|
|
params.end_date ||
|
|
|
|
moment
|
|
|
|
.utc()
|
|
|
|
.endOf("day")
|
|
|
|
.format("YYYY-MM-DD");
|
|
|
|
delete params.end_date;
|
|
|
|
|
|
|
|
return params;
|
|
|
|
},
|
|
|
|
|
|
|
|
deserializeQueryParam(value, urlKey, defaultValueType) {
|
|
|
|
if (urlKey === "filters") {
|
|
|
|
return JSON.parse(decodeURIComponent(value));
|
2018-07-20 02:33:11 +08:00
|
|
|
}
|
2014-11-06 03:46:27 +08:00
|
|
|
|
2019-04-26 18:17:10 +08: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,
|
|
|
|
start_date: params.startDate,
|
|
|
|
filters: params.filters,
|
|
|
|
end_date: params.endDate
|
|
|
|
};
|
|
|
|
|
|
|
|
this.transitionTo("adminReports.show", { queryParams });
|
2018-07-20 02:33:11 +08:00
|
|
|
}
|
2013-02-28 11:39:42 +08:00
|
|
|
}
|
2014-06-10 23:54:38 +08:00
|
|
|
});
|