diff --git a/src/plugins/condition/Condition.js b/src/plugins/condition/Condition.js index 8eb3e05cd7..556feb766b 100644 --- a/src/plugins/condition/Condition.js +++ b/src/plugins/condition/Condition.js @@ -191,14 +191,12 @@ export default class ConditionClass extends EventEmitter { handleCriterionResult(eventData) { const id = eventData.id; - const conditionData = eventData.data; - + if (this.findCriterion(id)) { this.criteriaResults[id] = eventData.data.result; } - conditionData.result = computeCondition(this.criteriaResults, this.trigger === TRIGGER.ALL); - this.emitEvent('conditionResultUpdated', conditionData); + this.handleConditionUpdated(eventData.data); } subscribe() { @@ -208,6 +206,14 @@ export default class ConditionClass extends EventEmitter { }) } + handleConditionUpdated(datum) { + // trigger an updated event so that consumers can react accordingly + this.evaluate(); + this.emitEvent('conditionResultUpdated', + Object.assign({}, datum, { result: this.result }) + ); + } + getCriteria() { return this.criteria; } @@ -221,6 +227,10 @@ export default class ConditionClass extends EventEmitter { return success; } + evaluate() { + this.result = computeCondition(this.criteriaResults, this.trigger === TRIGGER.ALL); + } + emitEvent(eventName, data) { this.emit(eventName, { id: this.id, diff --git a/src/plugins/condition/ConditionManager.js b/src/plugins/condition/ConditionManager.js index 67d71405ed..25a3512155 100644 --- a/src/plugins/condition/ConditionManager.js +++ b/src/plugins/condition/ConditionManager.js @@ -29,6 +29,8 @@ export default class ConditionManager extends EventEmitter { super(); this.domainObject = domainObject; this.openmct = openmct; + this.timeAPI = this.openmct.time; + this.latestTimestamp = {}; this.instantiate = this.openmct.$injector.get('instantiate'); this.initialize(); } @@ -213,6 +215,7 @@ export default class ConditionManager extends EventEmitter { if (this.findConditionById(idAsString)) { this.conditionResults[idAsString] = resultObj.data.result; } + this.updateTimestamp(resultObj.data); } for (let i = 0; i < conditionCollection.length - 1; i++) { @@ -226,18 +229,28 @@ export default class ConditionManager extends EventEmitter { this.openmct.objects.get(currentConditionIdentifier).then((obj) => { this.emit('conditionSetResultUpdated', - Object.assign({}, - resultObj ? resultObj.data : {}, + Object.assign( { output: obj.configuration.output, id: this.domainObject.identifier, conditionId: currentConditionIdentifier - } + }, + this.latestTimestamp ) ) }); } + updateTimestamp(timestamp) { + this.timeAPI.getAllTimeSystems().forEach(timeSystem => { + if (!this.latestTimestamp[timeSystem.key] + || timestamp[timeSystem.key] > this.latestTimestamp[timeSystem.key] + ) { + this.latestTimestamp[timeSystem.key] = timestamp[timeSystem.key]; + } + }); + } + persist() { this.openmct.objects.mutate(this.domainObject, 'configuration.conditionCollection', this.domainObject.configuration.conditionCollection); } diff --git a/src/plugins/condition/criterion/TelemetryCriterion.js b/src/plugins/condition/criterion/TelemetryCriterion.js index 4c4958036a..c9b9498b21 100644 --- a/src/plugins/condition/criterion/TelemetryCriterion.js +++ b/src/plugins/condition/criterion/TelemetryCriterion.js @@ -56,12 +56,14 @@ export default class TelemetryCriterion extends EventEmitter { } handleSubscription(data) { - const datum = {}; - const timeSystemKey = this.timeAPI.timeSystem().key; - - datum.result = this.computeResult(data); - if (data && data[timeSystemKey]) { - datum[timeSystemKey] = data[timeSystemKey] + const datum = { + result: this.computeResult(data) + }; + if (data) { + // TODO check back to see if we should format times here + this.timeAPI.getAllTimeSystems().forEach(timeSystem => { + datum[timeSystem.key] = data[timeSystem.key] + }); } this.emitEvent('criterionResultUpdated', datum); diff --git a/src/plugins/condition/criterion/TelemetryCriterionSpec.js b/src/plugins/condition/criterion/TelemetryCriterionSpec.js index 86ccbd6a68..e68e7c5f9d 100644 --- a/src/plugins/condition/criterion/TelemetryCriterionSpec.js +++ b/src/plugins/condition/criterion/TelemetryCriterionSpec.js @@ -63,10 +63,11 @@ describe("The telemetry criterion", function () { openmct.telemetry.getMetadata.and.returnValue(testTelemetryObject.telemetry.values); openmct.time = jasmine.createSpyObj('timeAPI', - ['timeSystem', 'bounds'] + ['timeSystem', 'bounds', 'getAllTimeSystems'] ); openmct.time.timeSystem.and.returnValue({key: 'system'}); openmct.time.bounds.and.returnValue({start: 0, end: 1}); + openmct.time.getAllTimeSystems.and.returnValue([{key: 'system'}]); testCriterionDefinition = { id: 'test-criterion-id',