diff --git a/src/plugins/condition/ConditionSetViewProvider.js b/src/plugins/condition/ConditionSetViewProvider.js index 958c41af5b..0906abc06a 100644 --- a/src/plugins/condition/ConditionSetViewProvider.js +++ b/src/plugins/condition/ConditionSetViewProvider.js @@ -58,7 +58,7 @@ export default class ConditionSetViewProvider { isEditing } }, - template: '' + template: '' }); }, onEditModeChange: (isEditing) => { diff --git a/src/plugins/condition/components/ConditionCollection.vue b/src/plugins/condition/components/ConditionCollection.vue index e067997626..50808dd27b 100644 --- a/src/plugins/condition/components/ConditionCollection.vue +++ b/src/plugins/condition/components/ConditionCollection.vue @@ -28,18 +28,18 @@ Add Condition -
-
- -
-
- +
+
+
+ +
+
+ +
@@ -63,41 +63,28 @@ export default { data() { return { expanded: true, - conditions: [ - { - identifier: { - key: 'testConditionKey', - namespace: '' - }, - type: 'condition', - isDefault: true - } - ], - parentKeyString: this.openmct.objects.makeKeyString(this.domainObject.identifier) + parentKeyString: this.openmct.objects.makeKeyString(this.domainObject.identifier), + conditionCollection: [{ + isDefault: true + }] }; }, destroyed() { - this.composition.off('add', this.added); - // this.composition.off('remove', this.removeCondition); - // this.composition.off('reorder', this.reorder); + }, mounted() { this.instantiate = this.openmct.$injector.get('instantiate'); - this.composition = this.openmct.composition.get(this.domainObject); - this.composition.on('add', this.added); - // this.composition.on('remove', this.removeCondition); - // this.composition.on('reorder', this.reorder); - this.composition.load(); + this.conditionCollection = this.domainObject.configuration.conditionCollection; }, methods: { added(conditionDO) { - this.conditions.unshift(conditionDO); + this.conditionCollection.unshift(conditionDO); }, addCondition() { let conditionObjId = uuid(); let conditionObj = { "composition": [], - "name": "Condition"+this.conditions.length, + "name": "condition" + this.conditionCollection.length, "type": "condition", "id": conditionObjId, "location": this.parentKeyString, @@ -112,19 +99,27 @@ export default { newDO.useCapability('location').setPrimaryLocation(this.parentKeyString); let conditionDO = newDO.useCapability('adapter'); - this.composition.add(conditionDO); + this.conditionCollection.unshift(conditionDO); + + this.persist(); }, removeCondition(identifier) { - console.log(`remove condition`); - // let index = _.findIndex(this.conditions, (condition) => this.openmct.objects.makeKeyString(identifier) === item.key); + let index = _.findIndex(this.conditionCollection, (condition) => this.openmct.objects.makeKeyString(identifier) === condition.identifier.key); - // this.conditions.splice(index, 1); + this.conditionCollection.splice(index, 1); }, reorder(reorderPlan) { - let oldConditions = this.conditions.slice(); + let oldConditions = this.conditionCollection.slice(); reorderPlan.forEach((reorderEvent) => { - this.$set(this.conditions, reorderEvent.newIndex, oldConditions[reorderEvent.oldIndex]); + this.$set(this.conditionCollection, reorderEvent.newIndex, oldConditions[reorderEvent.oldIndex]); }); + }, + persist(index) { + if (index) { + this.openmct.objects.mutate(this.domainObject, `configuration.conditionCollection[${index}]`, this.conditionCollection[index]); + } else { + this.openmct.objects.mutate(this.domainObject, 'configuration.conditionCollection', this.conditionCollection); + } } } } diff --git a/src/plugins/condition/components/ConditionEdit.vue b/src/plugins/condition/components/ConditionEdit.vue index 2eff394a24..189c112689 100644 --- a/src/plugins/condition/components/ConditionEdit.vue +++ b/src/plugins/condition/components/ConditionEdit.vue @@ -1,6 +1,5 @@