2020-04-02 07:21:57 +02:00
|
|
|
import EmberObject from "@ember/object";
|
2020-04-05 03:37:09 +02:00
|
|
|
import { A } from "@ember/array";
|
2020-04-01 12:58:30 +02:00
|
|
|
|
|
|
|
// Inputs
|
|
|
|
|
|
|
|
function defaultInputType(options = {}) {
|
|
|
|
return options.inputTypes.split(',')[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
function mapInputTypes(types) {
|
|
|
|
return types.map(function(type) {
|
|
|
|
return {
|
|
|
|
id: type,
|
|
|
|
name: I18n.t(`admin.wizard.input.${type}.name`)
|
|
|
|
};
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function inputTypesContent(options = {}) {
|
|
|
|
return options.inputTypes ?
|
|
|
|
mapInputTypes(options.inputTypes.split(',')) :
|
|
|
|
mapInputTypes(selectableInputTypes);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Connectors
|
|
|
|
|
|
|
|
const connectors = {
|
|
|
|
output: [
|
|
|
|
'then',
|
|
|
|
'set',
|
|
|
|
],
|
|
|
|
pair: [
|
|
|
|
'equal',
|
|
|
|
'greater',
|
|
|
|
'less',
|
|
|
|
'greater_or_equal',
|
2020-04-06 10:36:38 +02:00
|
|
|
'less_or_equal',
|
|
|
|
'regex'
|
2020-04-01 12:58:30 +02:00
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
function defaultConnector(connectorType, inputType, opts = {}) {
|
|
|
|
if (opts[`${connectorType}Connector`]) return opts[`${connectorType}Connector`];
|
2020-04-02 07:21:57 +02:00
|
|
|
if (inputType === 'conditional' && connectorType === 'output') return 'then';
|
|
|
|
if (inputType === 'conditional' && connectorType === 'pair') return 'equal';
|
2020-04-06 10:36:38 +02:00
|
|
|
if (inputType === 'assignment' && connectorType === 'output') return 'set';
|
|
|
|
if (inputType === 'association' && connectorType === 'pair') return 'association';
|
|
|
|
if (inputType === 'validation' && connectorType === 'pair') return 'equal';
|
|
|
|
return 'equal';
|
2020-04-01 12:58:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function connectorContent(connectorType, inputType, opts) {
|
2020-04-02 07:21:57 +02:00
|
|
|
let connector = opts[`${connectorType}Connector`];
|
|
|
|
|
|
|
|
if (!connector && connectorType === 'output') {
|
|
|
|
connector = defaultConnector(connectorType, inputType, opts);
|
|
|
|
}
|
2020-04-01 12:58:30 +02:00
|
|
|
|
2020-04-02 07:21:57 +02:00
|
|
|
let content = connector ? [connector] : connectors[connectorType];
|
|
|
|
|
|
|
|
return content.map(function(item) {
|
|
|
|
return {
|
|
|
|
id: item,
|
|
|
|
name: I18n.t(`admin.wizard.connector.${item}`)
|
|
|
|
};
|
2020-04-01 12:58:30 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// Selectors
|
|
|
|
|
|
|
|
const selectionTypes = [
|
|
|
|
'text',
|
2020-04-06 03:54:16 +02:00
|
|
|
'list',
|
2020-04-05 03:37:09 +02:00
|
|
|
'wizardField',
|
2020-04-02 10:21:03 +02:00
|
|
|
'userField',
|
2020-04-01 12:58:30 +02:00
|
|
|
'group',
|
|
|
|
'category',
|
2020-04-02 10:21:03 +02:00
|
|
|
'tag',
|
2020-04-06 03:54:16 +02:00
|
|
|
'user'
|
2020-04-01 12:58:30 +02:00
|
|
|
]
|
|
|
|
|
|
|
|
function defaultSelectionType(inputType, options = {}) {
|
|
|
|
if (options[`${inputType}DefaultSelection`]) {
|
|
|
|
return options[`${inputType}DefaultSelection`];
|
|
|
|
}
|
|
|
|
|
|
|
|
let type = selectionTypes[0];
|
|
|
|
|
|
|
|
for (let t of selectionTypes) {
|
|
|
|
let inputTypes = options[`${t}Selection`];
|
|
|
|
|
|
|
|
if (inputTypes === true ||
|
|
|
|
((typeof inputTypes === 'string') &&
|
|
|
|
inputTypes.split(',').indexOf(inputType) > -1)) {
|
2020-04-02 07:21:57 +02:00
|
|
|
|
2020-04-01 12:58:30 +02:00
|
|
|
type = t;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
|
|
|
// items
|
|
|
|
|
|
|
|
function newPair(inputType, options = {}) {
|
|
|
|
let params = {
|
|
|
|
index: options.index,
|
|
|
|
pairCount: options.pairCount,
|
|
|
|
key: '',
|
|
|
|
key_type: defaultSelectionType('key', options),
|
|
|
|
value: '',
|
|
|
|
value_type: defaultSelectionType('value', options),
|
|
|
|
connector: defaultConnector('pair', inputType, options)
|
|
|
|
}
|
|
|
|
|
2020-04-02 07:21:57 +02:00
|
|
|
return EmberObject.create(params);
|
2020-04-01 12:58:30 +02:00
|
|
|
}
|
|
|
|
|
2020-04-06 10:36:38 +02:00
|
|
|
function newInput(options = {}, count) {
|
2020-04-01 12:58:30 +02:00
|
|
|
const inputType = defaultInputType(options);
|
2020-04-06 03:54:16 +02:00
|
|
|
|
2020-04-01 12:58:30 +02:00
|
|
|
let params = {
|
|
|
|
type: inputType,
|
2020-04-05 03:37:09 +02:00
|
|
|
pairs: A(
|
2020-04-01 12:58:30 +02:00
|
|
|
[
|
|
|
|
newPair(
|
|
|
|
inputType,
|
|
|
|
Object.assign({},
|
|
|
|
options,
|
|
|
|
{ index: 0, pairCount: 1 }
|
|
|
|
)
|
|
|
|
)
|
|
|
|
]
|
|
|
|
)
|
|
|
|
}
|
2020-04-06 10:36:38 +02:00
|
|
|
|
|
|
|
if (count > 0) {
|
|
|
|
params.connector = options.inputConnector;
|
|
|
|
}
|
2020-04-01 12:58:30 +02:00
|
|
|
|
2020-04-06 03:54:16 +02:00
|
|
|
if (['conditional', 'assignment'].indexOf(inputType) > -1 ||
|
|
|
|
options.outputDefaultSelection ||
|
|
|
|
options.outputConnector) {
|
|
|
|
|
2020-04-01 12:58:30 +02:00
|
|
|
params['output_type'] = defaultSelectionType('output', options);
|
2020-04-06 10:36:38 +02:00
|
|
|
params['output_connector'] = defaultConnector('output', inputType, options);
|
2020-04-01 12:58:30 +02:00
|
|
|
}
|
|
|
|
|
2020-04-02 07:21:57 +02:00
|
|
|
return EmberObject.create(params);
|
2020-04-01 12:58:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export {
|
|
|
|
defaultInputType,
|
|
|
|
defaultSelectionType,
|
|
|
|
connectorContent,
|
|
|
|
inputTypesContent,
|
2020-04-05 03:37:09 +02:00
|
|
|
selectionTypes,
|
2020-04-01 12:58:30 +02:00
|
|
|
newInput,
|
2020-04-05 03:37:09 +02:00
|
|
|
newPair
|
2020-04-01 12:58:30 +02:00
|
|
|
}
|