From e580734c9593ab863f397b52ec9662f045fc7b61 Mon Sep 17 00:00:00 2001 From: Shefali Joshi Date: Fri, 31 Jan 2020 14:44:28 -0800 Subject: [PATCH] Set criteria options (#2630) * Set criteria options on condition edit * Persists telemetry options correctly and loads them on mount * Fixes saving the input value for criteria * Display active condition's output in read only view * Destroy classes and unsubscribe when condition set view is destroyed * Fixes saving the input value for a criteria * Handle telemetry removal * Fixes tests * Addresses comments - change function names, consolidate compute function * Addresses review comments - Use camelCase for events (did not change properties as eslint complains) - Reduce repeated property access by assigning to a variable - Use descriptive variable name * Addressing comments - improves input value field visibility logic * Change variable name to reflect intent --- src/plugins/condition/Condition.js | 8 +- src/plugins/condition/ConditionSpec.js | 1 - .../condition/components/Condition.vue | 18 +++ .../components/ConditionCollection.vue | 42 +++-- .../condition/components/ConditionEdit.vue | 150 +++++++++++++----- .../condition/components/ConditionSet.vue | 2 +- src/plugins/condition/utils/evaluator.js | 27 +--- 7 files changed, 163 insertions(+), 85 deletions(-) diff --git a/src/plugins/condition/Condition.js b/src/plugins/condition/Condition.js index 6ff4a41b56..ab3bc0858d 100644 --- a/src/plugins/condition/Condition.js +++ b/src/plugins/condition/Condition.js @@ -24,7 +24,7 @@ import * as EventEmitter from 'eventemitter3'; import uuid from 'uuid'; import TelemetryCriterion from "@/plugins/condition/criterion/TelemetryCriterion"; import { TRIGGER } from "@/plugins/condition/utils/constants"; -import {computeConditionForAll, computeConditionForAny} from "@/plugins/condition/utils/evaluator"; +import {computeCondition} from "@/plugins/condition/utils/evaluator"; /* * conditionDefinition = { @@ -228,11 +228,7 @@ export default class ConditionClass extends EventEmitter { //TODO: implement as part of the evaluator class task. evaluate() { - if (this.trigger === TRIGGER.ANY) { - this.result = computeConditionForAny(this.criteriaResults); - } else if (this.trigger === TRIGGER.ALL) { - this.result = computeConditionForAll(this.criteriaResults); - } + this.result = computeCondition(this.criteriaResults, this.trigger === TRIGGER.ALL); } emitEvent(eventName, data) { diff --git a/src/plugins/condition/ConditionSpec.js b/src/plugins/condition/ConditionSpec.js index 2f58676cef..18334bcada 100644 --- a/src/plugins/condition/ConditionSpec.js +++ b/src/plugins/condition/ConditionSpec.js @@ -103,7 +103,6 @@ describe("The condition", function () { it("initializes with criteria from the condition definition", function () { expect(conditionObj.criteria.length).toEqual(1); let criterion = conditionObj.criteria[0]; - console.log(criterion); expect(criterion instanceof TelemetryCriterion).toBeTrue(); expect(criterion.operator).toEqual(testConditionDefinition.definition.criteria[0].operator); expect(criterion.input).toEqual(testConditionDefinition.definition.criteria[0].input); diff --git a/src/plugins/condition/components/Condition.vue b/src/plugins/condition/components/Condition.vue index 57001c8347..1e37bc6479 100644 --- a/src/plugins/condition/components/Condition.vue +++ b/src/plugins/condition/components/Condition.vue @@ -22,6 +22,8 @@ diff --git a/src/plugins/condition/components/ConditionCollection.vue b/src/plugins/condition/components/ConditionCollection.vue index e8ffa3438d..1044506d9b 100644 --- a/src/plugins/condition/components/ConditionCollection.vue +++ b/src/plugins/condition/components/ConditionCollection.vue @@ -35,15 +35,17 @@ >
@@ -72,7 +74,8 @@ export default { parentKeyString: this.openmct.objects.makeKeyString(this.domainObject.identifier), conditionCollection: [], conditions: [], - currentConditionIdentifier: this.currentConditionIdentifier || {} + currentConditionIdentifier: this.currentConditionIdentifier || {}, + telemetryObjs: this.telemetryObjs }; }, destroyed() { @@ -84,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) { @@ -108,16 +112,26 @@ export default { break; } } - this.$emit('current-condition-updated', currentConditionIdentifier); + this.$emit('currentConditionUpdated', currentConditionIdentifier); }, 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 - this.openmct.objects.mutate(conditionDO, 'created', new Date()); - this.conditionCollection.unshift(conditionDO.identifier); + let conditionDomainObject = this.getConditionDomainObject(!!isDefault); + //persist the condition domain object so that we can do an openmct.objects.get on it and only persist the identifier in the conditionCollection of conditionSet + this.openmct.objects.mutate(conditionDomainObject, 'created', new Date()); + this.conditionCollection.unshift(conditionDomainObject.identifier); this.persist(); }, updateCurrentCondition(identifier) { @@ -137,16 +151,16 @@ export default { criteria: isDefault ? [] : [{ operation: '', input: '', - metaDataKey: this.openmct.telemetry.getMetadata(this.telemetryObjs[0]).values()[0].key, - key: this.telemetryObjs.length ? this.openmct.objects.makeKeyString(this.telemetryObjs[0].identifier) : null + metaDataKey: '', + key: '' }] }, summary: 'summary description' }; - let conditionDOKeyString = this.openmct.objects.makeKeyString(conditionObj.identifier); - let newDO = this.instantiate(conditionObj, conditionDOKeyString); + let conditionDomainObjectKeyString = this.openmct.objects.makeKeyString(conditionObj.identifier); + let newDomainObject = this.instantiate(conditionObj, conditionDomainObjectKeyString); - return newDO.useCapability('adapter'); + return newDomainObject.useCapability('adapter'); }, updateCondition(updatedCondition) { //TODO: this should only happen for reordering diff --git a/src/plugins/condition/components/ConditionEdit.vue b/src/plugins/condition/components/ConditionEdit.vue index d549d166f8..56ab70f5c1 100644 --- a/src/plugins/condition/components/ConditionEdit.vue +++ b/src/plugins/condition/components/ConditionEdit.vue @@ -84,17 +84,22 @@