mirror of
https://github.com/discourse/discourse.git
synced 2024-12-05 11:33:43 +08:00
489e7f220d
UX: show the counts when displaying only overridden settings UX: show 30+ count when more than 30 site settings matches the current filter
77 lines
2.4 KiB
JavaScript
77 lines
2.4 KiB
JavaScript
import debounce from 'discourse/lib/debounce';
|
|
|
|
export default Ember.Controller.extend({
|
|
filter: null,
|
|
onlyOverridden: false,
|
|
|
|
filterContentNow(category) {
|
|
// If we have no content, don't bother filtering anything
|
|
if (!!Ember.isEmpty(this.get('allSiteSettings'))) return;
|
|
|
|
let filter;
|
|
if (this.get('filter')) {
|
|
filter = this.get('filter').toLowerCase();
|
|
}
|
|
|
|
if ((!filter || 0 === filter.length) && !this.get('onlyOverridden')) {
|
|
this.set('model', this.get('allSiteSettings'));
|
|
this.transitionToRoute('adminSiteSettings');
|
|
return;
|
|
}
|
|
|
|
const all = {nameKey: 'all_results', name: I18n.t('admin.site_settings.categories.all_results'), siteSettings: []};
|
|
const matchesGroupedByCategory = [all];
|
|
|
|
const matches = [];
|
|
this.get('allSiteSettings').forEach(settingsCategory => {
|
|
const siteSettings = settingsCategory.siteSettings.filter(item => {
|
|
if (this.get('onlyOverridden') && !item.get('overridden')) return false;
|
|
if (filter) {
|
|
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);
|
|
matchesGroupedByCategory.pushObject({
|
|
nameKey: settingsCategory.nameKey,
|
|
name: I18n.t('admin.site_settings.categories.' + settingsCategory.nameKey),
|
|
siteSettings,
|
|
count: siteSettings.length
|
|
});
|
|
}
|
|
});
|
|
|
|
all.siteSettings.pushObjects(matches.slice(0, 30));
|
|
all.hasMore = matches.length > 30;
|
|
all.count = all.hasMore ? '30+' : matches.length;
|
|
|
|
this.set('model', matchesGroupedByCategory);
|
|
this.transitionToRoute('adminSiteSettingsCategory', category || 'all_results');
|
|
},
|
|
|
|
filterContent: debounce(function() {
|
|
if (this.get('_skipBounce')) {
|
|
this.set('_skipBounce', false);
|
|
} else {
|
|
this.filterContentNow();
|
|
}
|
|
}, 250).observes('filter', 'onlyOverridden'),
|
|
|
|
actions: {
|
|
clearFilter() {
|
|
this.setProperties({ filter: '', onlyOverridden: false });
|
|
},
|
|
|
|
toggleMenu() {
|
|
$('.admin-detail').toggleClass('mobile-closed mobile-open');
|
|
}
|
|
}
|
|
|
|
});
|