Merge commit 'e580734c9593ab863f397b52ec9662f045fc7b61' of https://github.com/nasa/openmct into condition-ui-redo

This commit is contained in:
Joshi 2020-02-04 14:37:39 -08:00
commit 7029dcf09e
9 changed files with 165 additions and 89 deletions

View File

@ -24,7 +24,7 @@ import * as EventEmitter from 'eventemitter3';
import uuid from 'uuid';
import TelemetryCriterion from "@/plugins/condition/criterion/TelemetryCriterion";
import { TRIGGER } from "@/plugins/condition/utils/constants";
import {computeConditionForAll, computeConditionForAny} from "@/plugins/condition/utils/evaluator";
import {computeCondition} from "@/plugins/condition/utils/evaluator";
/*
* conditionDefinition = {
@ -228,11 +228,7 @@ export default class ConditionClass extends EventEmitter {
//TODO: implement as part of the evaluator class task.
evaluate() {
if (this.trigger === TRIGGER.ANY) {
this.result = computeConditionForAny(this.criteriaResults);
} else if (this.trigger === TRIGGER.ALL) {
this.result = computeConditionForAll(this.criteriaResults);
}
this.result = computeCondition(this.criteriaResults, this.trigger === TRIGGER.ALL);
}
emitEvent(eventName, data) {

View File

@ -58,7 +58,7 @@ export default class ConditionSetViewProvider {
isEditing
}
},
template: '<condition-set ref="conditionSet" :isEditing="isEditing"></condition-set>'
template: '<condition-set :isEditing="isEditing"></condition-set>'
});
},
onEditModeChange: (isEditing) => {

View File

@ -103,7 +103,6 @@ describe("The condition", function () {
it("initializes with criteria from the condition definition", function () {
expect(conditionObj.criteria.length).toEqual(1);
let criterion = conditionObj.criteria[0];
console.log(criterion);
expect(criterion instanceof TelemetryCriterion).toBeTrue();
expect(criterion.operator).toEqual(testConditionDefinition.definition.criteria[0].operator);
expect(criterion.input).toEqual(testConditionDefinition.definition.criteria[0].input);

View File

@ -1,4 +1,5 @@
<template>
<!-- TODO: current condition class should be set using openmct.objects.makeKeyString(<identifier>) -->
<div v-if="condition"
id="conditionArea"
class="c-cs-ui__conditions"
@ -21,6 +22,8 @@
</template>
<script>
import ConditionClass from "@/plugins/condition/Condition";
export default {
inject: ['openmct'],
props: {
@ -38,10 +41,26 @@ export default {
condition: this.condition
};
},
destroyed() {
this.conditionClass.off('conditionResultUpdated', this.handleConditionResult.bind(this));
if (this.conditionClass && typeof this.conditionClass.destroy === 'function') {
this.conditionClass.destroy();
}
},
mounted() {
this.openmct.objects.get(this.conditionIdentifier).then((obj => {
this.condition = obj;
this.conditionClass = new ConditionClass(this.condition, this.openmct);
this.conditionClass.on('conditionResultUpdated', this.handleConditionResult.bind(this));
}));
},
methods: {
handleConditionResult(args) {
this.$emit('conditionResultUpdated', {
id: this.conditionIdentifier,
result: args.data.result
})
}
}
}
</script>

View File

@ -63,6 +63,7 @@
@dragover.prevent
></div>
<ConditionEdit :condition-identifier="conditionIdentifier"
:telemetry="telemetryObjs"
:current-condition-identifier="currentConditionIdentifier"
:condition-index="index"
@updateCurrentCondition="updateCurrentCondition"
@ -74,6 +75,7 @@
<div v-else>
<Condition :condition-identifier="conditionIdentifier"
:current-condition-identifier="currentConditionIdentifier"
@conditionResultUpdated="handleConditionResult"
/>
</div>
</li>
@ -88,7 +90,6 @@ import Condition from '../../condition/components/Condition.vue';
import ConditionEdit from '../../condition/components/ConditionEdit.vue';
import uuid from 'uuid';
export default {
inject: ['openmct', 'domainObject'],
components: {
@ -105,6 +106,7 @@ export default {
conditionCollection: [],
conditions: [],
currentConditionIdentifier: this.currentConditionIdentifier || {},
telemetryObjs: this.telemetryObjs,
moveIndex: Number,
isDragging: false
};
@ -118,6 +120,7 @@ export default {
this.instantiate = this.openmct.$injector.get('instantiate');
this.composition = this.openmct.composition.get(this.domainObject);
this.composition.on('add', this.addTelemetry);
this.composition.on('remove', this.removeTelemetry);
this.composition.load();
this.conditionCollection = this.domainObject.configuration ? this.domainObject.configuration.conditionCollection : [];
if (!this.conditionCollection.length) {
@ -188,16 +191,26 @@ export default {
break;
}
}
this.$emit('current-condition-updated', currentConditionIdentifier);
this.$emit('currentConditionUpdated', currentConditionIdentifier);
},
addTelemetry(telemetryDomainObject) {
this.telemetryObjs.push(telemetryDomainObject);
},
removeTelemetry(telemetryDomainObjectIdentifier) {
let index = _.findIndex(this.telemetryObjs, (obj) => {
let objId = this.openmct.objects.makeKeyString(obj.identifier);
let id = this.openmct.objects.makeKeyString(telemetryDomainObjectIdentifier);
return objId === id;
});
if (index > -1) {
this.telemetryObjs.splice(index, 1);
}
},
addCondition(event, isDefault) {
let conditionDO = this.getConditionDomainObject(!!isDefault);
//persist the condition DO so that we can do an openmct.objects.get on it and only persist the identifier in the conditionCollection of conditionSet
this.openmct.objects.mutate(conditionDO, 'created', new Date());
this.conditionCollection.unshift(conditionDO.identifier);
let conditionDomainObject = this.getConditionDomainObject(!!isDefault);
//persist the condition domain object so that we can do an openmct.objects.get on it and only persist the identifier in the conditionCollection of conditionSet
this.openmct.objects.mutate(conditionDomainObject, 'created', new Date());
this.conditionCollection.unshift(conditionDomainObject.identifier);
this.persist();
},
updateCurrentCondition(identifier) {
@ -217,16 +230,16 @@ export default {
criteria: isDefault ? [] : [{
operation: '',
input: '',
metaDataKey: this.openmct.telemetry.getMetadata(this.telemetryObjs[0]).values()[0].key,
key: this.telemetryObjs.length ? this.openmct.objects.makeKeyString(this.telemetryObjs[0].identifier) : null
metaDataKey: '',
key: ''
}]
},
summary: 'summary description'
};
let conditionDOKeyString = this.openmct.objects.makeKeyString(conditionObj.identifier);
let newDO = this.instantiate(conditionObj, conditionDOKeyString);
let conditionDomainObjectKeyString = this.openmct.objects.makeKeyString(conditionObj.identifier);
let newDomainObject = this.instantiate(conditionObj, conditionDomainObjectKeyString);
return newDO.useCapability('adapter');
return newDomainObject.useCapability('adapter');
},
updateCondition(updatedCondition) {
//TODO: this should only happen for reordering

View File

@ -21,6 +21,7 @@
*****************************************************************************/
<template>
<!-- TODO: current condition class should be set using openmct.objects.makeKeyString(<identifier>) -->
<div v-if="condition"
class="c-c-editui__conditions c-c-container__container c-c__drag-wrapper"
:class="['widget-condition', { 'widget-condition--current': currentConditionIdentifier && (currentConditionIdentifier.key === conditionIdentifier.key) }]"
@ -39,6 +40,7 @@
></span>
<div class="condition-summary">
<span class="condition-name">{{ condition.definition.name }}</span>
<!-- TODO: description should be derived from criteria -->
<span class="condition-description">{{ condition.definition.name }}</span>
</div>
<span v-if="!condition.isDefault"
@ -105,17 +107,22 @@
</li>
</ul>
<ul class="t-widget-condition-config">
<li v-if="telemetryObject && telemetryMetadata"
<li v-if="telemetry.length"
class="has-local-controls t-condition"
>
<label>when</label>
<span class="t-configuration">
<span class="controls">
<select v-model="selectedTelemetryKey"
class=""
@change="updateTelemetryMetaData"
>
<option value="">- Select Telemetry -</option>
<option :value="telemetryObject.identifier">{{ telemetryObject.name }}</option>
<option v-for="telemetryOption in telemetry"
:key="telemetryOption.identifier.key"
:value="telemetryOption.identifier"
>
{{ telemetryOption.name }}
</option>
</select>
</span>
<span class="controls">
@ -130,8 +137,8 @@
</select>
</span>
<span class="controls">
<select v-model="selectedOperationKey"
@change="operationKeyChange"
<select v-model="selectOperationName"
@change="setInputValueVisibility"
>
<option value="">- Select Comparison -</option>
<option v-for="option in operations"
@ -144,7 +151,7 @@
<input v-if="comparisonValueField"
class="t-condition-name-input"
type="text"
@keyup="getOperationValue"
v-model="operationValue"
>
</span>
</span>
@ -174,6 +181,11 @@ export default {
type: Object,
required: true
},
telemetry: {
type: Array,
required: true,
default: () => []
},
conditionIndex: {
type: Number,
required: true
@ -186,12 +198,13 @@ export default {
telemetryObject: this.telemetryObject,
telemetryMetadata: this.telemetryMetadata,
operations: OPERATIONS,
selectedMetaDataKey: null,
selectedMetaDataKey: '',
selectedTelemetryKey: '',
selectedOperationKey: '',
selectedOutputKey: null,
selectOperationName: '',
selectedOutputKey: '',
stringOutputField: false,
comparisonValueField: false,
operationValue: this.operationValue,
outputOptions: [
{
key: 'false',
@ -210,25 +223,17 @@ export default {
};
},
destroyed() {
this.conditionClass.off('conditionResultUpdated', this.handleConditionResult.bind(this));
if (this.conditionClass && typeof this.conditionClass.destroy === 'function') {
this.conditionClass.destroy();
}
this.destroy();
},
mounted() {
this.openmct.objects.get(this.conditionIdentifier).then((obj => {
this.condition = obj;
this.setOutput();
this.setOperation();
this.updateTelemetry();
this.conditionClass = new ConditionClass(this.condition, this.openmct);
this.conditionClass.on('conditionResultUpdated', this.handleConditionResult.bind(this));
this.initialize();
}));
},
updated() {
if (this.isCurrent && this.isCurrent.key === this.condition.key) {
this.updateCurrentCondition();
}
//validate telemetry exists, update criteria as needed
this.validate();
this.persist();
},
methods: {
@ -237,20 +242,50 @@ export default {
e.dataTransfer.setDragImage(e.target.closest('.c-c-container__container'), 0, 0);
this.$emit('setMoveIndex', this.conditionIndex);
},
initialize() {
this.setOutput();
this.setOperation();
this.updateTelemetry();
this.conditionClass = new ConditionClass(this.condition, this.openmct);
this.conditionClass.on('conditionResultUpdated', this.handleConditionResult.bind(this));
},
destroy() {
this.conditionClass.off('conditionResultUpdated', this.handleConditionResult.bind(this));
if (this.conditionClass && typeof this.conditionClass.destroy === 'function') {
this.conditionClass.destroy();
delete this.conditionClass;
}
},
reset() {
this.selectedMetaDataKey = '';
this.selectedTelemetryKey = '';
this.selectOperationName = '';
this.operationValue = '';
},
validate() {
if (this.hasTelemetry() && !this.getTelemetryKey()) {
this.reset();
} else {
if (!this.conditionClass) {
this.initialize();
}
}
},
handleConditionResult(args) {
this.$emit('conditionResultUpdated', {
id: this.conditionIdentifier,
result: args.data.result
})
},
removeCondition(ev) { //move this to conditionCollection
removeCondition(ev) {
this.$emit('removeCondition', this.conditionIdentifier);
},
setOutput() {
if (this.condition.definition.output !== 'false' && this.condition.definition.output !== 'true') {
let conditionOutput = this.condition.definition.output;
if (conditionOutput !== 'false' && conditionOutput !== 'true') {
this.selectedOutputKey = this.outputOptions[2].key;
} else {
if (this.condition.definition.output === 'true') {
if (conditionOutput === 'true') {
this.selectedOutputKey = this.outputOptions[1].key;
} else {
this.selectedOutputKey = this.outputOptions[0].key;
@ -261,7 +296,11 @@ export default {
if (this.condition.definition.criteria.length && this.condition.definition.criteria[0].operation) {
for (let i=0, ii=this.operations.length; i < ii; i++) {
if (this.condition.definition.criteria[0].operation === this.operations[i].name) {
this.selectedOperationKey = this.operations[i].name;
this.selectOperationName = this.operations[i].name;
this.comparisonValueField = this.operations[i].inputCount > 0;
if (this.comparisonValueField) {
this.operationValue = this.condition.definition.criteria[0].input[0];
}
}
}
}
@ -271,17 +310,47 @@ export default {
this.openmct.objects.get(this.condition.definition.criteria[0].key).then((obj) => {
this.telemetryObject = obj;
this.telemetryMetadata = this.openmct.telemetry.getMetadata(this.telemetryObject).values();
this.selectedMetaDataKey = '';
this.selectedTelemetryKey = this.telemetryObject.identifier;
this.selectedMetaDataKey = this.getTelemetryMetadataKey();
this.selectedTelemetryKey = this.getTelemetryKey();
});
} else {
this.telemetryObject = null;
}
},
getTelemetryMetadataKey() {
let index = -1;
if (this.condition.definition.criteria[0].metaDataKey) {
index = _.findIndex(this.telemetryMetadata, (metadata) => {
return metadata.key === this.condition.definition.criteria[0].metaDataKey;
});
}
return this.telemetryMetadata.length && index > -1 ? this.telemetryMetadata[index].key : '';
},
getTelemetryKey() {
let index = -1;
if (this.condition.definition.criteria[0].key) {
index = _.findIndex(this.telemetry, (obj) => {
let key = this.openmct.objects.makeKeyString(obj.identifier);
let conditionKey = this.openmct.objects.makeKeyString(this.condition.definition.criteria[0].key);
return key === conditionKey;
});
}
return this.telemetry.length && index > -1 ? this.telemetry[index].identifier : '';
},
hasTelemetry() {
return this.condition.definition.criteria.length && this.condition.definition.criteria[0].key;
},
updateConditionCriteria() {
if (this.condition.definition.criteria.length) {
let criterion = this.condition.definition.criteria[0];
criterion.key = this.selectedTelemetryKey;
criterion.metaDataKey = this.selectedMetaDataKey;
criterion.operation = this.selectOperationName;
criterion.input = [this.operationValue];
}
},
persist() {
this.updateConditionCriteria();
this.openmct.objects.mutate(this.condition, 'definition', this.condition.definition);
},
checkInputValue() {
@ -291,20 +360,19 @@ export default {
this.condition.definition.output = this.selectedOutputKey;
}
},
operationKeyChange(ev) {
if (ev.target.value !== 'isUndefined' && ev.target.value !== 'isDefined') {
this.comparisonValueField = true;
} else {
this.comparisonValueField = false;
setInputValueVisibility(ev) {
for (let i=0, ii=this.operations.length; i < ii; i++) {
if (this.selectOperationName === this.operations[i].name) {
this.comparisonValueField = this.operations[i].inputCount > 0;
break;
}
}
this.condition.definition.criteria[0].operation = this.selectedOperationKey;
this.persist();
//find the criterion being updated and set the operation property
},
getOperationValue(ev) {
this.condition.definition.criteria[0].input = [ev.target.value];
this.persist();
//find the criterion being updated and set the input property
updateTelemetryMetaData() {
this.selectedMetaDataKey = '';
this.updateConditionCriteria();
this.updateTelemetry();
},
updateCurrentCondition() {
this.$emit('updateCurrentCondition', this.conditionIdentifier);

View File

@ -21,15 +21,13 @@
*****************************************************************************/
<template>
<div class="c-object-view u-contents">
<div class="c-cs-edit w-condition-set">
<div class="c-sw-edit__ui holder">
<CurrentOutput :condition="currentCondition" />
<TestData :is-editing="isEditing" />
<ConditionCollection :is-editing="isEditing"
@current-condition-updated="updateCurrentCondition"
/>
</div>
<div class="c-cs-edit w-condition-set">
<div class="c-sw-edit__ui holder">
<CurrentOutput :condition="currentCondition" />
<TestData :is-editing="isEditing" />
<ConditionCollection :is-editing="isEditing"
@currentConditionUpdated="updateCurrentCondition"
/>
</div>
</div>
</template>

View File

@ -1,28 +1,13 @@
/**
* Returns true only if at least one of the results is true
**/
export const computeConditionForAny = (resultMap) => {
export const computeCondition = (resultMap, allMustBeTrue) => {
let result = false;
for (let key in resultMap) {
if (resultMap.hasOwnProperty(key)) {
result = resultMap[key];
if (result) {
break;
}
}
}
return result;
};
/**
* Returns true only if all the results are true
**/
export const computeConditionForAll = (resultMap) => {
let result = false;
for (let key in resultMap) {
if (resultMap.hasOwnProperty(key)) {
result = resultMap[key];
if (!result) {
if (allMustBeTrue && !result) {
//If we want all conditions to be true, then even one negative result should break.
break;
} else if (!allMustBeTrue && result) {
//If we want at least one condition to be true, then even one positive result should break.
break;
}
}

View File

@ -1,2 +0,0 @@
import Vue from 'vue';
export const EventBus = new Vue();