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

Fix tag and category fields

Dieser Commit ist enthalten in:
Angus McLeod 2019-07-27 16:10:26 +10:00
Ursprung 0460f9342d
Commit c058340c84
3 geänderte Dateien mit 34 neuen und 18 gelöschten Zeilen

Datei anzeigen

@ -1,13 +1,28 @@
import { observes } from 'ember-addons/ember-computed-decorators'; import { observes } from 'ember-addons/ember-computed-decorators';
import Category from 'discourse/models/category';
export default Ember.Component.extend({ export default Ember.Component.extend({
didInsertElement() {
const value = this.get('field.value');
if (value) {
const property = this.get('field.property') || 'id';
const categories = [...value].map(v => {
return property === 'id' ?
Category.findById(v) :
Category.findBySlug(v);
});
this.set('categories', categories);
}
},
@observes('categories') @observes('categories')
setValue() { setValue() {
const categories = this.get('categories'); const categories = this.get('categories');
if (categories.length) { if (categories.length) {
const limit = this.get('field.limit');
const property = this.get('field.property') || 'id'; const property = this.get('field.property') || 'id';
let value = limit === 1 ? categories[0][property] : categories.map(c => c[property]); let value = categories.length === 1 ?
categories[0][property] :
categories.map(c => c[property]);
this.set('field.value', value); this.set('field.value', value);
} }
} }

Datei anzeigen

@ -1 +1 @@
{{tag-chooser value=field.value maximum=field.limit}} {{tag-chooser tags=field.value maximum=field.limit}}

Datei anzeigen

@ -107,13 +107,13 @@ class CustomWizard::Builder
step.on_update do |updater| step.on_update do |updater|
@updater = updater @updater = updater
user = @wizard.user user = @wizard.user
if step_template['fields'] && step_template['fields'].length if step_template['fields'] && step_template['fields'].length
step_template['fields'].each do |field| step_template['fields'].each do |field|
validate_field(field, updater, step_template) if field['type'] != 'text-only' validate_field(field, updater, step_template) if field['type'] != 'text-only'
end end
end end
next if updater.errors.any? next if updater.errors.any?
CustomWizard::Builder.step_handlers.each do |handler| CustomWizard::Builder.step_handlers.each do |handler|
@ -131,7 +131,7 @@ class CustomWizard::Builder
submission = @submissions.last submission = @submissions.last
data = submission.merge(data) data = submission.merge(data)
end end
if step_template['actions'] && step_template['actions'].length && data if step_template['actions'] && step_template['actions'].length && data
step_template['actions'].each do |action| step_template['actions'].each do |action|
self.send(action['type'].to_sym, user, action, data) self.send(action['type'].to_sym, user, action, data)
@ -331,7 +331,7 @@ class CustomWizard::Builder
else else
post = data[action['post']] post = data[action['post']]
end end
if title if title
params = { params = {
title: title, title: title,
@ -339,22 +339,23 @@ class CustomWizard::Builder
skip_validations: true skip_validations: true
} }
if action['custom_category_enabled'] && if action['custom_category_enabled']
!action['custom_category_wizard_field'] && if action['custom_category_wizard_field']
action['custom_category_user_field_key'] category_id = data[action['category_id']]
elsif action['custom_category_user_field_key']
if action['custom_category_user_field_key'].include?('custom_fields') if action['custom_category_user_field_key'].include?('custom_fields')
field = action['custom_category_user_field_key'].split('.').last field = action['custom_category_user_field_key'].split('.').last
category_id = user.custom_fields[field] category_id = user.custom_fields[field]
else else
category_id = user.send(action['custom_category_user_field_key']) category_id = user.send(action['custom_category_user_field_key'])
end
end end
else else
category_id = action['category_id'] category_id = action['category_id']
end end
params[:category] = category_id params[:category] = category_id
topic_custom_fields = {} topic_custom_fields = {}
if action['add_fields'] if action['add_fields']
@ -378,7 +379,7 @@ class CustomWizard::Builder
end end
end end
else else
value = [value] if key === 'tags' value = [*value] if key === 'tags'
params[key.to_sym] = value params[key.to_sym] = value
end end
end end