mirror of
https://github.com/nasa/openmct.git
synced 2025-03-24 13:05:35 +00:00
(WIP) conditionSets using ConditionClasses
This commit is contained in:
parent
cd25459ac9
commit
33632ef1dc
@ -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) {
|
||||
super();
|
||||
|
||||
this.openmct = openmct;
|
||||
this.telemetryAPI = this.openmct.telemetry;
|
||||
this.objectAPI = this.openmct.objects;
|
||||
this.id = uuid();
|
||||
if (conditionDefinition.criteria) {
|
||||
this.createCriteria(conditionDefinition.criteria);
|
||||
@ -87,14 +89,21 @@ export default class Condition extends EventEmitter {
|
||||
*/
|
||||
addCriterion(criterionDefinition) {
|
||||
let criterionDefinitionWithId = this.generateCriterion(criterionDefinition || null);
|
||||
let criterion = new TelemetryCriterion(criterionDefinitionWithId, this.openmct);
|
||||
criterion.on('criterionUpdated', this.handleCriterionUpdated);
|
||||
if (!this.criteria) {
|
||||
this.criteria = [];
|
||||
}
|
||||
this.criteria.push(criterion);
|
||||
this.handleConditionUpdated();
|
||||
return criterionDefinitionWithId.id;
|
||||
console.log(criterionDefinitionWithId);
|
||||
this.objectAPI.get(this.objectAPI.makeKeyString(criterionDefinitionWithId.key)).then((obj) => {
|
||||
if (this.telemetryAPI.isTelemetryObject(obj)) {
|
||||
let criterion = new TelemetryCriterion(obj, this.openmct);
|
||||
criterion.on('criterionUpdated', this.handleCriterionUpdated);
|
||||
if (!this.criteria) {
|
||||
this.criteria = [];
|
||||
}
|
||||
this.criteria.push(criterion);
|
||||
this.handleConditionUpdated();
|
||||
return criterionDefinitionWithId.id;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
findCriterion(id) {
|
||||
|
@ -51,6 +51,7 @@
|
||||
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'],
|
||||
@ -73,60 +74,79 @@ export default {
|
||||
},
|
||||
mounted() {
|
||||
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();
|
||||
console.log(this.conditionCollection);
|
||||
|
||||
},
|
||||
methods: {
|
||||
added(conditionDO) {
|
||||
this.conditionCollection.unshift(conditionDO);
|
||||
},
|
||||
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 = {
|
||||
isDefault: false,
|
||||
composition: [],
|
||||
name: "Unnamed Condition",
|
||||
type: "condition",
|
||||
id: conditionObjId,
|
||||
location: this.parentKeyString,
|
||||
identifier: {
|
||||
namespace: "",
|
||||
key: conditionObjId
|
||||
},
|
||||
output: 'test'
|
||||
isDefault: true,
|
||||
name: 'Unnamed Condition',
|
||||
trigger: 'any',
|
||||
criteria: [{
|
||||
operation: '',
|
||||
input: '',
|
||||
metaDataKey: 'sin',
|
||||
key: '2662a903-2c3c-4e46-b2fa-2b9e35a79c8c'
|
||||
}],
|
||||
output: 'Default test'
|
||||
};
|
||||
|
||||
let conditionDOKeyString = this.openmct.objects.makeKeyString(conditionObj.identifier);
|
||||
let newDO = this.instantiate(conditionObj, conditionDOKeyString);
|
||||
newDO.useCapability('location').setPrimaryLocation(this.parentKeyString);
|
||||
let conditionDO = newDO.useCapability('adapter');
|
||||
// let conditionDOKeyString = this.openmct.objects.makeKeyString(conditionObj.identifier);
|
||||
// let newDO = this.instantiate(conditionObj, conditionDOKeyString);
|
||||
// newDO.useCapability('location').setPrimaryLocation(this.parentKeyString);
|
||||
// let conditionDO = newDO.useCapability('adapter');
|
||||
let conditionDO = new ConditionClass(conditionObj, this.openmct);
|
||||
|
||||
this.conditionCollection.unshift(conditionDO);
|
||||
|
||||
this.$set(this.conditionCollection, 0, conditionDO);
|
||||
|
||||
console.log(this.conditionCollection);
|
||||
|
||||
console.log(conditionDO, this.conditionCollection);
|
||||
|
||||
this.persist();
|
||||
},
|
||||
addDefaultCondition() {
|
||||
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({
|
||||
description: 'when all fails',
|
||||
isDefault: true,
|
||||
composition: [],
|
||||
name: "Default",
|
||||
type: "condition",
|
||||
id: conditionObjId,
|
||||
location: this.parentKeyString,
|
||||
identifier: {
|
||||
namespace: "",
|
||||
key: conditionObjId
|
||||
},
|
||||
name: 'Default',
|
||||
description: 'when all fails - condition',
|
||||
trigger: '',
|
||||
criteria: [],
|
||||
output: 'Default test'
|
||||
});
|
||||
},
|
||||
|
@ -24,18 +24,17 @@ import * as EventEmitter from 'eventemitter3';
|
||||
|
||||
export default class TelemetryCriterion extends EventEmitter {
|
||||
|
||||
constructor(telemetryDomainObjectKey, openmct) {
|
||||
constructor(telemetryDomainObject, openmct) {
|
||||
super();
|
||||
|
||||
this.openmct = openmct;
|
||||
this.telemetryObject = this.openmct.objects.get(this.openmct.objects.makeKeyString(telemetryDomainObjectKey));
|
||||
console.log(telemetryDomainObject);
|
||||
this.telemetryAPI = this.openmct.telemetry;
|
||||
this.objectAPI = this.openmct.objects;
|
||||
this.subscription = null;
|
||||
this.telemetryMetadata = null;
|
||||
this.telemetryObjectIdAsString = null;
|
||||
if (this.telemetryAPI.isTelemetryObject(this.telemetryObject)) {
|
||||
this.telemetryObjectIdAsString = this.openmct.objects.makeKeyString(this.telemetryObject.identifier);
|
||||
}
|
||||
this.telemetryObject = telemetryDomainObject;
|
||||
this.telemetryObjectIdAsString = this.objectAPI.makeKeyString(this.telemetryObject.identifier);
|
||||
}
|
||||
|
||||
handleSubscription(datum) {
|
||||
|
@ -50,17 +50,17 @@ describe("The telemetry criterion", function () {
|
||||
}]
|
||||
}
|
||||
};
|
||||
openmct.objects = jasmine.createSpyObj('objects', ['get', 'makeKeyString']);
|
||||
openmct.objects.get.and.returnValue(testTelemetryObject);
|
||||
openmct.objects = jasmine.createSpyObj('objects', ['makeKeyString']);
|
||||
// openmct.objects.get.and.returnValue(testTelemetryObject);
|
||||
openmct.objects.makeKeyString.and.returnValue(testTelemetryObject.identifier.key);
|
||||
openmct.telemetry = jasmine.createSpyObj('telemetry', ['isTelemetryObject', "subscribe"]);
|
||||
openmct.telemetry.isTelemetryObject.and.returnValue(true);
|
||||
openmct.telemetry = jasmine.createSpyObj('telemetry', ["subscribe"]);
|
||||
// openmct.telemetry.isTelemetryObject.and.returnValue(true);
|
||||
openmct.telemetry.subscribe.and.returnValue(function () {});
|
||||
|
||||
mockListener = jasmine.createSpy('listener');
|
||||
|
||||
telemetryCriterion = new TelemetryCriterion(
|
||||
testTelemetryObject.identifier,
|
||||
testTelemetryObject,
|
||||
openmct
|
||||
);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user