diff --git a/assets/javascripts/discourse/components/wizard-custom-field.js.es6 b/assets/javascripts/discourse/components/wizard-custom-field.js.es6 index abd9f459..f7a7bb8b 100644 --- a/assets/javascripts/discourse/components/wizard-custom-field.js.es6 +++ b/assets/javascripts/discourse/components/wizard-custom-field.js.es6 @@ -7,9 +7,8 @@ export default Ember.Component.extend({ isUpload: Ember.computed.equal('field.type', 'upload'), isCategory: Ember.computed.equal('field.type', 'category'), disableId: Ember.computed.not('field.isNew'), - choicesTypes: generateSelectKitContent(['translation', 'preset', 'custom']), + choicesTypes: generateSelectKitContent(['translation', 'custom']), choicesTranslation: Ember.computed.equal('field.choices_type', 'translation'), - choicesPreset: Ember.computed.equal('field.choices_type', 'preset'), choicesCustom: Ember.computed.equal('field.choices_type', 'custom'), categoryPropertyTypes: generateSelectKitContent(['id', 'slug']), @@ -19,24 +18,6 @@ export default Ember.Component.extend({ @computed('field.type') isCategoryOrTag: (type) => type === 'tag' || type === 'category', - @computed() - presetChoices() { - let presets = [ - { - id: 'categories', - name: I18n.t('admin.wizard.field.choices_preset.categories') - },{ - id: 'groups', - name: I18n.t('admin.wizard.field.choices_preset.groups') - },{ - id: 'tags', - name: I18n.t('admin.wizard.field.choices_preset.tags') - } - ]; - - return presets; - }, - @on('didInsertElement') @observes('isUpload') setupFileType() { diff --git a/assets/javascripts/discourse/models/custom-wizard.js.es6 b/assets/javascripts/discourse/models/custom-wizard.js.es6 index e7860c01..fa056c9a 100644 --- a/assets/javascripts/discourse/models/custom-wizard.js.es6 +++ b/assets/javascripts/discourse/models/custom-wizard.js.es6 @@ -106,7 +106,7 @@ const CustomWizard = Discourse.Model.extend({ if (f.type === 'dropdown') { const choices = f.choices; - if ((!choices || choices.length < 1) && !f.choices_key && !f.choices_preset) { + if ((!choices || choices.length < 1) && !f.choices_key) { error = 'field.need_choices'; return; } diff --git a/assets/javascripts/discourse/templates/components/wizard-custom-field.hbs b/assets/javascripts/discourse/templates/components/wizard-custom-field.hbs index aa91b615..8b66ea2b 100644 --- a/assets/javascripts/discourse/templates/components/wizard-custom-field.hbs +++ b/assets/javascripts/discourse/templates/components/wizard-custom-field.hbs @@ -94,20 +94,6 @@ {{input name="key" value=field.choices_key placeholderKey="admin.wizard.key_placeholder"}} {{/if}} - {{#if choicesPreset}} -
- {{i18n 'admin.wizard.field.choices_preset.label'}} -
- {{combo-box - value=field.choices_preset - content=presetChoices - none='admin.wizard.none'}} -
- {{i18n 'admin.wizard.field.choices_preset.filter'}} -
- {{wizard-custom-inputs inputs=field.choices_filters}} - {{/if}} - {{#if choicesCustom}}
{{i18n 'admin.wizard.field.choices_custom'}} diff --git a/assets/javascripts/wizard/templates/components/wizard-field-group.hbs b/assets/javascripts/wizard/templates/components/wizard-field-group.hbs new file mode 100644 index 00000000..e69de29b diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index 65e3890d..00f81838 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -98,12 +98,6 @@ en: choices_type: "Choose a type" choices_translation: "Translation" choices_custom: "Custom" - choices_preset: - label: "Preset" - categories: "Categories" - groups: "Groups" - tags: "Tags" - filter: "Preset Filter" choice: value: "Value" label: "Label" diff --git a/config/locales/client.fr.yml b/config/locales/client.fr.yml index e61004c2..b1963539 100644 --- a/config/locales/client.fr.yml +++ b/config/locales/client.fr.yml @@ -83,10 +83,6 @@ fr: choices_type: "Choisir un type" choices_translation: "Traduction" choices_custom: "Personnalisé" - choices_preset: - label: "Prédéfini" - categories: "Catégories" - filter: "Filtre prédéfini" choice: value: "Valeur" label: "Étiquette" diff --git a/controllers/custom_wizard/admin.rb b/controllers/custom_wizard/admin.rb index b98cd9f9..2b09fcf2 100644 --- a/controllers/custom_wizard/admin.rb +++ b/controllers/custom_wizard/admin.rb @@ -69,7 +69,7 @@ class CustomWizard::AdminController < ::ApplicationController if f["type"] === 'dropdown' choices = f["choices"] - if (!choices || choices.length < 1) && !f["choices_key"] && !f["choices_preset"] + if (!choices || choices.length < 1) && !f["choices_key"] error = 'field.need_choices' break end diff --git a/lib/custom_wizard/builder.rb b/lib/custom_wizard/builder.rb index ea8bdc01..cc9053f0 100644 --- a/lib/custom_wizard/builder.rb +++ b/lib/custom_wizard/builder.rb @@ -246,10 +246,12 @@ class CustomWizard::Builder params[:property] = field_template['property'] end - if field_template['type'] === 'category' || - (field_template['type'] === 'dropdown' && - field_template['choices_preset'] === 'categories') - @wizard.needs_categories = true + if field_template['type'] === 'category' + @wizard.needs_categories = true + end + + if field_template['type'] === 'group' + @wizard.needs_groups = true end field = step.add_field(params) @@ -291,43 +293,6 @@ class CustomWizard::Builder choices.each { |k, v| field.add_choice(k, label: v) } end end - - def build_dropdown_preset(field, template) - objects = [] - guardian = Guardian.new(@wizard.user) - site = Site.new(guardian) - - case template['choices_preset'] - when 'categories' - objects = Set.new(Category.topic_create_allowed(guardian)) - when 'groups' - objects = site.groups - when 'tags' - objects = Tag.top_tags(guardian: guardian).map do |tag| - TagStruct.new(tag,tag) - end - else - # do nothing - end - - if template['choices_filters'] && template['choices_filters'].length > 0 - template['choices_filters'].each do |f| - objects.reject! do |o| - if f['key'].include? 'custom_fields' - o.custom_fields[f['key'].split('.')[1]].to_s != f['value'].to_s - else - o[f['key']].to_s != f['value'].to_s - end - end - end - end - - if objects.length > 0 - objects.each do |o| - field.add_choice(o.id, label: o.name) - end - end - end def validate_field(field, updater, step_template) value = updater.fields[field['id']] diff --git a/spec/components/custom_wizard/builder_spec.rb b/spec/components/custom_wizard/builder_spec.rb index 04554037..d63ba6e3 100644 --- a/spec/components/custom_wizard/builder_spec.rb +++ b/spec/components/custom_wizard/builder_spec.rb @@ -20,7 +20,6 @@ describe CustomWizard::Builder do let(:required_data_message) {"Nickname is required to match your name"} let(:checkbox_field) {{"id":"checkbox","type":"checkbox","label":"Checkbox"}} let(:composer_field) {{"id": "composer","label":"Composer","type":"composer"}} - let(:dropdown_categories_field) {{"id": "dropdown_categories","type": "dropdown","label": "Dropdown Categories","choices_type": "preset","choices_preset": "categories"}} let(:tag_field) {{"id": "tag","type": "tag","label": "Tag","limit": "2"}} let(:category_field) {{"id": "category","type": "category","limit": "1","label": "Category"}} let(:image_field) {{"id": "image","type": "image","label": "Image"}} @@ -29,11 +28,8 @@ describe CustomWizard::Builder do let(:text_only_field) {{"id": "text_only","type": "text-only","label": "Text only"}} let(:upload_field) {{"id": "upload","type": "upload","file_types": ".jpg,.png,.pdf","label": "Upload"}} let(:user_selector_field) {{"id": "user_selector","type": "user-selector","label": "User selector"}} - let(:dropdown_groups_field) {{"id": "dropdown_groups","type": "dropdown","choices_type": "preset","choices_preset": "groups","label": "Dropdown Groups"}} - let(:dropdown_tags_field) {{"id": "dropdown_tags","type": "dropdown","choices_type": "preset","choices_preset": "tags","label": "Dropdown Tags"}} let(:dropdown_custom_field) {{"id": "dropdown_custom","type": "dropdown","choices_type": "custom","choices": [{"key": "option_1","value": "Option 1"},{"key": "option_2","value": "Option 2"}]}} let(:dropdown_translation_field) {{"id": "dropdown_translation","type": "dropdown","choices_type": "translation","choices_key": "key1.key2"}} - let(:dropdown_categories_filtered_field) {{"id": "dropdown_categories_filtered_field","type": "dropdown","choices_type": "preset","choices_preset": "categories","choices_filters": [{"key": "slug","value": "cat2"}]}} let(:create_topic_action) {{"id":"create_topic","type":"create_topic","title":"text","post":"textarea"}} let(:send_message_action) {{"id":"send_message","type":"send_message","title":"text","post":"textarea","username":"angus"}} let(:route_to_action) {{"id":"route_to","type":"route_to","url":"https://google.com"}} @@ -190,23 +186,6 @@ describe CustomWizard::Builder do template['steps'][0]['fields'][1] = checkbox_field expect(build_wizard(template, user).steps[0].fields.length).to eq(2) end - - it 'returns a preset dropdown' do - SiteSetting.allow_uncategorized_topics = false - template['steps'][0]['fields'][0] = dropdown_categories_field - choices = build_wizard(template, user).steps[0].fields[0].choices - expect(choices.present?).to eq(true) - expect(choices.length).to eq(2) - expect(choices.first.label).to eq("

cat1

") - end - - it 'returns a filtered preset dropdown' do - template['steps'][0]['fields'][0] = dropdown_categories_filtered_field - choices = build_wizard(template, user).steps[0].fields[0].choices - expect(choices.present?).to eq(true) - expect(choices.length).to eq(1) - expect(choices.first.label).to eq("

cat2

") - end end context 'on update' do diff --git a/spec/serializers/custom_wizard/wizard_serializer_spec.rb b/spec/serializers/custom_wizard/wizard_serializer_spec.rb index 41568336..eabe26e4 100644 --- a/spec/serializers/custom_wizard/wizard_serializer_spec.rb +++ b/spec/serializers/custom_wizard/wizard_serializer_spec.rb @@ -12,7 +12,6 @@ describe CustomWizardSerializer do ).read) end - let(:dropdown_categories_field) {{"id": "dropdown_categories","type": "dropdown","label": "Dropdown Categories","choices_type": "preset","choices_preset": "categories"}} let(:category_field) {{"id": "category","type": "category","limit": "1","label": "Category"}} def build_wizard(t = template, u = user, build_opts = {}, params = {}) @@ -41,13 +40,6 @@ describe CustomWizardSerializer do expect(json[:custom_wizard][:uncategorized_category_id].present?).to eq(false) end - it "should return category attributes if there are dropdown category fields" do - template['steps'][0]['fields'][0] = dropdown_categories_field - json = CustomWizardSerializer.new(build_wizard(template), scope: Guardian.new(user)).as_json - expect(json[:custom_wizard][:categories].present?).to eq(true) - expect(json[:custom_wizard][:uncategorized_category_id].present?).to eq(true) - end - it "should return category attributes if there is a category selector field" do template['steps'][0]['fields'][0] = category_field json = CustomWizardSerializer.new(build_wizard(template), scope: Guardian.new(user)).as_json