mirror of
https://github.com/nasa/openmct.git
synced 2025-06-16 14:18:16 +00:00
Bug fixes:
Ensures that the default condition emits a condition result update Fixes remove condition
This commit is contained in:
@ -58,11 +58,11 @@ export default class ConditionClass extends EventEmitter {
|
|||||||
this.id = this.openmct.objects.makeKeyString(conditionConfiguration.identifier);
|
this.id = this.openmct.objects.makeKeyString(conditionConfiguration.identifier);
|
||||||
this.criteria = [];
|
this.criteria = [];
|
||||||
this.criteriaResults = {};
|
this.criteriaResults = {};
|
||||||
|
this.result = null;
|
||||||
if (conditionConfiguration.configuration.criteria) {
|
if (conditionConfiguration.configuration.criteria) {
|
||||||
this.createCriteria(conditionConfiguration.configuration.criteria);
|
this.createCriteria(conditionConfiguration.configuration.criteria);
|
||||||
}
|
}
|
||||||
this.trigger = conditionConfiguration.configuration.trigger;
|
this.trigger = conditionConfiguration.configuration.trigger;
|
||||||
this.result = null;
|
|
||||||
this.openmct.objects.get(this.id).then(obj => this.observeForChanges(obj));
|
this.openmct.objects.get(this.id).then(obj => this.observeForChanges(obj));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -199,9 +199,7 @@ export default class ConditionClass extends EventEmitter {
|
|||||||
|
|
||||||
subscribe() {
|
subscribe() {
|
||||||
this.criteria.forEach((criterion) => {
|
this.criteria.forEach((criterion) => {
|
||||||
if (criterion.isValid()) {
|
criterion.subscribe();
|
||||||
criterion.subscribe();
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,6 +91,11 @@ export default class ConditionManager extends EventEmitter {
|
|||||||
} else {
|
} else {
|
||||||
this.conditionCollection.unshift(condition);
|
this.conditionCollection.unshift(condition);
|
||||||
}
|
}
|
||||||
|
//There are no criteria for a default condition and hence no subscriptions.
|
||||||
|
//Hence the conditionResult must be manually triggered for it.
|
||||||
|
if (conditionConfiguration.isDefault) {
|
||||||
|
this.handleConditionResult();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
createConditionDomainObject(isDefault, conditionConfiguration) {
|
createConditionDomainObject(isDefault, conditionConfiguration) {
|
||||||
@ -160,7 +165,7 @@ export default class ConditionManager extends EventEmitter {
|
|||||||
if (found) {
|
if (found) {
|
||||||
let index = found.index;
|
let index = found.index;
|
||||||
let condition = this.conditionCollection[index];
|
let condition = this.conditionCollection[index];
|
||||||
let conditionIdAsString = this.openmct.objects.makeKeyString(condition.identifier);
|
let conditionIdAsString = condition.id;
|
||||||
condition.destroyCriteria();
|
condition.destroyCriteria();
|
||||||
condition.off('conditionResultUpdated', this.handleConditionResult.bind(this));
|
condition.off('conditionResultUpdated', this.handleConditionResult.bind(this));
|
||||||
this.conditionCollection.splice(index, 1);
|
this.conditionCollection.splice(index, 1);
|
||||||
@ -169,6 +174,7 @@ export default class ConditionManager extends EventEmitter {
|
|||||||
delete this.conditionResults[conditionIdAsString];
|
delete this.conditionResults[conditionIdAsString];
|
||||||
}
|
}
|
||||||
this.persist();
|
this.persist();
|
||||||
|
this.handleConditionResult();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -201,28 +207,33 @@ export default class ConditionManager extends EventEmitter {
|
|||||||
this.persist();
|
this.persist();
|
||||||
}
|
}
|
||||||
|
|
||||||
handleConditionResult(args) {
|
handleConditionResult(resultObj) {
|
||||||
let idAsString = this.openmct.objects.makeKeyString(args.id);
|
|
||||||
let found = this.findConditionById(idAsString);
|
|
||||||
let conditionCollection = this.domainObject.configuration.conditionCollection;
|
let conditionCollection = this.domainObject.configuration.conditionCollection;
|
||||||
let currentConditionIdentifier = conditionCollection[conditionCollection.length-1];
|
let currentConditionIdentifier = conditionCollection[conditionCollection.length-1];
|
||||||
if (found) {
|
|
||||||
this.conditionResults[idAsString] = args.data.result;
|
|
||||||
|
|
||||||
for (let i = 0, ii = conditionCollection.length - 1; i < ii; i++) {
|
if (resultObj) {
|
||||||
let conditionIdAsString = this.openmct.objects.makeKeyString(conditionCollection[i]);
|
let idAsString = this.openmct.objects.makeKeyString(resultObj.id);
|
||||||
if (this.conditionResults[conditionIdAsString]) {
|
let found = this.findConditionById(idAsString);
|
||||||
//first condition to be true wins
|
if (found) {
|
||||||
currentConditionIdentifier = conditionCollection[i];
|
this.conditionResults[idAsString] = resultObj.data.result;
|
||||||
break;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (let i = 0, ii = conditionCollection.length - 1; i < ii; i++) {
|
||||||
|
let conditionIdAsString = this.openmct.objects.makeKeyString(conditionCollection[i]);
|
||||||
|
if (this.conditionResults[conditionIdAsString]) {
|
||||||
|
//first condition to be true wins
|
||||||
|
currentConditionIdentifier = conditionCollection[i];
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.openmct.objects.get(currentConditionIdentifier).then((obj) => {
|
this.openmct.objects.get(currentConditionIdentifier).then((obj) => {
|
||||||
|
console.log(obj.configuration.output);
|
||||||
this.emit('conditionSetResultUpdated', {
|
this.emit('conditionSetResultUpdated', {
|
||||||
id: this.domainObject.identifier,
|
id: this.domainObject.identifier,
|
||||||
output: obj.configuration.output
|
output: obj.configuration.output,
|
||||||
|
conditionId: currentConditionIdentifier
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -25,55 +25,74 @@ import ConditionManager from './ConditionManager';
|
|||||||
describe('ConditionManager', () => {
|
describe('ConditionManager', () => {
|
||||||
|
|
||||||
let conditionMgr;
|
let conditionMgr;
|
||||||
let testTelemetryObject;
|
let mockListener;
|
||||||
let openmct = {};
|
let openmct = {};
|
||||||
let parentDomainObject;
|
let conditionSetDomainObject = {
|
||||||
let composition;
|
identifier: {
|
||||||
|
namespace: "",
|
||||||
|
key: "600a7372-8d48-4dc4-98b6-548611b1ff7e"
|
||||||
|
},
|
||||||
|
type: "conditionSet",
|
||||||
|
location: "mine",
|
||||||
|
configuration: {
|
||||||
|
conditionCollection: []
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let mockConditionDomainObject = {
|
||||||
|
isDefault: true,
|
||||||
|
type: 'condition',
|
||||||
|
identifier: {
|
||||||
|
namespace: '',
|
||||||
|
key: '1234-5678'
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
beforeAll(function () {
|
function mockAngularComponents() {
|
||||||
testTelemetryObject = {
|
let mockInjector = jasmine.createSpyObj('$injector', ['get']);
|
||||||
identifier:{ namespace: "", key: "test-object"},
|
|
||||||
type: "test-object",
|
let mockInstantiate = jasmine.createSpy('mockInstantiate');
|
||||||
name: "Test Object",
|
mockInstantiate.and.returnValue(mockInstantiate);
|
||||||
telemetry: {
|
|
||||||
values: [{
|
let mockDomainObject = {
|
||||||
key: "some-key",
|
useCapability: function () {
|
||||||
name: "Some attribute",
|
return mockConditionDomainObject;
|
||||||
hints: {
|
|
||||||
domain: 1
|
|
||||||
}
|
|
||||||
}, {
|
|
||||||
key: "some-other-key",
|
|
||||||
name: "Another attribute",
|
|
||||||
hints: {
|
|
||||||
range: 1
|
|
||||||
}
|
|
||||||
}]
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
openmct.objects = jasmine.createSpyObj('objects', ['get', 'makeKeyString']);
|
mockInstantiate.and.callFake(function () {
|
||||||
openmct.objects.get.and.returnValue(testTelemetryObject);
|
return mockDomainObject;
|
||||||
openmct.objects.makeKeyString.and.returnValue(testTelemetryObject.identifier.key);
|
});
|
||||||
openmct.telemetry = jasmine.createSpyObj('telemetry', ['isTelemetryObject']);
|
mockInjector.get.and.callFake(function (service) {
|
||||||
conditionMgr = new ConditionManager(openmct);
|
return {
|
||||||
parentDomainObject = {};
|
'instantiate': mockInstantiate
|
||||||
composition = {};
|
}[service];
|
||||||
|
});
|
||||||
|
|
||||||
|
openmct.$injector = mockInjector;
|
||||||
|
}
|
||||||
|
|
||||||
|
beforeAll(function () {
|
||||||
|
|
||||||
|
mockAngularComponents();
|
||||||
|
|
||||||
|
openmct.objects = jasmine.createSpyObj('objects', ['get', 'makeKeyString', 'observe', 'mutate']);
|
||||||
|
openmct.objects.get.and.returnValues(new Promise(function (resolve, reject) {
|
||||||
|
resolve(conditionSetDomainObject);
|
||||||
|
}), new Promise(function (resolve, reject) {
|
||||||
|
resolve(mockConditionDomainObject);
|
||||||
|
}));
|
||||||
|
openmct.objects.makeKeyString.and.returnValue(conditionSetDomainObject.identifier.key);
|
||||||
|
openmct.objects.observe.and.returnValue(function () {});
|
||||||
|
openmct.objects.mutate.and.returnValue(function () {});
|
||||||
|
conditionMgr = new ConditionManager(conditionSetDomainObject, openmct);
|
||||||
|
mockListener = jasmine.createSpy('mockListener');
|
||||||
|
|
||||||
|
conditionMgr.on('conditionSetResultUpdated', mockListener);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('creates a conditionCollection with a default condition', function () {
|
it('creates a conditionCollection with a default condition', function () {
|
||||||
|
expect(conditionMgr.domainObject.configuration.conditionCollection.length).toEqual(1);
|
||||||
});
|
let defaultConditionIdentifier = conditionMgr.domainObject.configuration.conditionCollection[0];
|
||||||
|
expect(defaultConditionIdentifier).toEqual(mockConditionDomainObject.identifier);
|
||||||
it('adds a condition to the collection with one criterion', function () {
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
it('updates a condition\'s criteria to something valid', function () {
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
it('removes a condition from the conditionCollection', function () {
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -200,12 +200,7 @@ export default {
|
|||||||
this.currentConditionIdentifier = identifier;
|
this.currentConditionIdentifier = identifier;
|
||||||
},
|
},
|
||||||
removeCondition(identifier) {
|
removeCondition(identifier) {
|
||||||
let index = _.findIndex(this.conditionCollection, (condition) => {
|
this.conditionManager.removeCondition(identifier);
|
||||||
let conditionId = this.openmct.objects.makeKeyString(condition);
|
|
||||||
let id = this.openmct.objects.makeKeyString(identifier);
|
|
||||||
return conditionId === id;
|
|
||||||
});
|
|
||||||
this.conditionManager.removeCondition(null, index);
|
|
||||||
},
|
},
|
||||||
reorder(reorderPlan) {
|
reorder(reorderPlan) {
|
||||||
this.conditionManager.reorderConditions(reorderPlan);
|
this.conditionManager.reorderConditions(reorderPlan);
|
||||||
|
@ -72,17 +72,19 @@ export default class TelemetryCriterion extends EventEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
computeResult(data) {
|
computeResult(data) {
|
||||||
let comparator = this.findOperation(this.operation);
|
|
||||||
let params = [];
|
|
||||||
let result = false;
|
let result = false;
|
||||||
params.push(data[this.metadata]);
|
if (data) {
|
||||||
if (this.input instanceof Array && this.input.length) {
|
let comparator = this.findOperation(this.operation);
|
||||||
params.push(this.input[0]);
|
let params = [];
|
||||||
} else if (this.input) {
|
params.push(data[this.metadata]);
|
||||||
params.push(this.input);
|
if (this.input instanceof Array && this.input.length) {
|
||||||
}
|
params.push(this.input[0]);
|
||||||
if (typeof comparator === 'function') {
|
} else if (this.input) {
|
||||||
result = comparator(params);
|
params.push(this.input);
|
||||||
|
}
|
||||||
|
if (typeof comparator === 'function') {
|
||||||
|
result = comparator(params);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -100,12 +102,17 @@ export default class TelemetryCriterion extends EventEmitter {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Subscribes to the telemetry object and returns an unsubscribe function
|
* Subscribes to the telemetry object and returns an unsubscribe function
|
||||||
|
* If the telemetry is not valid, returns nothing
|
||||||
*/
|
*/
|
||||||
subscribe() {
|
subscribe() {
|
||||||
this.unsubscribe();
|
if (this.isValid()) {
|
||||||
this.subscription = this.telemetryAPI.subscribe(this.telemetryObject, (datum) => {
|
this.unsubscribe();
|
||||||
this.handleSubscription(datum);
|
this.subscription = this.telemetryAPI.subscribe(this.telemetryObject, (datum) => {
|
||||||
});
|
this.handleSubscription(datum);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
this.handleSubscription();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user