mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-05-23 06:30:50 +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.
68 lines
1.6 KiB
JavaScript
Vendored
68 lines
1.6 KiB
JavaScript
Vendored
import { action } from "@ember/object";
|
|
import { service } from "@ember/service";
|
|
import DiscourseRoute from "discourse/routes/discourse";
|
|
import { i18n } from "discourse-i18n";
|
|
import SiteSettingFilter from "admin/lib/site-setting-filter";
|
|
import SiteSetting from "admin/models/site-setting";
|
|
|
|
export default class AdminSiteSettingsRoute extends DiscourseRoute {
|
|
@service siteSettingChangeTracker;
|
|
|
|
queryParams = {
|
|
filter: {
|
|
replace: true,
|
|
refreshModel: true,
|
|
},
|
|
onlyOverridden: {
|
|
replace: true,
|
|
refreshModel: true,
|
|
},
|
|
};
|
|
|
|
_siteSettings = null;
|
|
|
|
titleToken() {
|
|
return i18n("admin.config.site_settings.title");
|
|
}
|
|
|
|
async model(params) {
|
|
this._siteSettings ??= await SiteSetting.findAll();
|
|
|
|
return {
|
|
filteredSettings: this.filterSettings(
|
|
params.filter,
|
|
params.onlyOverridden
|
|
),
|
|
filtersApplied: params.filter || params.onlyOverridden,
|
|
};
|
|
}
|
|
|
|
@action
|
|
async willTransition(transition) {
|
|
if (
|
|
this.siteSettingChangeTracker.hasUnsavedChanges &&
|
|
transition.from.name !== transition.to.name
|
|
) {
|
|
transition.abort();
|
|
|
|
await this.siteSettingChangeTracker.confirmTransition();
|
|
|
|
transition.retry();
|
|
}
|
|
}
|
|
|
|
@action
|
|
filterSettings(filter, onlyOverridden) {
|
|
const settingFilter = new SiteSettingFilter(this._siteSettings);
|
|
|
|
return settingFilter.filterSettings(filter, {
|
|
onlyOverridden: onlyOverridden === "true",
|
|
});
|
|
}
|
|
|
|
resetController(controller, isExiting) {
|
|
if (isExiting) {
|
|
controller.set("filter", "");
|
|
}
|
|
}
|
|
}
|