(WIP) conditionSets using ConditionClasses

This commit is contained in:
Joshi 2020-01-14 09:52:12 -08:00
parent cd25459ac9
commit 33632ef1dc
4 changed files with 80 additions and 52 deletions

View File

@ -38,12 +38,14 @@ import { TRIGGER } from "@/plugins/condition/utils/constants";
* ] * ]
* } * }
*/ */
export default class Condition extends EventEmitter { export default class ConditionClass extends EventEmitter {
constructor(conditionDefinition, openmct) { constructor(conditionDefinition, openmct) {
super(); super();
this.openmct = openmct; this.openmct = openmct;
this.telemetryAPI = this.openmct.telemetry;
this.objectAPI = this.openmct.objects;
this.id = uuid(); this.id = uuid();
if (conditionDefinition.criteria) { if (conditionDefinition.criteria) {
this.createCriteria(conditionDefinition.criteria); this.createCriteria(conditionDefinition.criteria);
@ -87,14 +89,21 @@ export default class Condition extends EventEmitter {
*/ */
addCriterion(criterionDefinition) { addCriterion(criterionDefinition) {
let criterionDefinitionWithId = this.generateCriterion(criterionDefinition || null); let criterionDefinitionWithId = this.generateCriterion(criterionDefinition || null);
let criterion = new TelemetryCriterion(criterionDefinitionWithId, this.openmct); console.log(criterionDefinitionWithId);
criterion.on('criterionUpdated', this.handleCriterionUpdated); this.objectAPI.get(this.objectAPI.makeKeyString(criterionDefinitionWithId.key)).then((obj) => {
if (!this.criteria) { if (this.telemetryAPI.isTelemetryObject(obj)) {
this.criteria = []; let criterion = new TelemetryCriterion(obj, this.openmct);
} criterion.on('criterionUpdated', this.handleCriterionUpdated);
this.criteria.push(criterion); if (!this.criteria) {
this.handleConditionUpdated(); this.criteria = [];
return criterionDefinitionWithId.id; }
this.criteria.push(criterion);
this.handleConditionUpdated();
return criterionDefinitionWithId.id;
} else {
return null;
}
});
} }
findCriterion(id) { findCriterion(id) {

View File

@ -51,6 +51,7 @@
import Condition from '../../condition/components/Condition.vue'; import Condition from '../../condition/components/Condition.vue';
import ConditionEdit from '../../condition/components/ConditionEdit.vue'; import ConditionEdit from '../../condition/components/ConditionEdit.vue';
import uuid from 'uuid'; import uuid from 'uuid';
import ConditionClass from '../Condition';
export default { export default {
inject: ['openmct', 'domainObject'], inject: ['openmct', 'domainObject'],
@ -73,60 +74,79 @@ export default {
}, },
mounted() { mounted() {
this.instantiate = this.openmct.$injector.get('instantiate'); this.instantiate = this.openmct.$injector.get('instantiate');
this.conditionCollection = this.domainObject.configuration.conditionCollection || this.conditionCollection; this.conditionCollection = this.domainObject.configuration ? this.domainObject.configuration.conditionCollection : [];
this.addDefaultCondition(); this.addDefaultCondition();
console.log(this.conditionCollection);
}, },
methods: { methods: {
added(conditionDO) { added(conditionDO) {
this.conditionCollection.unshift(conditionDO); this.conditionCollection.unshift(conditionDO);
}, },
addCondition() { addCondition() {
let conditionObjId = uuid(); // let conditionObjId = uuid();
// let conditionObj = {
// isDefault: false,
// composition: [],
// name: "Unnamed Condition",
// type: "condition",
// id: conditionObjId,
// location: this.parentKeyString,
// identifier: {
// namespace: "",
// key: conditionObjId
// },
// output: 'test'
// };
let conditionObj = { let conditionObj = {
isDefault: false, isDefault: true,
composition: [], name: 'Unnamed Condition',
name: "Unnamed Condition", trigger: 'any',
type: "condition", criteria: [{
id: conditionObjId, operation: '',
location: this.parentKeyString, input: '',
identifier: { metaDataKey: 'sin',
namespace: "", key: '2662a903-2c3c-4e46-b2fa-2b9e35a79c8c'
key: conditionObjId }],
}, output: 'Default test'
output: 'test'
}; };
let conditionDOKeyString = this.openmct.objects.makeKeyString(conditionObj.identifier); // let conditionDOKeyString = this.openmct.objects.makeKeyString(conditionObj.identifier);
let newDO = this.instantiate(conditionObj, conditionDOKeyString); // let newDO = this.instantiate(conditionObj, conditionDOKeyString);
newDO.useCapability('location').setPrimaryLocation(this.parentKeyString); // newDO.useCapability('location').setPrimaryLocation(this.parentKeyString);
let conditionDO = newDO.useCapability('adapter'); // let conditionDO = newDO.useCapability('adapter');
let conditionDO = new ConditionClass(conditionObj, this.openmct);
this.conditionCollection.unshift(conditionDO); this.conditionCollection.unshift(conditionDO);
this.$set(this.conditionCollection, 0, conditionDO); this.$set(this.conditionCollection, 0, conditionDO);
console.log(this.conditionCollection); console.log(conditionDO, this.conditionCollection);
this.persist(); this.persist();
}, },
addDefaultCondition() { addDefaultCondition() {
this.conditionCollection = []; this.conditionCollection = [];
let conditionObjId = uuid(); // let conditionObjId = uuid();
// this.conditionCollection.push({
// description: 'when all fails',
// isDefault: true,
// composition: [],
// name: "Default",
// type: "condition",
// id: conditionObjId,
// location: this.parentKeyString,
// identifier: {
// namespace: "",
// key: conditionObjId
// },
// output: 'Default test'
// });
this.conditionCollection.push({ this.conditionCollection.push({
description: 'when all fails',
isDefault: true, isDefault: true,
composition: [], name: 'Default',
name: "Default", description: 'when all fails - condition',
type: "condition", trigger: '',
id: conditionObjId, criteria: [],
location: this.parentKeyString,
identifier: {
namespace: "",
key: conditionObjId
},
output: 'Default test' output: 'Default test'
}); });
}, },

View File

@ -24,18 +24,17 @@ import * as EventEmitter from 'eventemitter3';
export default class TelemetryCriterion extends EventEmitter { export default class TelemetryCriterion extends EventEmitter {
constructor(telemetryDomainObjectKey, openmct) { constructor(telemetryDomainObject, openmct) {
super(); super();
this.openmct = openmct; this.openmct = openmct;
this.telemetryObject = this.openmct.objects.get(this.openmct.objects.makeKeyString(telemetryDomainObjectKey)); console.log(telemetryDomainObject);
this.telemetryAPI = this.openmct.telemetry; this.telemetryAPI = this.openmct.telemetry;
this.objectAPI = this.openmct.objects;
this.subscription = null; this.subscription = null;
this.telemetryMetadata = null; this.telemetryMetadata = null;
this.telemetryObjectIdAsString = null; this.telemetryObject = telemetryDomainObject;
if (this.telemetryAPI.isTelemetryObject(this.telemetryObject)) { this.telemetryObjectIdAsString = this.objectAPI.makeKeyString(this.telemetryObject.identifier);
this.telemetryObjectIdAsString = this.openmct.objects.makeKeyString(this.telemetryObject.identifier);
}
} }
handleSubscription(datum) { handleSubscription(datum) {

View File

@ -50,17 +50,17 @@ describe("The telemetry criterion", function () {
}] }]
} }
}; };
openmct.objects = jasmine.createSpyObj('objects', ['get', 'makeKeyString']); openmct.objects = jasmine.createSpyObj('objects', ['makeKeyString']);
openmct.objects.get.and.returnValue(testTelemetryObject); // openmct.objects.get.and.returnValue(testTelemetryObject);
openmct.objects.makeKeyString.and.returnValue(testTelemetryObject.identifier.key); openmct.objects.makeKeyString.and.returnValue(testTelemetryObject.identifier.key);
openmct.telemetry = jasmine.createSpyObj('telemetry', ['isTelemetryObject', "subscribe"]); openmct.telemetry = jasmine.createSpyObj('telemetry', ["subscribe"]);
openmct.telemetry.isTelemetryObject.and.returnValue(true); // openmct.telemetry.isTelemetryObject.and.returnValue(true);
openmct.telemetry.subscribe.and.returnValue(function () {}); openmct.telemetry.subscribe.and.returnValue(function () {});
mockListener = jasmine.createSpy('listener'); mockListener = jasmine.createSpy('listener');
telemetryCriterion = new TelemetryCriterion( telemetryCriterion = new TelemetryCriterion(
testTelemetryObject.identifier, testTelemetryObject,
openmct openmct
); );