discourse/app/assets/javascripts/admin/controllers/admin-site-settings.js.es6

92 lines
2.6 KiB
Plaintext
Raw Normal View History

2018-06-15 23:03:24 +08:00
import debounce from "discourse/lib/debounce";
2015-04-09 02:17:21 +08:00
export default Ember.Controller.extend({
filter: null,
allSiteSettings: Ember.computed.alias("model"),
visibleSiteSettings: null,
onlyOverridden: false,
filterContentNow(category) {
// If we have no content, don't bother filtering anything
2018-06-15 23:03:24 +08:00
if (!!Ember.isEmpty(this.get("allSiteSettings"))) return;
2015-03-03 01:12:19 +08:00
let filter;
2018-06-15 23:03:24 +08:00
if (this.get("filter")) {
filter = this.get("filter").toLowerCase();
}
2018-06-15 23:03:24 +08:00
if ((!filter || 0 === filter.length) && !this.get("onlyOverridden")) {
this.set("visibleSiteSettings", this.get("allSiteSettings"));
2018-06-15 23:03:24 +08:00
this.transitionToRoute("adminSiteSettings");
return;
}
2018-06-15 23:03:24 +08:00
const all = {
nameKey: "all_results",
name: I18n.t("admin.site_settings.categories.all_results"),
siteSettings: []
};
const matchesGroupedByCategory = [all];
const matches = [];
2018-06-15 23:03:24 +08:00
this.get("allSiteSettings").forEach(settingsCategory => {
const siteSettings = settingsCategory.siteSettings.filter(item => {
2018-06-15 23:03:24 +08:00
if (this.get("onlyOverridden") && !item.get("overridden")) return false;
if (filter) {
2018-06-15 23:03:24 +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)
);
} else {
return true;
}
});
if (siteSettings.length > 0) {
matches.pushObjects(siteSettings);
2015-06-09 20:34:06 +08:00
matchesGroupedByCategory.pushObject({
nameKey: settingsCategory.nameKey,
2018-06-15 23:03:24 +08:00
name: I18n.t(
"admin.site_settings.categories." + settingsCategory.nameKey
),
siteSettings,
count: siteSettings.length
2015-06-09 20:34:06 +08:00
});
}
});
all.siteSettings.pushObjects(matches.slice(0, 30));
all.hasMore = matches.length > 30;
2018-06-15 23:03:24 +08:00
all.count = all.hasMore ? "30+" : matches.length;
this.set("visibleSiteSettings", matchesGroupedByCategory);
2018-06-15 23:03:24 +08:00
this.transitionToRoute(
"adminSiteSettingsCategory",
category || "all_results"
);
},
2015-08-11 05:11:27 +08:00
filterContent: debounce(function() {
2018-06-15 23:03:24 +08:00
if (this.get("_skipBounce")) {
this.set("_skipBounce", false);
} else {
this.filterContentNow();
}
2018-06-15 23:03:24 +08:00
}, 250).observes("filter", "onlyOverridden"),
actions: {
2015-03-03 01:12:19 +08:00
clearFilter() {
2018-06-15 23:03:24 +08:00
this.setProperties({ filter: "", onlyOverridden: false });
2015-08-17 01:35:23 +08:00
},
toggleMenu() {
2018-06-15 23:03:24 +08:00
$(".admin-detail").toggleClass("mobile-closed mobile-open");
}
}
});