2023-03-15 21:17:51 +08:00
|
|
|
import { action } from "@ember/object";
|
2023-07-19 03:52:55 +08:00
|
|
|
import { inject as service } from "@ember/service";
|
2023-10-11 02:38:59 +08:00
|
|
|
import DiscourseRoute from "discourse/routes/discourse";
|
2019-10-22 21:46:10 +08:00
|
|
|
|
2023-03-15 21:17:51 +08:00
|
|
|
export default class AdminReportsShowRoute extends DiscourseRoute {
|
2023-07-19 03:52:55 +08:00
|
|
|
@service router;
|
|
|
|
|
2023-03-15 21:17:51 +08:00
|
|
|
queryParams = {
|
2019-04-26 18:17:10 +08:00
|
|
|
start_date: { refreshModel: true },
|
|
|
|
end_date: { refreshModel: true },
|
2020-07-28 22:14:41 +08:00
|
|
|
filters: { refreshModel: true },
|
|
|
|
chart_grouping: { refreshModel: true },
|
2021-06-17 15:15:20 +08:00
|
|
|
mode: { refreshModel: true },
|
2023-03-15 21:17:51 +08:00
|
|
|
};
|
2019-04-26 18:17:10 +08:00
|
|
|
|
|
|
|
model(params) {
|
|
|
|
params.customFilters = params.filters;
|
|
|
|
delete params.filters;
|
|
|
|
|
|
|
|
params.startDate =
|
|
|
|
params.start_date ||
|
2020-04-23 04:17:53 +08:00
|
|
|
moment()
|
2019-04-26 18:17:10 +08:00
|
|
|
.subtract(1, "day")
|
|
|
|
.subtract(1, "month")
|
|
|
|
.startOf("day")
|
|
|
|
.format("YYYY-MM-DD");
|
|
|
|
delete params.start_date;
|
|
|
|
|
|
|
|
params.endDate =
|
|
|
|
params.end_date || moment().endOf("day").format("YYYY-MM-DD");
|
|
|
|
delete params.end_date;
|
|
|
|
|
2020-07-28 22:14:41 +08:00
|
|
|
params.chartGrouping = params.chart_grouping || "daily";
|
|
|
|
delete params.chart_grouping;
|
|
|
|
|
2019-04-26 18:17:10 +08:00
|
|
|
return params;
|
2023-03-15 21:17:51 +08:00
|
|
|
}
|
2019-04-26 18:17:10 +08:00
|
|
|
|
|
|
|
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
|
|
|
|
2023-03-15 21:17:51 +08:00
|
|
|
return super.deserializeQueryParam(value, urlKey, defaultValueType);
|
|
|
|
}
|
2019-04-26 18:17:10 +08:00
|
|
|
|
|
|
|
serializeQueryParam(value, urlKey, defaultValueType) {
|
|
|
|
if (urlKey === "filters") {
|
|
|
|
if (value && Object.keys(value).length > 0) {
|
|
|
|
return JSON.stringify(value);
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-15 21:17:51 +08:00
|
|
|
return super.serializeQueryParam(value, urlKey, defaultValueType);
|
|
|
|
}
|
2019-04-26 18:17:10 +08:00
|
|
|
|
2023-03-15 21:17:51 +08:00
|
|
|
@action
|
|
|
|
onParamsChange(params) {
|
|
|
|
const queryParams = {
|
|
|
|
type: params.type,
|
|
|
|
mode: params.mode,
|
|
|
|
start_date: params.startDate
|
|
|
|
? params.startDate.toISOString(true).split("T")[0]
|
|
|
|
: null,
|
|
|
|
chart_grouping: params.chartGrouping,
|
|
|
|
filters: params.filters,
|
|
|
|
end_date: params.endDate
|
|
|
|
? params.endDate.toISOString(true).split("T")[0]
|
|
|
|
: null,
|
|
|
|
};
|
2019-04-26 18:17:10 +08:00
|
|
|
|
2023-07-19 03:52:55 +08:00
|
|
|
this.router.transitionTo("adminReports.show", { queryParams });
|
2023-03-15 21:17:51 +08:00
|
|
|
}
|
|
|
|
}
|