Merge branch 'condition-ui' of https://github.com/nasa/openmct into condition-ui

This commit is contained in:
Joshi 2020-01-28 12:36:57 -08:00
commit de03cfbe64
6 changed files with 31 additions and 37 deletions

View File

@ -64,6 +64,7 @@ describe("The condition", function () {
openmct.telemetry.getMetadata.and.returnValue(testTelemetryObject.telemetry.values); openmct.telemetry.getMetadata.and.returnValue(testTelemetryObject.telemetry.values);
testConditionDefinition = { testConditionDefinition = {
definition: {
trigger: TRIGGER.ANY, trigger: TRIGGER.ANY,
criteria: [ criteria: [
{ {
@ -73,6 +74,7 @@ describe("The condition", function () {
key: testTelemetryObject.identifier key: testTelemetryObject.identifier
} }
] ]
}
}; };
conditionObj = new Condition( conditionObj = new Condition(
@ -85,7 +87,7 @@ describe("The condition", function () {
}); });
it("generates criteria with an id", function () { it("generates criteria with an id", function () {
const testCriterion = testConditionDefinition.criteria[0]; const testCriterion = testConditionDefinition.definition.criteria[0];
let criterion = conditionObj.generateCriterion(testCriterion); let criterion = conditionObj.generateCriterion(testCriterion);
expect(criterion.id).toBeDefined(); expect(criterion.id).toBeDefined();
expect(criterion.operation).toEqual(testCriterion.operation); expect(criterion.operation).toEqual(testCriterion.operation);
@ -101,15 +103,15 @@ describe("The condition", function () {
it("initializes with criteria from the condition definition", function () { it("initializes with criteria from the condition definition", function () {
expect(conditionObj.criteria.length).toEqual(1); expect(conditionObj.criteria.length).toEqual(1);
let criterion = conditionObj.criteria[0]; let criterion = conditionObj.criteria[0];
console.log(criterion);
expect(criterion instanceof TelemetryCriterion).toBeTrue(); expect(criterion instanceof TelemetryCriterion).toBeTrue();
expect(criterion.operator).toEqual(testConditionDefinition.operator); expect(criterion.operator).toEqual(testConditionDefinition.definition.criteria[0].operator);
expect(criterion.input).toEqual(testConditionDefinition.input); expect(criterion.input).toEqual(testConditionDefinition.definition.criteria[0].input);
expect(criterion.metaDataKey).toEqual(testConditionDefinition.metaDataKey); expect(criterion.metaDataKey).toEqual(testConditionDefinition.definition.criteria[0].metaDataKey);
expect(criterion.key).toEqual(testConditionDefinition.key);
}); });
it("initializes with the trigger from the condition definition", function () { it("initializes with the trigger from the condition definition", function () {
expect(conditionObj.trigger).toEqual(testConditionDefinition.trigger); expect(conditionObj.trigger).toEqual(testConditionDefinition.definition.trigger);
}); });
it("destroys all criteria for a condition", function () { it("destroys all criteria for a condition", function () {

View File

@ -2,7 +2,7 @@
<div v-if="condition" <div v-if="condition"
id="conditionArea" id="conditionArea"
class="c-cs-ui__conditions" class="c-cs-ui__conditions"
:class="['widget-condition', { 'widget-condition--current': isCurrent && (isCurrent.key === conditionIdentifier.key) }]" :class="['widget-condition', { 'widget-condition--current': currentConditionIdentifier && (currentConditionIdentifier.key === conditionIdentifier.key) }]"
> >
<div class="title-bar"> <div class="title-bar">
<span class="condition-name"> <span class="condition-name">
@ -28,7 +28,7 @@ export default {
type: Object, type: Object,
required: true required: true
}, },
isCurrent: { currentConditionIdentifier: {
type: Object, type: Object,
required: true required: true
} }

View File

@ -35,7 +35,7 @@
> >
<div v-if="isEditing"> <div v-if="isEditing">
<ConditionEdit :condition-identifier="conditionIdentifier" <ConditionEdit :condition-identifier="conditionIdentifier"
:is-current="currentConditionIdentifier" :current-condition-identifier="currentConditionIdentifier"
@update-current-condition="updateCurrentCondition" @update-current-condition="updateCurrentCondition"
@remove-condition="removeCondition" @remove-condition="removeCondition"
@condition-result-updated="handleConditionResult" @condition-result-updated="handleConditionResult"
@ -43,7 +43,7 @@
</div> </div>
<div v-else> <div v-else>
<Condition :condition-identifier="conditionIdentifier" <Condition :condition-identifier="conditionIdentifier"
:is-current="currentConditionIdentifier" :current-condition-identifier="currentConditionIdentifier"
/> />
</div> </div>
</div> </div>
@ -88,6 +88,8 @@ export default {
this.conditionCollection = this.domainObject.configuration ? this.domainObject.configuration.conditionCollection : []; this.conditionCollection = this.domainObject.configuration ? this.domainObject.configuration.conditionCollection : [];
if (!this.conditionCollection.length) { if (!this.conditionCollection.length) {
this.addCondition(null, true); this.addCondition(null, true);
} else {
this.updateCurrentCondition(this.conditionCollection[0]);
} }
}, },
methods: { methods: {
@ -98,7 +100,6 @@ export default {
}, },
updateCurrentConditionId() { updateCurrentConditionId() {
let currentConditionIdentifier = this.conditionCollection[this.conditionCollection.length-1]; let currentConditionIdentifier = this.conditionCollection[this.conditionCollection.length-1];
for (let i=0, ii = this.conditionCollection.length-1; i< ii; i++) { for (let i=0, ii = this.conditionCollection.length-1; i< ii; i++) {
let conditionIdAsString = this.openmct.objects.makeKeyString(this.conditionCollection[i]); let conditionIdAsString = this.openmct.objects.makeKeyString(this.conditionCollection[i]);
if (this.conditionResults[conditionIdAsString]) { if (this.conditionResults[conditionIdAsString]) {

View File

@ -1,7 +1,7 @@
<template> <template>
<div v-if="condition" <div v-if="condition"
class="c-cs-editui__conditions" class="c-cs-editui__conditions"
:class="['widget-condition', { 'widget-condition--current': isCurrent && (isCurrent.key === conditionIdentifier.key) }]" :class="['widget-condition', { 'widget-condition--current': currentConditionIdentifier && (currentConditionIdentifier.key === conditionIdentifier.key) }]"
> >
<div class="title-bar"> <div class="title-bar">
<span <span
@ -147,7 +147,7 @@ export default {
type: Object, type: Object,
required: true required: true
}, },
isCurrent: { currentConditionIdentifier: {
type: Object, type: Object,
required: true required: true
} }
@ -160,8 +160,8 @@ export default {
telemetryMetadata: this.telemetryMetadata, telemetryMetadata: this.telemetryMetadata,
operations: OPERATIONS, operations: OPERATIONS,
selectedMetaDataKey: null, selectedMetaDataKey: null,
selectedTelemetryKey: null, selectedTelemetryKey: '',
selectedOperationKey: null, selectedOperationKey: '',
selectedOutputKey: null, selectedOutputKey: null,
stringOutputField: false, stringOutputField: false,
comparisonValueField: false, comparisonValueField: false,
@ -239,7 +239,7 @@ export default {
this.openmct.objects.get(this.condition.definition.criteria[0].key).then((obj) => { this.openmct.objects.get(this.condition.definition.criteria[0].key).then((obj) => {
this.telemetryObject = obj; this.telemetryObject = obj;
this.telemetryMetadata = this.openmct.telemetry.getMetadata(this.telemetryObject).values(); this.telemetryMetadata = this.openmct.telemetry.getMetadata(this.telemetryObject).values();
this.selectedMetaDataKey = this.telemetryMetadata[0].key; this.selectedMetaDataKey = '';
this.selectedTelemetryKey = this.telemetryObject.identifier; this.selectedTelemetryKey = this.telemetryObject.identifier;
}); });
} else { } else {

View File

@ -77,7 +77,9 @@ export default class TelemetryCriterion extends EventEmitter {
let params = []; let params = [];
let result = false; let result = false;
params.push(data[this.metaDataKey]); params.push(data[this.metaDataKey]);
params.push(this.input); if (this.input instanceof Array && this.input.length) {
params.push(this.input[0]);
}
if (typeof comparator === 'function') { if (typeof comparator === 'function') {
result = comparator(params); result = comparator(params);
} }

View File

@ -94,17 +94,6 @@ describe("The telemetry criterion", function () {
expect(telemetryCriterion.subscription).toBeDefined(); expect(telemetryCriterion.subscription).toBeDefined();
}); });
it("normalizes telemetry data", function () {
let result = telemetryCriterion.normalizeData({
key: 'some-key',
source: 'testSource',
testSource: 'Hello'
});
expect(result).toEqual({
'some-key': 'Hello'
})
});
it("emits update event on new data from telemetry providers", function () { it("emits update event on new data from telemetry providers", function () {
spyOn(telemetryCriterion, 'emitEvent').and.callThrough(); spyOn(telemetryCriterion, 'emitEvent').and.callThrough();
telemetryCriterion.handleSubscription({ telemetryCriterion.handleSubscription({