Add user field options as dropdown option
Dieser Commit ist enthalten in:
Ursprung
1a5c66bf20
Commit
d194a8313a
9 geänderte Dateien mit 69 neuen und 36 gelöschten Zeilen
|
@ -62,7 +62,8 @@ export default Component.extend({
|
|||
|
||||
if (this.isDropdown) {
|
||||
options.wizardFieldSelection = 'key,value';
|
||||
options.inputTypes = 'association';
|
||||
options.userFieldOptionsSelection = 'output';
|
||||
options.inputTypes = 'association,assignment';
|
||||
options.pairConnector = 'association';
|
||||
options.keyPlaceholder = 'admin.wizard.key';
|
||||
options.valuePlaceholder = 'admin.wizard.value';
|
||||
|
|
|
@ -3,32 +3,36 @@ import { computed } from "@ember/object";
|
|||
import { default as discourseComputed, observes, on } from "discourse-common/utils/decorators";
|
||||
import { getOwner } from 'discourse-common/lib/get-owner';
|
||||
import { defaultSelectionType, selectionTypes } from '../lib/wizard-mapper';
|
||||
import { snakeCase } from '../lib/wizard';
|
||||
import { snakeCase, generateName, userProperties } from '../lib/wizard';
|
||||
import Component from "@ember/component";
|
||||
import { bind, later } from "@ember/runloop";
|
||||
|
||||
export default Component.extend({
|
||||
classNameBindings: [':mapper-selector', 'activeType'],
|
||||
groups: alias('site.groups'),
|
||||
categories: alias('site.categories'),
|
||||
|
||||
showText: computed('activeType', function() { return this.showInput('text') }),
|
||||
showWizardField: computed('activeType', function() { return this.showInput('wizardField') }),
|
||||
showUserField: computed('activeType', function() { return this.showInput('userField') }),
|
||||
showUserFieldOptions: computed('activeType', function() { return this.showInput('userFieldOptions') }),
|
||||
showCategory: computed('activeType', function() { return this.showInput('category') }),
|
||||
showTag: computed('activeType', function() { return this.showInput('tag') }),
|
||||
showGroup: computed('activeType', function() { return this.showInput('group') }),
|
||||
showUser: computed('activeType', function() { return this.showInput('user') }),
|
||||
showList: computed('activeType', function() { return this.showInput('list') }),
|
||||
showComboBox: or('showWizardField', 'showUserField'),
|
||||
showMultiSelect: or('showCategory', 'showGroup'),
|
||||
textEnabled: computed('options.textSelection', 'inputType', function() { return this.optionEnabled('textSelection') }),
|
||||
wizardFieldEnabled: computed('options.wizardFieldSelection', 'inputType', function() { return this.optionEnabled('wizardFieldSelection') }),
|
||||
userFieldEnabled: computed('options.userFieldSelection', 'inputType', function() { return this.optionEnabled('userFieldSelection') }),
|
||||
userFieldOptionsEnabled: computed('options.userFieldOptionsSelection', 'inputType', function() { return this.optionEnabled('userFieldOptionsSelection') }),
|
||||
categoryEnabled: computed('options.categorySelection', 'inputType', function() { return this.optionEnabled('categorySelection') }),
|
||||
tagEnabled: computed('options.tagSelection', 'inputType', function() { return this.optionEnabled('tagSelection') }),
|
||||
groupEnabled: computed('options.groupSelection', 'inputType', function() { return this.optionEnabled('groupSelection') }),
|
||||
userEnabled: computed('options.userSelection', 'inputType', function() { return this.optionEnabled('userSelection') }),
|
||||
listEnabled: computed('options.listSelection', 'inputType', function() { return this.optionEnabled('listSelection') }),
|
||||
|
||||
groups: alias('site.groups'),
|
||||
categories: alias('site.categories'),
|
||||
showComboBox: or('showWizardField', 'showUserField', 'showUserFieldOptions'),
|
||||
showMultiSelect: or('showCategory', 'showGroup'),
|
||||
hasTypes: gt('selectorTypes.length', 1),
|
||||
showTypes: false,
|
||||
|
||||
|
@ -81,22 +85,36 @@ export default Component.extend({
|
|||
@discourseComputed('activeType')
|
||||
comboBoxContent(activeType) {
|
||||
const controller = getOwner(this).lookup('controller:admin-wizards-wizard-show');
|
||||
let content = controller[`${activeType}s`];
|
||||
const wizardFields = controller.wizardFields;
|
||||
const userFields = controller.userFields;
|
||||
let content;
|
||||
|
||||
// you can't select the current field in the field context
|
||||
if (activeType === 'wizardField' && this.options.context === 'field') {
|
||||
if (activeType === 'wizardField') {
|
||||
content = wizardFields;
|
||||
|
||||
if (this.options.context === 'field') {
|
||||
content = content.filter(field => field.id !== controller.currentField.id);
|
||||
}
|
||||
}
|
||||
|
||||
// updating certain user fields via the profile update action is not supported
|
||||
if (activeType === 'userField' &&
|
||||
this.options.context === 'action' &&
|
||||
if (activeType ===' userField') {
|
||||
content = userProperties.map((f) => ({
|
||||
id: f,
|
||||
name: generateName(f)
|
||||
})).concat((userFields || []));
|
||||
|
||||
if (this.options.context === 'action' &&
|
||||
this.inputType === 'association' &&
|
||||
this.selectorType === 'key') {
|
||||
|
||||
const excludedFields = ['username','email', 'trust_level'];
|
||||
content = content.filter(userField => excludedFields.indexOf(userField.id) === -1);
|
||||
}
|
||||
}
|
||||
|
||||
if (activeType === 'userFieldOptions') {
|
||||
content = userFields;
|
||||
}
|
||||
|
||||
return content;
|
||||
},
|
||||
|
|
|
@ -36,7 +36,7 @@ export default Component.extend({
|
|||
},
|
||||
|
||||
@discourseComputed()
|
||||
userFieldList() {
|
||||
userPropertyList() {
|
||||
return userProperties.map((f) => ` u{${f}}`);
|
||||
},
|
||||
|
||||
|
|
|
@ -79,6 +79,7 @@ const selectionTypes = [
|
|||
'list',
|
||||
'wizardField',
|
||||
'userField',
|
||||
'userFieldOptions',
|
||||
'group',
|
||||
'category',
|
||||
'tag',
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import DiscourseRoute from "discourse/routes/discourse";
|
||||
import { userProperties, generateName } from '../lib/wizard';
|
||||
import { buildFieldTypes } from '../lib/wizard-schema';
|
||||
import { set } from "@ember/object";
|
||||
import { all } from "rsvp";
|
||||
|
@ -44,12 +43,7 @@ export default DiscourseRoute.extend({
|
|||
result.content.map((f) => ({
|
||||
id: `user_field_${f.id}`,
|
||||
name: f.name
|
||||
})).concat(
|
||||
userProperties.map((f) => ({
|
||||
id: f,
|
||||
name: generateName(f)
|
||||
}))
|
||||
)
|
||||
);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -18,8 +18,8 @@
|
|||
{{#if showPopover}}
|
||||
<div class="wizard-editor-gutter-popover">
|
||||
<label>
|
||||
{{i18n 'admin.wizard.action.post_builder.user_fields'}}
|
||||
{{userFieldList}}
|
||||
{{i18n 'admin.wizard.action.post_builder.user_properties'}}
|
||||
{{userPropertyList}}
|
||||
</label>
|
||||
|
||||
{{#if hasWizardFields}}
|
||||
|
|
|
@ -83,6 +83,7 @@ en:
|
|||
text: "text"
|
||||
wizard_field: "wizard field"
|
||||
user_field: "user field"
|
||||
user_field_options: "user field options"
|
||||
user: "user"
|
||||
category: "category"
|
||||
tag: "tag"
|
||||
|
@ -94,6 +95,7 @@ en:
|
|||
property: "Select property"
|
||||
wizard_field: "Select field"
|
||||
user_field: "Select field"
|
||||
user_field_options: "Select field"
|
||||
user: "Select user"
|
||||
category: "Select category"
|
||||
tag: "Select tag"
|
||||
|
@ -182,9 +184,9 @@ en:
|
|||
post_builder:
|
||||
checkbox: "Post Builder"
|
||||
label: "Builder"
|
||||
user_fields: "User Fields: "
|
||||
wizard_fields: "Wizard Fields: "
|
||||
placeholder: "Insert wizard fields using the field_id in w{}. Insert user fields using field key in u{}."
|
||||
user_properties: "User Properties"
|
||||
wizard_fields: "Wizard Fields"
|
||||
placeholder: "Insert wizard fields using the field_id in w{}. Insert user properties using property in u{}."
|
||||
add_to_group:
|
||||
label: "Add to Group"
|
||||
route_to:
|
||||
|
|
|
@ -267,6 +267,15 @@ class CustomWizard::Builder
|
|||
end
|
||||
end
|
||||
|
||||
if content[:type] == 'assignment' && field_template['type'] === 'dropdown'
|
||||
content[:result] = content[:result].map do |item|
|
||||
{
|
||||
id: item,
|
||||
name: item
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
params[:content] = content[:result]
|
||||
end
|
||||
end
|
||||
|
|
|
@ -169,7 +169,7 @@ class CustomWizard::Mapper
|
|||
end
|
||||
|
||||
def map_user_field(value)
|
||||
if value.include?('user_field_')
|
||||
if value.include?(User::USER_FIELD_PREFIX)
|
||||
UserCustomField.where(user_id: user.id, name: value).pluck(:value).first
|
||||
elsif PROFILE_FIELDS.include?(value)
|
||||
UserProfile.find_by(user_id: user.id).send(value)
|
||||
|
@ -178,6 +178,14 @@ class CustomWizard::Mapper
|
|||
end
|
||||
end
|
||||
|
||||
def map_user_field_options(value)
|
||||
if value.include?(User::USER_FIELD_PREFIX)
|
||||
if field = UserField.find(value.split('_').last)
|
||||
field.user_field_options.map(&:value)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def interpolate(string, opts={ user: true, wizard: true, value: true })
|
||||
return string if string.blank?
|
||||
|
||||
|
|
Laden …
In neuem Issue referenzieren