1
0
Fork 0
discourse-custom-wizard-unl.../assets/javascripts/discourse/components/wizard-mapper-input.js.es6

58 Zeilen
1,8 KiB
Text

2020-04-01 07:03:26 +02:00
import { computed, set } from "@ember/object";
2020-04-07 09:54:30 +02:00
import { alias, equal, or, not } from "@ember/object/computed";
2020-04-02 07:21:57 +02:00
import { newPair, connectorContent, inputTypesContent } from '../lib/wizard-mapper';
2020-04-05 03:37:09 +02:00
import Component from "@ember/component";
2020-04-06 03:54:16 +02:00
import { observes } from "discourse-common/utils/decorators";
2020-04-01 07:03:26 +02:00
2020-04-05 03:37:09 +02:00
export default Component.extend({
2020-04-06 10:36:38 +02:00
classNameBindings: [':mapper-input', 'inputType'],
2020-04-01 07:03:26 +02:00
inputType: alias('input.type'),
isConditional: equal('inputType', 'conditional'),
2020-04-05 03:37:09 +02:00
isAssignment: equal('inputType', 'assignment'),
2020-04-06 10:36:38 +02:00
isAssociation: equal('inputType', 'association'),
isValidation: equal('inputType', 'validation'),
2020-04-05 03:37:09 +02:00
hasOutput: or('isConditional', 'isAssignment'),
2020-04-06 10:36:38 +02:00
hasPairs: or('isConditional', 'isAssociation', 'isValidation'),
2020-04-07 09:54:30 +02:00
canAddPair: not('isAssignment'),
2020-04-01 07:03:26 +02:00
connectors: computed(function() { return connectorContent('output', this.input.type, this.options) }),
inputTypes: computed(function() { return inputTypesContent(this.options) }),
2020-04-07 10:33:51 +02:00
@observes('input.type')
setupPairs() {
if (this.hasPairs && (!this.input.pairs || this.input.pairs.length < 1)) {
this.send('addPair');
}
},
2020-04-01 07:03:26 +02:00
actions: {
addPair() {
const pairs = this.input.pairs;
const pairCount = pairs.length + 1;
pairs.forEach(p => (set(p, 'pairCount', pairCount)));
pairs.pushObject(
newPair(
this.input.type,
Object.assign(
{},
this.options,
{
index: pairs.length,
pairCount,
}
)
)
);
},
removePair(pair) {
const pairs = this.input.pairs;
const pairCount = pairs.length - 1;
pairs.forEach(p => (set(p, 'pairCount', pairCount)));
pairs.removeObject(pair);
}
}
});