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 @@
{{textField value=filter placeholderKey="type_to_filter"}} @@ -12,7 +12,7 @@ diff --git a/app/assets/javascripts/admin/templates/site_settings_category.js.handlebars b/app/assets/javascripts/admin/templates/site_settings_category.js.handlebars index 8c65f5226..3b1264102 100644 --- a/app/assets/javascripts/admin/templates/site_settings_category.js.handlebars +++ b/app/assets/javascripts/admin/templates/site_settings_category.js.handlebars @@ -1 +1 @@ -{{collection contentBinding="content" classNames="form-horizontal settings" itemViewClass="Discourse.SiteSettingView"}} +{{collection contentBinding="filteredContent" classNames="form-horizontal settings" itemViewClass="Discourse.SiteSettingView"}} diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index c500b71e8..89c1c60d5 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -1418,7 +1418,7 @@ en: reset: 'reset to default' none: 'none' categories: - mandatory: 'Mandatory' + required: 'Required' users: 'Users' posting: 'Posting' email: 'Email' diff --git a/config/site_settings.yml b/config/site_settings.yml index 81dbb23d4..17fabb30c 100644 --- a/config/site_settings.yml +++ b/config/site_settings.yml @@ -1,4 +1,4 @@ -mandatory: +required: title: client: true default: 'Discourse' diff --git a/test/javascripts/admin/controllers/admin_site_settings_controller_test.js b/test/javascripts/admin/controllers/admin_site_settings_controller_test.js new file mode 100644 index 000000000..ee37882ae --- /dev/null +++ b/test/javascripts/admin/controllers/admin_site_settings_controller_test.js @@ -0,0 +1,39 @@ +module("Discourse.AdminSiteSettingsController"); + +test("filter", function() { + var allSettings = Em.A([Ember.Object.create({ + nameKey: 'users', name: 'users', + siteSettings: [Discourse.SiteSetting.create({"setting":"username_change_period","description":"x","default":3,"type":"fixnum","value":"3","category":"users"})] + }), Ember.Object.create({ + nameKey: 'posting', name: 'posting', + siteSettings: [Discourse.SiteSetting.create({"setting":"display_name_on_posts","description":"x","default":false,"type":"bool","value":"true","category":"posting"})] + })]); + var adminSiteSettingsController = testController(Discourse.AdminSiteSettingsController, allSettings); + adminSiteSettingsController.set('allSiteSettings', allSettings); + + equal(adminSiteSettingsController.get('content')[0].nameKey, 'users', "Can get first site setting category's name key."); + + adminSiteSettingsController.set('filter', 'username_change'); + equal(adminSiteSettingsController.get('content').length, 1, "a. Filter with one match for username_change"); + equal(adminSiteSettingsController.get('content')[0].nameKey, "users", "b. Filter with one match for username_change"); + equal(adminSiteSettingsController.get('content')[0].siteSettings[0].setting, "username_change_period", "c. Filter with one match for username_change"); + + adminSiteSettingsController.set('filter', 'name_on'); + equal(adminSiteSettingsController.get('content').length, 1, "a. Filter with one match for name_on"); + equal(adminSiteSettingsController.get('content')[0].nameKey, "posting", "b. Filter with one match for name_on"); + equal(adminSiteSettingsController.get('content')[0].siteSettings[0].setting, "display_name_on_posts", "c. Filter with one match for name_on"); + + adminSiteSettingsController.set('filter', 'name'); + equal(adminSiteSettingsController.get('content').length, 2, "a. Filter with one match for name"); + equal(adminSiteSettingsController.get('content')[0].nameKey, "users", "b. Filter with one match for name"); + equal(adminSiteSettingsController.get('content')[1].nameKey, "posting", "c. Filter with one match for name"); + equal(adminSiteSettingsController.get('content')[0].siteSettings[0].setting, "username_change_period", "d. Filter with one match for name"); + equal(adminSiteSettingsController.get('content')[1].siteSettings[0].setting, "display_name_on_posts", "d. Filter with one match for name"); + + adminSiteSettingsController.set('filter', ''); + adminSiteSettingsController.set('onlyOverridden', true); + equal(adminSiteSettingsController.get('content').length, 1, "a. onlyOverridden with one match"); + equal(adminSiteSettingsController.get('content')[0].nameKey, "posting", "b. onlyOverridden with one match"); + equal(adminSiteSettingsController.get('content')[0].siteSettings[0].setting, "display_name_on_posts", "c. onlyOverridden with one match"); + +});