Set criteria options on condition edit

This commit is contained in:
Joshi 2020-01-23 15:51:08 -08:00
parent 23aaada79d
commit 862ea6986f
2 changed files with 48 additions and 8 deletions

View File

@ -35,6 +35,7 @@
> >
<div v-if="isEditing"> <div v-if="isEditing">
<ConditionEdit :condition-identifier="conditionIdentifier" <ConditionEdit :condition-identifier="conditionIdentifier"
:telemetry="telemetryObjs"
:is-current="currentConditionIdentifier" :is-current="currentConditionIdentifier"
@update-current-condition="updateCurrentCondition" @update-current-condition="updateCurrentCondition"
@remove-condition="removeCondition" @remove-condition="removeCondition"
@ -72,7 +73,8 @@ export default {
parentKeyString: this.openmct.objects.makeKeyString(this.domainObject.identifier), parentKeyString: this.openmct.objects.makeKeyString(this.domainObject.identifier),
conditionCollection: [], conditionCollection: [],
conditions: [], conditions: [],
currentConditionIdentifier: this.currentConditionIdentifier || {} currentConditionIdentifier: this.currentConditionIdentifier || {},
telemetryObjs: this.telemetryObjs
}; };
}, },
destroyed() { destroyed() {
@ -136,8 +138,8 @@ export default {
criteria: isDefault ? [] : [{ criteria: isDefault ? [] : [{
operation: '', operation: '',
input: '', input: '',
metaDataKey: this.openmct.telemetry.getMetadata(this.telemetryObjs[0]).values()[0].key, metaDataKey: '',
key: this.telemetryObjs.length ? this.openmct.objects.makeKeyString(this.telemetryObjs[0].identifier) : null key: ''
}] }]
}, },
summary: 'summary description' summary: 'summary description'

View File

@ -82,17 +82,21 @@
</li> </li>
</ul> </ul>
<ul class="t-widget-rule-config"> <ul class="t-widget-rule-config">
<li v-if="telemetryObject && telemetryMetadata" <li v-if="telemetry.length"
class="has-local-controls t-condition" class="has-local-controls t-condition"
> >
<label>when</label> <label>when</label>
<span class="t-configuration"> <span class="t-configuration">
<span class="controls"> <span class="controls">
<select v-model="selectedTelemetryKey" <select v-model="selectedTelemetryKey"
class=""
> >
<option value="">- Select Telemetry -</option> <option value="">- Select Telemetry -</option>
<option :value="telemetryObject.identifier">{{ telemetryObject.name }}</option> <option v-for="telemetryOption in telemetry"
:key="telemetryOption.identifier.key"
:value="telemetryOption.identifier"
>
{{ telemetryOption.name }}
</option>
</select> </select>
</span> </span>
<span class="controls"> <span class="controls">
@ -121,6 +125,7 @@
<input v-if="comparisonValueField" <input v-if="comparisonValueField"
class="t-rule-name-input" class="t-rule-name-input"
type="text" type="text"
v-model="operationValue"
@keyup="getOperationValue" @keyup="getOperationValue"
> >
</span> </span>
@ -150,6 +155,11 @@ export default {
isCurrent: { isCurrent: {
type: Object, type: Object,
required: true required: true
},
telemetry: {
type: Array,
required: true,
default: () => []
} }
}, },
data() { data() {
@ -165,6 +175,7 @@ export default {
selectedOutputKey: null, selectedOutputKey: null,
stringOutputField: false, stringOutputField: false,
comparisonValueField: false, comparisonValueField: false,
operationValue: this.operationValue,
outputOptions: [ outputOptions: [
{ {
key: 'false', key: 'false',
@ -230,6 +241,10 @@ export default {
for (let i=0, ii=this.operations.length; i < ii; i++) { for (let i=0, ii=this.operations.length; i < ii; i++) {
if (this.condition.definition.criteria[0].operation === this.operations[i].name) { if (this.condition.definition.criteria[0].operation === this.operations[i].name) {
this.selectedOperationKey = this.operations[i].name; this.selectedOperationKey = this.operations[i].name;
this.comparisonValueField = this.operations[i].inputCount > 0;
if (this.comparisonValueField) {
this.operationValue = this.condition.definition.criteria[0].input;
}
} }
} }
} }
@ -239,17 +254,40 @@ export default {
this.openmct.objects.get(this.condition.definition.criteria[0].key).then((obj) => { this.openmct.objects.get(this.condition.definition.criteria[0].key).then((obj) => {
this.telemetryObject = obj; this.telemetryObject = obj;
this.telemetryMetadata = this.openmct.telemetry.getMetadata(this.telemetryObject).values(); this.telemetryMetadata = this.openmct.telemetry.getMetadata(this.telemetryObject).values();
this.selectedMetaDataKey = this.telemetryMetadata[0].key; this.selectedMetaDataKey = this.getTelemetryMetadataKey();
this.selectedTelemetryKey = this.telemetryObject.identifier; this.selectedTelemetryKey = this.getTelemetryKey();
}); });
} else { } else {
this.telemetryObject = null; this.telemetryObject = null;
} }
}, },
getTelemetryMetadataKey() {
let index = 0;
if (this.condition.definition.criteria[0].metaDataKey) {
index = _.findIndex(this.telemetryMetadata, (metadata) => {
return metadata.key === this.condition.definition.criteria[0].metaDataKey;
});
}
return this.telemetryMetadata.length ? this.telemetryMetadata[index].key : null;
},
getTelemetryKey() {
let index = 0;
if (this.condition.definition.criteria[0].key) {
index = _.findIndex(this.telemetry, (obj) => {
let key = this.openmct.objects.makeKeyString(obj.identifier);
return key === this.condition.definition.criteria[0].key;
});
}
return this.telemetry.length ? this.telemetry[index].identifier : null;
},
hasTelemetry() { hasTelemetry() {
return this.condition.definition.criteria.length && this.condition.definition.criteria[0].key; return this.condition.definition.criteria.length && this.condition.definition.criteria[0].key;
}, },
persist() { persist() {
if (this.condition.definition.criteria.length) {
this.condition.definition.criteria[0].metaDataKey = this.selectedMetaDataKey;
this.condition.definition.criteria[0].input = this.operationValue || '';
}
this.openmct.objects.mutate(this.condition, 'definition', this.condition.definition); this.openmct.objects.mutate(this.condition, 'definition', this.condition.definition);
}, },
checkInputValue() { checkInputValue() {