mirror of
https://github.com/nasa/openmct.git
synced 2025-05-30 22:24:18 +00:00
Updates copyright, jsdocs, small refactor
This commit is contained in:
parent
8034317796
commit
36222d79c6
@ -1,5 +1,5 @@
|
|||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
* Open MCT, Copyright (c) 2014-2019, United States Government
|
* Open MCT, Copyright (c) 2014-2020, United States Government
|
||||||
* as represented by the Administrator of the National Aeronautics and Space
|
* as represented by the Administrator of the National Aeronautics and Space
|
||||||
* Administration. All rights reserved.
|
* Administration. All rights reserved.
|
||||||
*
|
*
|
||||||
@ -27,6 +27,10 @@ import { TRIGGER } from "@/plugins/condition/utils/constants";
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* conditionDefinition = {
|
* conditionDefinition = {
|
||||||
|
* identifier: {
|
||||||
|
* key: '',
|
||||||
|
* namespace: ''
|
||||||
|
* },
|
||||||
* trigger: 'any'/'all',
|
* trigger: 'any'/'all',
|
||||||
* criteria: [
|
* criteria: [
|
||||||
* {
|
* {
|
||||||
@ -38,13 +42,19 @@ import { TRIGGER } from "@/plugins/condition/utils/constants";
|
|||||||
* ]
|
* ]
|
||||||
* }
|
* }
|
||||||
*/
|
*/
|
||||||
export default class Condition extends EventEmitter {
|
export default class ConditionClass extends EventEmitter {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Manages criteria and emits the result of - true or false - based on criteria evaluated.
|
||||||
|
* @constructor
|
||||||
|
* @param conditionDefinition: {identifier: {domainObject.identifier},trigger: enum, criteria: Array of {id: uuid, operation: enum, input: Array, metaDataKey: string, key: {domainObject.identifier} }
|
||||||
|
* @param openmct
|
||||||
|
*/
|
||||||
constructor(conditionDefinition, openmct) {
|
constructor(conditionDefinition, openmct) {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
this.openmct = openmct;
|
this.openmct = openmct;
|
||||||
this.id = uuid();
|
this.id = this.openmct.objects.makeKeyString(conditionDefinition.identifier);
|
||||||
if (conditionDefinition.criteria) {
|
if (conditionDefinition.criteria) {
|
||||||
this.createCriteria(conditionDefinition.criteria);
|
this.createCriteria(conditionDefinition.criteria);
|
||||||
} else {
|
} else {
|
||||||
@ -147,16 +157,21 @@ export default class Condition extends EventEmitter {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
handleCriterionUpdated(id, result) {
|
handleCriterionUpdated(criterion) {
|
||||||
// reevaluate the condition's output
|
let found = this.findCriterion(criterion.id);
|
||||||
// TODO: should we save the result of a criterion here or in the criterion object itself?
|
if (found) {
|
||||||
this.evaluate();
|
this.criteria[found.index] = criterion;
|
||||||
|
this.emitEvent('conditionUpdated', {
|
||||||
|
trigger: this.trigger,
|
||||||
|
criteria: this.criteria
|
||||||
|
});
|
||||||
|
}
|
||||||
this.handleConditionUpdated();
|
this.handleConditionUpdated();
|
||||||
}
|
}
|
||||||
|
|
||||||
handleConditionUpdated() {
|
handleConditionUpdated() {
|
||||||
// trigger an updated event so that consumers can react accordingly
|
// trigger an updated event so that consumers can react accordingly
|
||||||
this.emitResult();
|
this.emitEvent('conditionResultUpdated');
|
||||||
}
|
}
|
||||||
|
|
||||||
getCriteria() {
|
getCriteria() {
|
||||||
@ -181,11 +196,10 @@ export default class Condition extends EventEmitter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
emitResult(data, error) {
|
emitEvent(eventName, data) {
|
||||||
this.emit('conditionUpdated', {
|
this.emit(eventName, {
|
||||||
identifier: this.id,
|
id: this.id,
|
||||||
data: data,
|
data: data
|
||||||
error: error
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
* Open MCT, Copyright (c) 2014-2019, United States Government
|
* Open MCT, Copyright (c) 2014-2020, United States Government
|
||||||
* as represented by the Administrator of the National Aeronautics and Space
|
* as represented by the Administrator of the National Aeronautics and Space
|
||||||
* Administration. All rights reserved.
|
* Administration. All rights reserved.
|
||||||
*
|
*
|
||||||
@ -55,11 +55,13 @@ describe("The condition", function () {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
openmct.objects = jasmine.createSpyObj('objects', ['get', 'makeKeyString']);
|
openmct.objects = jasmine.createSpyObj('objects', ['get', 'makeKeyString']);
|
||||||
openmct.objects.get.and.returnValue(testTelemetryObject);
|
openmct.objects.get.and.returnValue(new Promise(function (resolve, reject) {
|
||||||
openmct.objects.makeKeyString.and.returnValue(testTelemetryObject.identifier.key);
|
resolve(testTelemetryObject);
|
||||||
openmct.telemetry = jasmine.createSpyObj('telemetry', ['isTelemetryObject', 'subscribe']);
|
})); openmct.objects.makeKeyString.and.returnValue(testTelemetryObject.identifier.key);
|
||||||
|
openmct.telemetry = jasmine.createSpyObj('telemetry', ['isTelemetryObject', 'subscribe', 'getMetadata']);
|
||||||
openmct.telemetry.isTelemetryObject.and.returnValue(true);
|
openmct.telemetry.isTelemetryObject.and.returnValue(true);
|
||||||
openmct.telemetry.subscribe.and.returnValue(function () {});
|
openmct.telemetry.subscribe.and.returnValue(function () {});
|
||||||
|
openmct.telemetry.getMetadata.and.returnValue(testTelemetryObject.telemetry.values);
|
||||||
|
|
||||||
testConditionDefinition = {
|
testConditionDefinition = {
|
||||||
trigger: TRIGGER.ANY,
|
trigger: TRIGGER.ANY,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user