Fixes subscription of telelemtry when new criteria is added to a condition

This commit is contained in:
Joshi 2020-02-19 12:51:24 -08:00
parent 0ad2d59924
commit 93e3065b3e
7 changed files with 21 additions and 52 deletions

View File

@ -38,8 +38,7 @@ import {computeCondition} from "@/plugins/condition/utils/evaluator";
* telemetry: '', * telemetry: '',
* operation: '', * operation: '',
* input: '', * input: '',
* metadata: '', * metadata: ''
* key: 'someTelemetryObjectKey'
* } * }
* ] * ]
* } * }
@ -84,14 +83,12 @@ export default class ConditionClass extends EventEmitter {
} }
generateCriterion(criterionConfiguration) { generateCriterion(criterionConfiguration) {
console.log('Identifier', criterionConfiguration);
return { return {
id: uuid(), id: uuid(),
telemetry: criterionConfiguration.telemetry || '', telemetry: criterionConfiguration.telemetry || '',
operation: criterionConfiguration.operation || '', operation: criterionConfiguration.operation || '',
input: criterionConfiguration.input === undefined ? [] : criterionConfiguration.input, input: criterionConfiguration.input === undefined ? [] : criterionConfiguration.input,
metadata: criterionConfiguration.metadata || '', metadata: criterionConfiguration.metadata || ''
identifier: criterionConfiguration.identifier || ''
}; };
} }
@ -111,7 +108,6 @@ export default class ConditionClass extends EventEmitter {
*/ */
addCriterion(criterionConfiguration) { addCriterion(criterionConfiguration) {
let criterionConfigurationWithId = this.generateCriterion(criterionConfiguration || null); let criterionConfigurationWithId = this.generateCriterion(criterionConfiguration || null);
console.log('condition class criterionConfigurationWithId', criterionConfigurationWithId );
let criterion = new TelemetryCriterion(criterionConfigurationWithId, this.openmct); let criterion = new TelemetryCriterion(criterionConfigurationWithId, this.openmct);
criterion.on('criterionUpdated', (obj) => this.handleCriterionUpdated(obj)); criterion.on('criterionUpdated', (obj) => this.handleCriterionUpdated(obj));
criterion.on('criterionResultUpdated', (obj) => this.handleCriterionResult(obj)); criterion.on('criterionResultUpdated', (obj) => this.handleCriterionResult(obj));
@ -119,8 +115,6 @@ export default class ConditionClass extends EventEmitter {
this.criteria = []; this.criteria = [];
} }
this.criteria.push(criterion); this.criteria.push(criterion);
//Do we need this here?
this.handleConditionUpdated();
return criterionConfigurationWithId.id; return criterionConfigurationWithId.id;
} }
@ -142,9 +136,8 @@ export default class ConditionClass extends EventEmitter {
updateCriterion(id, criterionConfiguration) { updateCriterion(id, criterionConfiguration) {
let found = this.findCriterion(id); let found = this.findCriterion(id);
if (found) { if (found) {
console.log('updateCriterion found') const newCriterionConfiguration = this.generateCriterion(criterionConfiguration);
const newcriterionConfiguration = this.generateCriterion(criterionConfiguration); let newCriterion = new TelemetryCriterion(newCriterionConfiguration, this.openmct);
let newCriterion = new TelemetryCriterion(newcriterionConfiguration, this.openmct);
newCriterion.on('criterionUpdated', (obj) => this.handleCriterionUpdated(obj)); newCriterion.on('criterionUpdated', (obj) => this.handleCriterionUpdated(obj));
newCriterion.on('criterionResultUpdated', (obj) => this.handleCriterionResult(obj)); newCriterion.on('criterionResultUpdated', (obj) => this.handleCriterionResult(obj));
@ -156,7 +149,6 @@ export default class ConditionClass extends EventEmitter {
if (this.criteriaResults[criterion.id] !== undefined) { if (this.criteriaResults[criterion.id] !== undefined) {
delete this.criteriaResults[criterion.id]; delete this.criteriaResults[criterion.id];
} }
this.handleConditionUpdated();
} }
} }
@ -187,7 +179,6 @@ export default class ConditionClass extends EventEmitter {
let found = this.findCriterion(criterion.id); let found = this.findCriterion(criterion.id);
if (found) { if (found) {
this.criteria[found.index] = criterion.data; this.criteria[found.index] = criterion.data;
//Most likely don't need this.
this.subscribe(); this.subscribe();
this.emitEvent('conditionUpdated', { this.emitEvent('conditionUpdated', {
trigger: this.trigger, trigger: this.trigger,
@ -208,7 +199,9 @@ export default class ConditionClass extends EventEmitter {
subscribe() { subscribe() {
this.criteria.forEach((criterion) => { this.criteria.forEach((criterion) => {
criterion.subscribe(); if (criterion.isValid()) {
criterion.subscribe();
}
}) })
} }
@ -231,7 +224,6 @@ export default class ConditionClass extends EventEmitter {
return success; return success;
} }
//TODO: implement as part of the evaluator class task.
evaluate() { evaluate() {
this.result = computeCondition(this.criteriaResults, this.trigger === TRIGGER.ALL); this.result = computeCondition(this.criteriaResults, this.trigger === TRIGGER.ALL);
} }

View File

@ -68,6 +68,7 @@
v-model="domainObject.configuration.output" v-model="domainObject.configuration.output"
class="t-condition-name-input" class="t-condition-name-input"
type="text" type="text"
@blur="persist"
> >
</span> </span>
</li> </li>
@ -196,10 +197,6 @@ export default {
this.initialize(); this.initialize();
})); }));
}, },
updated() {
//validate telemetry exists, update criteria as needed
// this.persist();
},
methods: { methods: {
initialize() { initialize() {
this.setOutput(); this.setOutput();
@ -213,11 +210,7 @@ export default {
telemetry: '', telemetry: '',
operation: '', operation: '',
input: '', input: '',
metadata: '', metadata: ''
key: {
namespace: '',
key: uuid()
}
}; };
this.domainObject.configuration.criteria.push(criteriaObject); this.domainObject.configuration.criteria.push(criteriaObject);
}, },
@ -262,21 +255,13 @@ export default {
this.openmct.objects.mutate(this.domainObject, 'configuration', this.domainObject.configuration); this.openmct.objects.mutate(this.domainObject, 'configuration', this.domainObject.configuration);
}, },
checkInputValue() { checkInputValue() {
if (this.selectedOutputOption === 'string') { if (this.selectedOutputKey === 'string') {
this.domainObject.configuration.output = ''; this.domainObject.configuration.output = '';
} else { } else {
this.domainObject.configuration.output = this.selectedOutputOption; this.domainObject.configuration.output = this.selectedOutputKey;
}
},
updateOutputOption(ev) {
if (this.selectedOutputOption === 'string') {
this.domainObject.configuration.output = '';
} else {
this.domainObject.configuration.output = this.selectedOutputOption;
} }
}, },
updateCurrentCondition() { updateCurrentCondition() {
console.log('condition this.currentConditionIdentifier', this.currentConditionIdentifier);
this.$emit('updateCurrentCondition', this.currentConditionIdentifier); this.$emit('updateCurrentCondition', this.currentConditionIdentifier);
}, },
hasTelemetry(identifier) { hasTelemetry(identifier) {

View File

@ -184,7 +184,6 @@ export default {
break; break;
} }
} }
// console.log('conditioncollection before emit currentConditionIdentifier', currentConditionIdentifier)
this.$emit('currentConditionUpdated', currentConditionIdentifier); this.$emit('currentConditionUpdated', currentConditionIdentifier);
}, },
addTelemetryObject(domainObject) { addTelemetryObject(domainObject) {
@ -219,7 +218,6 @@ export default {
}, },
updateCurrentCondition(identifier) { updateCurrentCondition(identifier) {
this.currentConditionIdentifier = identifier; this.currentConditionIdentifier = identifier;
// console.log('conditionCollection this.conditionIdentifier', this.currentConditionIdentifier);
}, },
createConditionDomainObject(isDefault) { createConditionDomainObject(isDefault) {
let conditionObj = { let conditionObj = {
@ -238,11 +236,7 @@ export default {
telemetry: '', telemetry: '',
operation: '', operation: '',
input: '', input: '',
metadata: '', metadata: ''
identifier: {
namespace: '',
key: ''
}
}] }]
}, },
summary: 'summary description', summary: 'summary description',

View File

@ -55,7 +55,6 @@ export default {
mounted() { mounted() {
let conditionCollection = this.domainObject.configuration.conditionCollection; let conditionCollection = this.domainObject.configuration.conditionCollection;
this.currentConditionIdentifier = conditionCollection.length ? this.updateCurrentCondition(conditionCollection[0]) : null; this.currentConditionIdentifier = conditionCollection.length ? this.updateCurrentCondition(conditionCollection[0]) : null;
// console.log('conditionCollection[0]', conditionCollection[0]);
}, },
methods: { methods: {
setCurrentCondition() { setCurrentCondition() {
@ -66,8 +65,6 @@ export default {
} }
}, },
updateCurrentCondition(conditionIdentifier) { updateCurrentCondition(conditionIdentifier) {
// console.log('conditionIdentifier', conditionIdentifier);
this.currentConditionIdentifier = conditionIdentifier; this.currentConditionIdentifier = conditionIdentifier;
this.setCurrentCondition(); this.setCurrentCondition();
} }

View File

@ -22,7 +22,7 @@
<option value="">- Select Field -</option> <option value="">- Select Field -</option>
<option v-for="option in telemetryMetadata" <option v-for="option in telemetryMetadata"
:key="option.key" :key="option.key"
:value="option" :value="option.key"
> >
{{ option.name }} {{ option.name }}
</option> </option>

View File

@ -58,7 +58,6 @@ export default {
} }
}, },
mounted() { mounted() {
// console.log('this.condition', this.condition);
}, },
updated() { updated() {

View File

@ -29,7 +29,7 @@ export default class TelemetryCriterion extends EventEmitter {
* Subscribes/Unsubscribes to telemetry and emits the result * Subscribes/Unsubscribes to telemetry and emits the result
* of operations performed on the telemetry data returned and a given input value. * of operations performed on the telemetry data returned and a given input value.
* @constructor * @constructor
* @param telemetryDomainObjectDefinition {id: uuid, operation: enum, input: Array, metaDataKey: string, key: {domainObject.identifier} } * @param telemetryDomainObjectDefinition {id: uuid, operation: enum, input: Array, metadata: string, key: {domainObject.identifier} }
* @param openmct * @param openmct
*/ */
constructor(telemetryDomainObjectDefinition, openmct) { constructor(telemetryDomainObjectDefinition, openmct) {
@ -44,7 +44,6 @@ export default class TelemetryCriterion extends EventEmitter {
this.input = telemetryDomainObjectDefinition.input; this.input = telemetryDomainObjectDefinition.input;
this.metadata = telemetryDomainObjectDefinition.metadata; this.metadata = telemetryDomainObjectDefinition.metadata;
this.subscription = null; this.subscription = null;
this.telemetryMetadata = null;
this.telemetryObjectIdAsString = null; this.telemetryObjectIdAsString = null;
this.objectAPI.get(this.objectAPI.makeKeyString(this.telemetry)).then((obj) => this.initialize(obj)); this.objectAPI.get(this.objectAPI.makeKeyString(this.telemetry)).then((obj) => this.initialize(obj));
} }
@ -52,7 +51,6 @@ export default class TelemetryCriterion extends EventEmitter {
initialize(obj) { initialize(obj) {
this.telemetryObject = obj; this.telemetryObject = obj;
this.telemetryObjectIdAsString = this.objectAPI.makeKeyString(this.telemetryObject.identifier); this.telemetryObjectIdAsString = this.objectAPI.makeKeyString(this.telemetryObject.identifier);
this.telemetryMetadata = this.telemetryAPI.getMetadata(this.telemetryObject.identifier);
this.emitEvent('criterionUpdated', this); this.emitEvent('criterionUpdated', this);
} }
@ -77,9 +75,11 @@ export default class TelemetryCriterion extends EventEmitter {
let comparator = this.findOperation(this.operation); let comparator = this.findOperation(this.operation);
let params = []; let params = [];
let result = false; let result = false;
params.push(data[this.metaDataKey]); params.push(data[this.metadata]);
if (this.input instanceof Array && this.input.length) { if (this.input instanceof Array && this.input.length) {
params.push(this.input[0]); params.push(this.input[0]);
} else if (this.input) {
params.push(this.input);
} }
if (typeof comparator === 'function') { if (typeof comparator === 'function') {
result = comparator(params); result = comparator(params);
@ -94,12 +94,15 @@ export default class TelemetryCriterion extends EventEmitter {
}); });
} }
isValid() {
return this.telemetryObject && this.metadata && this.operation;
}
/** /**
* Subscribes to the telemetry object and returns an unsubscribe function * Subscribes to the telemetry object and returns an unsubscribe function
*/ */
subscribe() { subscribe() {
this.unsubscribe(); this.unsubscribe();
console.log('criteria subscribe this.telemetryObject', this.telemetryObject);
this.subscription = this.telemetryAPI.subscribe(this.telemetryObject, (datum) => { this.subscription = this.telemetryAPI.subscribe(this.telemetryObject, (datum) => {
this.handleSubscription(datum); this.handleSubscription(datum);
}); });
@ -121,6 +124,5 @@ export default class TelemetryCriterion extends EventEmitter {
this.emitEvent('criterionRemoved'); this.emitEvent('criterionRemoved');
delete this.telemetryObjectIdAsString; delete this.telemetryObjectIdAsString;
delete this.telemetryObject; delete this.telemetryObject;
delete this.telemetryMetadata;
} }
} }