Addresses comments: Fixes dropdown logic

This commit is contained in:
Joshi 2020-03-30 12:17:49 -07:00
parent 89a298f5b3
commit 14eaf4e899
2 changed files with 56 additions and 60 deletions

View File

@ -39,7 +39,7 @@
class="c-cdef__control" class="c-cdef__control"
> >
<select v-model="criterion.operation" <select v-model="criterion.operation"
@change="updateOperationInputVisibility" @change="updateInputVisibilityAndValues"
> >
<option value="">- Select Comparison -</option> <option value="">- Select Comparison -</option>
<option v-for="option in filteredOps" <option v-for="option in filteredOps"
@ -110,7 +110,6 @@ export default {
}, },
data() { data() {
return { return {
telemetryMetadata: {},
telemetryMetadataOptions: [], telemetryMetadataOptions: [],
operations: OPERATIONS, operations: OPERATIONS,
inputCount: 0, inputCount: 0,
@ -126,17 +125,13 @@ export default {
return (this.index !== 0 ? operator : '') + 'when'; return (this.index !== 0 ? operator : '') + 'when';
}, },
filteredOps: function () { filteredOps: function () {
if (this.operationFormat === 'all') { return this.operations.filter(op => op.appliesTo.indexOf(this.operationFormat) !== -1);
return this.operations;
} else {
return [...this.operations.filter(op => op.appliesTo.indexOf(this.operationFormat) !== -1)];
}
}, },
setInputType: function () { setInputType: function () {
let type = ''; let type = '';
for (let i = 0; i < this.filteredOps.length; i++) { for (let i = 0; i < this.filteredOps.length; i++) {
if (this.criterion.operation === this.filteredOps[i].name) { if (this.criterion.operation === this.filteredOps[i].name) {
if (this.filteredOps[i].appliesTo.length === 1) { if (this.filteredOps[i].appliesTo.length) {
type = this.inputTypes[this.filteredOps[i].appliesTo[0]]; type = this.inputTypes[this.filteredOps[i].appliesTo[0]];
} else { } else {
type = 'text' type = 'text'
@ -175,56 +170,46 @@ export default {
} }
} }
}, },
getOperationFormat() { updateOperationFormat() {
this.enumerations = []; this.enumerations = [];
if (this.criterion.telemetry && (this.criterion.telemetry === 'any' || this.criterion.telemetry === 'all')) { let foundMetadata = this.telemetryMetadataOptions.find((value) => {
this.operationFormat = 'all'; return value.key === this.criterion.metadata;
} else {
this.telemetryMetadata.valueMetadatas.forEach((value, index) => {
if (value.key === this.criterion.metadata) {
let valueMetadata = this.telemetryMetadataOptions[index];
if (valueMetadata.enumerations !== undefined) {
this.operationFormat = 'enum';
this.enumerations = valueMetadata.enumerations;
} else if (valueMetadata.hints.hasOwnProperty('range')) {
this.operationFormat = 'number';
} else if (valueMetadata.hints.hasOwnProperty('domain')) {
this.operationFormat = 'number';
} else if (valueMetadata.key === 'name') {
this.operationFormat = 'string';
} else {
this.operationFormat = 'string';
}
}
}); });
if (foundMetadata) {
if (foundMetadata.enumerations !== undefined) {
this.operationFormat = 'enum';
this.enumerations = foundMetadata.enumerations;
} else if (foundMetadata.hints.hasOwnProperty('range')) {
this.operationFormat = 'number';
} else if (foundMetadata.hints.hasOwnProperty('domain')) {
this.operationFormat = 'number';
} else if (foundMetadata.key === 'name') {
this.operationFormat = 'string';
} else {
this.operationFormat = 'string';
} }
}
this.updateInputVisibilityAndValues();
}, },
updateMetadataOptions(ev) { updateMetadataOptions(ev) {
if (ev) { if (ev) {
this.clearDependentFields(ev.target) this.clearDependentFields(ev.target);
this.persist();
} }
if (this.criterion.telemetry) { if (this.criterion.telemetry) {
if (this.criterion.telemetry === 'any' || this.criterion.telemetry === 'all') { const telemetry = (this.criterion.telemetry === 'all' || this.criterion.telemetry === 'any') ? this.telemetry : [{
let telemetryPromises = this.telemetry.map((telemetryObject) => this.openmct.objects.get(telemetryObject.identifier)); identifier: this.criterion.telemetry
}];
let telemetryPromises = telemetry.map((telemetryObject) => this.openmct.objects.get(telemetryObject.identifier));
Promise.all(telemetryPromises).then(telemetryObjects => { Promise.all(telemetryPromises).then(telemetryObjects => {
this.telemetryMetadataOptions = []; this.telemetryMetadataOptions = [];
telemetryObjects.forEach(telemetryObject => { telemetryObjects.forEach(telemetryObject => {
let telemetryMetadata = this.openmct.telemetry.getMetadata(telemetryObject); let telemetryMetadata = this.openmct.telemetry.getMetadata(telemetryObject);
this.addMetaDataOptions(telemetryMetadata.values()); this.addMetaDataOptions(telemetryMetadata.values());
this.updateOperations(ev);
this.updateOperationInputVisibility();
}); });
this.updateOperations();
}); });
} else {
this.openmct.objects.get(this.criterion.telemetry).then((telemetryObject) => {
this.telemetryMetadata = this.openmct.telemetry.getMetadata(telemetryObject);
this.telemetryMetadataOptions = this.telemetryMetadata.values();
this.updateOperations(ev);
this.updateOperationInputVisibility();
});
}
} else {
this.criterion.metadata = '';
} }
}, },
addMetaDataOptions(options) { addMetaDataOptions(options) {
@ -241,34 +226,45 @@ export default {
}); });
}, },
updateOperations(ev) { updateOperations(ev) {
if (ev && ev.target === this.$refs.telemetrySelect) { this.updateOperationFormat();
if (ev) {
this.clearDependentFields(ev.target); this.clearDependentFields(ev.target);
this.persist(); this.persist();
} }
this.getOperationFormat();
}, },
updateOperationInputVisibility(ev) { updateInputVisibilityAndValues(ev) {
if (ev) { if (ev) {
this.criterion.input = this.enumerations.length ? [this.enumerations[0].value.toString()] : []; this.clearDependentFields();
this.inputCount = 0;
this.persist(); this.persist();
} }
for (let i = 0; i < this.filteredOps.length; i++) { for (let i = 0; i < this.filteredOps.length; i++) {
if (this.criterion.operation === this.filteredOps[i].name) { if (this.criterion.operation === this.filteredOps[i].name) {
this.inputCount = this.filteredOps[i].inputCount; this.inputCount = this.filteredOps[i].inputCount;
if (!this.inputCount) {this.criterion.input = []}
} }
} }
if (!this.inputCount) {
this.criterion.input = [];
}
}, },
clearDependentFields(el) { clearDependentFields(el) {
if (el === this.$refs.telemetrySelect) { if (el === this.$refs.telemetrySelect) {
this.criterion.metadata = ''; this.criterion.metadata = '';
this.criterion.operation = ''; this.criterion.operation = '';
} else if (el === this.$refs.metadataSelect) { this.criterion.input = this.enumerations.length ? [this.enumerations[0].value.toString()] : [];
this.criterion.operation = '';
}
this.criterion.input = [];
this.inputCount = 0; this.inputCount = 0;
} else if (el === this.$refs.metadataSelect) {
if (!this.filteredOps.find(operation => operation.name === this.criterion.operation)) {
this.criterion.operation = '';
this.criterion.input = this.enumerations.length ? [this.enumerations[0].value.toString()] : [];
this.inputCount = 0;
}
} else {
if (this.enumerations.length && !this.criterion.input.length) {
this.criterion.input = [this.enumerations[0].value.toString()];
}
this.inputCount = 0;
}
}, },
persist() { persist() {
this.$emit('persist', this.criterion); this.$emit('persist', this.criterion);

View File

@ -87,7 +87,7 @@ export default class TelemetryCriterion extends EventEmitter {
} }
findOperation(operation) { findOperation(operation) {
for (let i=0, ii=OPERATIONS.length; i < ii; i++) { for (let i=0; i < OPERATIONS.length; i++) {
if (operation === OPERATIONS[i].name) { if (operation === OPERATIONS[i].name) {
return OPERATIONS[i].operation; return OPERATIONS[i].operation;
} }