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: '', * telemetry: '',
* operation: '', * operation: '',
* input: '', * input: [],
* metadata: '' * metadata: ''
* } * }
* ] * ]

View File

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

View File

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

View File

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