mirror of
https://github.com/nasa/openmct.git
synced 2024-12-30 09:58:52 +00:00
Adding telemetry options to ConditionEdit
This commit is contained in:
parent
a18a3b6099
commit
4c68c725b1
@ -43,12 +43,10 @@ export default class ConditionClass extends EventEmitter {
|
||||
constructor(conditionDefinition, openmct) {
|
||||
super();
|
||||
|
||||
this.id = uuid();
|
||||
this.name = conditionDefinition.name;
|
||||
this.description = conditionDefinition.description;
|
||||
this.isDefault = conditionDefinition.isDefault;
|
||||
this.openmct = openmct;
|
||||
this.id = this.openmct.objects.makeKeyString(conditionDefinition.identifier);
|
||||
if (conditionDefinition.criteria) {
|
||||
this.createCriteria(conditionDefinition.criteria, openmct);
|
||||
this.createCriteria(conditionDefinition.criteria);
|
||||
} else {
|
||||
this.criteria = [];
|
||||
}
|
||||
@ -73,9 +71,9 @@ export default class ConditionClass extends EventEmitter {
|
||||
};
|
||||
}
|
||||
|
||||
createCriteria(criterionDefinitions, openmct) {
|
||||
createCriteria(criterionDefinitions) {
|
||||
criterionDefinitions.forEach((criterionDefinition) => {
|
||||
this.addCriterion(criterionDefinition, openmct);
|
||||
this.addCriterion(criterionDefinition);
|
||||
});
|
||||
}
|
||||
|
||||
@ -87,22 +85,18 @@ export default class ConditionClass extends EventEmitter {
|
||||
/**
|
||||
* adds criterion to the condition.
|
||||
*/
|
||||
addCriterion(criterionDefinition, openmct) {
|
||||
addCriterion(criterionDefinition) {
|
||||
let criterionDefinitionWithId = this.generateCriterion(criterionDefinition || null);
|
||||
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 = [];
|
||||
}
|
||||
this.criteria.push(criterion);
|
||||
this.handleConditionUpdated();
|
||||
return criterionDefinitionWithId.id;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
let criterion = new TelemetryCriterion(criterionDefinitionWithId, this.openmct);
|
||||
criterion.on('criterionUpdated', (data) => {
|
||||
this.handleCriterionUpdated(data);
|
||||
});
|
||||
if (!this.criteria) {
|
||||
this.criteria = [];
|
||||
}
|
||||
this.criteria.push(criterion);
|
||||
this.handleConditionUpdated();
|
||||
return criterionDefinitionWithId.id;
|
||||
}
|
||||
|
||||
findCriterion(id) {
|
||||
@ -120,11 +114,11 @@ export default class ConditionClass extends EventEmitter {
|
||||
return criterion;
|
||||
}
|
||||
|
||||
updateCriterion(id, criterionDefinition, openmct) {
|
||||
updateCriterion(id, criterionDefinition) {
|
||||
let found = this.findCriterion(id);
|
||||
if (found) {
|
||||
const newCriterionDefinition = this.generateCriterion(criterionDefinition);
|
||||
let newCriterion = new TelemetryCriterion(newCriterionDefinition, openmct);
|
||||
let newCriterion = new TelemetryCriterion(newCriterionDefinition, this.openmct);
|
||||
let criterion = found.item;
|
||||
criterion.unsubscribe();
|
||||
criterion.off('criterionUpdated', (result) => {
|
||||
@ -155,14 +149,19 @@ export default class ConditionClass extends EventEmitter {
|
||||
return false;
|
||||
}
|
||||
|
||||
handleCriterionUpdated(id, result) {
|
||||
handleCriterionUpdated(criterion) {
|
||||
// reevaluate the condition's output
|
||||
// TODO: should we save the result of a criterion here or in the criterion object itself?
|
||||
this.evaluate();
|
||||
this.handleConditionUpdated();
|
||||
let found = this.findCriterion(criterion.id);
|
||||
if (found) {
|
||||
this.criteria[found.index] = criterion;
|
||||
this.handleConditionUpdated();
|
||||
}
|
||||
// this.handleConditionUpdated();
|
||||
}
|
||||
|
||||
handleConditionUpdated() {
|
||||
console.log(this);
|
||||
// trigger an updated event so that consumers can react accordingly
|
||||
this.emitResult();
|
||||
}
|
||||
@ -191,11 +190,9 @@ export default class ConditionClass extends EventEmitter {
|
||||
|
||||
emitResult() {
|
||||
this.emit('conditionUpdated', {
|
||||
identifier: this.id,
|
||||
data: {
|
||||
trigger: this.trigger,
|
||||
criteria: this.criteria
|
||||
}
|
||||
id: this.id,
|
||||
trigger: this.trigger,
|
||||
criteria: this.criteria
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -30,7 +30,7 @@
|
||||
</div>
|
||||
<div class="condition-collection">
|
||||
<div v-for="condition in conditionCollection"
|
||||
:key="condition.key"
|
||||
:key="condition.id"
|
||||
class="conditionArea"
|
||||
>
|
||||
<div v-if="isEditing">
|
||||
@ -64,7 +64,8 @@ export default {
|
||||
return {
|
||||
expanded: true,
|
||||
parentKeyString: this.openmct.objects.makeKeyString(this.domainObject.identifier),
|
||||
conditionCollection: []
|
||||
conditionCollection: [],
|
||||
conditions: []
|
||||
};
|
||||
},
|
||||
destroyed() {
|
||||
@ -72,39 +73,52 @@ export default {
|
||||
},
|
||||
mounted() {
|
||||
this.telemetryObjs = [];
|
||||
this.instantiate = this.openmct.$injector.get('instantiate');
|
||||
this.composition = this.openmct.composition.get(this.domainObject);
|
||||
this.composition.on('add', this.addTelemetry);
|
||||
this.composition.load();
|
||||
this.conditionCollection = this.domainObject.configuration ? this.domainObject.configuration.conditionCollection : [];
|
||||
if (!this.conditionCollection.length) {this.addCondition(true)}
|
||||
if (!this.conditionCollection.length) {this.addCondition(null, true)}
|
||||
},
|
||||
methods: {
|
||||
addTelemetry(domainObjectAdded) {
|
||||
this.telemetryObjs.push(domainObjectAdded);
|
||||
console.log(this.telemetryObjs);
|
||||
addTelemetry(telemetryDomainObject) {
|
||||
this.telemetryObjs.push(telemetryDomainObject);
|
||||
},
|
||||
addCondition(isDefault) {
|
||||
if (isDefault !== true) {isDefault = false}
|
||||
addCondition(event, isDefault) {
|
||||
let conditionDO = this.getConditionDomainObject(!!isDefault);
|
||||
this.conditionCollection.unshift(conditionDO);
|
||||
|
||||
let condition = new ConditionClass(conditionDO, this.openmct);
|
||||
this.conditions.push(condition);
|
||||
},
|
||||
getConditionDomainObject(isDefault) {
|
||||
let conditionObj = {
|
||||
isDefault: isDefault,
|
||||
identifier: {
|
||||
namespace: "",
|
||||
key: uuid()
|
||||
},
|
||||
name: isDefault ? 'Default' : 'Unnamed Condition',
|
||||
trigger: 'any',
|
||||
criteria: isDefault ? [] : [{
|
||||
operation: '',
|
||||
input: '',
|
||||
metaDataKey: 'sin',
|
||||
key: isDefault ? '' : this.telemetryObjs.length ? this.openmct.objects.makeKeyString(this.telemetryObjs[0].identifier) : ''
|
||||
metaDataKey: this.openmct.telemetry.getMetadata(this.telemetryObjs[0]).values()[0].key,
|
||||
key: this.telemetryObjs.length ? this.openmct.objects.makeKeyString(this.telemetryObjs[0].identifier) : null
|
||||
}],
|
||||
output: 'Default test'
|
||||
output: 'Default test',
|
||||
type: 'condition'
|
||||
};
|
||||
|
||||
let conditionDO = new ConditionClass(conditionObj, this.openmct);
|
||||
console.log(JSON.stringify(conditionDO));
|
||||
this.conditionCollection.unshift(conditionDO);
|
||||
console.log(JSON.stringify(this.conditionCollection));
|
||||
let conditionDOKeyString = this.openmct.objects.makeKeyString(conditionObj.identifier);
|
||||
let newDO = this.instantiate(conditionObj, conditionDOKeyString);
|
||||
return newDO.useCapability('adapter');
|
||||
},
|
||||
updateCondition(updatedCondition) {
|
||||
let index = _.findIndex(this.conditions, (condition) => condition.id === updatedCondition.id);
|
||||
this.conditions[index] = updatedCondition;
|
||||
},
|
||||
removeCondition(identifier) {
|
||||
let index = _.findIndex(this.conditionCollection, (condition) => this.openmct.objects.makeKeyString(identifier) === condition.identifier.key);
|
||||
|
||||
this.conditionCollection.splice(index, 1);
|
||||
},
|
||||
reorder(reorderPlan) {
|
||||
|
@ -36,7 +36,7 @@
|
||||
<div>
|
||||
<ul>
|
||||
<li>
|
||||
<label>Condition Name</label>
|
||||
<label>Condition Names</label>
|
||||
<span class="controls">
|
||||
<input v-model="condition.name"
|
||||
class="t-rule-name-input"
|
||||
@ -44,6 +44,14 @@
|
||||
>
|
||||
</span>
|
||||
</li>
|
||||
<li v-if="telemetryObject">
|
||||
<label>when</label>
|
||||
<span class="controls">
|
||||
<select class="">
|
||||
<option :value="telemetryObject.key">@{{ telemetryObject.name }}</option>
|
||||
</select>
|
||||
</span>
|
||||
</li>
|
||||
<li>
|
||||
<label>Output</label>
|
||||
<span class="controls">
|
||||
@ -74,14 +82,17 @@ export default {
|
||||
return {
|
||||
expanded: true,
|
||||
name: this.condition.name,
|
||||
description: this.condition.description
|
||||
description: this.condition.description,
|
||||
telemetryObject: this.telemetryObject
|
||||
};
|
||||
},
|
||||
mounted() {
|
||||
this.updateTelemetry();
|
||||
},
|
||||
updated() {
|
||||
console.log('updated');
|
||||
this.persist()
|
||||
this.persist();
|
||||
// this.updateTelemetry();
|
||||
},
|
||||
methods: {
|
||||
removeCondition(ev) {
|
||||
@ -91,6 +102,16 @@ export default {
|
||||
|
||||
this.domainObject.configuration.conditionCollection.splice(index, 1);
|
||||
},
|
||||
updateTelemetry() {
|
||||
this.telemetryObject = this.hasTelemetry() ? this.openmct.objects.get(this.condition.criteria[0].key) : null;
|
||||
if (this.telemetryObject) {
|
||||
this.telemetryMetadata = this.openmct.telemetry.getMetadata().values();
|
||||
}
|
||||
console.log('ConditionEdit', this.telemetryObject);
|
||||
},
|
||||
hasTelemetry() {
|
||||
return this.condition.criteria.length && this.condition.criteria[0].key;
|
||||
},
|
||||
persist(index) {
|
||||
if (index) {
|
||||
this.openmct.objects.mutate(this.domainObject, `configuration.conditionCollection[${index}]`, this.domainObject.configuration.conditionCollection[index]);
|
||||
|
@ -24,13 +24,21 @@ import * as EventEmitter from 'eventemitter3';
|
||||
|
||||
export default class TelemetryCriterion extends EventEmitter {
|
||||
|
||||
constructor(telemetryDomainObject, openmct) {
|
||||
constructor(telemetryDomainObjectDefinition, openmct) {
|
||||
super();
|
||||
|
||||
this.id = telemetryDomainObjectDefinition.id;
|
||||
this.subscription = null;
|
||||
this.telemetryMetadata = null;
|
||||
this.telemetryObject = telemetryDomainObject;
|
||||
this.telemetryObjectIdAsString = openmct.objects.makeKeyString(this.telemetryObject.identifier);
|
||||
this.telemetryObjectIdAsString = null;
|
||||
openmct.objects.get(openmct.objects.makeKeyString(telemetryDomainObjectDefinition.key)).then((obj) => {
|
||||
if (openmct.telemetry.isTelemetryObject(obj)) {
|
||||
this.telemetryObject = obj;
|
||||
this.telemetryObjectIdAsString = openmct.objects.makeKeyString(this.telemetryObject.identifier);
|
||||
this.telemetryMetadata = openmct.telemetry.getMetadata(this.telemetryObject.identifier);
|
||||
this.emit('criterionUpdated', this);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
handleSubscription(datum) {
|
||||
@ -48,7 +56,7 @@ export default class TelemetryCriterion extends EventEmitter {
|
||||
|
||||
emitResult(data, error) {
|
||||
this.emit('criterionUpdated', {
|
||||
identifier: this.telemetryObjectIdAsString,
|
||||
identifier: this.id,
|
||||
data: data,
|
||||
error: error
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user