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