2015-08-10 17:11:27 -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-11-15 16:43:56 -05:00
|
|
|
filtered: Ember.computed.notEmpty('filter'),
|
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
|
2015-08-11 12:27:07 -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;
|
2013-02-22 15:41:12 -05:00
|
|
|
if (this.get('filter')) {
|
|
|
|
filter = this.get('filter').toLowerCase();
|
|
|
|
}
|
2013-02-21 14:42:48 -05:00
|
|
|
|
2013-11-14 12:37:41 -05:00
|
|
|
if ((filter === undefined || filter.length < 1) && !this.get('onlyOverridden')) {
|
|
|
|
this.set('model', this.get('allSiteSettings'));
|
2014-12-29 15:56:33 -05:00
|
|
|
this.transitionToRoute("adminSiteSettings");
|
2013-11-14 12:37:41 -05:00
|
|
|
return;
|
|
|
|
}
|
2013-11-01 16:32:12 -04:00
|
|
|
|
2015-09-29 13:34:09 -04:00
|
|
|
const all = {nameKey: 'all_results', name: I18n.t('admin.site_settings.categories.all_results'), siteSettings: []};
|
|
|
|
const matchesGroupedByCategory = [all];
|
2013-11-14 12:37:41 -05:00
|
|
|
|
2015-09-29 13:34:09 -04:00
|
|
|
const matches = [];
|
|
|
|
this.get('allSiteSettings').forEach(settingsCategory => {
|
|
|
|
const siteSettings = settingsCategory.siteSettings.filter(item => {
|
|
|
|
if (this.get('onlyOverridden') && !item.get('overridden')) return false;
|
2013-11-14 12:37:41 -05:00
|
|
|
if (filter) {
|
|
|
|
if (item.get('setting').toLowerCase().indexOf(filter) > -1) return true;
|
2014-04-07 11:14:12 -04:00
|
|
|
if (item.get('setting').toLowerCase().replace(/_/g, ' ').indexOf(filter) > -1) return true;
|
2013-11-14 12:37:41 -05:00
|
|
|
if (item.get('description').toLowerCase().indexOf(filter) > -1) return true;
|
2018-03-13 15:59:12 -04:00
|
|
|
if ((item.get('value') || '').toLowerCase().indexOf(filter) > -1) return true;
|
2013-11-14 12:37:41 -05:00
|
|
|
return false;
|
|
|
|
} 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,
|
|
|
|
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));
|
|
|
|
all.count = matches.length;
|
|
|
|
|
2013-11-14 12:37:41 -05:00
|
|
|
this.set('model', matchesGroupedByCategory);
|
2015-07-14 03:04:54 -04:00
|
|
|
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() {
|
2015-07-02 12:45:17 -04:00
|
|
|
if (this.get("_skipBounce")) {
|
|
|
|
this.set("_skipBounce", false);
|
|
|
|
} else {
|
|
|
|
this.filterContentNow();
|
|
|
|
}
|
2013-12-20 11:06:07 -05:00
|
|
|
}, 250).observes('filter', 'onlyOverridden'),
|
|
|
|
|
|
|
|
actions: {
|
2015-03-02 12:12:19 -05:00
|
|
|
clearFilter() {
|
2015-09-29 13:34:09 -04:00
|
|
|
this.setProperties({ filter: '', onlyOverridden: false });
|
2015-08-16 13:35:23 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
toggleMenu() {
|
|
|
|
$('.admin-detail').toggleClass('mobile-closed mobile-open');
|
2013-12-20 11:06:07 -05:00
|
|
|
}
|
|
|
|
}
|
2013-03-01 12:45:25 -05:00
|
|
|
|
2013-02-22 15:41:12 -05:00
|
|
|
});
|