WIP add criteria

This commit is contained in:
Joel McKinnon 2020-01-30 12:02:08 -08:00
parent 04a5c8f69f
commit 9bcab02e35

View File

@ -94,8 +94,8 @@
<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="selectedTelemetryKey" <select v-model="selectedTelemetryKey[currentCriteria.key]"
@change="telemetryChange" @change="updateTelemetryMetaData"
> >
<option value="">- Select Telemetry -</option> <option value="">- Select Telemetry -</option>
<option v-for="telemetryOption in telemetry" <option v-for="telemetryOption in telemetry"
@ -107,7 +107,7 @@
</select> </select>
</span> </span>
<span class="controls"> <span class="controls">
<select v-model="selectedMetaDataKey"> <select v-model="selectedMetaDataKey[currentCriteria.key]">
<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"
@ -118,8 +118,8 @@
</select> </select>
</span> </span>
<span class="controls"> <span class="controls">
<select v-model="selectedOperationKey" <select v-model="selectedOperationKey[currentCriteria.key]"
@change="operationKeyChange" @change="setInputValueVisibility"
> >
<option value="">- Select Comparison -</option> <option value="">- Select Comparison -</option>
<option v-for="option in operations" <option v-for="option in operations"
@ -130,7 +130,7 @@
</option> </option>
</select> </select>
<input v-if="comparisonValueField" <input v-if="comparisonValueField"
v-model="operationValue" v-model="operationValue[currentCriteria.key]"
class="t-condition-name-input" class="t-condition-name-input"
type="text" type="text"
> >
@ -192,11 +192,11 @@ export default {
trigger: 'all', trigger: 'all',
selectedMetaDataKey: {}, selectedMetaDataKey: {},
selectedTelemetryKey: {}, selectedTelemetryKey: {},
selectedOperationKey: '', selectedOperationKey: {},
selectedOutputKey: '', selectedOutputKey: '',
stringOutputField: false, stringOutputField: false,
comparisonValueField: false, comparisonValueField: false,
operationValue: this.operationValue, operationValue: {},
outputOptions: [ outputOptions: [
{ {
key: 'false', key: 'false',
@ -222,13 +222,11 @@ export default {
this.condition = obj; this.condition = obj;
this.initialize(); this.initialize();
})); }));
this.dragGhost = document.getElementById('js-c-drag-ghost');
}, },
updated() { updated() {
//validate telemetry exists, update criteria as needed //validate telemetry exists, update criteria as needed
// this.validate(); this.validate();
// this.persist(); this.persist();
}, },
methods: { methods: {
addCriteria() { addCriteria() {
@ -242,15 +240,15 @@ export default {
} }
} }
this.condition.definition.criteria.push(criteriaObject); this.condition.definition.criteria.push(criteriaObject);
console.log('this.condition.definition.criteria', this.condition.definition.criteria);
}, },
dragStart(e) { dragStart(e) {
this.$emit('set-move-index', Number(e.target.getAttribute('data-condition-index'))); this.$emit('set-move-index', Number(e.target.getAttribute('data-condition-index')));
}, },
initialize() { initialize() {
if(this.condition.definition.criteria.length) { if (!this.condition.definition.criteria.length) {
this.setCurrentCriterion(0); this.setCurrentCriterion(0);
} }
console.log('this.currentCriteria', this.currentCriteria);
this.setOutput(); this.setOutput();
this.setOperation(); this.setOperation();
this.updateTelemetry(); this.updateTelemetry();
@ -258,7 +256,6 @@ export default {
this.conditionClass.on('conditionResultUpdated', this.handleConditionResult.bind(this)); this.conditionClass.on('conditionResultUpdated', this.handleConditionResult.bind(this));
}, },
setCurrentCriterion(index) { setCurrentCriterion(index) {
console.log('setCurrentCriterion', 'index', index);
this.currentCriteria = this.condition.definition.criteria[index]; this.currentCriteria = this.condition.definition.criteria[index];
}, },
destroy() { destroy() {
@ -271,8 +268,8 @@ export default {
reset() { reset() {
this.selectedMetaDataKey = {}; this.selectedMetaDataKey = {};
this.selectedTelemetryKey = {}; this.selectedTelemetryKey = {};
this.selectedOperationKey = ''; this.selectedOperationKey = {};
this.operationValue = ''; this.operationValue = {};
}, },
validate() { validate() {
if (this.hasTelemetry() && !this.getTelemetryKey()) { if (this.hasTelemetry() && !this.getTelemetryKey()) {
@ -313,23 +310,22 @@ export default {
if (this.currentCriteria && this.currentCriteria.operation) { if (this.currentCriteria && this.currentCriteria.operation) {
for (let i=0, ii=this.operations.length; i < ii; i++) { for (let i=0, ii=this.operations.length; i < ii; i++) {
if (this.currentCriteria.operation === this.operations[i].name) { if (this.currentCriteria.operation === this.operations[i].name) {
this.selectedOperationKey = this.operations[i].name; this.selectedOperationKey[this.currentCriteria.key] = this.operations[i].name;
this.comparisonValueField = this.operations[i].inputCount > 0; this.comparisonValueField[this.currentCriteria.key] = this.operations[i].inputCount > 0;
if (this.comparisonValueField) { if (this.comparisonValueField[this.currentCriteria.key]) {
this.operationValue = this.currentCriteria.input[0]; this.operationValue[this.currentCriteria.key] = this.currentCriteria.input[0];
} }
} }
} }
} }
}, },
updateTelemetry() { updateTelemetry() {
console.log('update telemetry - this.currentCriteria.key', this.currentCriteria.key);
if (this.hasTelemetry()) { if (this.hasTelemetry()) {
this.openmct.objects.get(this.condition.definition.criteria[0].key).then((obj) => { this.openmct.objects.get(this.currentCriteria.key).then((obj) => {
this.telemetryObject = obj; this.telemetryObject = obj;
this.telemetryMetadata = this.openmct.telemetry.getMetadata(this.telemetryObject).values(); this.telemetryMetadata[this.currentCriteria.key.key] = this.openmct.telemetry.getMetadata(this.telemetryObject).values();
this.selectedMetaDataKey = this.getTelemetryMetadataKey(); this.selectedMetaDataKey[this.currentCriteria.key.key] = this.getTelemetryMetadataKey();
this.selectedTelemetryKey = this.getTelemetryKey(); this.selectedTelemetryKey[this.currentCriteria.key.key] = this.getTelemetryKey();
}); });
} else { } else {
this.telemetryObject = null; this.telemetryObject = null;
@ -337,33 +333,36 @@ export default {
}, },
getTelemetryMetadataKey() { getTelemetryMetadataKey() {
let index = -1; let index = -1;
if (this.condition.definition.criteria[0].metaDataKey) { if (this.currentCriteria.metaDataKey) {
index = _.findIndex(this.telemetryMetadata, (metadata) => { index = _.findIndex(this.telemetryMetadata, (metadata) => {
return metadata.key === this.condition.definition.criteria[0].metaDataKey; return metadata.key === this.currentCriteria.metaDataKey;
}); });
} }
return this.telemetryMetadata.length && index > -1 ? this.telemetryMetadata[index].key : ''; return this.telemetryMetadata.length && index > -1 ? this.telemetryMetadata[index].key : '';
}, },
getTelemetryKey() { getTelemetryKey() {
let index = -1; let index = -1;
if (this.condition.definition.criteria[0].key) { if (this.currentCriteria) {
index = _.findIndex(this.telemetry, (obj) => { if (this.currentCriteria.key) {
let key = this.openmct.objects.makeKeyString(obj.identifier); index = _.findIndex(this.telemetry, (obj) => {
let conditionKey = this.openmct.objects.makeKeyString(this.condition.definition.criteria[0].key);
return key === conditionKey; let key = this.openmct.objects.makeKeyString(obj.identifier);
}); let conditionKey = this.openmct.objects.makeKeyString(this.currentCriteria.key);
return key === conditionKey;
});
}
} }
return this.telemetry.length && index > -1 ? this.telemetry[index].identifier : ''; return this.telemetry.length && index > -1 ? this.telemetry[index].identifier : '';
}, },
hasTelemetry() { hasTelemetry() {
return this.condition.definition.criteria.length && this.condition.definition.criteria[0].key; return this.currentCriteria && this.currentCriteria.key;
}, },
updateConditionCriteria() { updateConditionCriteria() {
if (this.condition.definition.criteria.length) { if (this.currentCriteria) {
this.condition.definition.criteria[0].key = this.selectedTelemetryKey; this.currentCriteria.key = this.selectedTelemetryKey[this.currentCriteria.key];
this.condition.definition.criteria[0].metaDataKey = this.selectedMetaDataKey; this.currentCriteria.metaDataKey = this.selectedMetaDataKey[this.currentCriteria.key];
this.condition.definition.criteria[0].operation = this.selectedOperationKey; this.currentCriteria.operation = this.selectedOperationKey[this.currentCriteria.key];
this.condition.definition.criteria[0].input = [this.operationValue]; this.currentCriteria.input = this.operationValue[this.currentCriteria.key];
} }
}, },
persist() { persist() {
@ -377,16 +376,16 @@ export default {
this.condition.definition.output = this.selectedOutputKey; this.condition.definition.output = this.selectedOutputKey;
} }
}, },
operationKeyChange(ev) { setInputValueVisibility(ev) {
if (this.selectedOperationKey !== 'isUndefined' && this.selectedOperationKey !== 'isDefined') { if (this.selectedOperationKey[this.currentCriteria.key] !== 'isUndefined' && this.selectedOperationKey[this.currentCriteria.key] !== 'isDefined') {
this.comparisonValueField = true; this.comparisonValueField = true;
} else { } else {
this.comparisonValueField = false; this.comparisonValueField = false;
} }
//find the criterion being updated and set the operation property //find the criterion being updated and set the operation property
}, },
telemetryChange() { updateTelemetryMetaData() {
this.selectedMetaDataKey = ''; this.selectedMetaDataKey = {};
this.updateConditionCriteria(); this.updateConditionCriteria();
this.updateTelemetry(); this.updateTelemetry();
}, },