discourse/app/assets/javascripts/admin/addon/routes/admin-logs-staff-action-logs.js
Isaac Janzen 011ba5b9f6
DEV: Update transitionTo on Route (#22644)
Per https://deprecations.emberjs.com/v3.x/#toc_routing-transition-methods

We are upgrading all `this.transitionTo` calls on routes to directly call the router service (`this.router.transitionTo`)
2023-07-18 14:52:55 -05:00

47 lines
1.2 KiB
JavaScript

import DiscourseRoute from "discourse/routes/discourse";
import EmberObject, { action } from "@ember/object";
import { inject as service } from "@ember/service";
export default class AdminLogsStaffActionLogsRoute extends DiscourseRoute {
@service router;
queryParams = {
filters: { refreshModel: true },
};
beforeModel(transition) {
const params = transition.to.queryParams;
const controller = this.controllerFor("admin-logs-staff-action-logs");
if (controller.filters === null || params.force_refresh) {
controller.resetFilters();
}
}
deserializeQueryParam(value, urlKey, defaultValueType) {
if (urlKey === "filters") {
return EmberObject.create(JSON.parse(decodeURIComponent(value)));
}
return super.deserializeQueryParam(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 super.serializeQueryParam(value, urlKey, defaultValueType);
}
@action
onFiltersChange(filters) {
this.router.transitionTo("adminLogs.staffActionLogs", {
queryParams: { filters },
});
}
}