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