mirror of
https://github.com/nasa/openmct.git
synced 2024-12-30 01:48:51 +00:00
Merge pull request #2751 from nasa/fix-enum-metadata
Handles enum meta data for criteria
This commit is contained in:
commit
e08b4ff0ab
@ -45,16 +45,32 @@
|
||||
{{ option.text }}
|
||||
</option>
|
||||
</select>
|
||||
<span v-for="(item, inputIndex) in inputCount"
|
||||
:key="inputIndex"
|
||||
class="c-cdef__control__inputs"
|
||||
>
|
||||
<input v-model="criterion.input[inputIndex]"
|
||||
class="c-cdef__control__input"
|
||||
:type="setInputType"
|
||||
@blur="persist"
|
||||
<span v-if="!enumerations.length">
|
||||
<span v-for="(item, inputIndex) in inputCount"
|
||||
:key="inputIndex"
|
||||
class="c-cdef__control__inputs"
|
||||
>
|
||||
<span v-if="inputIndex < inputCount-1">and</span>
|
||||
<input v-model="criterion.input[inputIndex]"
|
||||
class="c-cdef__control__input"
|
||||
:type="setInputType"
|
||||
@blur="persist"
|
||||
>
|
||||
<span v-if="inputIndex < inputCount-1">and</span>
|
||||
</span>
|
||||
</span>
|
||||
<span v-else>
|
||||
<span v-if="inputCount && criterion.operation"
|
||||
class="c-cdef__control"
|
||||
>
|
||||
<select v-model="criterion.input[0]">
|
||||
<option v-for="option in enumerations"
|
||||
:key="option.string"
|
||||
:value="option.value.toString()"
|
||||
>
|
||||
{{ option.string }}
|
||||
</option>
|
||||
</select>
|
||||
</span>
|
||||
</span>
|
||||
</span>
|
||||
</span>
|
||||
@ -92,7 +108,8 @@ export default {
|
||||
operations: OPERATIONS,
|
||||
inputCount: 0,
|
||||
rowLabel: '',
|
||||
operationFormat: ''
|
||||
operationFormat: '',
|
||||
enumerations: []
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
@ -123,11 +140,13 @@ export default {
|
||||
},
|
||||
methods: {
|
||||
getOperationFormat() {
|
||||
this.enumerations = [];
|
||||
this.telemetryMetadata.valueMetadatas.forEach((value, index) => {
|
||||
if (value.key === this.criterion.metadata) {
|
||||
let valueMetadata = this.telemetryMetadataOptions[index];
|
||||
if (valueMetadata.enumerations !== undefined) {
|
||||
this.operationFormat = 'enum';
|
||||
this.enumerations = valueMetadata.enumerations;
|
||||
} else if (valueMetadata.hints.hasOwnProperty('range')) {
|
||||
this.operationFormat = 'number';
|
||||
} else if (valueMetadata.hints.hasOwnProperty('domain')) {
|
||||
@ -164,7 +183,7 @@ export default {
|
||||
},
|
||||
updateOperationInputVisibility(ev) {
|
||||
if (ev) {
|
||||
this.criterion.input = [];
|
||||
this.criterion.input = this.enumerations.length ? [this.enumerations[0].value.toString()] : [];
|
||||
this.inputCount = 0;
|
||||
}
|
||||
for (let i = 0; i < this.filteredOps.length; i++) {
|
||||
|
@ -51,11 +51,15 @@ export default class TelemetryCriterion extends EventEmitter {
|
||||
|
||||
initialize(obj) {
|
||||
this.telemetryObject = obj;
|
||||
this.telemetryMetaData = this.openmct.telemetry.getMetadata(obj).valueMetadatas;
|
||||
this.telemetryObjectIdAsString = this.objectAPI.makeKeyString(this.telemetryObject.identifier);
|
||||
this.emitEvent('criterionUpdated', this);
|
||||
}
|
||||
|
||||
handleSubscription(data) {
|
||||
if (data) {
|
||||
data = this.createNormalizedDatum(data);
|
||||
}
|
||||
const datum = {
|
||||
result: this.computeResult(data)
|
||||
};
|
||||
@ -69,6 +73,13 @@ export default class TelemetryCriterion extends EventEmitter {
|
||||
this.emitEvent('criterionResultUpdated', datum);
|
||||
}
|
||||
|
||||
createNormalizedDatum(telemetryDatum) {
|
||||
return Object.values(this.telemetryMetaData).reduce((normalizedDatum, metadatum) => {
|
||||
normalizedDatum[metadatum.key] = telemetryDatum[metadatum.source];
|
||||
return normalizedDatum;
|
||||
}, {});
|
||||
}
|
||||
|
||||
findOperation(operation) {
|
||||
for (let i=0, ii=OPERATIONS.length; i < ii; i++) {
|
||||
if (operation === OPERATIONS[i].name) {
|
||||
|
@ -37,18 +37,25 @@ describe("The telemetry criterion", function () {
|
||||
type: "test-object",
|
||||
name: "Test Object",
|
||||
telemetry: {
|
||||
values: [{
|
||||
key: "some-key",
|
||||
name: "Some attribute",
|
||||
valueMetadatas: [{
|
||||
key: "value",
|
||||
name: "Value",
|
||||
hints: {
|
||||
range: 2
|
||||
}
|
||||
},
|
||||
{
|
||||
key: "utc",
|
||||
name: "Time",
|
||||
format: "utc",
|
||||
hints: {
|
||||
domain: 1
|
||||
}
|
||||
}, {
|
||||
key: "some-other-key",
|
||||
name: "Another attribute",
|
||||
hints: {
|
||||
range: 1
|
||||
}
|
||||
key: "testSource",
|
||||
source: "value",
|
||||
name: "Test",
|
||||
format: "enum"
|
||||
}]
|
||||
}
|
||||
};
|
||||
@ -60,7 +67,7 @@ describe("The telemetry criterion", function () {
|
||||
openmct.telemetry = jasmine.createSpyObj('telemetry', ['isTelemetryObject', "subscribe", "getMetadata"]);
|
||||
openmct.telemetry.isTelemetryObject.and.returnValue(true);
|
||||
openmct.telemetry.subscribe.and.returnValue(function () {});
|
||||
openmct.telemetry.getMetadata.and.returnValue(testTelemetryObject.telemetry.values);
|
||||
openmct.telemetry.getMetadata.and.returnValue(testTelemetryObject.telemetry);
|
||||
|
||||
openmct.time = jasmine.createSpyObj('timeAPI',
|
||||
['timeSystem', 'bounds', 'getAllTimeSystems']
|
||||
@ -101,11 +108,11 @@ describe("The telemetry criterion", function () {
|
||||
});
|
||||
|
||||
it("emits update event on new data from telemetry providers", function () {
|
||||
telemetryCriterion.initialize(testTelemetryObject);
|
||||
spyOn(telemetryCriterion, 'emitEvent').and.callThrough();
|
||||
telemetryCriterion.handleSubscription({
|
||||
key: 'some-key',
|
||||
source: 'testSource',
|
||||
testSource: 'Hello'
|
||||
value: 'Hello',
|
||||
utc: 'Hi'
|
||||
});
|
||||
expect(telemetryCriterion.emitEvent).toHaveBeenCalled();
|
||||
expect(mockListener).toHaveBeenCalled();
|
||||
|
Loading…
Reference in New Issue
Block a user