mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-05-20 21:25:23 +08:00
The filtering is currently being done in the controller. This leads to weird things where the filter loop might already be initiated and we get double filtering, as well as the issue that we can't abort like we could with a route transition. After this change we: - Cache the site settings fetched from the server in the route instance. - Hook up the controller to the query params. - Use the query params to filter the model in the route.
47 lines
1.4 KiB
JavaScript
Vendored
47 lines
1.4 KiB
JavaScript
Vendored
import Controller from "@ember/controller";
|
|
import { action } from "@ember/object";
|
|
import { alias } from "@ember/object/computed";
|
|
import { service } from "@ember/service";
|
|
import { debounce } from "discourse/lib/decorators";
|
|
import { INPUT_DELAY } from "discourse/lib/environment";
|
|
|
|
export default class AdminSiteSettingsController extends Controller {
|
|
@service router;
|
|
|
|
@alias("model.filteredSettings") visibleSiteSettings;
|
|
@alias("model.filtersApplied") filtersApplied;
|
|
|
|
@debounce(INPUT_DELAY)
|
|
filterContent(filterData) {
|
|
if (this._skipBounce) {
|
|
this.set("_skipBounce", false);
|
|
} else {
|
|
const currentParams = this.router.currentRoute.queryParams;
|
|
const queryParams = {
|
|
filter: filterData.filter || undefined,
|
|
onlyOverridden: filterData.onlyOverridden || undefined,
|
|
};
|
|
|
|
const paramsChanged =
|
|
currentParams.filter !== queryParams.filter ||
|
|
currentParams.onlyOverridden !== queryParams.onlyOverridden;
|
|
|
|
if (!this.isDestroyed && paramsChanged) {
|
|
this.router.transitionTo(this.router.currentRouteName, { queryParams });
|
|
}
|
|
}
|
|
}
|
|
|
|
@action
|
|
filterChanged(filterData) {
|
|
this.filterContent(filterData);
|
|
}
|
|
|
|
@action
|
|
toggleMenu() {
|
|
const adminDetail = document.querySelector(".admin-detail");
|
|
["mobile-closed", "mobile-open"].forEach((state) => {
|
|
adminDetail.classList.toggle(state);
|
|
});
|
|
}
|
|
}
|