2019-10-24 01:06:54 +08:00
|
|
|
import Controller from "@ember/controller";
|
2020-05-14 04:23:41 +08:00
|
|
|
import I18n from "I18n";
|
2019-11-01 01:37:24 +08:00
|
|
|
import { INPUT_DELAY } from "discourse-common/config/environment";
|
2019-10-31 04:28:29 +08:00
|
|
|
import { alias } from "@ember/object/computed";
|
2020-12-18 21:18:52 +08:00
|
|
|
import discourseDebounce from "discourse-common/lib/debounce";
|
2020-01-17 01:56:53 +08:00
|
|
|
import { isEmpty } from "@ember/utils";
|
|
|
|
import { observes } from "discourse-common/utils/decorators";
|
2021-12-09 20:47:56 +08:00
|
|
|
import { action } from "@ember/object";
|
2015-04-09 02:17:21 +08:00
|
|
|
|
2019-10-24 01:06:54 +08:00
|
|
|
export default Controller.extend({
|
2013-02-23 04:41:12 +08:00
|
|
|
filter: null,
|
2019-10-31 04:28:29 +08:00
|
|
|
allSiteSettings: alias("model"),
|
2018-12-11 23:48:12 +08:00
|
|
|
visibleSiteSettings: null,
|
2013-02-23 04:41:12 +08:00
|
|
|
onlyOverridden: false,
|
2013-02-22 01:58:21 +08:00
|
|
|
|
2015-09-30 01:34:09 +08:00
|
|
|
filterContentNow(category) {
|
2013-03-02 01:45:25 +08:00
|
|
|
// If we have no content, don't bother filtering anything
|
2020-09-22 22:28:28 +08:00
|
|
|
if (!!isEmpty(this.allSiteSettings)) {
|
|
|
|
return;
|
|
|
|
}
|
2013-03-02 01:45:25 +08:00
|
|
|
|
2020-05-10 19:07:45 +08:00
|
|
|
let filter, pluginFilter;
|
2019-05-27 16:15:39 +08:00
|
|
|
if (this.filter) {
|
2020-05-10 19:07:45 +08:00
|
|
|
filter = this.filter
|
|
|
|
.toLowerCase()
|
|
|
|
.split(" ")
|
|
|
|
.filter((word) => {
|
|
|
|
if (word.length === 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (word.startsWith("plugin:")) {
|
2022-04-01 23:35:17 +08:00
|
|
|
pluginFilter = word.slice("plugin:".length).trim();
|
2020-05-10 19:07:45 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
})
|
|
|
|
.join(" ")
|
|
|
|
.trim();
|
2013-02-23 04:41:12 +08:00
|
|
|
}
|
2013-02-22 03:42:48 +08:00
|
|
|
|
2020-05-10 19:07:45 +08:00
|
|
|
if (
|
|
|
|
(!filter || 0 === filter.length) &&
|
|
|
|
(!pluginFilter || 0 === pluginFilter.length) &&
|
|
|
|
!this.onlyOverridden
|
|
|
|
) {
|
2019-05-27 16:15:39 +08:00
|
|
|
this.set("visibleSiteSettings", this.allSiteSettings);
|
|
|
|
if (this.categoryNameKey === "all_results") {
|
2019-05-01 21:44:45 +08:00
|
|
|
this.transitionToRoute("adminSiteSettings");
|
|
|
|
}
|
2013-11-15 01:37:41 +08:00
|
|
|
return;
|
|
|
|
}
|
2013-11-02 04:32:12 +08:00
|
|
|
|
2015-09-30 01:34:09 +08:00
|
|
|
const all = {
|
|
|
|
nameKey: "all_results",
|
|
|
|
name: I18n.t("admin.site_settings.categories.all_results"),
|
|
|
|
siteSettings: [],
|
|
|
|
};
|
|
|
|
const matchesGroupedByCategory = [all];
|
2013-11-15 01:37:41 +08:00
|
|
|
|
2015-09-30 01:34:09 +08:00
|
|
|
const matches = [];
|
2019-05-27 16:15:39 +08:00
|
|
|
this.allSiteSettings.forEach((settingsCategory) => {
|
2015-09-30 01:34:09 +08:00
|
|
|
const siteSettings = settingsCategory.siteSettings.filter((item) => {
|
2020-09-22 22:28:28 +08:00
|
|
|
if (this.onlyOverridden && !item.get("overridden")) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (pluginFilter && item.plugin !== pluginFilter) {
|
|
|
|
return false;
|
|
|
|
}
|
2013-11-15 01:37:41 +08:00
|
|
|
if (filter) {
|
2018-05-16 21:37:40 +08:00
|
|
|
const setting = item.get("setting").toLowerCase();
|
|
|
|
return (
|
|
|
|
setting.includes(filter) ||
|
|
|
|
setting.replace(/_/g, " ").includes(filter) ||
|
|
|
|
item.get("description").toLowerCase().includes(filter) ||
|
|
|
|
(item.get("value") || "").toLowerCase().includes(filter)
|
|
|
|
);
|
2013-11-15 01:37:41 +08:00
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
2015-09-30 01:34:09 +08:00
|
|
|
if (siteSettings.length > 0) {
|
|
|
|
matches.pushObjects(siteSettings);
|
2015-06-09 20:34:06 +08:00
|
|
|
matchesGroupedByCategory.pushObject({
|
|
|
|
nameKey: settingsCategory.nameKey,
|
|
|
|
name: I18n.t(
|
|
|
|
"admin.site_settings.categories." + settingsCategory.nameKey
|
|
|
|
),
|
2015-09-30 01:34:09 +08:00
|
|
|
siteSettings,
|
|
|
|
count: siteSettings.length,
|
2015-06-09 20:34:06 +08:00
|
|
|
});
|
2013-02-21 02:15:50 +08:00
|
|
|
}
|
2013-11-15 01:37:41 +08:00
|
|
|
});
|
2013-02-22 01:58:21 +08:00
|
|
|
|
2015-09-30 01:34:09 +08:00
|
|
|
all.siteSettings.pushObjects(matches.slice(0, 30));
|
2018-05-16 21:37:40 +08:00
|
|
|
all.hasMore = matches.length > 30;
|
|
|
|
all.count = all.hasMore ? "30+" : matches.length;
|
2015-09-30 01:34:09 +08:00
|
|
|
|
2020-08-05 15:39:54 +08:00
|
|
|
const categoryMatches = matchesGroupedByCategory.findBy(
|
|
|
|
"nameKey",
|
|
|
|
category
|
|
|
|
);
|
|
|
|
if (!categoryMatches || categoryMatches.count === 0) {
|
|
|
|
category = "all_results";
|
|
|
|
}
|
|
|
|
|
2018-12-11 23:48:12 +08:00
|
|
|
this.set("visibleSiteSettings", matchesGroupedByCategory);
|
2018-05-16 21:37:40 +08:00
|
|
|
this.transitionToRoute(
|
|
|
|
"adminSiteSettingsCategory",
|
|
|
|
category || "all_results"
|
|
|
|
);
|
2015-07-03 00:45:17 +08:00
|
|
|
},
|
|
|
|
|
2020-01-17 01:56:53 +08:00
|
|
|
@observes("filter", "onlyOverridden", "model")
|
2020-12-18 21:18:52 +08:00
|
|
|
filterContent() {
|
|
|
|
discourseDebounce(
|
|
|
|
this,
|
|
|
|
() => {
|
|
|
|
if (this._skipBounce) {
|
|
|
|
this.set("_skipBounce", false);
|
|
|
|
} else {
|
|
|
|
this.filterContentNow(this.categoryNameKey);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
INPUT_DELAY
|
|
|
|
);
|
|
|
|
},
|
2013-12-21 00:06:07 +08:00
|
|
|
|
2021-12-09 20:47:56 +08:00
|
|
|
@action
|
|
|
|
clearFilter() {
|
|
|
|
this.setProperties({ filter: "", onlyOverridden: false });
|
|
|
|
},
|
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);
|
|
|
|
});
|
2013-12-21 00:06:07 +08:00
|
|
|
},
|
2013-02-23 04:41:12 +08:00
|
|
|
});
|