2019-10-24 01:06:54 +08:00
|
|
|
import Controller from "@ember/controller";
|
2021-12-09 20:47:56 +08:00
|
|
|
import { action } from "@ember/object";
|
2023-10-11 02:38:59 +08:00
|
|
|
import { alias } from "@ember/object/computed";
|
2024-03-07 01:05:11 +08:00
|
|
|
import { service } from "@ember/service";
|
2023-10-11 02:38:59 +08:00
|
|
|
import { isEmpty } from "@ember/utils";
|
2024-03-18 06:50:39 +08:00
|
|
|
import SiteSettingFilter from "discourse/lib/site-setting-filter";
|
2023-10-11 02:38:59 +08:00
|
|
|
import { INPUT_DELAY } from "discourse-common/config/environment";
|
|
|
|
import { debounce } from "discourse-common/utils/decorators";
|
2015-04-09 02:17:21 +08:00
|
|
|
|
2023-03-15 17:42:12 +08:00
|
|
|
export default class AdminSiteSettingsController extends Controller {
|
2023-07-19 03:53:23 +08:00
|
|
|
@service router;
|
|
|
|
|
2023-03-15 17:42:12 +08:00
|
|
|
@alias("model") allSiteSettings;
|
|
|
|
|
2024-03-18 06:50:39 +08:00
|
|
|
filter = "";
|
2023-03-15 17:42:12 +08:00
|
|
|
visibleSiteSettings = null;
|
2024-03-18 06:50:39 +08:00
|
|
|
siteSettingFilter = null;
|
2023-08-25 07:47:40 +08:00
|
|
|
|
2024-03-18 06:50:39 +08:00
|
|
|
filterContentNow(filterData, category) {
|
|
|
|
this.siteSettingFilter ??= new SiteSettingFilter(this.allSiteSettings);
|
2013-03-02 01:45:25 +08:00
|
|
|
|
2023-05-16 16:23:05 +08:00
|
|
|
if (isEmpty(this.allSiteSettings)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-03-18 06:50:39 +08:00
|
|
|
if (isEmpty(filterData.filter) && !filterData.onlyOverridden) {
|
2023-05-16 16:23:05 +08:00
|
|
|
this.set("visibleSiteSettings", this.allSiteSettings);
|
|
|
|
if (this.categoryNameKey === "all_results") {
|
2023-07-19 03:53:23 +08:00
|
|
|
this.router.transitionTo("adminSiteSettings");
|
2023-05-16 16:23:05 +08:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-03-18 06:50:39 +08:00
|
|
|
this.set("filter", filterData.filter);
|
|
|
|
|
|
|
|
const matchesGroupedByCategory = this.siteSettingFilter.filterSettings(
|
|
|
|
filterData.filter,
|
|
|
|
{ onlyOverridden: filterData.onlyOverridden }
|
2023-05-16 16:23:05 +08:00
|
|
|
);
|
2015-09-30 01:34:09 +08:00
|
|
|
|
2020-08-05 15:39:54 +08:00
|
|
|
const categoryMatches = matchesGroupedByCategory.findBy(
|
|
|
|
"nameKey",
|
|
|
|
category
|
|
|
|
);
|
2023-05-16 16:23:05 +08:00
|
|
|
|
2020-08-05 15:39:54 +08:00
|
|
|
if (!categoryMatches || categoryMatches.count === 0) {
|
|
|
|
category = "all_results";
|
|
|
|
}
|
|
|
|
|
2018-12-11 23:48:12 +08:00
|
|
|
this.set("visibleSiteSettings", matchesGroupedByCategory);
|
2023-07-19 03:53:23 +08:00
|
|
|
this.router.transitionTo(
|
2018-05-16 21:37:40 +08:00
|
|
|
"adminSiteSettingsCategory",
|
|
|
|
category || "all_results"
|
|
|
|
);
|
2023-03-15 17:42:12 +08:00
|
|
|
}
|
2015-07-03 00:45:17 +08:00
|
|
|
|
2022-10-20 19:28:09 +08:00
|
|
|
@debounce(INPUT_DELAY)
|
2024-03-18 06:50:39 +08:00
|
|
|
filterContent(filterData) {
|
2022-10-20 19:28:09 +08:00
|
|
|
if (this._skipBounce) {
|
|
|
|
this.set("_skipBounce", false);
|
|
|
|
} else {
|
2023-05-16 16:23:05 +08:00
|
|
|
if (!this.isDestroyed) {
|
2024-03-18 06:50:39 +08:00
|
|
|
this.filterContentNow(filterData, this.categoryNameKey);
|
2023-05-16 16:23:05 +08:00
|
|
|
}
|
2022-10-20 19:28:09 +08:00
|
|
|
}
|
2023-03-15 17:42:12 +08:00
|
|
|
}
|
2013-12-21 00:06:07 +08:00
|
|
|
|
2021-12-09 20:47:56 +08:00
|
|
|
@action
|
2024-03-18 06:50:39 +08:00
|
|
|
filterChanged(filterData) {
|
|
|
|
this.filterContent(filterData);
|
2023-03-15 17:42:12 +08:00
|
|
|
}
|
2015-08-17 01:35:23 +08:00
|
|
|
|
2021-12-09 20:47:56 +08:00
|
|
|
@action
|
|
|
|
toggleMenu() {
|
|
|
|
const adminDetail = document.querySelector(".admin-detail");
|
|
|
|
["mobile-closed", "mobile-open"].forEach((state) => {
|
|
|
|
adminDetail.classList.toggle(state);
|
|
|
|
});
|
2023-03-15 17:42:12 +08:00
|
|
|
}
|
|
|
|
}
|