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

49 Zeilen
1,5 KiB
Text

2020-04-01 07:03:26 +02:00
import { computed, set } from "@ember/object";
2020-04-05 03:37:09 +02:00
import { alias, equal, or } 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-01 07:03:26 +02:00
classNameBindings: [':mapper-input', 'type'],
inputType: alias('input.type'),
isConditional: equal('inputType', 'conditional'),
2020-04-05 03:37:09 +02:00
isAssignment: equal('inputType', 'assignment'),
isPair: equal('inputType', 'pair'),
hasOutput: or('isConditional', 'isAssignment'),
hasPairs: or('isConditional', 'isPair'),
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) }),
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);
}
}
});