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