From cdb7066bed30dcb78a80b67e503bf7922c7883f6 Mon Sep 17 00:00:00 2001 From: Joshi Date: Wed, 22 Jan 2020 12:07:14 -0800 Subject: [PATCH] Moves condition class initialization to conditionEdit component sets correct condition output in condition edit component --- src/plugins/condition/Condition.js | 39 +++-- .../components/ConditionCollection.vue | 35 ++-- .../condition/components/ConditionEdit.vue | 152 ++++++++++-------- .../condition/criterion/TelemetryCriterion.js | 4 + .../criterion/TelemetryCriterionSpec.js | 2 +- 5 files changed, 140 insertions(+), 92 deletions(-) diff --git a/src/plugins/condition/Condition.js b/src/plugins/condition/Condition.js index f2c5b35eac..15f101f027 100644 --- a/src/plugins/condition/Condition.js +++ b/src/plugins/condition/Condition.js @@ -55,13 +55,24 @@ export default class ConditionClass extends EventEmitter { this.openmct = openmct; this.id = this.openmct.objects.makeKeyString(conditionDefinition.identifier); - if (conditionDefinition.criteria) { - this.createCriteria(conditionDefinition.criteria); - } else { - this.criteria = []; + this.criteria = []; + if (conditionDefinition.definition.criteria) { + this.createCriteria(conditionDefinition.definition.criteria); } - this.trigger = conditionDefinition.trigger; + this.trigger = conditionDefinition.definition.trigger; this.result = null; + this.openmct.objects.get(this.id).then(obj => this.observeForChanges(obj)); + } + + observeForChanges(conditionDO) { + this.stopObservingForChanges = this.openmct.objects.observe(conditionDO, '*', this.update.bind(this)); + } + + update(newDomainObject) { + console.log('ConditionClass: ', newDomainObject.definition); + this.updateTrigger(newDomainObject.definition.trigger); + this.updateCriteria(newDomainObject.definition.criteria); + this.handleConditionUpdated(); } updateTrigger(conditionDefinition) { @@ -103,6 +114,7 @@ export default class ConditionClass extends EventEmitter { this.criteria = []; } this.criteria.push(criterion); + //Do we need this here? this.handleConditionUpdated(); return criterionDefinitionWithId.id; } @@ -147,7 +159,7 @@ export default class ConditionClass extends EventEmitter { let found = this.findCriterion(id); if (found) { let criterion = found.item; - criterion.unsubscribe(); + criterion.destroy(); criterion.off('criterionUpdated', (result) => { this.handleCriterionUpdated(id, result); }); @@ -160,7 +172,8 @@ export default class ConditionClass extends EventEmitter { handleCriterionUpdated(criterion) { let found = this.findCriterion(criterion.id); if (found) { - this.criteria[found.index] = criterion; + this.criteria[found.index] = criterion.data; + //Most likely don't need this. this.emitEvent('conditionUpdated', { trigger: this.trigger, criteria: this.criteria @@ -171,7 +184,8 @@ export default class ConditionClass extends EventEmitter { handleConditionUpdated() { // trigger an updated event so that consumers can react accordingly - this.emitEvent('conditionResultUpdated'); + this.evaluate(); + this.emitEvent('conditionResultUpdated', {result: this.result}); } getCriteria() { @@ -190,7 +204,7 @@ export default class ConditionClass extends EventEmitter { //TODO: implement as part of the evaluator class task. evaluate() { if (this.trigger === TRIGGER.ANY) { - this.result = false; + this.result = true; } else if (this.trigger === TRIGGER.ALL) { this.result = false; } @@ -202,4 +216,11 @@ export default class ConditionClass extends EventEmitter { data: data }); } + + destroy() { + if (typeof this.stopObservingForChanges === 'function') { + this.stopObservingForChanges(); + } + this.destroyCriteria(); + } } diff --git a/src/plugins/condition/components/ConditionCollection.vue b/src/plugins/condition/components/ConditionCollection.vue index edc2198fe7..d5b504541d 100644 --- a/src/plugins/condition/components/ConditionCollection.vue +++ b/src/plugins/condition/components/ConditionCollection.vue @@ -34,10 +34,12 @@ class="conditionArea" >
- +
- +
@@ -49,7 +51,6 @@ import Condition from '../../condition/components/Condition.vue'; import ConditionEdit from '../../condition/components/ConditionEdit.vue'; import uuid from 'uuid'; -import ConditionClass from '../Condition'; export default { inject: ['openmct', 'domainObject'], @@ -81,6 +82,9 @@ export default { if (!this.conditionCollection.length) {this.addCondition(null, true)} }, methods: { + handleConditionResult(args) { + console.log('ConditionCollection: ', args.result); + }, addTelemetry(telemetryDomainObject) { this.telemetryObjs.push(telemetryDomainObject); }, @@ -90,27 +94,25 @@ export default { this.openmct.objects.mutate(conditionDO, 'created', new Date()); this.conditionCollection.unshift(conditionDO.identifier); - - let condition = new ConditionClass(conditionDO, this.openmct); - this.conditions.push(condition); }, getConditionDomainObject(isDefault) { let conditionObj = { isDefault: isDefault, - isCurrent: true, identifier: { namespace: this.domainObject.identifier.namespace, key: uuid() }, - name: isDefault ? 'Default' : 'Unnamed Condition', - trigger: 'any', - 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 - }], - output: 'false', + definition: { + name: isDefault ? 'Default' : 'Unnamed Condition', + output: 'false', + trigger: 'any', + 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 + }] + }, summary: 'summary description' }; let conditionDOKeyString = this.openmct.objects.makeKeyString(conditionObj.identifier); @@ -119,6 +121,7 @@ export default { return newDO.useCapability('adapter'); }, updateCondition(updatedCondition) { + //TODO: this should only happen for reordering let index = _.findIndex(this.conditions, (condition) => condition.id === updatedCondition.id); this.conditions[index] = updatedCondition; }, diff --git a/src/plugins/condition/components/ConditionEdit.vue b/src/plugins/condition/components/ConditionEdit.vue index 85a796d63e..a680689c07 100644 --- a/src/plugins/condition/components/ConditionEdit.vue +++ b/src/plugins/condition/components/ConditionEdit.vue @@ -1,6 +1,6 @@