Add multiple criteria, set and persist inputs

This commit is contained in:
Joel McKinnon 2020-02-12 10:41:43 -08:00
parent 1f2b5ec5c8
commit 86316d8940
4 changed files with 67 additions and 197 deletions

View File

@ -35,9 +35,10 @@ import {computeCondition} from "@/plugins/condition/utils/evaluator";
* trigger: 'any'/'all', * trigger: 'any'/'all',
* criteria: [ * criteria: [
* { * {
* telemetry: '',
* operation: '', * operation: '',
* input: '', * input: '',
* metaDataKey: '', * metadata: '',
* key: 'someTelemetryObjectKey' * key: 'someTelemetryObjectKey'
* } * }
* ] * ]
@ -183,7 +184,7 @@ export default class ConditionClass extends EventEmitter {
if (found) { if (found) {
this.criteria[found.index] = criterion.data; this.criteria[found.index] = criterion.data;
//Most likely don't need this. //Most likely don't need this.
this.subscribe(); // this.subscribe();
this.emitEvent('conditionUpdated', { this.emitEvent('conditionUpdated', {
trigger: this.trigger, trigger: this.trigger,
criteria: this.criteria criteria: this.criteria

View File

@ -95,6 +95,7 @@
:criterion="criterion" :criterion="criterion"
:condition="domainObject" :condition="domainObject"
:index="index" :index="index"
@persist="persist"
/> />
</ul> </ul>
<div class="holder c-c-button-wrapper align-left"> <div class="holder c-c-button-wrapper align-left">
@ -138,7 +139,6 @@
</template> </template>
<script> <script>
// import { OPERATIONS } from '../utils/operations';
import ConditionClass from "@/plugins/condition/Condition"; import ConditionClass from "@/plugins/condition/Condition";
import Criterion from '../../condition/components/Criterion.vue'; import Criterion from '../../condition/components/Criterion.vue';
import uuid from 'uuid'; import uuid from 'uuid';
@ -205,16 +205,15 @@ export default {
}, },
addCriteria() { addCriteria() {
const criteriaObject = { const criteriaObject = {
telemetry: '',
operation: '', operation: '',
input: '', input: '',
metadataKey: '', metadata: '',
key: { key: {
namespace: '', namespace: '',
key: uuid() key: uuid()
} }
} }
this.selectedOperationName[this.currentCriteria.identifier] = undefined;
// this.comparisonValueField[id] = false;
this.domainObject.configuration.criteria.push(criteriaObject); this.domainObject.configuration.criteria.push(criteriaObject);
}, },
dragStart(e) { dragStart(e) {
@ -222,10 +221,10 @@ export default {
}, },
destroy() { destroy() {
// this.conditionClass.off('conditionResultUpdated', this.handleConditionResult.bind(this)); // this.conditionClass.off('conditionResultUpdated', this.handleConditionResult.bind(this));
// if (this.conditionClass && typeof this.conditionClass.destroy === 'function') { if (this.conditionClass && typeof this.conditionClass.destroy === 'function') {
// this.conditionClass.destroy(); this.conditionClass.destroy();
// delete this.conditionClass; delete this.conditionClass;
// } }
}, },
reset() { reset() {
this.selectedMetadataKey = {}; this.selectedMetadataKey = {};
@ -263,49 +262,7 @@ export default {
} }
} }
}, },
updateTelemetryObjects(criteriaId) {
if (this.hasTelemetry(criteriaId)) {
this.openmct.objects.get(criteriaId).then((obj) => {
this.telemetryMetadata[criteriaId] = this.openmct.telemetry.getMetadata(obj).values();
this.selectedFieldObject[criteriaId] = this.getTelemetryMetadataKey(criteriaId);
this.selectedTelemetryObject[criteriaId] = this.getTelemetryObject(criteriaId);
// console.log('this.telemetryMetadata[criteriaId]', this.telemetryMetadata[criteriaId])
// console.log('this.selectedMetadataKey[criteriaId]', this.selectedMetadataKey[criteriaId])
console.log('this.selectedTelemetryObject[criteriaId]', this.selectedTelemetryObject[criteriaId])
});
}
},
getTelemetryMetadataKey(criteriaId) {
let index = -1;
if (criteriaId) {
index = _.findIndex(this.telemetryMetadata[criteriaId], (metadata) => {
return metadata.key === this.currentCriteria.metadataKey;
});
}
return this.telemetryMetadata[criteriaId].length && index > -1 ? this.telemetryMetadata[criteriaId][index].key : '- Select Telemetry -';
},
getTelemetryObject(criteriaId) {
let index = -1;
if (this.currentCriteria && criteriaId) {
let conditionKey = this.openmct.objects.makeKeyString(criteriaId);
index = _.findIndex(this.telemetry, (obj) => {
let key = this.openmct.objects.makeKeyString(obj.identifier)
return key === conditionKey
});
}
return this.telemetry.length && index > -1 ? this.telemetry[index] : '';
},
// updateConditionCriteria(criteriaId) {
// if (this.domainObject.configuration.criteria.length) {
// let criterion = this.domainObject.configuration.criteria[0];
// criterion.key = this.selectedTelemetryKey[criteriaId];
// criterion.metadataKey = this.selectedMetadataKey[criteriaId];
// criterion.operation = this.selectedOperationName[criteriaId];
// criterion.input = this.operationValue;
// }
// },
persist() { persist() {
// this.updateConditionCriteria();
this.openmct.objects.mutate(this.domainObject, 'configuration', this.domainObject.configuration); this.openmct.objects.mutate(this.domainObject, 'configuration', this.domainObject.configuration);
}, },
checkInputValue() { checkInputValue() {
@ -315,15 +272,6 @@ export default {
this.domainObject.configuration.output = this.selectedOutputKey; this.domainObject.configuration.output = this.selectedOutputKey;
} }
}, },
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;
}
}
//find the criterion being updated and set the operation property
},
updateOutputOption(ev) { updateOutputOption(ev) {
if (this.selectedOutputKey === this.outputOptions[2].key) { if (this.selectedOutputKey === this.outputOptions[2].key) {
this.domainObject.configuration.output = ''; this.domainObject.configuration.output = '';
@ -331,33 +279,6 @@ export default {
this.domainObject.configuration.output = this.selectedOutputKey; this.domainObject.configuration.output = this.selectedOutputKey;
} }
}, },
// // I'm thinking the update select options handlers should call different functions
// updateTelemetryOptions() {
// this.updateConditionCriteria();
// this.updateTelemetryKeys();
// },
// updateFieldOptions() {
// this.updateConditionCriteria();
// this.updateTelemetryKeys();
// },
// updateComparisonOptions(ev, criteriaId) {
// if (ev.target.value !== undefined) {
// this.operationValue[criteriaId] = ev.target.value;
// // for (let i = 0, ii = this.operations.length; i < ii; i++) {
// // // console.log('this.selectedOperationName[criteriaId]', this.selectedOperationName[criteriaId])
// // // console.log('this.operations[i].name', this.operations[i].name)
// // if (this.selectedOperationName[criteriaId] === this.operations[i].name) {
// // // console.log('this.operations[i].inputCount', this.operations[i].inputCount);
// // //this.comparisonValueField[criteriaId] = this.operations[i].inputCount > 0;
// // console.log('this.comparisonValueField[criteriaId]', this.comparisonValueField[criteriaId]);
// // break;
// // }
// // }
// } else {
// this.operationValue[criteriaId] = undefined;
// }
// },
updateCurrentCondition() { updateCurrentCondition() {
this.$emit('updateCurrentCondition', this.conditionIdentifier); this.$emit('updateCurrentCondition', this.conditionIdentifier);
}, },

View File

@ -185,10 +185,10 @@ export default {
} }
this.$emit('currentConditionUpdated', currentConditionIdentifier); this.$emit('currentConditionUpdated', currentConditionIdentifier);
}, },
addTelemetryObject(domainObject) { // JM: don't see how object param ever gets passed to this addTelemetryObject(domainObject) {
this.telemetryObjs.push(domainObject); this.telemetryObjs.push(domainObject);
}, },
removeTelemetryObject(identifier) { // JM: don't see how identifier param ever gets passed to this removeTelemetryObject(identifier) {
let index = _.findIndex(this.telemetryObjs, (obj) => { let index = _.findIndex(this.telemetryObjs, (obj) => {
let objId = this.openmct.objects.makeKeyString(obj.identifier); let objId = this.openmct.objects.makeKeyString(obj.identifier);
let id = this.openmct.objects.makeKeyString(identifier); let id = this.openmct.objects.makeKeyString(identifier);
@ -220,9 +220,10 @@ export default {
output: 'false', output: 'false',
trigger: 'any', trigger: 'any',
criteria: isDefault ? [] : [{ criteria: isDefault ? [] : [{
telemetry: '',
operation: '', operation: '',
input: '', input: '',
metaDataKey: '', metadata: '',
identifier: { identifier: {
namespace: '', namespace: '',
key: this.telemetryObjs.length ? this.openmct.objects.makeKeyString(this.telemetryObjs[0].identifier) : null key: this.telemetryObjs.length ? this.openmct.objects.makeKeyString(this.telemetryObjs[0].identifier) : null
@ -258,39 +259,6 @@ export default {
}); });
this.persist(); this.persist();
}, },
updateTelemetryObjects(identifier) {
if (this.hasTelemetry(identifier)) {
this.openmct.objects.get(identifier).then((obj) => {
this.telemetryMetadata[identifier] = this.openmct.telemetry.getMetadata(obj).values();
this.selectedFieldObject[identifier] = this.getTelemetryMetadataKey(identifier);
this.selectedTelemetryObject[identifier] = this.getTelemetryObject(identifier);
// console.log('this.telemetryMetadata[identifier]', this.telemetryMetadata[identifier])
// console.log('this.selectedMetadataKey[identifier]', this.selectedMetadataKey[identifier])
console.log('this.selectedTelemetryObject[identifier]', this.selectedTelemetryObject[identifier])
});
}
},
getTelemetryMetadataKey(identifier) {
let index = -1;
if (identifier) {
index = _.findIndex(this.telemetryMetadata[identifier], (metadata) => {
return metadata.key === this.currentCriteria.metadataKey;
});
}
return this.telemetryMetadata[identifier].length && index > -1 ? this.telemetryMetadata[identifier][index].key : '- Select Telemetry -';
},
getTelemetryObject(identifier) {
let index = -1;
if (this.currentCriteria && identifier) {
let conditionKey = this.openmct.objects.makeKeyString(identifier);
index = _.findIndex(this.telemetry, (obj) => {
let key = this.openmct.objects.makeKeyString(obj.identifier)
return key === conditionKey
});
}
return this.telemetry.length && index > -1 ? this.telemetry[index] : '';
},
persist() { persist() {
this.openmct.objects.mutate(this.domainObject, 'configuration.conditionCollection', this.conditionCollection); this.openmct.objects.mutate(this.domainObject, 'configuration.conditionCollection', this.conditionCollection);
} }

View File

@ -3,7 +3,9 @@
<label>{{ index === 0 ? 'when' : 'and when' }}</label> <label>{{ index === 0 ? 'when' : 'and when' }}</label>
<span class="t-configuration"> <span class="t-configuration">
<span class="controls"> <span class="controls">
<select v-model="selectedTelemetryObject"> <select v-model="selectedTelemetryObject"
@change="updateFieldOptions"
>
<option value="">- Select Telemetry -</option> <option value="">- Select Telemetry -</option>
<option v-for="telemetryOption in telemetry" <option v-for="telemetryOption in telemetry"
:key="telemetryOption.identifier.key" :key="telemetryOption.identifier.key"
@ -14,18 +16,22 @@
</select> </select>
</span> </span>
<span class="controls"> <span class="controls">
<select v-model="selectedFieldObject"> <select v-model="selectedFieldOption"
@change="persist"
>
<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.key" :value="option"
> >
{{ option.name }} {{ option.name }}
</option> </option>
</select> </select>
</span> </span>
<span class="controls"> <span class="controls">
<select v-model="selectedOperationObject"> <select v-model="selectedOperationOption"
@change="updateOperationInput"
>
<option value="">- Select Comparison -</option> <option value="">- Select Comparison -</option>
<option v-for="option in operations" <option v-for="option in operations"
:key="option.name" :key="option.name"
@ -34,8 +40,11 @@
{{ option.text }} {{ option.text }}
</option> </option>
</select> </select>
<input class="t-condition-name-input" <input v-if="isInputOperation"
v-model="comparisonInputValue"
class="t-condition-name-input"
type="text" type="text"
@change="persist"
> >
</span> </span>
</span> </span>
@ -71,82 +80,53 @@ export default {
return { return {
telemetryMetadata: {}, telemetryMetadata: {},
operations: OPERATIONS, operations: OPERATIONS,
selectedTelemetryObject: {}, selectedTelemetryObject: '',
selectedFieldObject: {}, selectedFieldOption: {},
selectedOperationObject: {}, selectedOperationOption: '',
operationValue: {}, operationValue: '',
comparisonInputValue: {} comparisonInputValue: '',
isInputOperation: false
} }
}, },
mounted() { mounted() {
console.log('criterion', this.criterion);
console.log('condition', this.condition);
this.initialize(); this.initialize();
},
updated() {
// this.validate();
}, },
methods: { methods: {
initialize() { initialize() {
// 1. need to get values to appear in select menus and determine what should be selected this.selectedTelemetryObject = this.criterion.telemetry;
this.setTelemetrySelects() this.selectedFieldOption = this.criterion.metadata;
this.selectedOperationOption = this.criterion.operation;
// 2. for operation menu, show input unless isDefined, isUndefined are selected this.comparisonInputValue = this.criterion.input;
// this.setOperationInput() this.updateOperationInput();
this.updateFieldOptions();
}, },
setTelemetrySelects() { updateFieldOptions() {
console.log('this.domainObject', this.domainObject); if (this.selectedTelemetryObject) {
this.openmct.objects.get(this.selectedTelemetryObject).then((telemetryObject) => {
if (this.criterion.telemetryName) { this.telemetryMetadata = this.openmct.telemetry.getMetadata(telemetryObject).values();
this.selectedTelemetryObject.name = this.criterion.telemetryName;
} else {
this.telemetryObj[0].name = '- Select Telemetry -';
this.selectedTelemetryObject.name = '- Select Telemetry -';
}
this.openmct.objects.get(this.domainObject.identifier).then((condition) => {
// this.telemetryMetadata = this.openmct.telemetry.getMetadata(condition).values();
console.log('condition', condition);
}); });
}
// this.selectedFieldObject = this.getTelemetryMetadataKey(); this.persist();
// this.selectedTelemetryObject = this.getTelemetryObject();
// console.log('this.telemetryMetadata', this.telemetryMetadata)
// console.log('this.selectedMetadataKey', this.selectedMetadataKey)
// console.log('this.selectedTelemetryObject', this.selectedTelemetryObject)
}, },
setOperationInput() { updateOperationInput() {
if (this.selectedFieldObject !== undefined) { if (this.selectedOperationOption &&
if (this.operationValue !== undefined) { (this.selectedOperationOption !== 'isUndefined' &&
for (let i=0, ii=this.operations.length; i < ii; i++) { this.selectedOperationOption !== 'isDefined')) {
if (this.currentCriteria.operation === this.operations[i].name) { this.isInputOperation = true;
this.selectedFieldObject = this.operations[i].name; } else {
this.isInputOperation = false;
this.comparisonInputValue = this.operations[i].inputCount > 0; this.comparisonInputValue = '';
if (this.comparisonInputValue) {
this.operationValue = this.currentCriteria.input[0];
}
}
}
}
} }
this.persist();
}, },
hasTelemetry(identifier) { persist() {
// TODO: check parent domainObject.composition.hasTelemetry this.criterion.telemetry = this.selectedTelemetryObject;
return this.currentCriteria && identifier; this.criterion.metadata = this.selectedFieldOption;
this.criterion.operation = this.selectedOperationOption;
this.criterion.input = this.comparisonInputValue;
this.$emit('persist', this.criterion);
} }
// validate(criteriaId) {
// if (this.hasTelemetry(criteriaId) && !this.getTelemetryKey(criteriaId)) {
// this.reset();
// } else {
// if (!this.conditionClass) {
// this.initialize();
// }
// }
// }
} }
}; };
</script> </script>