mirror of
https://github.com/discourse/discourse.git
synced 2024-12-09 16:26:20 +08:00
78bafb331a
This commit makes it so the site settings filter controls and the list of settings input editors themselves can be used elsewhere in the admin UI outside of /admin/site_settings This allows us to provide more targeted groups of settings in different UI areas where it makes sense to provide them, such as on plugin pages. You could open a single page for a plugin where you can see information about that plugin, change settings, and configure it with custom UIs in the one place. In future we will do this in "config areas" for other parts of the admin UI.
81 lines
2.1 KiB
JavaScript
81 lines
2.1 KiB
JavaScript
import Controller from "@ember/controller";
|
|
import { action } from "@ember/object";
|
|
import { alias } from "@ember/object/computed";
|
|
import { service } from "@ember/service";
|
|
import { isEmpty } from "@ember/utils";
|
|
import SiteSettingFilter from "discourse/lib/site-setting-filter";
|
|
import { INPUT_DELAY } from "discourse-common/config/environment";
|
|
import { debounce } from "discourse-common/utils/decorators";
|
|
|
|
export default class AdminSiteSettingsController extends Controller {
|
|
@service router;
|
|
|
|
@alias("model") allSiteSettings;
|
|
|
|
filter = "";
|
|
visibleSiteSettings = null;
|
|
siteSettingFilter = null;
|
|
|
|
filterContentNow(filterData, category) {
|
|
this.siteSettingFilter ??= new SiteSettingFilter(this.allSiteSettings);
|
|
|
|
if (isEmpty(this.allSiteSettings)) {
|
|
return;
|
|
}
|
|
|
|
if (isEmpty(filterData.filter) && !filterData.onlyOverridden) {
|
|
this.set("visibleSiteSettings", this.allSiteSettings);
|
|
if (this.categoryNameKey === "all_results") {
|
|
this.router.transitionTo("adminSiteSettings");
|
|
}
|
|
return;
|
|
}
|
|
|
|
this.set("filter", filterData.filter);
|
|
|
|
const matchesGroupedByCategory = this.siteSettingFilter.filterSettings(
|
|
filterData.filter,
|
|
{ onlyOverridden: filterData.onlyOverridden }
|
|
);
|
|
|
|
const categoryMatches = matchesGroupedByCategory.findBy(
|
|
"nameKey",
|
|
category
|
|
);
|
|
|
|
if (!categoryMatches || categoryMatches.count === 0) {
|
|
category = "all_results";
|
|
}
|
|
|
|
this.set("visibleSiteSettings", matchesGroupedByCategory);
|
|
this.router.transitionTo(
|
|
"adminSiteSettingsCategory",
|
|
category || "all_results"
|
|
);
|
|
}
|
|
|
|
@debounce(INPUT_DELAY)
|
|
filterContent(filterData) {
|
|
if (this._skipBounce) {
|
|
this.set("_skipBounce", false);
|
|
} else {
|
|
if (!this.isDestroyed) {
|
|
this.filterContentNow(filterData, this.categoryNameKey);
|
|
}
|
|
}
|
|
}
|
|
|
|
@action
|
|
filterChanged(filterData) {
|
|
this.filterContent(filterData);
|
|
}
|
|
|
|
@action
|
|
toggleMenu() {
|
|
const adminDetail = document.querySelector(".admin-detail");
|
|
["mobile-closed", "mobile-open"].forEach((state) => {
|
|
adminDetail.classList.toggle(state);
|
|
});
|
|
}
|
|
}
|