refactored to address review comments

This commit is contained in:
Joel McKinnon 2020-02-14 15:23:15 -08:00
parent 11c205b5c4
commit 53e0ed4d4a

@ -3,7 +3,7 @@
<label>{{ setRowLabel }}</label>
<span class="t-configuration">
<span class="controls">
<select v-model="selectedTelemetryObject"
<select v-model="criterion.telemetry"
@change="updateMetadataOptions"
>
<option value="">- Select Telemetry -</option>
@ -16,7 +16,7 @@
</select>
</span>
<span class="controls">
<select v-model="selectedMetadataOption"
<select v-model="criterion.metadata"
@change="updateMetadataSelection"
>
<option value="">- Select Field -</option>
@ -29,8 +29,8 @@
</select>
</span>
<span class="controls">
<select v-model="selectedOperationOption"
@change="updateOperationOption"
<select v-model="criterion.operation"
@change="updateOperationInputVisibility"
>
<option value="">- Select Comparison -</option>
<option v-for="option in operations"
@ -41,10 +41,9 @@
</option>
</select>
<input v-if="isInputOperation"
v-model="comparisonInputValue"
v-model="criterion.input"
class="t-condition-name-input"
type="text"
@blur="setInput"
>
</span>
</span>
@ -80,10 +79,6 @@ export default {
return {
telemetryMetadata: {},
operations: OPERATIONS,
selectedTelemetryObject: this.criterion.telemetry || '',
selectedMetadataOption: this.criterion.metadata || {},
selectedOperationOption: this.criterion.operation || '',
comparisonInputValue: this.criterion.input || '',
isInputOperation: false,
rowLabel: ''
}
@ -91,55 +86,31 @@ export default {
computed: {
setRowLabel: function () {
let operator = this.trigger === 'all' ? 'and ': 'or ';
return (this.index !== 0 ? operator : '') + 'when';
}
},
mounted() {
this.initialize();
this.updateMetadataOptions();
this.updateOperationInputVisibility();
},
methods: {
initialize() {
this.updateMetadataOptions();
this.updateOperationInputVisibility();
},
updateMetadataOptions() {
if (this.selectedTelemetryObject) {
this.openmct.objects.get(this.selectedTelemetryObject).then((telemetryObject) => {
if (this.criterion.telemetry) {
this.openmct.objects.get(this.criterion.telemetry).then((telemetryObject) => {
this.telemetryMetadata = this.openmct.telemetry.getMetadata(telemetryObject).values();
});
this.criterion.telemetry = this.selectedTelemetryObject;
} else {
this.selectedMetadataOption = '';
}
this.persist();
},
updateOperationOption() {
this.criterion.operation = this.selectedOperationOption;
this.updateOperationInputVisibility();
this.persist();
},
updateOperationInputVisibility() {
for (let i=0; i < this.operations.length; i++) {
if (this.selectedOperationOption === this.operations[i].name) {
if (this.operations[i].inputCount > 0) {
this.isInputOperation = true;
} else {
this.isInputOperation = false;
this.comparisonInputValue = '';
}
if (this.criterion.operation === this.operations[i].name) {
this.isInputOperation = this.operations[i].inputCount > 0;
if (!this.isInputOperation) {this.criterion.input = ''}
}
}
this.criterion.operation = this.selectedOperationOption;
},
updateMetadataSelection() {
this.comparisonInputValue = '';
this.criterion.metadata = this.selectedMetadataOption;
this.persist();
},
setInput() {
this.criterion.input = this.comparisonInputValue;
this.persist();
},
persist() {
this.$emit('persist', this.criterion);