Adding telemetry options to ConditionEdit

This commit is contained in:
Joshi 2020-01-15 10:51:45 -08:00
parent a18a3b6099
commit 4c68c725b1
4 changed files with 95 additions and 55 deletions

View File

@ -43,12 +43,10 @@ export default class ConditionClass extends EventEmitter {
constructor(conditionDefinition, openmct) { constructor(conditionDefinition, openmct) {
super(); super();
this.id = uuid(); this.openmct = openmct;
this.name = conditionDefinition.name; this.id = this.openmct.objects.makeKeyString(conditionDefinition.identifier);
this.description = conditionDefinition.description;
this.isDefault = conditionDefinition.isDefault;
if (conditionDefinition.criteria) { if (conditionDefinition.criteria) {
this.createCriteria(conditionDefinition.criteria, openmct); this.createCriteria(conditionDefinition.criteria);
} else { } else {
this.criteria = []; this.criteria = [];
} }
@ -73,9 +71,9 @@ export default class ConditionClass extends EventEmitter {
}; };
} }
createCriteria(criterionDefinitions, openmct) { createCriteria(criterionDefinitions) {
criterionDefinitions.forEach((criterionDefinition) => { 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. * adds criterion to the condition.
*/ */
addCriterion(criterionDefinition, openmct) { addCriterion(criterionDefinition) {
let criterionDefinitionWithId = this.generateCriterion(criterionDefinition || null); let criterionDefinitionWithId = this.generateCriterion(criterionDefinition || null);
openmct.objects.get(openmct.objects.makeKeyString(criterionDefinitionWithId.key)).then((obj) => { let criterion = new TelemetryCriterion(criterionDefinitionWithId, this.openmct);
if (openmct.telemetry.isTelemetryObject(obj)) { criterion.on('criterionUpdated', (data) => {
let criterion = new TelemetryCriterion(obj, openmct); this.handleCriterionUpdated(data);
criterion.on('criterionUpdated', this.handleCriterionUpdated);
if (!this.criteria) {
this.criteria = [];
}
this.criteria.push(criterion);
this.handleConditionUpdated();
return criterionDefinitionWithId.id;
} else {
return null;
}
}); });
if (!this.criteria) {
this.criteria = [];
}
this.criteria.push(criterion);
this.handleConditionUpdated();
return criterionDefinitionWithId.id;
} }
findCriterion(id) { findCriterion(id) {
@ -120,11 +114,11 @@ export default class ConditionClass extends EventEmitter {
return criterion; return criterion;
} }
updateCriterion(id, criterionDefinition, openmct) { updateCriterion(id, criterionDefinition) {
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, openmct); let newCriterion = new TelemetryCriterion(newCriterionDefinition, this.openmct);
let criterion = found.item; let criterion = found.item;
criterion.unsubscribe(); criterion.unsubscribe();
criterion.off('criterionUpdated', (result) => { criterion.off('criterionUpdated', (result) => {
@ -155,14 +149,19 @@ export default class ConditionClass extends EventEmitter {
return false; return false;
} }
handleCriterionUpdated(id, result) { handleCriterionUpdated(criterion) {
// reevaluate the condition's output // reevaluate the condition's output
// TODO: should we save the result of a criterion here or in the criterion object itself? // TODO: should we save the result of a criterion here or in the criterion object itself?
this.evaluate(); let found = this.findCriterion(criterion.id);
this.handleConditionUpdated(); if (found) {
this.criteria[found.index] = criterion;
this.handleConditionUpdated();
}
// this.handleConditionUpdated();
} }
handleConditionUpdated() { handleConditionUpdated() {
console.log(this);
// trigger an updated event so that consumers can react accordingly // trigger an updated event so that consumers can react accordingly
this.emitResult(); this.emitResult();
} }
@ -191,11 +190,9 @@ export default class ConditionClass extends EventEmitter {
emitResult() { emitResult() {
this.emit('conditionUpdated', { this.emit('conditionUpdated', {
identifier: this.id, id: this.id,
data: { trigger: this.trigger,
trigger: this.trigger, criteria: this.criteria
criteria: this.criteria
}
}); });
} }
} }

View File

@ -30,7 +30,7 @@
</div> </div>
<div class="condition-collection"> <div class="condition-collection">
<div v-for="condition in conditionCollection" <div v-for="condition in conditionCollection"
:key="condition.key" :key="condition.id"
class="conditionArea" class="conditionArea"
> >
<div v-if="isEditing"> <div v-if="isEditing">
@ -64,7 +64,8 @@ export default {
return { return {
expanded: true, expanded: true,
parentKeyString: this.openmct.objects.makeKeyString(this.domainObject.identifier), parentKeyString: this.openmct.objects.makeKeyString(this.domainObject.identifier),
conditionCollection: [] conditionCollection: [],
conditions: []
}; };
}, },
destroyed() { destroyed() {
@ -72,39 +73,52 @@ export default {
}, },
mounted() { mounted() {
this.telemetryObjs = []; this.telemetryObjs = [];
this.instantiate = this.openmct.$injector.get('instantiate');
this.composition = this.openmct.composition.get(this.domainObject); this.composition = this.openmct.composition.get(this.domainObject);
this.composition.on('add', this.addTelemetry); this.composition.on('add', this.addTelemetry);
this.composition.load();
this.conditionCollection = this.domainObject.configuration ? this.domainObject.configuration.conditionCollection : []; 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: { methods: {
addTelemetry(domainObjectAdded) { addTelemetry(telemetryDomainObject) {
this.telemetryObjs.push(domainObjectAdded); this.telemetryObjs.push(telemetryDomainObject);
console.log(this.telemetryObjs);
}, },
addCondition(isDefault) { addCondition(event, isDefault) {
if (isDefault !== true) {isDefault = false} let conditionDO = this.getConditionDomainObject(!!isDefault);
this.conditionCollection.unshift(conditionDO);
let condition = new ConditionClass(conditionDO, this.openmct);
this.conditions.push(condition);
},
getConditionDomainObject(isDefault) {
let conditionObj = { let conditionObj = {
isDefault: isDefault, isDefault: isDefault,
identifier: {
namespace: "",
key: uuid()
},
name: isDefault ? 'Default' : 'Unnamed Condition', name: isDefault ? 'Default' : 'Unnamed Condition',
trigger: 'any', trigger: 'any',
criteria: isDefault ? [] : [{ criteria: isDefault ? [] : [{
operation: '', operation: '',
input: '', input: '',
metaDataKey: 'sin', metaDataKey: this.openmct.telemetry.getMetadata(this.telemetryObjs[0]).values()[0].key,
key: isDefault ? '' : this.telemetryObjs.length ? this.openmct.objects.makeKeyString(this.telemetryObjs[0].identifier) : '' key: this.telemetryObjs.length ? this.openmct.objects.makeKeyString(this.telemetryObjs[0].identifier) : null
}], }],
output: 'Default test' output: 'Default test',
type: 'condition'
}; };
let conditionDOKeyString = this.openmct.objects.makeKeyString(conditionObj.identifier);
let conditionDO = new ConditionClass(conditionObj, this.openmct); let newDO = this.instantiate(conditionObj, conditionDOKeyString);
console.log(JSON.stringify(conditionDO)); return newDO.useCapability('adapter');
this.conditionCollection.unshift(conditionDO); },
console.log(JSON.stringify(this.conditionCollection)); updateCondition(updatedCondition) {
let index = _.findIndex(this.conditions, (condition) => condition.id === updatedCondition.id);
this.conditions[index] = updatedCondition;
}, },
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);
this.conditionCollection.splice(index, 1); this.conditionCollection.splice(index, 1);
}, },
reorder(reorderPlan) { reorder(reorderPlan) {

View File

@ -36,7 +36,7 @@
<div> <div>
<ul> <ul>
<li> <li>
<label>Condition Name</label> <label>Condition Names</label>
<span class="controls"> <span class="controls">
<input v-model="condition.name" <input v-model="condition.name"
class="t-rule-name-input" class="t-rule-name-input"
@ -44,6 +44,14 @@
> >
</span> </span>
</li> </li>
<li v-if="telemetryObject">
<label>when</label>
<span class="controls">
<select class="">
<option :value="telemetryObject.key">@{{ telemetryObject.name }}</option>
</select>
</span>
</li>
<li> <li>
<label>Output</label> <label>Output</label>
<span class="controls"> <span class="controls">
@ -74,14 +82,17 @@ export default {
return { return {
expanded: true, expanded: true,
name: this.condition.name, name: this.condition.name,
description: this.condition.description description: this.condition.description,
telemetryObject: this.telemetryObject
}; };
}, },
mounted() { mounted() {
this.updateTelemetry();
}, },
updated() { updated() {
console.log('updated'); console.log('updated');
this.persist() this.persist();
// this.updateTelemetry();
}, },
methods: { methods: {
removeCondition(ev) { removeCondition(ev) {
@ -91,6 +102,16 @@ export default {
this.domainObject.configuration.conditionCollection.splice(index, 1); 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) { persist(index) {
if (index) { if (index) {
this.openmct.objects.mutate(this.domainObject, `configuration.conditionCollection[${index}]`, this.domainObject.configuration.conditionCollection[index]); this.openmct.objects.mutate(this.domainObject, `configuration.conditionCollection[${index}]`, this.domainObject.configuration.conditionCollection[index]);

View File

@ -24,13 +24,21 @@ import * as EventEmitter from 'eventemitter3';
export default class TelemetryCriterion extends EventEmitter { export default class TelemetryCriterion extends EventEmitter {
constructor(telemetryDomainObject, openmct) { constructor(telemetryDomainObjectDefinition, openmct) {
super(); super();
this.id = telemetryDomainObjectDefinition.id;
this.subscription = null; this.subscription = null;
this.telemetryMetadata = null; this.telemetryMetadata = null;
this.telemetryObject = telemetryDomainObject; this.telemetryObjectIdAsString = null;
this.telemetryObjectIdAsString = openmct.objects.makeKeyString(this.telemetryObject.identifier); 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) { handleSubscription(datum) {
@ -48,7 +56,7 @@ export default class TelemetryCriterion extends EventEmitter {
emitResult(data, error) { emitResult(data, error) {
this.emit('criterionUpdated', { this.emit('criterionUpdated', {
identifier: this.telemetryObjectIdAsString, identifier: this.id,
data: data, data: data,
error: error error: error
}); });