Merge branch 'topic-conditionals' of https://github.com/nasa/openmct into firefox-drag-fix

This commit is contained in:
Joel McKinnon 2020-02-28 14:39:02 -08:00
commit 71424dcf8d
4 changed files with 78 additions and 30 deletions

View File

@ -37,7 +37,7 @@ import {computeCondition} from "./utils/evaluator";
* {
* telemetry: '',
* operation: '',
* input: '',
* input: [],
* metadata: ''
* }
* ]

View File

@ -83,7 +83,7 @@
:key="option"
:value="option"
>
{{ option.charAt(0).toUpperCase() + option.slice(1) }}
{{ initCap(option) }}
</option>
</select>
<input v-if="selectedOutputKey === outputOptions[2]"
@ -218,11 +218,6 @@ export default {
criterionIndex: 0
};
},
computed: {
initCap: function (string) {
return string.charAt(0).toUpperCase() + string.slice(1)
}
},
destroyed() {
this.destroy();
},
@ -291,10 +286,14 @@ export default {
} else {
this.domainObject.configuration.output = this.selectedOutputKey;
}
this.persist();
},
hasTelemetry(identifier) {
// TODO: check parent domainObject.composition.hasTelemetry
return this.currentCriteria && identifier;
},
initCap: function (string) {
return string.charAt(0).toUpperCase() + string.slice(1)
}
}
}

View File

@ -15,10 +15,14 @@
</option>
</select>
</span>
<span class="controls">
<select v-model="criterion.metadata">
<span v-if="criterion.telemetry"
class="controls"
>
<select v-model="criterion.metadata"
@change="updateOperations"
>
<option value="">- Select Field -</option>
<option v-for="option in telemetryMetadata"
<option v-for="option in telemetryMetadataOptions"
:key="option.key"
:value="option.key"
>
@ -26,24 +30,30 @@
</option>
</select>
</span>
<span class="controls">
<span v-if="criterion.telemetry && criterion.metadata"
class="controls"
>
<select v-model="criterion.operation"
@change="updateOperationInputVisibility"
>
<option value="">- Select Comparison -</option>
<option v-for="option in operations"
<option v-for="option in filteredOps"
:key="option.name"
:value="option.name"
>
{{ option.text }}
</option>
</select>
<input v-if="isInputOperation"
v-model="criterion.input"
class="t-condition-name-input"
type="text"
@blur="persist"
<span v-for="(item, inputIndex) in inputCount"
:key="inputIndex"
>
<input v-model="criterion.input[inputIndex]"
class="t-condition-name-input"
type="text"
@blur="persist"
>
<span v-if="inputIndex < inputCount-1">and</span>
</span>
</span>
</span>
</div>
@ -76,39 +86,80 @@ export default {
data() {
return {
telemetryMetadata: {},
telemetryMetadataOptions: {},
operations: OPERATIONS,
isInputOperation: false,
rowLabel: ''
inputCount: 0,
rowLabel: '',
operationFormat: ''
}
},
computed: {
setRowLabel: function () {
let operator = this.trigger === 'all' ? 'and ': 'or ';
return (this.index !== 0 ? operator : '') + 'when';
},
filteredOps: function () {
return [...this.operations.filter(op => op.appliesTo.indexOf(this.operationFormat) !== -1)];
}
},
mounted() {
this.updateMetadataOptions();
this.updateOperationInputVisibility();
},
methods: {
updateMetadataOptions() {
getOperationFormat() {
this.telemetryMetadata.valueMetadatas.forEach((value, index) => {
if (value.key === this.criterion.metadata) {
let valueMetadata = this.telemetryMetadataOptions[index];
if (valueMetadata.enumerations !== undefined) {
this.operationFormat = 'enum';
} 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';
}
}
});
},
updateMetadataOptions(ev) {
if (ev) {this.clearInputs()}
if (this.criterion.telemetry) {
this.openmct.objects.get(this.criterion.telemetry).then((telemetryObject) => {
this.telemetryMetadata = this.openmct.telemetry.getMetadata(telemetryObject).values();
this.telemetryMetadata = this.openmct.telemetry.getMetadata(telemetryObject);
this.telemetryMetadataOptions = this.telemetryMetadata.values();
this.updateOperations();
this.updateOperationInputVisibility();
});
} else {
this.criterion.metadata = '';
}
},
updateOperations(ev) {
if (ev) {this.clearInputs()}
this.getOperationFormat();
this.persist();
},
updateOperationInputVisibility() {
for (let i=0; i < this.operations.length; i++) {
if (this.criterion.operation === this.operations[i].name) {
this.isInputOperation = this.operations[i].inputCount > 0;
if (!this.isInputOperation) {this.criterion.input = ''}
updateOperationInputVisibility(ev) {
if (ev) {
this.criterion.input = [];
this.inputCount = 0;
}
for (let i = 0; i < this.filteredOps.length; i++) {
if (this.criterion.operation === this.filteredOps[i].name) {
this.inputCount = this.filteredOps[i].inputCount;
if (!this.inputCount) {this.criterion.input = []}
}
}
this.persist();
},
clearInputs() {
this.criterion.operation = '';
this.criterion.input = [];
this.inputCount = 0;
},
updateMetadataSelection() {
this.updateOperationInputVisibility();
},

View File

@ -78,9 +78,7 @@ export default class TelemetryCriterion extends EventEmitter {
let params = [];
params.push(data[this.metadata]);
if (this.input instanceof Array && this.input.length) {
params.push(this.input[0]);
} else {
params.push(this.input);
this.input.forEach(input => params.push(input));
}
if (typeof comparator === 'function') {
result = comparator(params);