mirror of
https://github.com/nasa/openmct.git
synced 2024-12-30 09:58:52 +00:00
Add multiple criteria, set and persist inputs
This commit is contained in:
parent
1f2b5ec5c8
commit
86316d8940
@ -35,9 +35,10 @@ import {computeCondition} from "@/plugins/condition/utils/evaluator";
|
||||
* trigger: 'any'/'all',
|
||||
* criteria: [
|
||||
* {
|
||||
* telemetry: '',
|
||||
* operation: '',
|
||||
* input: '',
|
||||
* metaDataKey: '',
|
||||
* metadata: '',
|
||||
* key: 'someTelemetryObjectKey'
|
||||
* }
|
||||
* ]
|
||||
@ -183,7 +184,7 @@ export default class ConditionClass extends EventEmitter {
|
||||
if (found) {
|
||||
this.criteria[found.index] = criterion.data;
|
||||
//Most likely don't need this.
|
||||
this.subscribe();
|
||||
// this.subscribe();
|
||||
this.emitEvent('conditionUpdated', {
|
||||
trigger: this.trigger,
|
||||
criteria: this.criteria
|
||||
|
@ -90,11 +90,12 @@
|
||||
class="t-widget-condition-config"
|
||||
>
|
||||
<Criterion v-for="(criterion, index) in domainObject.configuration.criteria"
|
||||
:key="index"
|
||||
:telemetry="telemetry"
|
||||
:criterion="criterion"
|
||||
:condition="domainObject"
|
||||
:index="index"
|
||||
:key="index"
|
||||
:telemetry="telemetry"
|
||||
:criterion="criterion"
|
||||
:condition="domainObject"
|
||||
:index="index"
|
||||
@persist="persist"
|
||||
/>
|
||||
</ul>
|
||||
<div class="holder c-c-button-wrapper align-left">
|
||||
@ -138,7 +139,6 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
// import { OPERATIONS } from '../utils/operations';
|
||||
import ConditionClass from "@/plugins/condition/Condition";
|
||||
import Criterion from '../../condition/components/Criterion.vue';
|
||||
import uuid from 'uuid';
|
||||
@ -205,16 +205,15 @@ export default {
|
||||
},
|
||||
addCriteria() {
|
||||
const criteriaObject = {
|
||||
telemetry: '',
|
||||
operation: '',
|
||||
input: '',
|
||||
metadataKey: '',
|
||||
metadata: '',
|
||||
key: {
|
||||
namespace: '',
|
||||
key: uuid()
|
||||
}
|
||||
}
|
||||
this.selectedOperationName[this.currentCriteria.identifier] = undefined;
|
||||
// this.comparisonValueField[id] = false;
|
||||
this.domainObject.configuration.criteria.push(criteriaObject);
|
||||
},
|
||||
dragStart(e) {
|
||||
@ -222,10 +221,10 @@ export default {
|
||||
},
|
||||
destroy() {
|
||||
// this.conditionClass.off('conditionResultUpdated', this.handleConditionResult.bind(this));
|
||||
// if (this.conditionClass && typeof this.conditionClass.destroy === 'function') {
|
||||
// this.conditionClass.destroy();
|
||||
// delete this.conditionClass;
|
||||
// }
|
||||
if (this.conditionClass && typeof this.conditionClass.destroy === 'function') {
|
||||
this.conditionClass.destroy();
|
||||
delete this.conditionClass;
|
||||
}
|
||||
},
|
||||
reset() {
|
||||
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() {
|
||||
// this.updateConditionCriteria();
|
||||
this.openmct.objects.mutate(this.domainObject, 'configuration', this.domainObject.configuration);
|
||||
},
|
||||
checkInputValue() {
|
||||
@ -315,15 +272,6 @@ export default {
|
||||
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) {
|
||||
if (this.selectedOutputKey === this.outputOptions[2].key) {
|
||||
this.domainObject.configuration.output = '';
|
||||
@ -331,33 +279,6 @@ export default {
|
||||
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() {
|
||||
this.$emit('updateCurrentCondition', this.conditionIdentifier);
|
||||
},
|
||||
|
@ -185,10 +185,10 @@ export default {
|
||||
}
|
||||
this.$emit('currentConditionUpdated', currentConditionIdentifier);
|
||||
},
|
||||
addTelemetryObject(domainObject) { // JM: don't see how object param ever gets passed to this
|
||||
addTelemetryObject(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 objId = this.openmct.objects.makeKeyString(obj.identifier);
|
||||
let id = this.openmct.objects.makeKeyString(identifier);
|
||||
@ -220,9 +220,10 @@ export default {
|
||||
output: 'false',
|
||||
trigger: 'any',
|
||||
criteria: isDefault ? [] : [{
|
||||
telemetry: '',
|
||||
operation: '',
|
||||
input: '',
|
||||
metaDataKey: '',
|
||||
metadata: '',
|
||||
identifier: {
|
||||
namespace: '',
|
||||
key: this.telemetryObjs.length ? this.openmct.objects.makeKeyString(this.telemetryObjs[0].identifier) : null
|
||||
@ -258,39 +259,6 @@ export default {
|
||||
});
|
||||
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() {
|
||||
this.openmct.objects.mutate(this.domainObject, 'configuration.conditionCollection', this.conditionCollection);
|
||||
}
|
||||
|
@ -3,7 +3,9 @@
|
||||
<label>{{ index === 0 ? 'when' : 'and when' }}</label>
|
||||
<span class="t-configuration">
|
||||
<span class="controls">
|
||||
<select v-model="selectedTelemetryObject">
|
||||
<select v-model="selectedTelemetryObject"
|
||||
@change="updateFieldOptions"
|
||||
>
|
||||
<option value="">- Select Telemetry -</option>
|
||||
<option v-for="telemetryOption in telemetry"
|
||||
:key="telemetryOption.identifier.key"
|
||||
@ -14,18 +16,22 @@
|
||||
</select>
|
||||
</span>
|
||||
<span class="controls">
|
||||
<select v-model="selectedFieldObject">
|
||||
<select v-model="selectedFieldOption"
|
||||
@change="persist"
|
||||
>
|
||||
<option value="">- Select Field -</option>
|
||||
<option v-for="option in telemetryMetadata"
|
||||
:key="option.key"
|
||||
:value="option.key"
|
||||
:value="option"
|
||||
>
|
||||
{{ option.name }}
|
||||
</option>
|
||||
</select>
|
||||
</span>
|
||||
<span class="controls">
|
||||
<select v-model="selectedOperationObject">
|
||||
<select v-model="selectedOperationOption"
|
||||
@change="updateOperationInput"
|
||||
>
|
||||
<option value="">- Select Comparison -</option>
|
||||
<option v-for="option in operations"
|
||||
:key="option.name"
|
||||
@ -34,8 +40,11 @@
|
||||
{{ option.text }}
|
||||
</option>
|
||||
</select>
|
||||
<input class="t-condition-name-input"
|
||||
<input v-if="isInputOperation"
|
||||
v-model="comparisonInputValue"
|
||||
class="t-condition-name-input"
|
||||
type="text"
|
||||
@change="persist"
|
||||
>
|
||||
</span>
|
||||
</span>
|
||||
@ -71,82 +80,53 @@ export default {
|
||||
return {
|
||||
telemetryMetadata: {},
|
||||
operations: OPERATIONS,
|
||||
selectedTelemetryObject: {},
|
||||
selectedFieldObject: {},
|
||||
selectedOperationObject: {},
|
||||
operationValue: {},
|
||||
comparisonInputValue: {}
|
||||
selectedTelemetryObject: '',
|
||||
selectedFieldOption: {},
|
||||
selectedOperationOption: '',
|
||||
operationValue: '',
|
||||
comparisonInputValue: '',
|
||||
isInputOperation: false
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
console.log('criterion', this.criterion);
|
||||
console.log('condition', this.condition);
|
||||
this.initialize();
|
||||
|
||||
},
|
||||
updated() {
|
||||
// this.validate();
|
||||
},
|
||||
methods: {
|
||||
initialize() {
|
||||
// 1. need to get values to appear in select menus and determine what should be selected
|
||||
this.setTelemetrySelects()
|
||||
|
||||
// 2. for operation menu, show input unless isDefined, isUndefined are selected
|
||||
// this.setOperationInput()
|
||||
this.selectedTelemetryObject = this.criterion.telemetry;
|
||||
this.selectedFieldOption = this.criterion.metadata;
|
||||
this.selectedOperationOption = this.criterion.operation;
|
||||
this.comparisonInputValue = this.criterion.input;
|
||||
this.updateOperationInput();
|
||||
this.updateFieldOptions();
|
||||
|
||||
},
|
||||
setTelemetrySelects() {
|
||||
console.log('this.domainObject', this.domainObject);
|
||||
|
||||
if (this.criterion.telemetryName) {
|
||||
this.selectedTelemetryObject.name = this.criterion.telemetryName;
|
||||
updateFieldOptions() {
|
||||
if (this.selectedTelemetryObject) {
|
||||
this.openmct.objects.get(this.selectedTelemetryObject).then((telemetryObject) => {
|
||||
this.telemetryMetadata = this.openmct.telemetry.getMetadata(telemetryObject).values();
|
||||
});
|
||||
}
|
||||
this.persist();
|
||||
},
|
||||
updateOperationInput() {
|
||||
if (this.selectedOperationOption &&
|
||||
(this.selectedOperationOption !== 'isUndefined' &&
|
||||
this.selectedOperationOption !== 'isDefined')) {
|
||||
this.isInputOperation = true;
|
||||
} else {
|
||||
this.telemetryObj[0].name = '- Select Telemetry -';
|
||||
this.selectedTelemetryObject.name = '- Select Telemetry -';
|
||||
this.isInputOperation = false;
|
||||
this.comparisonInputValue = '';
|
||||
}
|
||||
|
||||
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.selectedTelemetryObject = this.getTelemetryObject();
|
||||
// console.log('this.telemetryMetadata', this.telemetryMetadata)
|
||||
// console.log('this.selectedMetadataKey', this.selectedMetadataKey)
|
||||
// console.log('this.selectedTelemetryObject', this.selectedTelemetryObject)
|
||||
this.persist();
|
||||
},
|
||||
setOperationInput() {
|
||||
if (this.selectedFieldObject !== undefined) {
|
||||
if (this.operationValue !== undefined) {
|
||||
for (let i=0, ii=this.operations.length; i < ii; i++) {
|
||||
if (this.currentCriteria.operation === this.operations[i].name) {
|
||||
this.selectedFieldObject = this.operations[i].name;
|
||||
|
||||
this.comparisonInputValue = this.operations[i].inputCount > 0;
|
||||
if (this.comparisonInputValue) {
|
||||
this.operationValue = this.currentCriteria.input[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
hasTelemetry(identifier) {
|
||||
// TODO: check parent domainObject.composition.hasTelemetry
|
||||
return this.currentCriteria && identifier;
|
||||
persist() {
|
||||
this.criterion.telemetry = this.selectedTelemetryObject;
|
||||
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>
|
||||
|
Loading…
Reference in New Issue
Block a user