wip
Dieser Commit ist enthalten in:
Ursprung
e3fa75597b
Commit
b5fce333f6
18 geänderte Dateien mit 86 neuen und 52 gelöschten Zeilen
|
@ -56,20 +56,22 @@ export default Component.extend({
|
|||
prefillOptions(fieldType) {
|
||||
let options = {
|
||||
wizardFieldSelection: true,
|
||||
textSelection: 'key,value',
|
||||
textSelection: true,
|
||||
userFieldSelection: 'key,value',
|
||||
context: 'field'
|
||||
}
|
||||
|
||||
let outputSelectionType = {
|
||||
category: 'category',
|
||||
tag: 'tag',
|
||||
group: 'group',
|
||||
dropdown: 'text'
|
||||
category: ['category'],
|
||||
tag: ['tag'],
|
||||
group: ['group'],
|
||||
dropdown: ['list']
|
||||
}[fieldType];
|
||||
|
||||
options[`${outputSelectionType}Selection`] = 'output';
|
||||
options.outputDefaultSelection = outputSelectionType;
|
||||
outputSelectionType.forEach(function(type) {
|
||||
options[`${type}Selection`] = 'output';
|
||||
options.outputDefaultSelection = type;
|
||||
});
|
||||
|
||||
return options;
|
||||
},
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { computed, set } from "@ember/object";
|
||||
import { alias, equal, or } from "@ember/object/computed";
|
||||
import { alias, equal, or, not } from "@ember/object/computed";
|
||||
import { newPair, connectorContent, inputTypesContent } from '../lib/wizard-mapper';
|
||||
import Component from "@ember/component";
|
||||
import { observes } from "discourse-common/utils/decorators";
|
||||
|
@ -13,6 +13,7 @@ export default Component.extend({
|
|||
isValidation: equal('inputType', 'validation'),
|
||||
hasOutput: or('isConditional', 'isAssignment'),
|
||||
hasPairs: or('isConditional', 'isAssociation', 'isValidation'),
|
||||
canAddPair: not('isAssignment'),
|
||||
connectors: computed(function() { return connectorContent('output', this.input.type, this.options) }),
|
||||
inputTypes: computed(function() { return inputTypesContent(this.options) }),
|
||||
|
||||
|
|
|
@ -3,14 +3,14 @@ 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, selectKitContent } from '../lib/wizard';
|
||||
import { snakeCase } from '../lib/wizard';
|
||||
import Component from "@ember/component";
|
||||
import { bind } from "@ember/runloop";
|
||||
|
||||
export default Component.extend({
|
||||
classNames: 'mapper-selector',
|
||||
groups: alias('site.groups'),
|
||||
categories: computed(function() { return selectKitContent(this.site.categories) }),
|
||||
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') }),
|
||||
|
@ -67,11 +67,6 @@ export default Component.extend({
|
|||
return I18n.t(`admin.wizard.selector.label.${snakeCase(type)}`)
|
||||
},
|
||||
|
||||
@discourseComputed('showTypes')
|
||||
typeSelectorIcon(showTypes) {
|
||||
return showTypes ? 'chevron-down' : 'chevron-right';
|
||||
},
|
||||
|
||||
@observes('inputType')
|
||||
resetActiveType() {
|
||||
this.set('activeType', defaultSelectionType(this.selectorType, this.options));
|
||||
|
|
|
@ -15,13 +15,16 @@ export default Controller.extend({
|
|||
@observes('currentStep')
|
||||
resetCurrentObjects() {
|
||||
const currentStep = this.currentStep;
|
||||
const fields = currentStep.fields;
|
||||
const actions = currentStep.actions;
|
||||
|
||||
this.setProperties({
|
||||
currentField: fields.length ? fields[0] : null,
|
||||
currentAction: actions.length ? actions[0] : null
|
||||
});
|
||||
if (currentStep) {
|
||||
const fields = currentStep.fields;
|
||||
const actions = currentStep.actions;
|
||||
|
||||
this.setProperties({
|
||||
currentField: fields.length ? fields[0] : null,
|
||||
currentAction: actions.length ? actions[0] : null
|
||||
});
|
||||
}
|
||||
|
||||
scheduleOnce('afterRender', () => ($("body").addClass('admin-wizard')));
|
||||
},
|
||||
|
|
|
@ -52,7 +52,7 @@ function defaultConnector(connectorType, inputType, opts = {}) {
|
|||
function connectorContent(connectorType, inputType, opts) {
|
||||
let connector = opts[`${connectorType}Connector`];
|
||||
|
||||
if (!connector && connectorType === 'output') {
|
||||
if ((!connector && connectorType === 'output') || inputType === 'association') {
|
||||
connector = defaultConnector(connectorType, inputType, opts);
|
||||
}
|
||||
|
||||
|
|
|
@ -139,6 +139,13 @@ const mappedProperties = {
|
|||
]
|
||||
}
|
||||
|
||||
const advancedFieldTypes = [
|
||||
'category',
|
||||
'tag',
|
||||
'group',
|
||||
'dropdown'
|
||||
]
|
||||
|
||||
const advancedFieldProperties = [
|
||||
'prefill',
|
||||
'content'
|
||||
|
@ -161,12 +168,11 @@ const advancedProperties = {
|
|||
'required_data',
|
||||
'permitted_params'
|
||||
],
|
||||
field: advancedFieldProperties.reduce(
|
||||
field: advancedFieldTypes.reduce(
|
||||
function(map, type) {
|
||||
console.log(map, type);
|
||||
map[type] = advancedFieldProperties;
|
||||
if (type === 'category') {
|
||||
map.push('property');
|
||||
map[type].push('property');
|
||||
}
|
||||
return map;
|
||||
}, {}
|
||||
|
|
|
@ -74,6 +74,7 @@
|
|||
inputs=step.permitted_params
|
||||
options=(hash
|
||||
pairConnector='set'
|
||||
inputTypes='association'
|
||||
keyPlaceholder='admin.wizard.param_key'
|
||||
valuePlaceholder='admin.wizard.submission_key'
|
||||
context='step'
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
removePair=(action 'removePair')}}
|
||||
{{/each}}
|
||||
|
||||
{{#if hasOutput}}
|
||||
{{#if canAddPair}}
|
||||
<a {{action 'addPair'}} class="add-pair">
|
||||
{{d-icon 'plus'}}
|
||||
</a>
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
{{#if hasTypes}}
|
||||
<a {{action "toggleTypes"}} class="active">
|
||||
{{activeTypeLabel}}
|
||||
{{d-icon typeSelectorIcon class="type-selector-icon"}}
|
||||
</a>
|
||||
|
||||
{{#if showTypes}}
|
||||
|
|
|
@ -82,7 +82,7 @@
|
|||
//= require discourse/components/d-button
|
||||
//= require discourse/components/composer-editor
|
||||
//= require discourse/components/d-editor
|
||||
//= require discourse/components/popup-input-tip
|
||||
//= require discourse/components/input-tip
|
||||
//= require discourse/components/emoji-picker
|
||||
|
||||
//= require discourse/templates/components/conditional-loading-spinner
|
||||
|
|
|
@ -277,5 +277,11 @@ export default {
|
|||
return valid;
|
||||
}
|
||||
});
|
||||
|
||||
WizardFieldDropdown.reopen({
|
||||
didInsertElement() {
|
||||
console.log(this.field)
|
||||
}
|
||||
})
|
||||
}
|
||||
};
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
{{combo-box elementId=field.id
|
||||
class=fieldClass
|
||||
value=field.value
|
||||
content=field.content
|
||||
nameProperty="label"
|
||||
tabindex="9"}}
|
||||
{{combo-box
|
||||
class=fieldClass
|
||||
value=field.value
|
||||
content=field.content
|
||||
options=(hash
|
||||
none="select_kit.default_header_text"
|
||||
)}}
|
|
@ -20,8 +20,9 @@
|
|||
|
||||
> .mapper-connector.single {
|
||||
width: min-content;
|
||||
margin-bottom: 10px;
|
||||
height: 20px
|
||||
margin-bottom: 5px;
|
||||
height: 20px;
|
||||
border: 2px solid $primary-low;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -56,7 +57,7 @@
|
|||
position: absolute;
|
||||
right: -14px;
|
||||
top: 0px;
|
||||
padding: 2px 5px;
|
||||
padding: 2px 4px;
|
||||
transform: translateY(-50%);
|
||||
background: $secondary;
|
||||
border-radius: 50%;
|
||||
|
@ -66,7 +67,7 @@
|
|||
}
|
||||
|
||||
.add-mapper-input {
|
||||
display: block;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.mapper-connector {
|
||||
|
@ -86,6 +87,10 @@
|
|||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.connector-single {
|
||||
padding: 0 5px;
|
||||
}
|
||||
}
|
||||
|
||||
.mapper-selector {
|
||||
|
|
|
@ -25,8 +25,7 @@ class CustomWizard::WizardController < ::ApplicationController
|
|||
builder_opts[:reset] = params[:reset] || builder.wizard.restart_on_revisit
|
||||
|
||||
if builder.wizard.present?
|
||||
wizard = builder.build(builder_opts, params)
|
||||
render_serialized(wizard, ::CustomWizardSerializer)
|
||||
render_serialized(builder.build(builder_opts, params), ::CustomWizardSerializer)
|
||||
else
|
||||
render json: { error: I18n.t('wizard.none') }
|
||||
end
|
||||
|
|
|
@ -265,7 +265,10 @@ class CustomWizard::Builder
|
|||
CustomWizard::Mapper.new(
|
||||
inputs: prefill,
|
||||
user: @wizard.user,
|
||||
data: @submissions.last
|
||||
data: @submissions.last,
|
||||
opts: {
|
||||
debug: true
|
||||
}
|
||||
).perform
|
||||
end
|
||||
end
|
||||
|
|
|
@ -68,7 +68,7 @@ class CustomWizard::Mapper
|
|||
end
|
||||
|
||||
def build_result(result, type)
|
||||
if opts[:with_type]
|
||||
if @opts[:with_type]
|
||||
{
|
||||
type: type,
|
||||
result: result
|
||||
|
@ -83,12 +83,13 @@ class CustomWizard::Mapper
|
|||
|
||||
pairs.each do |pair|
|
||||
key = map_field(pair['key'], pair['key_type'])
|
||||
operator = map_operator(pair['connector'])
|
||||
connector = pair['connector']
|
||||
operator = map_operator(connector)
|
||||
value = interpolate(map_field(pair['value'], pair['value_type']))
|
||||
value = "/#{value}/" if pair['connector'] == 'regex'
|
||||
value = Regexp.new(value) if connector == 'regex'
|
||||
|
||||
begin
|
||||
failed = true unless key.public_send(operator, value)
|
||||
failed = !cast_result(key.public_send(operator, value), connector)
|
||||
rescue NoMethodError
|
||||
#
|
||||
end
|
||||
|
@ -97,6 +98,14 @@ class CustomWizard::Mapper
|
|||
!failed
|
||||
end
|
||||
|
||||
def cast_result(result, connector)
|
||||
if connector == 'regex'
|
||||
result == 0 ? true : false
|
||||
else
|
||||
result
|
||||
end
|
||||
end
|
||||
|
||||
def map_pairs(pairs)
|
||||
result = []
|
||||
|
||||
|
|
|
@ -142,10 +142,10 @@ class CustomWizard::Wizard
|
|||
return true if mapper.blank?
|
||||
|
||||
mapper.all? do |m|
|
||||
if m.type === 'assignment'
|
||||
GroupUser.exists?(group_id: m.result, user_id: user.id)
|
||||
elsif m.type === 'validation'
|
||||
mapper.result
|
||||
if m[:type] === 'assignment'
|
||||
GroupUser.exists?(group_id: m[:result], user_id: user.id)
|
||||
elsif m[:type] === 'validation'
|
||||
m[:result]
|
||||
else
|
||||
true
|
||||
end
|
||||
|
|
|
@ -45,4 +45,8 @@ class CustomWizardFieldSerializer < ::WizardFieldSerializer
|
|||
def content
|
||||
object.content
|
||||
end
|
||||
|
||||
def include_choices?
|
||||
object.choices.present?
|
||||
end
|
||||
end
|
Laden …
In neuem Issue referenzieren