From dc08877bbb8778cc9529e481c73333558a54b361 Mon Sep 17 00:00:00 2001 From: Joshi Date: Tue, 18 Feb 2020 15:35:03 -0800 Subject: [PATCH 1/4] Persists the condition domain object so that we can retrieve it with it's identifier in child components like condition.vue --- src/plugins/condition/components/ConditionCollection.vue | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/plugins/condition/components/ConditionCollection.vue b/src/plugins/condition/components/ConditionCollection.vue index 0492cc338b..b9e9836aba 100644 --- a/src/plugins/condition/components/ConditionCollection.vue +++ b/src/plugins/condition/components/ConditionCollection.vue @@ -213,6 +213,7 @@ export default { addCondition(event, isDefault) { let conditionDomainObject = this.createConditionDomainObject(!!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', conditionDomainObject.created); this.conditionCollection.unshift(conditionDomainObject.identifier); this.persist(); }, @@ -223,6 +224,7 @@ export default { createConditionDomainObject(isDefault) { let conditionObj = { isDefault: isDefault, + type: 'condition', name: isDefault ? 'Default' : 'Unnamed Condition', identifier: { namespace: this.domainObject.identifier.namespace, From f4468a8233b55ee402fff769413faf04d31fea89 Mon Sep 17 00:00:00 2001 From: Joshi Date: Tue, 18 Feb 2020 16:04:14 -0800 Subject: [PATCH 2/4] Fixing condition output --- src/plugins/condition/Condition.js | 6 +++--- src/plugins/condition/components/Condition.vue | 14 ++++++++------ src/plugins/condition/components/Criterion.vue | 5 ++++- .../condition/criterion/TelemetryCriterion.js | 2 +- 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/plugins/condition/Condition.js b/src/plugins/condition/Condition.js index 97ec1b0f6b..6179674147 100644 --- a/src/plugins/condition/Condition.js +++ b/src/plugins/condition/Condition.js @@ -73,7 +73,7 @@ export default class ConditionClass extends EventEmitter { update(newDomainObject) { this.updateTrigger(newDomainObject.configuration.trigger); - // this.updateCriteria(newDomainObject.configuration.criteria); + this.updateCriteria(newDomainObject.configuration.criteria); } updateTrigger(trigger) { @@ -84,13 +84,14 @@ export default class ConditionClass extends EventEmitter { } generateCriterion(criterionConfiguration) { + console.log('Identifier', criterionConfiguration); return { id: uuid(), telemetry: criterionConfiguration.telemetry || '', operation: criterionConfiguration.operation || '', input: criterionConfiguration.input === undefined ? [] : criterionConfiguration.input, metadata: criterionConfiguration.metadata || '', - key: criterionConfiguration.key || '' + identifier: criterionConfiguration.identifier || '' }; } @@ -187,7 +188,6 @@ export default class ConditionClass extends EventEmitter { if (found) { this.criteria[found.index] = criterion.data; //Most likely don't need this. - console.log('conditiion subscribe') this.subscribe(); this.emitEvent('conditionUpdated', { trigger: this.trigger, diff --git a/src/plugins/condition/components/Condition.vue b/src/plugins/condition/components/Condition.vue index 237ad3330a..a770edb66c 100644 --- a/src/plugins/condition/components/Condition.vue +++ b/src/plugins/condition/components/Condition.vue @@ -144,7 +144,7 @@ import Criterion from '../../condition/components/Criterion.vue'; import uuid from 'uuid'; export default { - inject: ['openmct', 'domainObject'], + inject: ['openmct'], components: { Criterion }, @@ -198,7 +198,7 @@ export default { }, updated() { //validate telemetry exists, update criteria as needed - this.persist(); + // this.persist(); }, methods: { initialize() { @@ -218,16 +218,18 @@ export default { namespace: '', key: uuid() } - } + }; this.domainObject.configuration.criteria.push(criteriaObject); }, dragStart(e) { this.$emit('set-move-index', Number(e.target.getAttribute('data-condition-index'))); }, destroy() { - // this.conditionClass.off('conditionResultUpdated', this.handleConditionResult.bind(this)); - if (this.conditionClass && typeof this.conditionClass.destroy === 'function') { - this.conditionClass.destroy(); + if (this.conditionClass) { + this.conditionClass.off('conditionResultUpdated', this.handleConditionResult.bind(this)); + if (typeof this.conditionClass.destroy === 'function') { + this.conditionClass.destroy(); + } delete this.conditionClass; } }, diff --git a/src/plugins/condition/components/Criterion.vue b/src/plugins/condition/components/Criterion.vue index 71cff9075d..5e876d441c 100644 --- a/src/plugins/condition/components/Criterion.vue +++ b/src/plugins/condition/components/Criterion.vue @@ -44,6 +44,7 @@ v-model="criterion.input" class="t-condition-name-input" type="text" + @blur="persist" > @@ -100,6 +101,7 @@ export default { this.telemetryMetadata = this.openmct.telemetry.getMetadata(telemetryObject).values(); }); } + this.persist(); }, updateOperationInputVisibility() { for (let i=0; i < this.operations.length; i++) { @@ -108,9 +110,10 @@ export default { if (!this.isInputOperation) {this.criterion.input = ''} } } + this.persist(); }, updateMetadataSelection() { - this.comparisonInputValue = ''; + this.updateOperationInputVisibility(); }, persist() { this.$emit('persist', this.criterion); diff --git a/src/plugins/condition/criterion/TelemetryCriterion.js b/src/plugins/condition/criterion/TelemetryCriterion.js index c59c756106..4392191efb 100644 --- a/src/plugins/condition/criterion/TelemetryCriterion.js +++ b/src/plugins/condition/criterion/TelemetryCriterion.js @@ -46,7 +46,7 @@ export default class TelemetryCriterion extends EventEmitter { this.subscription = null; this.telemetryMetadata = null; this.telemetryObjectIdAsString = null; - this.objectAPI.get(this.objectAPI.makeKeyString(telemetryDomainObjectDefinition.key)).then((obj) => this.initialize(obj)); + this.objectAPI.get(this.objectAPI.makeKeyString(this.telemetry)).then((obj) => this.initialize(obj)); } initialize(obj) { From 0ad2d5992446f6c0818d2e53f9af0369e4734df9 Mon Sep 17 00:00:00 2001 From: Joshi Date: Wed, 19 Feb 2020 12:51:15 -0800 Subject: [PATCH 3/4] Fixes tests --- src/plugins/condition/ConditionSpec.js | 20 +++++++++---------- .../criterion/TelemetryCriterionSpec.js | 4 +--- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/plugins/condition/ConditionSpec.js b/src/plugins/condition/ConditionSpec.js index 18334bcada..b29cec9dd9 100644 --- a/src/plugins/condition/ConditionSpec.js +++ b/src/plugins/condition/ConditionSpec.js @@ -64,14 +64,14 @@ describe("The condition", function () { openmct.telemetry.getMetadata.and.returnValue(testTelemetryObject.telemetry.values); testConditionDefinition = { - definition: { + configuration: { trigger: TRIGGER.ANY, criteria: [ { operation: 'equalTo', input: false, - metaDataKey: 'value', - key: testTelemetryObject.identifier + metadata: 'value', + telemetry: testTelemetryObject.identifier } ] } @@ -87,13 +87,13 @@ describe("The condition", function () { }); it("generates criteria with an id", function () { - const testCriterion = testConditionDefinition.definition.criteria[0]; + const testCriterion = testConditionDefinition.configuration.criteria[0]; let criterion = conditionObj.generateCriterion(testCriterion); expect(criterion.id).toBeDefined(); expect(criterion.operation).toEqual(testCriterion.operation); expect(criterion.input).toEqual(testCriterion.input); - expect(criterion.metaDataKey).toEqual(testCriterion.metaDataKey); - expect(criterion.key).toEqual(testCriterion.key); + expect(criterion.metadata).toEqual(testCriterion.metadata); + expect(criterion.telemetry).toEqual(testCriterion.telemetry); }); it("initializes with an id", function () { @@ -104,13 +104,13 @@ describe("The condition", function () { expect(conditionObj.criteria.length).toEqual(1); let criterion = conditionObj.criteria[0]; expect(criterion instanceof TelemetryCriterion).toBeTrue(); - expect(criterion.operator).toEqual(testConditionDefinition.definition.criteria[0].operator); - expect(criterion.input).toEqual(testConditionDefinition.definition.criteria[0].input); - expect(criterion.metaDataKey).toEqual(testConditionDefinition.definition.criteria[0].metaDataKey); + expect(criterion.operator).toEqual(testConditionDefinition.configuration.criteria[0].operator); + expect(criterion.input).toEqual(testConditionDefinition.configuration.criteria[0].input); + expect(criterion.metadata).toEqual(testConditionDefinition.configuration.criteria[0].metadata); }); it("initializes with the trigger from the condition definition", function () { - expect(conditionObj.trigger).toEqual(testConditionDefinition.definition.trigger); + expect(conditionObj.trigger).toEqual(testConditionDefinition.configuration.trigger); }); it("destroys all criteria for a condition", function () { diff --git a/src/plugins/condition/criterion/TelemetryCriterionSpec.js b/src/plugins/condition/criterion/TelemetryCriterionSpec.js index 123fd600fb..8c9cb67671 100644 --- a/src/plugins/condition/criterion/TelemetryCriterionSpec.js +++ b/src/plugins/condition/criterion/TelemetryCriterionSpec.js @@ -64,7 +64,7 @@ describe("The telemetry criterion", function () { testCriterionDefinition = { id: 'test-criterion-id', - key: openmct.objects.makeKeyString(testTelemetryObject.identifier) + telemetry: openmct.objects.makeKeyString(testTelemetryObject.identifier) }; mockListener = jasmine.createSpy('listener'); @@ -85,7 +85,6 @@ describe("The telemetry criterion", function () { it("initializes with a telemetry objectId as string", function () { telemetryCriterion.initialize(testTelemetryObject); expect(telemetryCriterion.telemetryObjectIdAsString).toEqual(testTelemetryObject.identifier.key); - expect(telemetryCriterion.telemetryMetadata.length).toEqual(2); expect(mockListener2).toHaveBeenCalled(); }); @@ -112,7 +111,6 @@ describe("The telemetry criterion", function () { expect(telemetryCriterion.subscription).toBeUndefined(); expect(telemetryCriterion.telemetryObjectIdAsString).toBeUndefined(); expect(telemetryCriterion.telemetryObject).toBeUndefined(); - expect(telemetryCriterion.telemetryMetadata).toBeUndefined(); }); }); From 93e3065b3ea2bbcf2b1c63618caee9f02ee62101 Mon Sep 17 00:00:00 2001 From: Joshi Date: Wed, 19 Feb 2020 12:51:24 -0800 Subject: [PATCH 4/4] Fixes subscription of telelemtry when new criteria is added to a condition --- src/plugins/condition/Condition.js | 22 ++++++------------ .../condition/components/Condition.vue | 23 ++++--------------- .../components/ConditionCollection.vue | 8 +------ .../condition/components/ConditionSet.vue | 3 --- .../condition/components/Criterion.vue | 2 +- .../condition/components/CurrentOutput.vue | 1 - .../condition/criterion/TelemetryCriterion.js | 14 ++++++----- 7 files changed, 21 insertions(+), 52 deletions(-) diff --git a/src/plugins/condition/Condition.js b/src/plugins/condition/Condition.js index 6179674147..9e0a26e041 100644 --- a/src/plugins/condition/Condition.js +++ b/src/plugins/condition/Condition.js @@ -38,8 +38,7 @@ import {computeCondition} from "@/plugins/condition/utils/evaluator"; * telemetry: '', * operation: '', * input: '', -* metadata: '', -* key: 'someTelemetryObjectKey' +* metadata: '' * } * ] * } @@ -84,14 +83,12 @@ export default class ConditionClass extends EventEmitter { } generateCriterion(criterionConfiguration) { - console.log('Identifier', criterionConfiguration); return { id: uuid(), telemetry: criterionConfiguration.telemetry || '', operation: criterionConfiguration.operation || '', input: criterionConfiguration.input === undefined ? [] : criterionConfiguration.input, - metadata: criterionConfiguration.metadata || '', - identifier: criterionConfiguration.identifier || '' + metadata: criterionConfiguration.metadata || '' }; } @@ -111,7 +108,6 @@ export default class ConditionClass extends EventEmitter { */ addCriterion(criterionConfiguration) { let criterionConfigurationWithId = this.generateCriterion(criterionConfiguration || null); - console.log('condition class criterionConfigurationWithId', criterionConfigurationWithId ); let criterion = new TelemetryCriterion(criterionConfigurationWithId, this.openmct); criterion.on('criterionUpdated', (obj) => this.handleCriterionUpdated(obj)); criterion.on('criterionResultUpdated', (obj) => this.handleCriterionResult(obj)); @@ -119,8 +115,6 @@ export default class ConditionClass extends EventEmitter { this.criteria = []; } this.criteria.push(criterion); - //Do we need this here? - this.handleConditionUpdated(); return criterionConfigurationWithId.id; } @@ -142,9 +136,8 @@ export default class ConditionClass extends EventEmitter { updateCriterion(id, criterionConfiguration) { let found = this.findCriterion(id); if (found) { - console.log('updateCriterion found') - const newcriterionConfiguration = this.generateCriterion(criterionConfiguration); - let newCriterion = new TelemetryCriterion(newcriterionConfiguration, this.openmct); + const newCriterionConfiguration = this.generateCriterion(criterionConfiguration); + let newCriterion = new TelemetryCriterion(newCriterionConfiguration, this.openmct); newCriterion.on('criterionUpdated', (obj) => this.handleCriterionUpdated(obj)); newCriterion.on('criterionResultUpdated', (obj) => this.handleCriterionResult(obj)); @@ -156,7 +149,6 @@ export default class ConditionClass extends EventEmitter { if (this.criteriaResults[criterion.id] !== undefined) { delete this.criteriaResults[criterion.id]; } - this.handleConditionUpdated(); } } @@ -187,7 +179,6 @@ export default class ConditionClass extends EventEmitter { let found = this.findCriterion(criterion.id); if (found) { this.criteria[found.index] = criterion.data; - //Most likely don't need this. this.subscribe(); this.emitEvent('conditionUpdated', { trigger: this.trigger, @@ -208,7 +199,9 @@ export default class ConditionClass extends EventEmitter { subscribe() { this.criteria.forEach((criterion) => { - criterion.subscribe(); + if (criterion.isValid()) { + criterion.subscribe(); + } }) } @@ -231,7 +224,6 @@ export default class ConditionClass extends EventEmitter { return success; } - //TODO: implement as part of the evaluator class task. evaluate() { this.result = computeCondition(this.criteriaResults, this.trigger === TRIGGER.ALL); } diff --git a/src/plugins/condition/components/Condition.vue b/src/plugins/condition/components/Condition.vue index a770edb66c..a822f42797 100644 --- a/src/plugins/condition/components/Condition.vue +++ b/src/plugins/condition/components/Condition.vue @@ -68,6 +68,7 @@ v-model="domainObject.configuration.output" class="t-condition-name-input" type="text" + @blur="persist" > @@ -196,10 +197,6 @@ export default { this.initialize(); })); }, - updated() { - //validate telemetry exists, update criteria as needed - // this.persist(); - }, methods: { initialize() { this.setOutput(); @@ -213,11 +210,7 @@ export default { telemetry: '', operation: '', input: '', - metadata: '', - key: { - namespace: '', - key: uuid() - } + metadata: '' }; this.domainObject.configuration.criteria.push(criteriaObject); }, @@ -262,21 +255,13 @@ export default { this.openmct.objects.mutate(this.domainObject, 'configuration', this.domainObject.configuration); }, checkInputValue() { - if (this.selectedOutputOption === 'string') { + if (this.selectedOutputKey === 'string') { this.domainObject.configuration.output = ''; } else { - this.domainObject.configuration.output = this.selectedOutputOption; - } - }, - updateOutputOption(ev) { - if (this.selectedOutputOption === 'string') { - this.domainObject.configuration.output = ''; - } else { - this.domainObject.configuration.output = this.selectedOutputOption; + this.domainObject.configuration.output = this.selectedOutputKey; } }, updateCurrentCondition() { - console.log('condition this.currentConditionIdentifier', this.currentConditionIdentifier); this.$emit('updateCurrentCondition', this.currentConditionIdentifier); }, hasTelemetry(identifier) { diff --git a/src/plugins/condition/components/ConditionCollection.vue b/src/plugins/condition/components/ConditionCollection.vue index b9e9836aba..fc52c2251a 100644 --- a/src/plugins/condition/components/ConditionCollection.vue +++ b/src/plugins/condition/components/ConditionCollection.vue @@ -184,7 +184,6 @@ export default { break; } } - // console.log('conditioncollection before emit currentConditionIdentifier', currentConditionIdentifier) this.$emit('currentConditionUpdated', currentConditionIdentifier); }, addTelemetryObject(domainObject) { @@ -219,7 +218,6 @@ export default { }, updateCurrentCondition(identifier) { this.currentConditionIdentifier = identifier; - // console.log('conditionCollection this.conditionIdentifier', this.currentConditionIdentifier); }, createConditionDomainObject(isDefault) { let conditionObj = { @@ -238,11 +236,7 @@ export default { telemetry: '', operation: '', input: '', - metadata: '', - identifier: { - namespace: '', - key: '' - } + metadata: '' }] }, summary: 'summary description', diff --git a/src/plugins/condition/components/ConditionSet.vue b/src/plugins/condition/components/ConditionSet.vue index bf76cd6029..19f0959076 100644 --- a/src/plugins/condition/components/ConditionSet.vue +++ b/src/plugins/condition/components/ConditionSet.vue @@ -55,7 +55,6 @@ export default { mounted() { let conditionCollection = this.domainObject.configuration.conditionCollection; this.currentConditionIdentifier = conditionCollection.length ? this.updateCurrentCondition(conditionCollection[0]) : null; - // console.log('conditionCollection[0]', conditionCollection[0]); }, methods: { setCurrentCondition() { @@ -66,8 +65,6 @@ export default { } }, updateCurrentCondition(conditionIdentifier) { - // console.log('conditionIdentifier', conditionIdentifier); - this.currentConditionIdentifier = conditionIdentifier; this.setCurrentCondition(); } diff --git a/src/plugins/condition/components/Criterion.vue b/src/plugins/condition/components/Criterion.vue index 5e876d441c..39f38f7f37 100644 --- a/src/plugins/condition/components/Criterion.vue +++ b/src/plugins/condition/components/Criterion.vue @@ -22,7 +22,7 @@ diff --git a/src/plugins/condition/components/CurrentOutput.vue b/src/plugins/condition/components/CurrentOutput.vue index c8457483d6..a8e0dde8bd 100644 --- a/src/plugins/condition/components/CurrentOutput.vue +++ b/src/plugins/condition/components/CurrentOutput.vue @@ -58,7 +58,6 @@ export default { } }, mounted() { - // console.log('this.condition', this.condition); }, updated() { diff --git a/src/plugins/condition/criterion/TelemetryCriterion.js b/src/plugins/condition/criterion/TelemetryCriterion.js index 4392191efb..1ac7a2b150 100644 --- a/src/plugins/condition/criterion/TelemetryCriterion.js +++ b/src/plugins/condition/criterion/TelemetryCriterion.js @@ -29,7 +29,7 @@ export default class TelemetryCriterion extends EventEmitter { * Subscribes/Unsubscribes to telemetry and emits the result * of operations performed on the telemetry data returned and a given input value. * @constructor - * @param telemetryDomainObjectDefinition {id: uuid, operation: enum, input: Array, metaDataKey: string, key: {domainObject.identifier} } + * @param telemetryDomainObjectDefinition {id: uuid, operation: enum, input: Array, metadata: string, key: {domainObject.identifier} } * @param openmct */ constructor(telemetryDomainObjectDefinition, openmct) { @@ -44,7 +44,6 @@ export default class TelemetryCriterion extends EventEmitter { this.input = telemetryDomainObjectDefinition.input; this.metadata = telemetryDomainObjectDefinition.metadata; this.subscription = null; - this.telemetryMetadata = null; this.telemetryObjectIdAsString = null; this.objectAPI.get(this.objectAPI.makeKeyString(this.telemetry)).then((obj) => this.initialize(obj)); } @@ -52,7 +51,6 @@ export default class TelemetryCriterion extends EventEmitter { initialize(obj) { this.telemetryObject = obj; this.telemetryObjectIdAsString = this.objectAPI.makeKeyString(this.telemetryObject.identifier); - this.telemetryMetadata = this.telemetryAPI.getMetadata(this.telemetryObject.identifier); this.emitEvent('criterionUpdated', this); } @@ -77,9 +75,11 @@ export default class TelemetryCriterion extends EventEmitter { let comparator = this.findOperation(this.operation); let params = []; let result = false; - params.push(data[this.metaDataKey]); + params.push(data[this.metadata]); if (this.input instanceof Array && this.input.length) { params.push(this.input[0]); + } else if (this.input) { + params.push(this.input); } if (typeof comparator === 'function') { result = comparator(params); @@ -94,12 +94,15 @@ export default class TelemetryCriterion extends EventEmitter { }); } + isValid() { + return this.telemetryObject && this.metadata && this.operation; + } + /** * Subscribes to the telemetry object and returns an unsubscribe function */ subscribe() { this.unsubscribe(); - console.log('criteria subscribe this.telemetryObject', this.telemetryObject); this.subscription = this.telemetryAPI.subscribe(this.telemetryObject, (datum) => { this.handleSubscription(datum); }); @@ -121,6 +124,5 @@ export default class TelemetryCriterion extends EventEmitter { this.emitEvent('criterionRemoved'); delete this.telemetryObjectIdAsString; delete this.telemetryObject; - delete this.telemetryMetadata; } }