0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-10 12:22:54 +01:00
discourse-custom-wizard/assets/javascripts/discourse/components/wizard-mapper.js.es6

65 Zeilen
1,9 KiB
Text

2020-04-01 07:03:26 +02:00
import { getOwner } from 'discourse-common/lib/get-owner';
2020-04-05 03:37:09 +02:00
import { newInput, selectionTypes } from '../lib/wizard-mapper';
2020-04-06 10:36:38 +02:00
import { default as discourseComputed, observes, on } from 'discourse-common/utils/decorators';
import { gt } from "@ember/object/computed";
2020-04-05 03:37:09 +02:00
import Component from "@ember/component";
import { A } from "@ember/array";
2020-04-01 07:03:26 +02:00
2020-04-05 03:37:09 +02:00
export default Component.extend({
2020-04-01 07:03:26 +02:00
classNames: 'wizard-mapper',
2020-04-06 10:36:38 +02:00
hasInput: gt('inputs.length', 0),
2020-04-01 07:03:26 +02:00
2020-04-06 10:36:38 +02:00
@discourseComputed('options.singular', 'hasInput')
canAdd(singular, hasInput) {
return !singular || !hasInput;
2020-04-01 07:03:26 +02:00
},
2020-04-06 10:36:38 +02:00
@discourseComputed('options.@each.inputType')
2020-04-01 07:03:26 +02:00
inputOptions(options) {
2020-04-05 03:37:09 +02:00
let result = {
inputTypes: options.inputTypes || 'conditional,assignment',
2020-04-06 10:36:38 +02:00
inputConnector: options.inputConnector || 'or',
2020-04-01 07:03:26 +02:00
pairConnector: options.pairConnector || null,
2020-04-06 03:54:16 +02:00
outputConnector: options.outputConnector || null,
context: options.context || null
2020-04-01 07:03:26 +02:00
}
2020-04-06 10:36:38 +02:00
2020-04-05 03:37:09 +02:00
let inputTypes = ['key', 'value', 'output'];
inputTypes.forEach(type => {
2020-04-06 03:54:16 +02:00
result[`${type}Placeholder`] = options[`${type}Placeholder`] || null;
2020-04-05 03:37:09 +02:00
result[`${type}DefaultSelection`] = options[`${type}DefaultSelection`] || null;
});
selectionTypes.forEach(type => {
if (options[`${type}Selection`]) {
result[`${type}Selection`] = options[`${type}Selection`]
} else {
result[`${type}Selection`] = type === 'text' ? true : false;
}
});
2020-04-06 03:54:16 +02:00
2020-04-05 03:37:09 +02:00
return result;
},
2020-04-01 07:03:26 +02:00
actions: {
add() {
2020-04-06 03:54:16 +02:00
if (!this.get('inputs')) {
this.set('inputs', A());
}
2020-04-06 10:36:38 +02:00
this.get('inputs').pushObject(
newInput(this.inputOptions, this.inputs.length)
);
2020-04-01 07:03:26 +02:00
},
remove(input) {
2020-04-07 06:56:16 +02:00
const inputs = this.inputs;
inputs.removeObject(input);
if (inputs.length) {
inputs[0].set('connector', null);
}
2020-04-01 07:03:26 +02:00
}
}
});