Spiegel von
https://github.com/paviliondev/discourse-custom-wizard.git
synchronisiert 2024-11-22 17:30:29 +01:00
Add content conditionals
Dieser Commit ist enthalten in:
Ursprung
3a14cb0805
Commit
fe7283ab3c
24 geänderte Dateien mit 414 neuen und 177 gelöschten Zeilen
|
@ -1,5 +1,5 @@
|
||||||
import { default as computed, observes, on } from 'discourse-common/utils/decorators';
|
import { default as computed, observes, on } from 'discourse-common/utils/decorators';
|
||||||
import { equal, not } from "@ember/object/computed";
|
import { equal, not, or } from "@ember/object/computed";
|
||||||
import { generateSelectKitContent } from '../lib/custom-wizard';
|
import { generateSelectKitContent } from '../lib/custom-wizard';
|
||||||
|
|
||||||
export default Ember.Component.extend({
|
export default Ember.Component.extend({
|
||||||
|
@ -34,25 +34,35 @@ export default Ember.Component.extend({
|
||||||
let options = {
|
let options = {
|
||||||
hasOutput: true,
|
hasOutput: true,
|
||||||
enableConnectors: true,
|
enableConnectors: true,
|
||||||
allowWizard: true,
|
wizardFieldSelection: true,
|
||||||
allowUser: true
|
userFieldSelection: true
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isCategory) {
|
if (isCategory || isGroup || isTag) {
|
||||||
options.allowUser = 'key,value';
|
options.userFieldSelection = 'key,value';
|
||||||
options.allowCategory = 'output';
|
options[`${this.field.type}Selection`] = 'output';
|
||||||
}
|
|
||||||
|
|
||||||
if (isGroup) {
|
|
||||||
options.allowUser = 'key,value';
|
|
||||||
options.allowGroup = 'output';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isTag) {
|
|
||||||
options.allowUser = 'key,value';
|
|
||||||
options.allowTag = 'output';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return options;
|
return options;
|
||||||
|
},
|
||||||
|
|
||||||
|
canFilter: or('isCategory', 'isTag', 'isGroup'),
|
||||||
|
|
||||||
|
@computed('field.type')
|
||||||
|
filterOptions(fieldType) {
|
||||||
|
if (!this.canFilter) return {};
|
||||||
|
|
||||||
|
let options = {
|
||||||
|
hasOutput: true,
|
||||||
|
enableConnectors: true,
|
||||||
|
wizardFieldSelection: 'key,value',
|
||||||
|
userFieldSelection: 'key,value',
|
||||||
|
textDisabled: 'output'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
options[`${this.field.type}Selection`] = 'output';
|
||||||
|
options[`${this.field.type}AllowMultiple`] = true;
|
||||||
|
|
||||||
|
return options;
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,52 +0,0 @@
|
||||||
import { alias, equal } from "@ember/object/computed";
|
|
||||||
import { computed } from "@ember/object";
|
|
||||||
import {
|
|
||||||
default as discourseComputed,
|
|
||||||
observes
|
|
||||||
} from "discourse-common/utils/decorators";
|
|
||||||
|
|
||||||
export default Ember.Component.extend({
|
|
||||||
@observes('activeType')
|
|
||||||
clearValue() {
|
|
||||||
this.set('value', null);
|
|
||||||
},
|
|
||||||
|
|
||||||
@discourseComputed('customPlaceholder')
|
|
||||||
textPlaceholder(customPlaceholder) {
|
|
||||||
return customPlaceholder || 'admin.wizard.text';
|
|
||||||
},
|
|
||||||
|
|
||||||
showText: equal('activeType', 'text'),
|
|
||||||
|
|
||||||
showInput(type) {
|
|
||||||
return this.activeType === type && this[`${type}Enabled`];
|
|
||||||
},
|
|
||||||
|
|
||||||
showWizard: computed('activeType', function() { return this.showInput('wizard') }),
|
|
||||||
showUser: computed('activeType', function() { return this.showInput('user') }),
|
|
||||||
showCategory: computed('activeType', function() { return this.showInput('category') }),
|
|
||||||
showTag: computed('activeType', function() { return this.showInput('tag') }),
|
|
||||||
showGroup: computed('activeType', function() { return this.showInput('group') }),
|
|
||||||
|
|
||||||
optionEnabled(type) {
|
|
||||||
const options = this.options;
|
|
||||||
if (!options) return false;
|
|
||||||
|
|
||||||
const option = options[type];
|
|
||||||
if (option === true) return true;
|
|
||||||
if (typeof option !== 'string') return false;
|
|
||||||
return option.split(',').indexOf(this.inputType) > -1;
|
|
||||||
},
|
|
||||||
|
|
||||||
wizardEnabled: computed('options.allowWizard', function() { return this.optionEnabled('allowWizard') }),
|
|
||||||
userEnabled: computed('options.allowUser', function() { return this.optionEnabled('allowUser') }),
|
|
||||||
categoryEnabled: computed('options.allowCategory', function() { return this.optionEnabled('allowCategory') }),
|
|
||||||
tagEnabled: computed('options.allowTag', function() { return this.optionEnabled('allowTag') }),
|
|
||||||
groupEnabled: computed('options.allowGroup', function() { return this.optionEnabled('allowGroup') }),
|
|
||||||
|
|
||||||
actions: {
|
|
||||||
toggleType(type) {
|
|
||||||
this.set('activeType', type);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
|
@ -3,7 +3,7 @@ import { gt, or, alias } from "@ember/object/computed";
|
||||||
import { computed, observes} from "@ember/object";
|
import { computed, observes} from "@ember/object";
|
||||||
|
|
||||||
export default Ember.Component.extend({
|
export default Ember.Component.extend({
|
||||||
classNames: 'pair',
|
classNameBindings: [':input-pair', 'hasConnector::no-connector'],
|
||||||
connectors: connectors,
|
connectors: connectors,
|
||||||
hasConnector: or('options.enableConnectors', 'connectorKey'),
|
hasConnector: or('options.enableConnectors', 'connectorKey'),
|
||||||
firstPair: gt('pair.index', 0),
|
firstPair: gt('pair.index', 0),
|
||||||
|
|
|
@ -0,0 +1,71 @@
|
||||||
|
import { alias, equal } from "@ember/object/computed";
|
||||||
|
import { computed } from "@ember/object";
|
||||||
|
import {
|
||||||
|
default as discourseComputed,
|
||||||
|
observes
|
||||||
|
} from "discourse-common/utils/decorators";
|
||||||
|
import { defaultSelectionType } from '../lib/custom-wizard';
|
||||||
|
|
||||||
|
export default Ember.Component.extend({
|
||||||
|
classNames: 'input-selector',
|
||||||
|
groups: alias('site.groups'),
|
||||||
|
categories: computed(function() {
|
||||||
|
return this.site.categories.map(c => ({ id: c.id, name: c.name }));
|
||||||
|
}),
|
||||||
|
|
||||||
|
@observes('options.@each')
|
||||||
|
resetActiveType() {
|
||||||
|
this.set('activeType', defaultSelectionType(this.selectorType, this.options));
|
||||||
|
},
|
||||||
|
|
||||||
|
@observes('activeType')
|
||||||
|
clearValue() {
|
||||||
|
this.set('value', null);
|
||||||
|
},
|
||||||
|
|
||||||
|
@discourseComputed('customPlaceholder')
|
||||||
|
textPlaceholder(customPlaceholder) {
|
||||||
|
return customPlaceholder || 'admin.wizard.text';
|
||||||
|
},
|
||||||
|
|
||||||
|
showText: equal('activeType', 'text'),
|
||||||
|
|
||||||
|
showInput(type) {
|
||||||
|
return this.activeType === type && this[`${type}Enabled`] && !this[`${type}Disabled`];
|
||||||
|
},
|
||||||
|
|
||||||
|
showWizard: computed('activeType', function() { return this.showInput('wizard') }),
|
||||||
|
showUser: computed('activeType', function() { return this.showInput('user') }),
|
||||||
|
showCategory: computed('activeType', function() { return this.showInput('category') }),
|
||||||
|
showTag: computed('activeType', function() { return this.showInput('tag') }),
|
||||||
|
showGroup: computed('activeType', function() { return this.showInput('group') }),
|
||||||
|
|
||||||
|
optionEnabled(type) {
|
||||||
|
const options = this.options;
|
||||||
|
if (!options) return false;
|
||||||
|
|
||||||
|
const option = options[type];
|
||||||
|
|
||||||
|
if (option === true) return true;
|
||||||
|
if (typeof option !== 'string') return false;
|
||||||
|
|
||||||
|
const types = [this.selectorType, this.inputType];
|
||||||
|
|
||||||
|
console.log('running', types, option)
|
||||||
|
|
||||||
|
return option.split(',').filter(o => types.indexOf(o) !== -1).length
|
||||||
|
},
|
||||||
|
|
||||||
|
textDisabled: computed('options.textDisabled', 'inputType', function() { return this.optionEnabled('textDisabled') }),
|
||||||
|
wizardEnabled: computed('options.wizardFieldSelection', 'inputType', function() { return this.optionEnabled('wizardFieldSelection') }),
|
||||||
|
userEnabled: computed('options.userFieldSelection', 'inputType', function() { return this.optionEnabled('userFieldSelection') }),
|
||||||
|
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') }),
|
||||||
|
|
||||||
|
actions: {
|
||||||
|
toggleType(type) {
|
||||||
|
this.set('activeType', type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
|
@ -1,12 +1,48 @@
|
||||||
import { newPair } from '../lib/custom-wizard';
|
import {
|
||||||
|
newPair,
|
||||||
|
generateSelectKitContent,
|
||||||
|
defaultInputType
|
||||||
|
} from '../lib/custom-wizard';
|
||||||
|
import {
|
||||||
|
default as discourseComputed,
|
||||||
|
on
|
||||||
|
} from 'discourse-common/utils/decorators';
|
||||||
import { computed } from "@ember/object";
|
import { computed } from "@ember/object";
|
||||||
|
import { alias } from "@ember/object/computed";
|
||||||
|
|
||||||
export default Ember.Component.extend({
|
export default Ember.Component.extend({
|
||||||
classNames: 'custom-input',
|
classNameBindings: [':custom-input', 'type'],
|
||||||
outputConnector: computed(function() {
|
inputType: alias('input.type'),
|
||||||
return I18n.t(this.outputConnectorKey || 'admin.wizard.output.connector').toLowerCase();
|
outputConnector: computed('inputTypes', function() {
|
||||||
|
const key = this.outputConnectorKey || `admin.wizard.input.${this.type}.output`;
|
||||||
|
return I18n.t(key).toLowerCase();
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
@on('init')
|
||||||
|
setDefaults() {
|
||||||
|
if (!this.type) this.set('type', defaultInputType(this.options));
|
||||||
|
},
|
||||||
|
|
||||||
|
@discourseComputed
|
||||||
|
inputTypes() {
|
||||||
|
return ['conditional', 'assignment'].map((type) => {
|
||||||
|
return {
|
||||||
|
id: type,
|
||||||
|
name: I18n.t(`admin.wizard.input.${type}.prefix`)
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
@discourseComputed('options.hasOutput', 'input.type')
|
||||||
|
hasPairs(hasOutput, inputType) {
|
||||||
|
return !hasOutput || inputType === 'conditional';
|
||||||
|
},
|
||||||
|
|
||||||
|
@discourseComputed('input.type')
|
||||||
|
hasOutputConnector(inputType) {
|
||||||
|
return inputType === 'conditional';
|
||||||
|
},
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
addPair() {
|
addPair() {
|
||||||
const pairs = this.get('input.pairs');
|
const pairs = this.get('input.pairs');
|
||||||
|
|
|
@ -3,7 +3,7 @@ import { on } from 'discourse-common/utils/decorators';
|
||||||
import { newInput } from '../lib/custom-wizard';
|
import { newInput } from '../lib/custom-wizard';
|
||||||
|
|
||||||
export default Ember.Component.extend({
|
export default Ember.Component.extend({
|
||||||
classNames: 'custom-inputs',
|
classNames: 'field-mapper',
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
add() {
|
add() {
|
|
@ -53,28 +53,68 @@ const actionTypes = [
|
||||||
'open_composer'
|
'open_composer'
|
||||||
];
|
];
|
||||||
|
|
||||||
|
const selectionTypes = [
|
||||||
|
'text',
|
||||||
|
'wizardField',
|
||||||
|
'userField',
|
||||||
|
'group',
|
||||||
|
'category',
|
||||||
|
'tag'
|
||||||
|
]
|
||||||
|
|
||||||
|
const inputTypes = [
|
||||||
|
'pair',
|
||||||
|
'conditional',
|
||||||
|
'assignment'
|
||||||
|
]
|
||||||
|
|
||||||
|
function defaultInputType(options = {}) {
|
||||||
|
return options.hasOutput ? 'conditional' : 'pair';
|
||||||
|
}
|
||||||
|
|
||||||
|
function defaultSelectionType(inputType, options = {}) {
|
||||||
|
const textDisabled = options.textDisabled;
|
||||||
|
let type = 'text';
|
||||||
|
|
||||||
|
if (textDisabled === true ||
|
||||||
|
((typeof textDisabled == 'string') && textDisabled.indexOf(inputType) > -1)) {
|
||||||
|
|
||||||
|
for (let t of selectionTypes) {
|
||||||
|
let inputTypes = options[`${t}Selection`];
|
||||||
|
|
||||||
|
if (inputTypes === true ||
|
||||||
|
((typeof inputTypes == 'string') && inputTypes.indexOf(inputType) > -1)) {
|
||||||
|
|
||||||
|
type = t;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
function newInput(options = {}) {
|
function newInput(options = {}) {
|
||||||
let params = {
|
let params = {
|
||||||
|
type: defaultInputType(options),
|
||||||
pairs: Ember.A([newPair({ index: 0, pairCount: 1 })])
|
pairs: Ember.A([newPair({ index: 0, pairCount: 1 })])
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.hasOutput) {
|
if (options.hasOutput) {
|
||||||
params['output'] = '';
|
params['output_type'] = defaultSelectionType('output', options);
|
||||||
params['output_type'] = 'text';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return Ember.Object.create(params);
|
return Ember.Object.create(params);
|
||||||
}
|
}
|
||||||
|
|
||||||
function newPair(options = {}) {
|
function newPair(options = {}) {
|
||||||
console.log('newPair: ', options)
|
|
||||||
let params = {
|
let params = {
|
||||||
index: options.index,
|
index: options.index,
|
||||||
pairCount: options.pairCount,
|
pairCount: options.pairCount,
|
||||||
key: '',
|
key: '',
|
||||||
key_type: 'text',
|
key_type: defaultSelectionType('text', options),
|
||||||
value: '',
|
value: '',
|
||||||
value_type: 'text',
|
value_type: defaultSelectionType('text', options),
|
||||||
connector: 'eq'
|
connector: 'eq'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,6 +126,8 @@ export {
|
||||||
profileFields,
|
profileFields,
|
||||||
actionTypes,
|
actionTypes,
|
||||||
generateName,
|
generateName,
|
||||||
|
defaultInputType,
|
||||||
|
defaultSelectionType,
|
||||||
connectors,
|
connectors,
|
||||||
newInput,
|
newInput,
|
||||||
newPair
|
newPair
|
||||||
|
|
|
@ -170,12 +170,12 @@
|
||||||
{{#if createTopic}}
|
{{#if createTopic}}
|
||||||
<div class="setting full">
|
<div class="setting full">
|
||||||
<label>{{i18n 'admin.wizard.action.add_fields' type='Topic'}}</label>
|
<label>{{i18n 'admin.wizard.action.add_fields' type='Topic'}}</label>
|
||||||
{{wizard-custom-inputs
|
{{wizard-field-mapper
|
||||||
inputs=action.add_fields
|
inputs=action.add_fields
|
||||||
userFields=userFields
|
userFields=userFields
|
||||||
wizardFields=wizardFields
|
wizardFields=wizardFields
|
||||||
options=(hash
|
options=(hash
|
||||||
allowWizard=true
|
wizardFieldSelection=true
|
||||||
)}}
|
)}}
|
||||||
</div>
|
</div>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
@ -212,7 +212,7 @@
|
||||||
|
|
||||||
<div class="setting full">
|
<div class="setting full">
|
||||||
<label>{{i18n "admin.wizard.action.add_fields" type='Message'}}</label>
|
<label>{{i18n "admin.wizard.action.add_fields" type='Message'}}</label>
|
||||||
{{wizard-custom-inputs
|
{{wizard-field-mapper
|
||||||
inputs=action.add_fields
|
inputs=action.add_fields
|
||||||
userFields=userFields
|
userFields=userFields
|
||||||
wizardFields=wizardFields}}
|
wizardFields=wizardFields}}
|
||||||
|
@ -222,13 +222,13 @@
|
||||||
{{#if updateProfile}}
|
{{#if updateProfile}}
|
||||||
<div class="setting full">
|
<div class="setting full">
|
||||||
<label>{{i18n "admin.wizard.action.add_fields" type='Profile'}}</label>
|
<label>{{i18n "admin.wizard.action.add_fields" type='Profile'}}</label>
|
||||||
{{wizard-custom-inputs
|
{{wizard-field-mapper
|
||||||
inputs=action.profile_updates
|
inputs=action.profile_updates
|
||||||
userFields=userFields
|
userFields=userFields
|
||||||
wizardFields=wizardFields
|
wizardFields=wizardFields
|
||||||
options=(hash
|
options=(hash
|
||||||
allowWizard=true
|
wizardFieldSelection=true
|
||||||
allowUser=true
|
userFieldSelection=true
|
||||||
)}}
|
)}}
|
||||||
</div>
|
</div>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
@ -284,17 +284,17 @@
|
||||||
<h3>{{i18n "admin.wizard.action.add_to_group.group"}}</h3>
|
<h3>{{i18n "admin.wizard.action.add_to_group.group"}}</h3>
|
||||||
</div>
|
</div>
|
||||||
<div class="setting-value">
|
<div class="setting-value">
|
||||||
{{wizard-custom-inputs
|
{{wizard-field-mapper
|
||||||
inputs=action.selection
|
inputs=action.inputs
|
||||||
userFields=userFields
|
userFields=userFields
|
||||||
wizardFields=wizardFields
|
wizardFields=wizardFields
|
||||||
outputConnectorKey='admin.wizard.action.add_to_group.output_connector'
|
outputConnectorKey='admin.wizard.action.add_to_group.output_connector'
|
||||||
options=(hash
|
options=(hash
|
||||||
hasOutput=true
|
hasOutput=true
|
||||||
enableConnectors=true
|
enableConnectors=true
|
||||||
allowWizard='key,value'
|
wizardFieldSelection='key,value,assignment'
|
||||||
allowUser='key,value'
|
userFieldSelection='key,value,assignment'
|
||||||
allowGroup='value,output'
|
groupSelection='value,output'
|
||||||
)}}
|
)}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -102,7 +102,7 @@
|
||||||
<div class="wizard-header small">
|
<div class="wizard-header small">
|
||||||
{{i18n 'admin.wizard.field.choices_custom'}}
|
{{i18n 'admin.wizard.field.choices_custom'}}
|
||||||
</div>
|
</div>
|
||||||
{{wizard-custom-inputs
|
{{wizard-field-mapper
|
||||||
inputs=field.choices
|
inputs=field.choices
|
||||||
userFields=userFields
|
userFields=userFields
|
||||||
wizardFields=wizardFields}}
|
wizardFields=wizardFields}}
|
||||||
|
@ -153,16 +153,30 @@
|
||||||
</div>
|
</div>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
<div class="setting full">
|
<div class="setting full custom-inputs">
|
||||||
<div class="setting-label">
|
<div class="setting-label">
|
||||||
<h3>{{i18n 'admin.wizard.field.prefill'}}</h3>
|
<h3>{{i18n 'admin.wizard.field.prefill'}}</h3>
|
||||||
</div>
|
</div>
|
||||||
<div class="setting-value">
|
<div class="setting-value">
|
||||||
{{wizard-custom-inputs
|
{{wizard-field-mapper
|
||||||
inputs=field.prefill
|
inputs=field.prefill
|
||||||
userFields=userFields
|
userFields=userFields
|
||||||
wizardFields=wizardFields
|
wizardFields=wizardFields
|
||||||
outputConnectorKey='admin.wizard.field.prefill'
|
|
||||||
options=prefillOptions}}
|
options=prefillOptions}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{{#if canFilter}}
|
||||||
|
<div class="setting full custom-inputs">
|
||||||
|
<div class="setting-label">
|
||||||
|
<h3>{{i18n 'admin.wizard.field.filter'}}</h3>
|
||||||
|
</div>
|
||||||
|
<div class="setting-value">
|
||||||
|
{{wizard-field-mapper
|
||||||
|
inputs=field.filters
|
||||||
|
userFields=userFields
|
||||||
|
wizardFields=wizardFields
|
||||||
|
options=filterOptions}}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{{/if}}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
<div class="key input-block">
|
<div class="key input-block">
|
||||||
{{wizard-custom-input-chooser
|
{{wizard-custom-input-selector
|
||||||
inputType='key'
|
selectorType='key'
|
||||||
|
inputType=inputType
|
||||||
userFields=userFields
|
userFields=userFields
|
||||||
wizardFields=wizardFields
|
wizardFields=wizardFields
|
||||||
value=pair.key
|
value=pair.key
|
||||||
|
@ -26,8 +27,9 @@
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
<div class="value input-block">
|
<div class="value input-block">
|
||||||
{{wizard-custom-input-chooser
|
{{wizard-custom-input-selector
|
||||||
inputType='value'
|
selectorType='value'
|
||||||
|
inputType=inputType
|
||||||
userFields=userFields
|
userFields=userFields
|
||||||
wizardFields=wizardFields
|
wizardFields=wizardFields
|
||||||
value=pair.value
|
value=pair.value
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
<div class="type-selector">
|
<div class="type-selector">
|
||||||
|
{{#unless textDisabled}}
|
||||||
{{input-type-toggle
|
{{input-type-toggle
|
||||||
activeType=activeType
|
activeType=activeType
|
||||||
type='text'
|
type='text'
|
||||||
toggle=(action 'toggleType')}}
|
toggle=(action 'toggleType')}}
|
||||||
|
{{/unless}}
|
||||||
|
|
||||||
{{#if wizardEnabled}}
|
{{#if wizardEnabled}}
|
||||||
{{input-type-toggle
|
{{input-type-toggle
|
||||||
|
@ -69,19 +71,24 @@
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
{{#if showCategory}}
|
{{#if showCategory}}
|
||||||
{{category-chooser value=value}}
|
{{multi-select
|
||||||
|
content=categories
|
||||||
|
value=value
|
||||||
|
onChange=(action (mut value))
|
||||||
|
options=(hash
|
||||||
|
none='admin.wizard.select_category'
|
||||||
|
)}}
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
{{#if showTag}}
|
{{#if showTag}}
|
||||||
{{tag-chooser
|
{{tag-chooser
|
||||||
tags=value
|
tags=value
|
||||||
filterable=true
|
filterable=true}}
|
||||||
allowCreate=true}}
|
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
{{#if showGroup}}
|
{{#if showGroup}}
|
||||||
{{combo-box
|
{{multi-select
|
||||||
content=site.groups
|
content=groups
|
||||||
value=value
|
value=value
|
||||||
onChange=(action (mut value))
|
onChange=(action (mut value))
|
||||||
options=(hash
|
options=(hash
|
|
@ -1,18 +1,18 @@
|
||||||
{{#if options.hasOutput}}
|
{{#if options.hasOutput}}
|
||||||
<div class="prefix">
|
<div class="connector prefix">
|
||||||
{{combo-box
|
{{combo-box
|
||||||
value=input.type
|
value=input.type
|
||||||
contents=inputTypes
|
content=inputTypes}}
|
||||||
onChange=(mut (input.prefix))}}
|
|
||||||
</div>
|
</div>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
{{#if hasPairs}}
|
{{#if hasPairs}}
|
||||||
<div class="pairs">
|
<div class="input-pairs">
|
||||||
{{#each input.pairs as |pair|}}
|
{{#each input.pairs as |pair|}}
|
||||||
{{wizard-custom-input-pair
|
{{wizard-custom-input-pair
|
||||||
pair=pair
|
pair=pair
|
||||||
last=pair.last
|
last=pair.last
|
||||||
|
inputType=inputType
|
||||||
keyPlaceholder=keyPlaceholder
|
keyPlaceholder=keyPlaceholder
|
||||||
valuePlaceholder=valuePlaceholder
|
valuePlaceholder=valuePlaceholder
|
||||||
userFields=userFields
|
userFields=userFields
|
||||||
|
@ -21,21 +21,26 @@
|
||||||
removePair=(action 'removePair')}}
|
removePair=(action 'removePair')}}
|
||||||
{{/each}}
|
{{/each}}
|
||||||
{{#if options.hasOutput}}
|
{{#if options.hasOutput}}
|
||||||
<a {{action 'addPair'}} class="add-pair">{{d-icon 'plus'}}</a>
|
<a {{action 'addPair'}} class="add-pair">
|
||||||
|
{{d-icon 'plus'}}
|
||||||
|
</a>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
</div>
|
</div>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
{{#if options.hasOutput}}
|
{{#if options.hasOutput}}
|
||||||
|
{{#if hasOutputConnector}}
|
||||||
<div class="connector">
|
<div class="connector">
|
||||||
<span class="output-connector">
|
<span class="output-connector">
|
||||||
{{outputConnector}}
|
{{outputConnector}}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
{{/if}}
|
||||||
|
|
||||||
<div class="output input-block">
|
<div class="output input-block">
|
||||||
{{wizard-custom-input-chooser
|
{{wizard-custom-input-selector
|
||||||
inputType='output'
|
selectorType='output'
|
||||||
|
inputType=inputType
|
||||||
userFields=userFields
|
userFields=userFields
|
||||||
wizardFields=wizardFields
|
wizardFields=wizardFields
|
||||||
value=input.output
|
value=input.output
|
||||||
|
@ -45,8 +50,6 @@
|
||||||
</div>
|
</div>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
{{d-button
|
<a class="remove-input" {{action remove input}}>
|
||||||
action=remove
|
{{d-icon 'times'}}
|
||||||
actionParam=input
|
</a>
|
||||||
icon='times'
|
|
||||||
class='remove-input'}}
|
|
||||||
|
|
|
@ -50,15 +50,15 @@
|
||||||
<h3>{{i18n 'admin.wizard.step.required_data.label'}}</h3>
|
<h3>{{i18n 'admin.wizard.step.required_data.label'}}</h3>
|
||||||
</div>
|
</div>
|
||||||
<div class="setting-value">
|
<div class="setting-value">
|
||||||
{{wizard-custom-inputs
|
{{wizard-field-mapper
|
||||||
inputs=step.required_data
|
inputs=step.required_data
|
||||||
userFields=userFields
|
userFields=userFields
|
||||||
wizardFields=wizardFields
|
wizardFields=wizardFields
|
||||||
keyPlaceholder="admin.wizard.submission_key"
|
keyPlaceholder="admin.wizard.submission_key"
|
||||||
options=(hash
|
options=(hash
|
||||||
enableConnectors=true
|
enableConnectors=true
|
||||||
allowWizard='value'
|
wizardFieldSelection='value'
|
||||||
allowUser='value'
|
userFieldSelection='value'
|
||||||
)}}
|
)}}
|
||||||
{{#if step.required_data}}
|
{{#if step.required_data}}
|
||||||
<div class="required-data-message">
|
<div class="required-data-message">
|
||||||
|
@ -76,7 +76,7 @@
|
||||||
<h3>{{i18n 'admin.wizard.step.permitted_params.label'}}</h3>
|
<h3>{{i18n 'admin.wizard.step.permitted_params.label'}}</h3>
|
||||||
</div>
|
</div>
|
||||||
<div class="setting-value">
|
<div class="setting-value">
|
||||||
{{wizard-custom-inputs
|
{{wizard-field-mapper
|
||||||
inputs=step.permitted_params
|
inputs=step.permitted_params
|
||||||
userFields=userFields
|
userFields=userFields
|
||||||
wizardFields=wizardFields
|
wizardFields=wizardFields
|
||||||
|
|
12
assets/javascripts/wizard/components/wizard-category-selector.js.es6
Normale Datei
12
assets/javascripts/wizard/components/wizard-category-selector.js.es6
Normale Datei
|
@ -0,0 +1,12 @@
|
||||||
|
import CategorySelector from 'discourse/components/category-selector';
|
||||||
|
import { computed } from "@ember/object";
|
||||||
|
import { makeArray } from "discourse-common/lib/helpers";
|
||||||
|
|
||||||
|
export default CategorySelector.extend({
|
||||||
|
content: computed("categories.[]", "blacklist.[]", "whitelist.[]", function() {
|
||||||
|
return this._super().filter(category => {
|
||||||
|
const whitelist = makeArray(this.whitelist);
|
||||||
|
return !whitelist.length || whitelist.indexOf(category.id) > -1;
|
||||||
|
});
|
||||||
|
})
|
||||||
|
})
|
12
assets/javascripts/wizard/components/wizard-group-selector.js.es6
Normale Datei
12
assets/javascripts/wizard/components/wizard-group-selector.js.es6
Normale Datei
|
@ -0,0 +1,12 @@
|
||||||
|
import ComboBox from 'select-kit/components/combo-box';
|
||||||
|
import { computed } from "@ember/object";
|
||||||
|
import { makeArray } from "discourse-common/lib/helpers";
|
||||||
|
|
||||||
|
export default ComboBox.extend({
|
||||||
|
content: computed("groups.[]", "whitelist.[]", function() {
|
||||||
|
const whitelist = makeArray(this.whitelist);
|
||||||
|
return this.groups.filter(group => {
|
||||||
|
return !whitelist.length || whitelist.indexOf(group.id) > -1;
|
||||||
|
});
|
||||||
|
})
|
||||||
|
})
|
11
assets/javascripts/wizard/components/wizard-tag-selector.js.es6
Normale Datei
11
assets/javascripts/wizard/components/wizard-tag-selector.js.es6
Normale Datei
|
@ -0,0 +1,11 @@
|
||||||
|
import TagChooser from 'select-kit/components/tag-chooser';
|
||||||
|
import { makeArray } from "discourse-common/lib/helpers";
|
||||||
|
|
||||||
|
export default TagChooser.extend({
|
||||||
|
_transformJson(context, json) {
|
||||||
|
return this._super(context, json).filter((tag) => {
|
||||||
|
const whitelist = makeArray(context.whitelist);
|
||||||
|
return !whitelist.length || whitelist.indexOf(tag.id) > 1;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
})
|
|
@ -1,5 +1,6 @@
|
||||||
{{category-selector
|
{{wizard-category-selector
|
||||||
categories=categories
|
categories=categories
|
||||||
|
whitelist=field.filter
|
||||||
maximum=field.limit
|
maximum=field.limit
|
||||||
onChange=(action (mut categories))}}
|
onChange=(action (mut categories))}}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
{{combo-box
|
{{wizard-group-selector
|
||||||
content=wizard.groups
|
groups=wizard.groups
|
||||||
|
whitelist=field.filter
|
||||||
value=field.value
|
value=field.value
|
||||||
onChange=(action (mut field.value))
|
onChange=(action (mut field.value))
|
||||||
options=(hash
|
options=(hash
|
||||||
|
|
|
@ -31,7 +31,6 @@
|
||||||
|
|
||||||
.admin-wizard.settings {
|
.admin-wizard.settings {
|
||||||
margin-left: 30px;
|
margin-left: 30px;
|
||||||
margin-right: 30px;
|
|
||||||
|
|
||||||
.setting {
|
.setting {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
|
@ -71,6 +70,28 @@
|
||||||
&.full {
|
&.full {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
|
||||||
|
&.custom-inputs {
|
||||||
|
padding-bottom: 30px;
|
||||||
|
|
||||||
|
.setting-label {
|
||||||
|
margin-top: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.add-custom-input:first-child {
|
||||||
|
margin-top: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.multi-select {
|
||||||
|
.multi-select-header, input {
|
||||||
|
min-height: 25px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.choices .choice {
|
||||||
|
height: 24px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.setting-label {
|
.setting-label {
|
||||||
width: 10%;
|
width: 10%;
|
||||||
}
|
}
|
||||||
|
@ -206,7 +227,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.pairs {
|
.input-pairs {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
@ -230,11 +251,15 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.pair {
|
.input-pair {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: flex-end;
|
align-items: flex-end;
|
||||||
position: relative;
|
position: relative;
|
||||||
margin-bottom: 10px;
|
margin-bottom: 10px;
|
||||||
|
|
||||||
|
&.no-connector div.input-block:not(:last-of-type) {
|
||||||
|
margin-right: 10px;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.d-icon {
|
.d-icon {
|
||||||
|
@ -255,12 +280,17 @@
|
||||||
min-width: 160px;
|
min-width: 160px;
|
||||||
}
|
}
|
||||||
|
|
||||||
button.remove-input {
|
a.remove-input {
|
||||||
margin: 21px 0 0 10px;
|
margin: 25px 0 0 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.connector {
|
.connector {
|
||||||
margin: 0 10px;
|
margin: 0 10px;
|
||||||
|
margin-top: 21px;
|
||||||
|
|
||||||
|
&.prefix {
|
||||||
|
margin-left: 0;
|
||||||
|
}
|
||||||
|
|
||||||
.select-kit {
|
.select-kit {
|
||||||
min-width: 50px;
|
min-width: 50px;
|
||||||
|
@ -272,17 +302,9 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
.output-connector {
|
.output-connector {
|
||||||
margin-top: 25px;
|
|
||||||
display: inline-block;
|
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.prefix {
|
|
||||||
position: absolute;
|
|
||||||
left: -20px;
|
|
||||||
top: 24px;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.required-data .setting-value {
|
.required-data .setting-value {
|
||||||
|
@ -297,10 +319,6 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.setting .add-custom-input {
|
|
||||||
margin-top: 5px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.admin-contents .wizard-submissions {
|
.admin-contents .wizard-submissions {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
|
|
|
@ -65,10 +65,12 @@ en:
|
||||||
submission_key: 'submission key'
|
submission_key: 'submission key'
|
||||||
param_key: 'param'
|
param_key: 'param'
|
||||||
|
|
||||||
output:
|
input:
|
||||||
label: "Output"
|
conditional:
|
||||||
prefix: 'if'
|
prefix: 'if'
|
||||||
connector: 'then'
|
output: 'then'
|
||||||
|
assignment:
|
||||||
|
prefix: 'set'
|
||||||
|
|
||||||
error:
|
error:
|
||||||
name_required: "Wizards must have a name."
|
name_required: "Wizards must have a name."
|
||||||
|
@ -121,6 +123,7 @@ en:
|
||||||
limit: "Limit"
|
limit: "Limit"
|
||||||
property: "Property"
|
property: "Property"
|
||||||
prefill: "Prefill"
|
prefill: "Prefill"
|
||||||
|
filter: "Content"
|
||||||
|
|
||||||
action:
|
action:
|
||||||
header: "Actions<sup>*</sup>"
|
header: "Actions<sup>*</sup>"
|
||||||
|
|
|
@ -262,7 +262,9 @@ class CustomWizard::Builder
|
||||||
@wizard.needs_groups = true
|
@wizard.needs_groups = true
|
||||||
end
|
end
|
||||||
|
|
||||||
puts "ADDING FIELD: #{params.inspect}"
|
if (prefill = field_template['filters']).present?
|
||||||
|
params[:filter] = get_output(field_template['filters'])
|
||||||
|
end
|
||||||
|
|
||||||
field = step.add_field(params)
|
field = step.add_field(params)
|
||||||
|
|
||||||
|
@ -273,25 +275,47 @@ class CustomWizard::Builder
|
||||||
|
|
||||||
def prefill_field(field_template, step_template)
|
def prefill_field(field_template, step_template)
|
||||||
if (prefill = field_template['prefill']).present?
|
if (prefill = field_template['prefill']).present?
|
||||||
output = nil
|
get_output(prefill)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
prefill.each do |item|
|
def get_output(inputs, opts = {})
|
||||||
if validate_pairs(item['pairs'])
|
output = opts[:multiple] ? [] : nil
|
||||||
output = get_field(item['output'], item['output_type'])
|
|
||||||
|
inputs.each do |input|
|
||||||
|
if input['type'] === 'conditional' && validate_pairs(input['pairs'])
|
||||||
|
if opts[:multiple]
|
||||||
|
output.push(get_field(input['output'], input['output_type'], opts))
|
||||||
|
else
|
||||||
|
output = get_field(input['output'], input['output_type'], opts)
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if input['type'] === 'assignment'
|
||||||
|
value = get_field(input['output'], input['output_type'], opts)
|
||||||
|
|
||||||
|
if opts[:multiple]
|
||||||
|
output.push(value)
|
||||||
|
else
|
||||||
|
output = value
|
||||||
|
break
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
output
|
output
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
def validate_pairs(pairs)
|
def validate_pairs(pairs)
|
||||||
failed = false
|
failed = false
|
||||||
|
|
||||||
pairs.each do |pair|
|
pairs.each do |pair|
|
||||||
key = get_field(pair['key'], pair['key_type'])
|
key = get_field(pair['key'], pair['key_type'])
|
||||||
value = get_field(pair['value'], pair['value_type'])
|
value = get_field(pair['value'], pair['value_type'])
|
||||||
failed = true unless key.public_send(get_operator(pair['connector']), value)
|
failed = true unless key.public_send(get_operator(pair['connector']), value)
|
||||||
end
|
end
|
||||||
|
|
||||||
!failed
|
!failed
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -299,23 +323,22 @@ class CustomWizard::Builder
|
||||||
OPERATORS[connector] || '=='
|
OPERATORS[connector] || '=='
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_field(value, type)
|
def get_field(value, type, opts = {})
|
||||||
method = "get_#{type}_field"
|
method = "get_#{type}_field"
|
||||||
|
|
||||||
if self.respond_to?(method)
|
if self.respond_to?(method)
|
||||||
self.send(method, value)
|
self.send(method, value, opts)
|
||||||
else
|
else
|
||||||
value
|
value
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_wizard_field(value)
|
def get_wizard_field(value, opts = {})
|
||||||
@submissions.last &&
|
data = opts[:data] || @submissions.last
|
||||||
!@submissions.last.key?("submitted_at") &&
|
data && !data.key?("submitted_at") && data[value]
|
||||||
@submissions.last[value]
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_user_field(value)
|
def get_user_field(value, opts = {})
|
||||||
puts "GETTING USER FIELD: #{value.inspect}"
|
puts "GETTING USER FIELD: #{value.inspect}"
|
||||||
if value.include?('user_field_')
|
if value.include?('user_field_')
|
||||||
UserCustomField.where(user_id: @wizard.user.id, name: value).pluck(:value).first
|
UserCustomField.where(user_id: @wizard.user.id, name: value).pluck(:value).first
|
||||||
|
@ -592,9 +615,25 @@ class CustomWizard::Builder
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_to_group(user, action, data)
|
def add_to_group(user, action, data)
|
||||||
if value = data[action['value']]
|
groups = get_output(action['inputs'], multiple: true, data: data)
|
||||||
if group = Group.where("#{action['property']} = '#{value}'").first
|
|
||||||
group.add(user)
|
groups = groups.reduce([]) do |result, g|
|
||||||
|
g = g.first if g.is_a?(Array)
|
||||||
|
|
||||||
|
begin
|
||||||
|
result.push(Integer(g))
|
||||||
|
rescue ArgumentError
|
||||||
|
group = Group.find_by(name: g)
|
||||||
|
result.push(group.id) if group
|
||||||
|
end
|
||||||
|
|
||||||
|
result
|
||||||
|
end
|
||||||
|
|
||||||
|
if groups.present?
|
||||||
|
groups.each do |group_id|
|
||||||
|
group = Group.find(group_id) if group_id
|
||||||
|
group.add(user) if group
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -6,7 +6,8 @@ module CustomWizardFieldExtension
|
||||||
:min_length,
|
:min_length,
|
||||||
:file_types,
|
:file_types,
|
||||||
:limit,
|
:limit,
|
||||||
:property
|
:property,
|
||||||
|
:filter
|
||||||
|
|
||||||
attr_accessor :dropdown_none
|
attr_accessor :dropdown_none
|
||||||
|
|
||||||
|
@ -25,6 +26,7 @@ module CustomWizardFieldExtension
|
||||||
@file_types = attrs[:file_types]
|
@file_types = attrs[:file_types]
|
||||||
@limit = attrs[:limit]
|
@limit = attrs[:limit]
|
||||||
@property = attrs[:property]
|
@property = attrs[:property]
|
||||||
|
@filter = attrs[:filter]
|
||||||
end
|
end
|
||||||
|
|
||||||
def label
|
def label
|
||||||
|
|
|
@ -6,7 +6,8 @@ class CustomWizardFieldSerializer < ::WizardFieldSerializer
|
||||||
:image,
|
:image,
|
||||||
:file_types,
|
:file_types,
|
||||||
:limit,
|
:limit,
|
||||||
:property
|
:property,
|
||||||
|
:filter
|
||||||
|
|
||||||
has_many :choices, serializer: WizardFieldChoiceSerializer, embed: :objects
|
has_many :choices, serializer: WizardFieldChoiceSerializer, embed: :objects
|
||||||
|
|
||||||
|
@ -47,4 +48,8 @@ class CustomWizardFieldSerializer < ::WizardFieldSerializer
|
||||||
def property
|
def property
|
||||||
object.property
|
object.property
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def filter
|
||||||
|
object.filter
|
||||||
|
end
|
||||||
end
|
end
|
Laden …
In neuem Issue referenzieren