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