mirror of
https://github.com/nasa/openmct.git
synced 2025-03-25 13:28:38 +00:00
Fixes subscription of telelemtry when new criteria is added to a condition
This commit is contained in:
parent
0ad2d59924
commit
93e3065b3e
@ -38,8 +38,7 @@ import {computeCondition} from "@/plugins/condition/utils/evaluator";
|
||||
* telemetry: '',
|
||||
* operation: '',
|
||||
* input: '',
|
||||
* metadata: '',
|
||||
* key: 'someTelemetryObjectKey'
|
||||
* metadata: ''
|
||||
* }
|
||||
* ]
|
||||
* }
|
||||
@ -84,14 +83,12 @@ export default class ConditionClass extends EventEmitter {
|
||||
}
|
||||
|
||||
generateCriterion(criterionConfiguration) {
|
||||
console.log('Identifier', criterionConfiguration);
|
||||
return {
|
||||
id: uuid(),
|
||||
telemetry: criterionConfiguration.telemetry || '',
|
||||
operation: criterionConfiguration.operation || '',
|
||||
input: criterionConfiguration.input === undefined ? [] : criterionConfiguration.input,
|
||||
metadata: criterionConfiguration.metadata || '',
|
||||
identifier: criterionConfiguration.identifier || ''
|
||||
metadata: criterionConfiguration.metadata || ''
|
||||
};
|
||||
}
|
||||
|
||||
@ -111,7 +108,6 @@ export default class ConditionClass extends EventEmitter {
|
||||
*/
|
||||
addCriterion(criterionConfiguration) {
|
||||
let criterionConfigurationWithId = this.generateCriterion(criterionConfiguration || null);
|
||||
console.log('condition class criterionConfigurationWithId', criterionConfigurationWithId );
|
||||
let criterion = new TelemetryCriterion(criterionConfigurationWithId, this.openmct);
|
||||
criterion.on('criterionUpdated', (obj) => this.handleCriterionUpdated(obj));
|
||||
criterion.on('criterionResultUpdated', (obj) => this.handleCriterionResult(obj));
|
||||
@ -119,8 +115,6 @@ export default class ConditionClass extends EventEmitter {
|
||||
this.criteria = [];
|
||||
}
|
||||
this.criteria.push(criterion);
|
||||
//Do we need this here?
|
||||
this.handleConditionUpdated();
|
||||
return criterionConfigurationWithId.id;
|
||||
}
|
||||
|
||||
@ -142,9 +136,8 @@ export default class ConditionClass extends EventEmitter {
|
||||
updateCriterion(id, criterionConfiguration) {
|
||||
let found = this.findCriterion(id);
|
||||
if (found) {
|
||||
console.log('updateCriterion found')
|
||||
const newcriterionConfiguration = this.generateCriterion(criterionConfiguration);
|
||||
let newCriterion = new TelemetryCriterion(newcriterionConfiguration, this.openmct);
|
||||
const newCriterionConfiguration = this.generateCriterion(criterionConfiguration);
|
||||
let newCriterion = new TelemetryCriterion(newCriterionConfiguration, this.openmct);
|
||||
newCriterion.on('criterionUpdated', (obj) => this.handleCriterionUpdated(obj));
|
||||
newCriterion.on('criterionResultUpdated', (obj) => this.handleCriterionResult(obj));
|
||||
|
||||
@ -156,7 +149,6 @@ export default class ConditionClass extends EventEmitter {
|
||||
if (this.criteriaResults[criterion.id] !== undefined) {
|
||||
delete this.criteriaResults[criterion.id];
|
||||
}
|
||||
this.handleConditionUpdated();
|
||||
}
|
||||
}
|
||||
|
||||
@ -187,7 +179,6 @@ export default class ConditionClass extends EventEmitter {
|
||||
let found = this.findCriterion(criterion.id);
|
||||
if (found) {
|
||||
this.criteria[found.index] = criterion.data;
|
||||
//Most likely don't need this.
|
||||
this.subscribe();
|
||||
this.emitEvent('conditionUpdated', {
|
||||
trigger: this.trigger,
|
||||
@ -208,7 +199,9 @@ export default class ConditionClass extends EventEmitter {
|
||||
|
||||
subscribe() {
|
||||
this.criteria.forEach((criterion) => {
|
||||
criterion.subscribe();
|
||||
if (criterion.isValid()) {
|
||||
criterion.subscribe();
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@ -231,7 +224,6 @@ export default class ConditionClass extends EventEmitter {
|
||||
return success;
|
||||
}
|
||||
|
||||
//TODO: implement as part of the evaluator class task.
|
||||
evaluate() {
|
||||
this.result = computeCondition(this.criteriaResults, this.trigger === TRIGGER.ALL);
|
||||
}
|
||||
|
@ -68,6 +68,7 @@
|
||||
v-model="domainObject.configuration.output"
|
||||
class="t-condition-name-input"
|
||||
type="text"
|
||||
@blur="persist"
|
||||
>
|
||||
</span>
|
||||
</li>
|
||||
@ -196,10 +197,6 @@ export default {
|
||||
this.initialize();
|
||||
}));
|
||||
},
|
||||
updated() {
|
||||
//validate telemetry exists, update criteria as needed
|
||||
// this.persist();
|
||||
},
|
||||
methods: {
|
||||
initialize() {
|
||||
this.setOutput();
|
||||
@ -213,11 +210,7 @@ export default {
|
||||
telemetry: '',
|
||||
operation: '',
|
||||
input: '',
|
||||
metadata: '',
|
||||
key: {
|
||||
namespace: '',
|
||||
key: uuid()
|
||||
}
|
||||
metadata: ''
|
||||
};
|
||||
this.domainObject.configuration.criteria.push(criteriaObject);
|
||||
},
|
||||
@ -262,21 +255,13 @@ export default {
|
||||
this.openmct.objects.mutate(this.domainObject, 'configuration', this.domainObject.configuration);
|
||||
},
|
||||
checkInputValue() {
|
||||
if (this.selectedOutputOption === 'string') {
|
||||
if (this.selectedOutputKey === 'string') {
|
||||
this.domainObject.configuration.output = '';
|
||||
} else {
|
||||
this.domainObject.configuration.output = this.selectedOutputOption;
|
||||
}
|
||||
},
|
||||
updateOutputOption(ev) {
|
||||
if (this.selectedOutputOption === 'string') {
|
||||
this.domainObject.configuration.output = '';
|
||||
} else {
|
||||
this.domainObject.configuration.output = this.selectedOutputOption;
|
||||
this.domainObject.configuration.output = this.selectedOutputKey;
|
||||
}
|
||||
},
|
||||
updateCurrentCondition() {
|
||||
console.log('condition this.currentConditionIdentifier', this.currentConditionIdentifier);
|
||||
this.$emit('updateCurrentCondition', this.currentConditionIdentifier);
|
||||
},
|
||||
hasTelemetry(identifier) {
|
||||
|
@ -184,7 +184,6 @@ export default {
|
||||
break;
|
||||
}
|
||||
}
|
||||
// console.log('conditioncollection before emit currentConditionIdentifier', currentConditionIdentifier)
|
||||
this.$emit('currentConditionUpdated', currentConditionIdentifier);
|
||||
},
|
||||
addTelemetryObject(domainObject) {
|
||||
@ -219,7 +218,6 @@ export default {
|
||||
},
|
||||
updateCurrentCondition(identifier) {
|
||||
this.currentConditionIdentifier = identifier;
|
||||
// console.log('conditionCollection this.conditionIdentifier', this.currentConditionIdentifier);
|
||||
},
|
||||
createConditionDomainObject(isDefault) {
|
||||
let conditionObj = {
|
||||
@ -238,11 +236,7 @@ export default {
|
||||
telemetry: '',
|
||||
operation: '',
|
||||
input: '',
|
||||
metadata: '',
|
||||
identifier: {
|
||||
namespace: '',
|
||||
key: ''
|
||||
}
|
||||
metadata: ''
|
||||
}]
|
||||
},
|
||||
summary: 'summary description',
|
||||
|
@ -55,7 +55,6 @@ export default {
|
||||
mounted() {
|
||||
let conditionCollection = this.domainObject.configuration.conditionCollection;
|
||||
this.currentConditionIdentifier = conditionCollection.length ? this.updateCurrentCondition(conditionCollection[0]) : null;
|
||||
// console.log('conditionCollection[0]', conditionCollection[0]);
|
||||
},
|
||||
methods: {
|
||||
setCurrentCondition() {
|
||||
@ -66,8 +65,6 @@ export default {
|
||||
}
|
||||
},
|
||||
updateCurrentCondition(conditionIdentifier) {
|
||||
// console.log('conditionIdentifier', conditionIdentifier);
|
||||
|
||||
this.currentConditionIdentifier = conditionIdentifier;
|
||||
this.setCurrentCondition();
|
||||
}
|
||||
|
@ -22,7 +22,7 @@
|
||||
<option value="">- Select Field -</option>
|
||||
<option v-for="option in telemetryMetadata"
|
||||
:key="option.key"
|
||||
:value="option"
|
||||
:value="option.key"
|
||||
>
|
||||
{{ option.name }}
|
||||
</option>
|
||||
|
@ -58,7 +58,6 @@ export default {
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
// console.log('this.condition', this.condition);
|
||||
},
|
||||
updated() {
|
||||
|
||||
|
@ -29,7 +29,7 @@ export default class TelemetryCriterion extends EventEmitter {
|
||||
* Subscribes/Unsubscribes to telemetry and emits the result
|
||||
* of operations performed on the telemetry data returned and a given input value.
|
||||
* @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
|
||||
*/
|
||||
constructor(telemetryDomainObjectDefinition, openmct) {
|
||||
@ -44,7 +44,6 @@ export default class TelemetryCriterion extends EventEmitter {
|
||||
this.input = telemetryDomainObjectDefinition.input;
|
||||
this.metadata = telemetryDomainObjectDefinition.metadata;
|
||||
this.subscription = null;
|
||||
this.telemetryMetadata = null;
|
||||
this.telemetryObjectIdAsString = null;
|
||||
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) {
|
||||
this.telemetryObject = obj;
|
||||
this.telemetryObjectIdAsString = this.objectAPI.makeKeyString(this.telemetryObject.identifier);
|
||||
this.telemetryMetadata = this.telemetryAPI.getMetadata(this.telemetryObject.identifier);
|
||||
this.emitEvent('criterionUpdated', this);
|
||||
}
|
||||
|
||||
@ -77,9 +75,11 @@ export default class TelemetryCriterion extends EventEmitter {
|
||||
let comparator = this.findOperation(this.operation);
|
||||
let params = [];
|
||||
let result = false;
|
||||
params.push(data[this.metaDataKey]);
|
||||
params.push(data[this.metadata]);
|
||||
if (this.input instanceof Array && this.input.length) {
|
||||
params.push(this.input[0]);
|
||||
} else if (this.input) {
|
||||
params.push(this.input);
|
||||
}
|
||||
if (typeof comparator === 'function') {
|
||||
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
|
||||
*/
|
||||
subscribe() {
|
||||
this.unsubscribe();
|
||||
console.log('criteria subscribe this.telemetryObject', this.telemetryObject);
|
||||
this.subscription = this.telemetryAPI.subscribe(this.telemetryObject, (datum) => {
|
||||
this.handleSubscription(datum);
|
||||
});
|
||||
@ -121,6 +124,5 @@ export default class TelemetryCriterion extends EventEmitter {
|
||||
this.emitEvent('criterionRemoved');
|
||||
delete this.telemetryObjectIdAsString;
|
||||
delete this.telemetryObject;
|
||||
delete this.telemetryMetadata;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user