2020-02-02 11:42:05 +01:00
|
|
|
function generateSelectKitContent(content) {
|
|
|
|
return content.map(i => ({id: i, name: i}))
|
|
|
|
}
|
|
|
|
|
2020-03-21 18:30:11 +01:00
|
|
|
function generateName(id) {
|
|
|
|
return id.replace(/[_\-]+/g, ' ')
|
|
|
|
.toLowerCase()
|
|
|
|
.replace(/(^\w|\b\w)/g, (m) => m.toUpperCase())
|
|
|
|
}
|
|
|
|
|
|
|
|
const profileFields = [
|
|
|
|
'name',
|
2020-03-30 08:16:03 +02:00
|
|
|
'username',
|
|
|
|
'email',
|
2020-03-21 18:30:11 +01:00
|
|
|
'date_of_birth',
|
|
|
|
'title',
|
|
|
|
'locale',
|
|
|
|
'location',
|
|
|
|
'website',
|
|
|
|
'bio_raw',
|
2020-03-30 08:16:03 +02:00
|
|
|
'trust_level'
|
2020-03-21 18:30:11 +01:00
|
|
|
];
|
|
|
|
|
|
|
|
const connectors = [
|
2020-03-22 07:47:56 +01:00
|
|
|
{
|
|
|
|
id: 'eq',
|
|
|
|
name: '='
|
|
|
|
},{
|
|
|
|
id: 'gt',
|
|
|
|
name: '>'
|
|
|
|
},{
|
|
|
|
id: 'lt',
|
|
|
|
name: '<'
|
|
|
|
},{
|
|
|
|
id: 'gte',
|
|
|
|
name: '>='
|
|
|
|
},{
|
|
|
|
id: 'lte',
|
|
|
|
name: '<='
|
|
|
|
}
|
2020-03-21 18:30:11 +01:00
|
|
|
]
|
|
|
|
|
|
|
|
const actionTypes = [
|
|
|
|
'create_topic',
|
|
|
|
'update_profile',
|
|
|
|
'create_topic',
|
|
|
|
'update_profile',
|
|
|
|
'send_message',
|
|
|
|
'send_to_api',
|
|
|
|
'add_to_group',
|
|
|
|
'route_to',
|
|
|
|
'open_composer'
|
|
|
|
];
|
|
|
|
|
2020-03-24 10:35:46 +01:00
|
|
|
const selectionTypes = [
|
|
|
|
'text',
|
|
|
|
'wizardField',
|
|
|
|
'userField',
|
|
|
|
'group',
|
|
|
|
'category',
|
|
|
|
'tag'
|
|
|
|
]
|
|
|
|
|
|
|
|
const inputTypes = [
|
|
|
|
'pair',
|
|
|
|
'conditional',
|
|
|
|
'assignment'
|
|
|
|
]
|
|
|
|
|
|
|
|
function defaultInputType(options = {}) {
|
2020-03-30 08:16:03 +02:00
|
|
|
if (!options.hasOutput) return 'pair';
|
|
|
|
const allowedInputs = options.allowedInputs;
|
|
|
|
if (!allowedInputs) return 'conditional';
|
|
|
|
return allowedInputs.split(',')[0];
|
2020-03-24 10:35:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function defaultSelectionType(inputType, options = {}) {
|
2020-03-31 10:30:53 +02:00
|
|
|
if (options[`${inputType}DefaultType`]) {
|
|
|
|
return options[`${inputType}DefaultType`];
|
|
|
|
}
|
|
|
|
|
2020-03-24 10:35:46 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2020-03-21 18:30:11 +01:00
|
|
|
function newInput(options = {}) {
|
2020-03-24 10:35:46 +01:00
|
|
|
let params = {
|
|
|
|
type: defaultInputType(options),
|
2020-03-31 10:30:53 +02:00
|
|
|
pairs: Ember.A(
|
|
|
|
[
|
|
|
|
newPair(
|
|
|
|
Object.assign(
|
|
|
|
{},
|
|
|
|
options,
|
|
|
|
{ index: 0, pairCount: 1 }
|
|
|
|
)
|
|
|
|
)
|
|
|
|
]
|
|
|
|
)
|
2020-03-21 18:30:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (options.hasOutput) {
|
2020-03-24 10:35:46 +01:00
|
|
|
params['output_type'] = defaultSelectionType('output', options);
|
2020-03-21 18:30:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return Ember.Object.create(params);
|
|
|
|
}
|
|
|
|
|
2020-03-23 06:41:04 +01:00
|
|
|
function newPair(options = {}) {
|
2020-03-21 18:30:11 +01:00
|
|
|
let params = {
|
2020-03-23 06:41:04 +01:00
|
|
|
index: options.index,
|
|
|
|
pairCount: options.pairCount,
|
2020-03-21 18:30:11 +01:00
|
|
|
key: '',
|
2020-03-31 10:30:53 +02:00
|
|
|
key_type: defaultSelectionType('key', options),
|
2020-03-21 18:30:11 +01:00
|
|
|
value: '',
|
2020-03-31 10:30:53 +02:00
|
|
|
value_type: defaultSelectionType('value', options),
|
2020-03-22 07:47:56 +01:00
|
|
|
connector: 'eq'
|
2020-03-21 18:30:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return Ember.Object.create(params);
|
|
|
|
}
|
|
|
|
|
2020-03-30 01:53:28 +02:00
|
|
|
function generateId(name) {
|
|
|
|
return name.replace(/[^\w ]/g, '')
|
|
|
|
.replace(/ /g,"_")
|
|
|
|
.toLowerCase();
|
|
|
|
}
|
|
|
|
|
2020-03-21 18:30:11 +01:00
|
|
|
export {
|
|
|
|
generateSelectKitContent,
|
|
|
|
profileFields,
|
|
|
|
actionTypes,
|
|
|
|
generateName,
|
2020-03-24 10:35:46 +01:00
|
|
|
defaultInputType,
|
|
|
|
defaultSelectionType,
|
2020-03-21 18:30:11 +01:00
|
|
|
connectors,
|
|
|
|
newInput,
|
2020-03-30 01:53:28 +02:00
|
|
|
newPair,
|
|
|
|
generateId
|
2020-03-21 18:30:11 +01:00
|
|
|
};
|