Spiegel von
https://github.com/paviliondev/discourse-custom-wizard.git
synchronisiert 2024-11-25 18:50:27 +01:00
remove preset dropdown
Dieser Commit ist enthalten in:
Ursprung
ca5afcb95d
Commit
b8369146c7
10 geänderte Dateien mit 9 neuen und 116 gelöschten Zeilen
|
@ -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() {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -94,20 +94,6 @@
|
|||
{{input name="key" value=field.choices_key placeholderKey="admin.wizard.key_placeholder"}}
|
||||
{{/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}}
|
||||
<div class="wizard-header small">
|
||||
{{i18n 'admin.wizard.field.choices_custom'}}
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
@ -292,43 +294,6 @@ class CustomWizard::Builder
|
|||
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']]
|
||||
min_length = false
|
||||
|
|
|
@ -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("<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
|
||||
|
||||
context 'on update' do
|
||||
|
|
|
@ -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
|
||||
|
|
Laden …
In neuem Issue referenzieren