Handle telemetry removal

This commit is contained in:
Joshi 2020-01-26 23:30:19 -08:00
parent d6a422fbdb
commit f42ec7e2c5
2 changed files with 46 additions and 10 deletions

View File

@ -87,6 +87,7 @@ export default {
this.instantiate = this.openmct.$injector.get('instantiate'); this.instantiate = this.openmct.$injector.get('instantiate');
this.composition = this.openmct.composition.get(this.domainObject); this.composition = this.openmct.composition.get(this.domainObject);
this.composition.on('add', this.addTelemetry); this.composition.on('add', this.addTelemetry);
this.composition.on('remove', this.removeTelemetry);
this.composition.load(); this.composition.load();
this.conditionCollection = this.domainObject.configuration ? this.domainObject.configuration.conditionCollection : []; this.conditionCollection = this.domainObject.configuration ? this.domainObject.configuration.conditionCollection : [];
if (!this.conditionCollection.length) { if (!this.conditionCollection.length) {
@ -116,6 +117,16 @@ export default {
addTelemetry(telemetryDomainObject) { addTelemetry(telemetryDomainObject) {
this.telemetryObjs.push(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) { addCondition(event, isDefault) {
let conditionDO = this.getConditionDomainObject(!!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 //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

View File

@ -194,25 +194,49 @@ export default {
}; };
}, },
destroyed() { destroyed() {
this.conditionClass.off('conditionResultUpdated', this.handleConditionResult.bind(this)); this.destroy();
if (this.conditionClass && typeof this.conditionClass.destroy === 'function') {
this.conditionClass.destroy();
}
}, },
mounted() { mounted() {
this.openmct.objects.get(this.conditionIdentifier).then((obj => { this.openmct.objects.get(this.conditionIdentifier).then((obj => {
this.condition = obj; this.condition = obj;
this.initialize();
}));
},
updated() {
//validate telemetry exists, update criteria as needed
this.validate();
this.persist();
},
methods: {
initialize() {
this.setOutput(); this.setOutput();
this.setOperation(); this.setOperation();
this.updateTelemetry(); this.updateTelemetry();
this.conditionClass = new ConditionClass(this.condition, this.openmct); this.conditionClass = new ConditionClass(this.condition, this.openmct);
this.conditionClass.on('conditionResultUpdated', this.handleConditionResult.bind(this)); this.conditionClass.on('conditionResultUpdated', this.handleConditionResult.bind(this));
}));
}, },
updated() { destroy() {
this.persist(); 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();
}
}
}, },
methods: {
handleConditionResult(args) { handleConditionResult(args) {
this.$emit('condition-result-updated', { this.$emit('condition-result-updated', {
id: this.conditionIdentifier, id: this.conditionIdentifier,
@ -310,6 +334,7 @@ export default {
}, },
telemetryChange() { telemetryChange() {
this.selectedMetaDataKey = ''; this.selectedMetaDataKey = '';
this.updateConditionCriteria();
this.updateTelemetry(); this.updateTelemetry();
}, },
updateCurrentCondition() { updateCurrentCondition() {