0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-22 09:20:29 +01:00

remove preset dropdown

Dieser Commit ist enthalten in:
Angus McLeod 2020-03-19 18:58:45 +11:00
Ursprung ca5afcb95d
Commit b8369146c7
10 geänderte Dateien mit 9 neuen und 116 gelöschten Zeilen

Datei anzeigen

@ -7,9 +7,8 @@ export default Ember.Component.extend({
isUpload: Ember.computed.equal('field.type', 'upload'), isUpload: Ember.computed.equal('field.type', 'upload'),
isCategory: Ember.computed.equal('field.type', 'category'), isCategory: Ember.computed.equal('field.type', 'category'),
disableId: Ember.computed.not('field.isNew'), disableId: Ember.computed.not('field.isNew'),
choicesTypes: generateSelectKitContent(['translation', 'preset', 'custom']), choicesTypes: generateSelectKitContent(['translation', 'custom']),
choicesTranslation: Ember.computed.equal('field.choices_type', 'translation'), choicesTranslation: Ember.computed.equal('field.choices_type', 'translation'),
choicesPreset: Ember.computed.equal('field.choices_type', 'preset'),
choicesCustom: Ember.computed.equal('field.choices_type', 'custom'), choicesCustom: Ember.computed.equal('field.choices_type', 'custom'),
categoryPropertyTypes: generateSelectKitContent(['id', 'slug']), categoryPropertyTypes: generateSelectKitContent(['id', 'slug']),
@ -19,24 +18,6 @@ export default Ember.Component.extend({
@computed('field.type') @computed('field.type')
isCategoryOrTag: (type) => type === 'tag' || type === 'category', 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') @on('didInsertElement')
@observes('isUpload') @observes('isUpload')
setupFileType() { setupFileType() {

Datei anzeigen

@ -106,7 +106,7 @@ const CustomWizard = Discourse.Model.extend({
if (f.type === 'dropdown') { if (f.type === 'dropdown') {
const choices = f.choices; 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'; error = 'field.need_choices';
return; return;
} }

Datei anzeigen

@ -94,20 +94,6 @@
{{input name="key" value=field.choices_key placeholderKey="admin.wizard.key_placeholder"}} {{input name="key" value=field.choices_key placeholderKey="admin.wizard.key_placeholder"}}
{{/if}} {{/if}}
{{#if choicesPreset}}
<div class="wizard-header small">
{{i18n 'admin.wizard.field.choices_preset.label'}}
</div>
{{combo-box
value=field.choices_preset
content=presetChoices
none='admin.wizard.none'}}
<div class="wizard-header small">
{{i18n 'admin.wizard.field.choices_preset.filter'}}
</div>
{{wizard-custom-inputs inputs=field.choices_filters}}
{{/if}}
{{#if choicesCustom}} {{#if choicesCustom}}
<div class="wizard-header small"> <div class="wizard-header small">
{{i18n 'admin.wizard.field.choices_custom'}} {{i18n 'admin.wizard.field.choices_custom'}}

Datei anzeigen

@ -98,12 +98,6 @@ en:
choices_type: "Choose a type" choices_type: "Choose a type"
choices_translation: "Translation" choices_translation: "Translation"
choices_custom: "Custom" choices_custom: "Custom"
choices_preset:
label: "Preset"
categories: "Categories"
groups: "Groups"
tags: "Tags"
filter: "Preset Filter"
choice: choice:
value: "Value" value: "Value"
label: "Label" label: "Label"

Datei anzeigen

@ -83,10 +83,6 @@ fr:
choices_type: "Choisir un type" choices_type: "Choisir un type"
choices_translation: "Traduction" choices_translation: "Traduction"
choices_custom: "Personnalisé" choices_custom: "Personnalisé"
choices_preset:
label: "Prédéfini"
categories: "Catégories"
filter: "Filtre prédéfini"
choice: choice:
value: "Valeur" value: "Valeur"
label: "Étiquette" label: "Étiquette"

Datei anzeigen

@ -69,7 +69,7 @@ class CustomWizard::AdminController < ::ApplicationController
if f["type"] === 'dropdown' if f["type"] === 'dropdown'
choices = f["choices"] 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' error = 'field.need_choices'
break break
end end

Datei anzeigen

@ -246,10 +246,12 @@ class CustomWizard::Builder
params[:property] = field_template['property'] params[:property] = field_template['property']
end end
if field_template['type'] === 'category' || if field_template['type'] === 'category'
(field_template['type'] === 'dropdown' && @wizard.needs_categories = true
field_template['choices_preset'] === 'categories') end
@wizard.needs_categories = true
if field_template['type'] === 'group'
@wizard.needs_groups = true
end end
field = step.add_field(params) field = step.add_field(params)
@ -291,43 +293,6 @@ class CustomWizard::Builder
choices.each { |k, v| field.add_choice(k, label: v) } choices.each { |k, v| field.add_choice(k, label: v) }
end end
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) def validate_field(field, updater, step_template)
value = updater.fields[field['id']] value = updater.fields[field['id']]

Datei anzeigen

@ -20,7 +20,6 @@ describe CustomWizard::Builder do
let(:required_data_message) {"Nickname is required to match your name"} let(:required_data_message) {"Nickname is required to match your name"}
let(:checkbox_field) {{"id":"checkbox","type":"checkbox","label":"Checkbox"}} let(:checkbox_field) {{"id":"checkbox","type":"checkbox","label":"Checkbox"}}
let(:composer_field) {{"id": "composer","label":"Composer","type":"composer"}} 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(:tag_field) {{"id": "tag","type": "tag","label": "Tag","limit": "2"}}
let(:category_field) {{"id": "category","type": "category","limit": "1","label": "Category"}} let(:category_field) {{"id": "category","type": "category","limit": "1","label": "Category"}}
let(:image_field) {{"id": "image","type": "image","label": "Image"}} 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(: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(: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(: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_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_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(: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(: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"}} 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 template['steps'][0]['fields'][1] = checkbox_field
expect(build_wizard(template, user).steps[0].fields.length).to eq(2) expect(build_wizard(template, user).steps[0].fields.length).to eq(2)
end 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("<p>cat1</p>")
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("<p>cat2</p>")
end
end end
context 'on update' do context 'on update' do

Datei anzeigen

@ -12,7 +12,6 @@ describe CustomWizardSerializer do
).read) ).read)
end 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"}} let(:category_field) {{"id": "category","type": "category","limit": "1","label": "Category"}}
def build_wizard(t = template, u = user, build_opts = {}, params = {}) 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) expect(json[:custom_wizard][:uncategorized_category_id].present?).to eq(false)
end 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 it "should return category attributes if there is a category selector field" do
template['steps'][0]['fields'][0] = category_field template['steps'][0]['fields'][0] = category_field
json = CustomWizardSerializer.new(build_wizard(template), scope: Guardian.new(user)).as_json json = CustomWizardSerializer.new(build_wizard(template), scope: Guardian.new(user)).as_json