diff --git a/app/assets/javascripts/admin/controllers/admin_site_settings_category_controller.js b/app/assets/javascripts/admin/controllers/admin_site_settings_category_controller.js new file mode 100644 index 000000000..271d26cfd --- /dev/null +++ b/app/assets/javascripts/admin/controllers/admin_site_settings_category_controller.js @@ -0,0 +1,19 @@ +Discourse.AdminSiteSettingsCategoryController = Ember.ObjectController.extend({ + categoryNameKey: null, + needs: ['adminSiteSettings'], + + filteredContent: function() { + if (!this.get('categoryNameKey')) { return Em.A(); } + + var category = this.get('controllers.adminSiteSettings.content').find(function(siteSettingCategory) { + return siteSettingCategory.nameKey === this.get('categoryNameKey'); + }, this); + + if (category) { + return category.siteSettings; + } else { + return Em.A(); + } + }.property('controllers.adminSiteSettings.content', 'categoryNameKey') + +}); diff --git a/app/assets/javascripts/admin/controllers/admin_site_settings_controller.js b/app/assets/javascripts/admin/controllers/admin_site_settings_controller.js index e3d2dacd5..d5d3a963d 100644 --- a/app/assets/javascripts/admin/controllers/admin_site_settings_controller.js +++ b/app/assets/javascripts/admin/controllers/admin_site_settings_controller.js @@ -15,31 +15,47 @@ Discourse.AdminSiteSettingsController = Ember.ArrayController.extend(Discourse.P @property filteredContent **/ - filteredContent: function() { + filterContent: function() { // If we have no content, don't bother filtering anything - if (!this.present('content')) return null; + if (!this.present('allSiteSettings')) return; var filter; if (this.get('filter')) { filter = this.get('filter').toLowerCase(); } - var adminSettingsController = this; + if ((filter === undefined || filter.length < 1) && !this.get('onlyOverridden')) { + this.set('model', this.get('allSiteSettings')); + return; + } - var maxResults = Em.isNone(filter) ? this.get('content.length') : 20; - return _.first(this.get('content').filter(function(item, index, enumerable) { - if (adminSettingsController.get('onlyOverridden') && !item.get('overridden')) return false; - if (filter) { - if (item.get('setting').toLowerCase().indexOf(filter) > -1) return true; - if (item.get('description').toLowerCase().indexOf(filter) > -1) return true; - if (item.get('value').toLowerCase().indexOf(filter) > -1) return true; - return false; + var self = this, + matches, + matchesGroupedByCategory = Em.A(); + + _.each(this.get('allSiteSettings'), function(settingsCategory) { + matches = settingsCategory.siteSettings.filter(function(item) { + if (self.get('onlyOverridden') && !item.get('overridden')) return false; + if (filter) { + if (item.get('setting').toLowerCase().indexOf(filter) > -1) return true; + if (item.get('description').toLowerCase().indexOf(filter) > -1) return true; + if (item.get('value').toLowerCase().indexOf(filter) > -1) return true; + return false; + } else { + return true; + } + }); + if (matches.length > 0) { + matchesGroupedByCategory.pushObject({ + nameKey: settingsCategory.nameKey, + name: settingsCategory.name, + siteSettings: matches}); } + }); - return true; - }), maxResults); - }.property('filter', 'content.@each', 'onlyOverridden'), + this.set('model', matchesGroupedByCategory); + }.observes('filter', 'onlyOverridden'), actions: { diff --git a/app/assets/javascripts/admin/models/site_setting.js b/app/assets/javascripts/admin/models/site_setting.js index 5284c3043..987b79368 100644 --- a/app/assets/javascripts/admin/models/site_setting.js +++ b/app/assets/javascripts/admin/models/site_setting.js @@ -118,7 +118,7 @@ Discourse.SiteSetting.reopenClass({ categories[s.category].pushObject(Discourse.SiteSetting.create(s)); }); _.each(categoryNames, function(n) { - result.pushObject({nameKey: n, name: I18n.t('admin.site_settings.categories.' + n),siteSettings: categories[n]}); + result.pushObject({nameKey: n, name: I18n.t('admin.site_settings.categories.' + n), siteSettings: categories[n]}); }); return result; }); diff --git a/app/assets/javascripts/admin/routes/admin_site_setting_category_route.js b/app/assets/javascripts/admin/routes/admin_site_settings_category_route.js similarity index 57% rename from app/assets/javascripts/admin/routes/admin_site_setting_category_route.js rename to app/assets/javascripts/admin/routes/admin_site_settings_category_route.js index 889be542d..531749f0f 100644 --- a/app/assets/javascripts/admin/routes/admin_site_setting_category_route.js +++ b/app/assets/javascripts/admin/routes/admin_site_settings_category_route.js @@ -8,11 +8,6 @@ **/ Discourse.AdminSiteSettingsCategoryRoute = Discourse.Route.extend({ model: function(params) { - var category = this.modelFor('adminSiteSettings').find(function(siteSettingCategory) { - return siteSettingCategory.nameKey === params.category_id; - }); - if (category) { - return category.siteSettings; - } + this.controllerFor('adminSiteSettingsCategory').set('categoryNameKey', params.category_id); } }); diff --git a/app/assets/javascripts/admin/routes/admin_site_settings_route.js b/app/assets/javascripts/admin/routes/admin_site_settings_route.js index 3dbe5ad1f..a06a9848b 100644 --- a/app/assets/javascripts/admin/routes/admin_site_settings_route.js +++ b/app/assets/javascripts/admin/routes/admin_site_settings_route.js @@ -9,6 +9,10 @@ Discourse.AdminSiteSettingsRoute = Discourse.Route.extend({ model: function() { return Discourse.SiteSetting.findAll(); + }, + + afterModel: function(siteSettings) { + this.controllerFor('adminSiteSettings').set('allSiteSettings', siteSettings); } }); diff --git a/app/assets/javascripts/admin/templates/site_settings.js.handlebars b/app/assets/javascripts/admin/templates/site_settings.js.handlebars index a5b948cc6..edb28155e 100644 --- a/app/assets/javascripts/admin/templates/site_settings.js.handlebars +++ b/app/assets/javascripts/admin/templates/site_settings.js.handlebars @@ -1,9 +1,9 @@