From f42ec7e2c512b4546e8420df1d5d5c45a2bc0512 Mon Sep 17 00:00:00 2001 From: Joshi Date: Sun, 26 Jan 2020 23:30:19 -0800 Subject: [PATCH] Handle telemetry removal --- .../components/ConditionCollection.vue | 11 +++++ .../condition/components/ConditionEdit.vue | 45 ++++++++++++++----- 2 files changed, 46 insertions(+), 10 deletions(-) diff --git a/src/plugins/condition/components/ConditionCollection.vue b/src/plugins/condition/components/ConditionCollection.vue index 43cdd4f485..7b28e0c6c7 100644 --- a/src/plugins/condition/components/ConditionCollection.vue +++ b/src/plugins/condition/components/ConditionCollection.vue @@ -87,6 +87,7 @@ export default { this.instantiate = this.openmct.$injector.get('instantiate'); this.composition = this.openmct.composition.get(this.domainObject); this.composition.on('add', this.addTelemetry); + this.composition.on('remove', this.removeTelemetry); this.composition.load(); this.conditionCollection = this.domainObject.configuration ? this.domainObject.configuration.conditionCollection : []; if (!this.conditionCollection.length) { @@ -116,6 +117,16 @@ export default { addTelemetry(telemetryDomainObject) { this.telemetryObjs.push(telemetryDomainObject); }, + removeTelemetry(telemetryDomainObjectIdentifier) { + let index = _.findIndex(this.telemetryObjs, (obj) => { + let objId = this.openmct.objects.makeKeyString(obj.identifier); + let id = this.openmct.objects.makeKeyString(telemetryDomainObjectIdentifier); + return objId === id; + }); + if (index > -1) { + this.telemetryObjs.splice(index, 1); + } + }, addCondition(event, isDefault) { let conditionDO = this.getConditionDomainObject(!!isDefault); //persist the condition DO so that we can do an openmct.objects.get on it and only persist the identifier in the conditionCollection of conditionSet diff --git a/src/plugins/condition/components/ConditionEdit.vue b/src/plugins/condition/components/ConditionEdit.vue index 9f985e21b3..d4625aed5c 100644 --- a/src/plugins/condition/components/ConditionEdit.vue +++ b/src/plugins/condition/components/ConditionEdit.vue @@ -194,25 +194,49 @@ export default { }; }, destroyed() { - this.conditionClass.off('conditionResultUpdated', this.handleConditionResult.bind(this)); - if (this.conditionClass && typeof this.conditionClass.destroy === 'function') { - this.conditionClass.destroy(); - } + this.destroy(); }, mounted() { this.openmct.objects.get(this.conditionIdentifier).then((obj => { this.condition = obj; + this.initialize(); + })); + }, + updated() { + //validate telemetry exists, update criteria as needed + this.validate(); + this.persist(); + }, + methods: { + initialize() { this.setOutput(); this.setOperation(); this.updateTelemetry(); this.conditionClass = new ConditionClass(this.condition, this.openmct); this.conditionClass.on('conditionResultUpdated', this.handleConditionResult.bind(this)); - })); - }, - updated() { - this.persist(); - }, - methods: { + }, + destroy() { + this.conditionClass.off('conditionResultUpdated', this.handleConditionResult.bind(this)); + if (this.conditionClass && typeof this.conditionClass.destroy === 'function') { + this.conditionClass.destroy(); + delete this.conditionClass; + } + }, + reset() { + this.selectedMetaDataKey = ''; + this.selectedTelemetryKey = ''; + this.selectedOperationKey = ''; + this.operationValue = ''; + }, + validate() { + if (this.hasTelemetry() && !this.getTelemetryKey()) { + this.reset(); + } else { + if (!this.conditionClass) { + this.initialize(); + } + } + }, handleConditionResult(args) { this.$emit('condition-result-updated', { id: this.conditionIdentifier, @@ -310,6 +334,7 @@ export default { }, telemetryChange() { this.selectedMetaDataKey = ''; + this.updateConditionCriteria(); this.updateTelemetry(); }, updateCurrentCondition() {