1
0
Fork 0
Dieser Commit ist enthalten in:
Angus McLeod 2020-04-07 17:54:30 +10:00
Ursprung e3fa75597b
Commit b5fce333f6
18 geänderte Dateien mit 86 neuen und 52 gelöschten Zeilen

Datei anzeigen

@ -56,20 +56,22 @@ export default Component.extend({
prefillOptions(fieldType) { prefillOptions(fieldType) {
let options = { let options = {
wizardFieldSelection: true, wizardFieldSelection: true,
textSelection: 'key,value', textSelection: true,
userFieldSelection: 'key,value', userFieldSelection: 'key,value',
context: 'field' context: 'field'
} }
let outputSelectionType = { let outputSelectionType = {
category: 'category', category: ['category'],
tag: 'tag', tag: ['tag'],
group: 'group', group: ['group'],
dropdown: 'text' dropdown: ['list']
}[fieldType]; }[fieldType];
options[`${outputSelectionType}Selection`] = 'output'; outputSelectionType.forEach(function(type) {
options.outputDefaultSelection = outputSelectionType; options[`${type}Selection`] = 'output';
options.outputDefaultSelection = type;
});
return options; return options;
}, },

Datei anzeigen

@ -1,5 +1,5 @@
import { computed, set } from "@ember/object"; 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 { newPair, connectorContent, inputTypesContent } from '../lib/wizard-mapper';
import Component from "@ember/component"; import Component from "@ember/component";
import { observes } from "discourse-common/utils/decorators"; import { observes } from "discourse-common/utils/decorators";
@ -13,6 +13,7 @@ export default Component.extend({
isValidation: equal('inputType', 'validation'), isValidation: equal('inputType', 'validation'),
hasOutput: or('isConditional', 'isAssignment'), hasOutput: or('isConditional', 'isAssignment'),
hasPairs: or('isConditional', 'isAssociation', 'isValidation'), hasPairs: or('isConditional', 'isAssociation', 'isValidation'),
canAddPair: not('isAssignment'),
connectors: computed(function() { return connectorContent('output', this.input.type, this.options) }), connectors: computed(function() { return connectorContent('output', this.input.type, this.options) }),
inputTypes: computed(function() { return inputTypesContent(this.options) }), inputTypes: computed(function() { return inputTypesContent(this.options) }),

Datei anzeigen

@ -3,14 +3,14 @@ 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, selectKitContent } from '../lib/wizard'; import { snakeCase } from '../lib/wizard';
import Component from "@ember/component"; import Component from "@ember/component";
import { bind } from "@ember/runloop"; import { bind } from "@ember/runloop";
export default Component.extend({ export default Component.extend({
classNames: 'mapper-selector', classNames: 'mapper-selector',
groups: alias('site.groups'), groups: alias('site.groups'),
categories: computed(function() { return selectKitContent(this.site.categories) }), 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') }),
@ -67,11 +67,6 @@ export default Component.extend({
return I18n.t(`admin.wizard.selector.label.${snakeCase(type)}`) return I18n.t(`admin.wizard.selector.label.${snakeCase(type)}`)
}, },
@discourseComputed('showTypes')
typeSelectorIcon(showTypes) {
return showTypes ? 'chevron-down' : 'chevron-right';
},
@observes('inputType') @observes('inputType')
resetActiveType() { resetActiveType() {
this.set('activeType', defaultSelectionType(this.selectorType, this.options)); this.set('activeType', defaultSelectionType(this.selectorType, this.options));

Datei anzeigen

@ -15,13 +15,16 @@ export default Controller.extend({
@observes('currentStep') @observes('currentStep')
resetCurrentObjects() { resetCurrentObjects() {
const currentStep = this.currentStep; const currentStep = this.currentStep;
const fields = currentStep.fields;
const actions = currentStep.actions;
this.setProperties({ if (currentStep) {
currentField: fields.length ? fields[0] : null, const fields = currentStep.fields;
currentAction: actions.length ? actions[0] : null const actions = currentStep.actions;
});
this.setProperties({
currentField: fields.length ? fields[0] : null,
currentAction: actions.length ? actions[0] : null
});
}
scheduleOnce('afterRender', () => ($("body").addClass('admin-wizard'))); scheduleOnce('afterRender', () => ($("body").addClass('admin-wizard')));
}, },

Datei anzeigen

@ -52,7 +52,7 @@ function defaultConnector(connectorType, inputType, opts = {}) {
function connectorContent(connectorType, inputType, opts) { function connectorContent(connectorType, inputType, opts) {
let connector = opts[`${connectorType}Connector`]; let connector = opts[`${connectorType}Connector`];
if (!connector && connectorType === 'output') { if ((!connector && connectorType === 'output') || inputType === 'association') {
connector = defaultConnector(connectorType, inputType, opts); connector = defaultConnector(connectorType, inputType, opts);
} }

Datei anzeigen

@ -139,6 +139,13 @@ const mappedProperties = {
] ]
} }
const advancedFieldTypes = [
'category',
'tag',
'group',
'dropdown'
]
const advancedFieldProperties = [ const advancedFieldProperties = [
'prefill', 'prefill',
'content' 'content'
@ -161,12 +168,11 @@ const advancedProperties = {
'required_data', 'required_data',
'permitted_params' 'permitted_params'
], ],
field: advancedFieldProperties.reduce( field: advancedFieldTypes.reduce(
function(map, type) { function(map, type) {
console.log(map, type);
map[type] = advancedFieldProperties; map[type] = advancedFieldProperties;
if (type === 'category') { if (type === 'category') {
map.push('property'); map[type].push('property');
} }
return map; return map;
}, {} }, {}

Datei anzeigen

@ -74,6 +74,7 @@
inputs=step.permitted_params inputs=step.permitted_params
options=(hash options=(hash
pairConnector='set' pairConnector='set'
inputTypes='association'
keyPlaceholder='admin.wizard.param_key' keyPlaceholder='admin.wizard.param_key'
valuePlaceholder='admin.wizard.submission_key' valuePlaceholder='admin.wizard.submission_key'
context='step' context='step'

Datei anzeigen

@ -14,7 +14,7 @@
removePair=(action 'removePair')}} removePair=(action 'removePair')}}
{{/each}} {{/each}}
{{#if hasOutput}} {{#if canAddPair}}
<a {{action 'addPair'}} class="add-pair"> <a {{action 'addPair'}} class="add-pair">
{{d-icon 'plus'}} {{d-icon 'plus'}}
</a> </a>

Datei anzeigen

@ -2,7 +2,6 @@
{{#if hasTypes}} {{#if hasTypes}}
<a {{action "toggleTypes"}} class="active"> <a {{action "toggleTypes"}} class="active">
{{activeTypeLabel}} {{activeTypeLabel}}
{{d-icon typeSelectorIcon class="type-selector-icon"}}
</a> </a>
{{#if showTypes}} {{#if showTypes}}

Datei anzeigen

@ -82,7 +82,7 @@
//= require discourse/components/d-button //= require discourse/components/d-button
//= require discourse/components/composer-editor //= require discourse/components/composer-editor
//= require discourse/components/d-editor //= require discourse/components/d-editor
//= require discourse/components/popup-input-tip //= require discourse/components/input-tip
//= require discourse/components/emoji-picker //= require discourse/components/emoji-picker
//= require discourse/templates/components/conditional-loading-spinner //= require discourse/templates/components/conditional-loading-spinner

Datei anzeigen

@ -277,5 +277,11 @@ export default {
return valid; return valid;
} }
}); });
WizardFieldDropdown.reopen({
didInsertElement() {
console.log(this.field)
}
})
} }
}; };

Datei anzeigen

@ -1,6 +1,7 @@
{{combo-box elementId=field.id {{combo-box
class=fieldClass class=fieldClass
value=field.value value=field.value
content=field.content content=field.content
nameProperty="label" options=(hash
tabindex="9"}} none="select_kit.default_header_text"
)}}

Datei anzeigen

@ -20,8 +20,9 @@
> .mapper-connector.single { > .mapper-connector.single {
width: min-content; width: min-content;
margin-bottom: 10px; margin-bottom: 5px;
height: 20px height: 20px;
border: 2px solid $primary-low;
} }
} }
@ -56,7 +57,7 @@
position: absolute; position: absolute;
right: -14px; right: -14px;
top: 0px; top: 0px;
padding: 2px 5px; padding: 2px 4px;
transform: translateY(-50%); transform: translateY(-50%);
background: $secondary; background: $secondary;
border-radius: 50%; border-radius: 50%;
@ -66,7 +67,7 @@
} }
.add-mapper-input { .add-mapper-input {
display: block; display: inline-block;
} }
.mapper-connector { .mapper-connector {
@ -86,6 +87,10 @@
align-items: center; align-items: center;
justify-content: center; justify-content: center;
} }
.connector-single {
padding: 0 5px;
}
} }
.mapper-selector { .mapper-selector {

Datei anzeigen

@ -25,8 +25,7 @@ class CustomWizard::WizardController < ::ApplicationController
builder_opts[:reset] = params[:reset] || builder.wizard.restart_on_revisit builder_opts[:reset] = params[:reset] || builder.wizard.restart_on_revisit
if builder.wizard.present? if builder.wizard.present?
wizard = builder.build(builder_opts, params) render_serialized(builder.build(builder_opts, params), ::CustomWizardSerializer)
render_serialized(wizard, ::CustomWizardSerializer)
else else
render json: { error: I18n.t('wizard.none') } render json: { error: I18n.t('wizard.none') }
end end

Datei anzeigen

@ -244,7 +244,7 @@ class CustomWizard::Builder
with_type: true with_type: true
} }
).perform ).perform
if content[:type] == 'association' if content[:type] == 'association'
content[:result] = content[:result].map do |item| content[:result] = content[:result].map do |item|
{ {
@ -265,7 +265,10 @@ class CustomWizard::Builder
CustomWizard::Mapper.new( CustomWizard::Mapper.new(
inputs: prefill, inputs: prefill,
user: @wizard.user, user: @wizard.user,
data: @submissions.last data: @submissions.last,
opts: {
debug: true
}
).perform ).perform
end end
end end

Datei anzeigen

@ -63,12 +63,12 @@ class CustomWizard::Mapper
end end
end end
end end
perform_result perform_result
end end
def build_result(result, type) def build_result(result, type)
if opts[:with_type] if @opts[:with_type]
{ {
type: type, type: type,
result: result result: result
@ -83,12 +83,13 @@ class CustomWizard::Mapper
pairs.each do |pair| pairs.each do |pair|
key = map_field(pair['key'], pair['key_type']) 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 = interpolate(map_field(pair['value'], pair['value_type']))
value = "/#{value}/" if pair['connector'] == 'regex' value = Regexp.new(value) if connector == 'regex'
begin begin
failed = true unless key.public_send(operator, value) failed = !cast_result(key.public_send(operator, value), connector)
rescue NoMethodError rescue NoMethodError
# #
end end
@ -97,6 +98,14 @@ class CustomWizard::Mapper
!failed !failed
end end
def cast_result(result, connector)
if connector == 'regex'
result == 0 ? true : false
else
result
end
end
def map_pairs(pairs) def map_pairs(pairs)
result = [] result = []

Datei anzeigen

@ -142,10 +142,10 @@ class CustomWizard::Wizard
return true if mapper.blank? return true if mapper.blank?
mapper.all? do |m| mapper.all? do |m|
if m.type === 'assignment' if m[:type] === 'assignment'
GroupUser.exists?(group_id: m.result, user_id: user.id) GroupUser.exists?(group_id: m[:result], user_id: user.id)
elsif m.type === 'validation' elsif m[:type] === 'validation'
mapper.result m[:result]
else else
true true
end end

Datei anzeigen

@ -45,4 +45,8 @@ class CustomWizardFieldSerializer < ::WizardFieldSerializer
def content def content
object.content object.content
end end
def include_choices?
object.choices.present?
end
end end