mirror of
https://github.com/nasa/openmct.git
synced 2024-12-21 14:07:50 +00:00
(WIP) Fixes cyclic error while saving conditionCollection
This commit is contained in:
parent
31736fa194
commit
81b8a76f1b
@ -43,12 +43,12 @@ 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();
|
||||
this.name = conditionDefinition.name;
|
||||
this.description = conditionDefinition.description;
|
||||
this.isDefault = conditionDefinition.isDefault;
|
||||
if (conditionDefinition.criteria) {
|
||||
this.createCriteria(conditionDefinition.criteria);
|
||||
this.createCriteria(conditionDefinition.criteria, openmct);
|
||||
} else {
|
||||
this.criteria = [];
|
||||
}
|
||||
@ -73,9 +73,9 @@ export default class ConditionClass extends EventEmitter {
|
||||
};
|
||||
}
|
||||
|
||||
createCriteria(criterionDefinitions) {
|
||||
createCriteria(criterionDefinitions, openmct) {
|
||||
criterionDefinitions.forEach((criterionDefinition) => {
|
||||
this.addCriterion(criterionDefinition);
|
||||
this.addCriterion(criterionDefinition, openmct);
|
||||
});
|
||||
}
|
||||
|
||||
@ -87,12 +87,11 @@ export default class ConditionClass extends EventEmitter {
|
||||
/**
|
||||
* adds criterion to the condition.
|
||||
*/
|
||||
addCriterion(criterionDefinition) {
|
||||
addCriterion(criterionDefinition, openmct) {
|
||||
let criterionDefinitionWithId = this.generateCriterion(criterionDefinition || null);
|
||||
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);
|
||||
openmct.objects.get(openmct.objects.makeKeyString(criterionDefinitionWithId.key)).then((obj) => {
|
||||
if (openmct.telemetry.isTelemetryObject(obj)) {
|
||||
let criterion = new TelemetryCriterion(obj, openmct);
|
||||
criterion.on('criterionUpdated', this.handleCriterionUpdated);
|
||||
if (!this.criteria) {
|
||||
this.criteria = [];
|
||||
@ -121,11 +120,11 @@ export default class ConditionClass extends EventEmitter {
|
||||
return criterion;
|
||||
}
|
||||
|
||||
updateCriterion(id, criterionDefinition) {
|
||||
updateCriterion(id, criterionDefinition, openmct) {
|
||||
let found = this.findCriterion(id);
|
||||
if (found) {
|
||||
const newCriterionDefinition = this.generateCriterion(criterionDefinition);
|
||||
let newCriterion = new TelemetryCriterion(newCriterionDefinition, this.openmct);
|
||||
let newCriterion = new TelemetryCriterion(newCriterionDefinition, openmct);
|
||||
let criterion = found.item;
|
||||
criterion.unsubscribe();
|
||||
criterion.off('criterionUpdated', (result) => {
|
||||
@ -190,11 +189,13 @@ export default class ConditionClass extends EventEmitter {
|
||||
}
|
||||
}
|
||||
|
||||
emitResult(data, error) {
|
||||
emitResult() {
|
||||
this.emit('conditionUpdated', {
|
||||
identifier: this.id,
|
||||
data: data,
|
||||
error: error
|
||||
data: {
|
||||
trigger: this.trigger,
|
||||
criteria: this.criteria
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -72,20 +72,17 @@ 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 : [];
|
||||
if (!this.conditionCollection.length) {this.addCondition(true)}
|
||||
},
|
||||
methods: {
|
||||
added(conditionDO) {
|
||||
this.conditionCollection.unshift(conditionDO);
|
||||
},
|
||||
addCondition(isDefault) {
|
||||
if (isDefault !== true) {isDefault = false}
|
||||
let conditionObj = {
|
||||
isDefault: true,
|
||||
isDefault: isDefault,
|
||||
name: isDefault ? 'Default' : 'Unnamed Condition',
|
||||
trigger: 'any',
|
||||
criteria: [{
|
||||
criteria: isDefault ? [] : [{
|
||||
operation: '',
|
||||
input: '',
|
||||
metaDataKey: 'sin',
|
||||
@ -94,13 +91,10 @@ export default {
|
||||
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 conditionDO = new ConditionClass(conditionObj, this.openmct);
|
||||
|
||||
console.log(JSON.stringify(conditionDO));
|
||||
this.conditionCollection.unshift(conditionDO);
|
||||
console.log(JSON.stringify(this.conditionCollection));
|
||||
},
|
||||
removeCondition(identifier) {
|
||||
let index = _.findIndex(this.conditionCollection, (condition) => this.openmct.objects.makeKeyString(identifier) === condition.identifier.key);
|
||||
|
@ -27,14 +27,10 @@ export default class TelemetryCriterion extends EventEmitter {
|
||||
constructor(telemetryDomainObject, openmct) {
|
||||
super();
|
||||
|
||||
this.openmct = openmct;
|
||||
console.log(telemetryDomainObject);
|
||||
this.telemetryAPI = this.openmct.telemetry;
|
||||
this.objectAPI = this.openmct.objects;
|
||||
this.subscription = null;
|
||||
this.telemetryMetadata = null;
|
||||
this.telemetryObject = telemetryDomainObject;
|
||||
this.telemetryObjectIdAsString = this.objectAPI.makeKeyString(this.telemetryObject.identifier);
|
||||
this.telemetryObjectIdAsString = openmct.objects.makeKeyString(this.telemetryObject.identifier);
|
||||
}
|
||||
|
||||
handleSubscription(datum) {
|
||||
@ -61,8 +57,8 @@ export default class TelemetryCriterion extends EventEmitter {
|
||||
/**
|
||||
* Subscribes to the telemetry object and returns an unsubscribe function
|
||||
*/
|
||||
subscribe() {
|
||||
this.subscription = this.telemetryAPI.subscribe(this.telemetryObject, (datum) => {
|
||||
subscribe(openmct) {
|
||||
this.subscription = openmct.telemetry.subscribe(this.telemetryObject, (datum) => {
|
||||
this.handleSubscription(datum);
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user