A platform for community discussion. Free, open, simple.
DEV: add site setting type group_list for a list of groups
Neil Lalonde1ba72ccab869
diff --git a/app/assets/javascripts/admin/components/site-settings/group-list.js.es6 b/app/assets/javascripts/admin/components/site-settings/group-list.js.es6new file mode 100644index 00000000000..c67f41f8d0c--- /dev/null+++ b/app/assets/javascripts/admin/components/site-settings/group-list.js.es6@@ -0,0 +1,8 @@+import computed from "ember-addons/ember-computed-decorators";++export default Ember.Component.extend({+ @computed()+ groupChoices() {+ return this.site.get('groups').map(g => g.name);+ }+});diff --git a/app/assets/javascripts/admin/mixins/setting-component.js.es6 b/app/assets/javascripts/admin/mixins/setting-component.js.es6index 444fe6aa76b..c3f4f19e3d3 100644--- a/app/assets/javascripts/admin/mixins/setting-component.js.es6+++ b/app/assets/javascripts/admin/mixins/setting-component.js.es6@@ -13,7 +13,8 @@ const CUSTOM_TYPES = ["uploaded_image_list","compact_list","secret_list",- "upload"+ "upload",+ "group_list"];export default Ember.Mixin.create({diff --git a/app/assets/javascripts/admin/templates/components/site-settings/group-list.hbs b/app/assets/javascripts/admin/templates/components/site-settings/group-list.hbsnew file mode 100644index 00000000000..adb6ec50982--- /dev/null+++ b/app/assets/javascripts/admin/templates/components/site-settings/group-list.hbs@@ -0,0 +1,3 @@+{{list-setting settingValue=value choices=groupChoices settingName=setting.setting}}+{{setting-validation-message message=validationMessage}}+<div class='desc'>{{{unbound setting.description}}}</div>diff --git a/config/locales/client.en.yml b/config/locales/client.en.ymlindex 6d217d85c46..336179ecb24 100644--- a/config/locales/client.en.yml+++ b/config/locales/client.en.yml@@ -4106,6 +4106,7 @@ en:clear_filter: "Clear"add_url: "add URL"add_host: "add host"+ add_group: "add group"uploaded_image_list:label: "Edit list"empty: "There are no pictures yet. Please upload one."diff --git a/lib/site_settings/type_supervisor.rb b/lib/site_settings/type_supervisor.rbindex 2137561b88b..da210d82109 100644--- a/lib/site_settings/type_supervisor.rb+++ b/lib/site_settings/type_supervisor.rb@@ -33,6 +33,7 @@ class SiteSettings::TypeSupervisoruploaded_image_list: 17,upload: 18,group: 19,+ group_list: 20,)enddiff --git a/spec/components/site_settings/type_supervisor_spec.rb b/spec/components/site_settings/type_supervisor_spec.rbindex f795d824434..2fae2ff5818 100644--- a/spec/components/site_settings/type_supervisor_spec.rb+++ b/spec/components/site_settings/type_supervisor_spec.rb@@ -72,10 +72,15 @@ describe SiteSettings::TypeSupervisor doit "'uploaded_image_list' should be at 17th position" doexpect(SiteSettings::TypeSupervisor.types[:uploaded_image_list]).to eq(17)end-it "'upload' should be at the right position" doexpect(SiteSettings::TypeSupervisor.types[:upload]).to eq(18)end+ it "'group' should be at the right position" do+ expect(SiteSettings::TypeSupervisor.types[:group]).to eq(19)+ end+ it "'group_list' should be at the right position" do+ expect(SiteSettings::TypeSupervisor.types[:group_list]).to eq(20)+ endendenddiff --git a/test/javascripts/admin/components/group-list-setting-test.js.es6 b/test/javascripts/admin/components/group-list-setting-test.js.es6new file mode 100644index 00000000000..d64bd9d7d11--- /dev/null+++ b/test/javascripts/admin/components/group-list-setting-test.js.es6@@ -0,0 +1,57 @@+import componentTest from "helpers/component-test";++moduleForComponent("group-list", { integration: true });++componentTest("default", {+ template: "{{site-setting setting=setting}}",++ beforeEach() {+ this.site.groups = [+ {+ id: 1,+ name: "Donuts"+ },+ {+ id: 2,+ name: "Cheese cake"+ }+ ];++ this.set(+ "setting",+ Ember.Object.create({+ allowsNone: undefined,+ category: "foo",+ default: "",+ description: "Choose groups",+ overridden: false,+ placeholder: null,+ preview: null,+ secret: false,+ setting: "foo_bar",+ type: "group_list",+ validValues: undefined,+ value: "Donuts"+ })+ );+ },++ async test(assert) {+ const subject = selectKit(".list-setting");++ assert.equal(+ subject.header().value(),+ "Donuts",+ "it selects the setting's value"+ );++ await subject.expand();+ await subject.selectRowByValue("Cheese cake");++ assert.equal(+ subject.header().value(),+ "Donuts,Cheese cake",+ "it allows to select a setting from the list of choices"+ );+ }+});