WIP - Adding criteria using this.currentCriteria

This commit is contained in:
Joshi 2020-01-29 14:43:12 -08:00
parent 6f6fb859d6
commit f25eebdf3f

View File

@ -81,14 +81,16 @@
</span>
</li>
</ul>
<ul class="t-widget-rule-config">
<li v-if="telemetry.length"
<ul class="t-widget-rule-config"
v-if="telemetry.length">
<li v-for="criteria in condition.definition.criteria"
:key="criteria.key.key"
class="has-local-controls t-condition"
>
<label>when</label>
<span class="t-configuration">
<span class="controls">
<select v-model="selectedTelemetryKey"
<select v-model="selectedTelemetryKey[criteria.key.key]"
@change="updateTelemetryMetaData"
>
<option value="">- Select Telemetry -</option>
@ -144,6 +146,7 @@
<script>
import { OPERATIONS } from '../utils/operations';
import ConditionClass from "@/plugins/condition/Condition";
import uuid from 'uuid';
export default {
inject: ['openmct', 'domainObject'],
@ -169,8 +172,8 @@ export default {
telemetryObject: this.telemetryObject,
telemetryMetadata: this.telemetryMetadata,
operations: OPERATIONS,
selectedMetaDataKey: '',
selectedTelemetryKey: '',
selectedMetaDataKey: {},
selectedTelemetryKey: {},
selectedOperationKey: '',
selectedOutputKey: '',
stringOutputField: false,
@ -209,12 +212,27 @@ export default {
},
methods: {
initialize() {
this.condition.definition.criteria.push({
operation: '',
input: '',
metaDataKey: '',
key: {
namespace: '',
key: uuid()
}
});
if(this.condition.definition.criteria.length) {
this.setCurrentCriterion(0);
}
this.setOutput();
this.setOperation();
this.updateTelemetry();
this.conditionClass = new ConditionClass(this.condition, this.openmct);
this.conditionClass.on('conditionResultUpdated', this.handleConditionResult.bind(this));
},
setCurrentCriterion(index) {
this.currentCriteria = this.condition.definition.criteria[index];
},
destroy() {
this.conditionClass.off('conditionResultUpdated', this.handleConditionResult.bind(this));
if (this.conditionClass && typeof this.conditionClass.destroy === 'function') {
@ -223,8 +241,8 @@ export default {
}
},
reset() {
this.selectedMetaDataKey = '';
this.selectedTelemetryKey = '';
this.selectedMetaDataKey = {};
this.selectedTelemetryKey = {};
this.selectedOperationKey = '';
this.operationValue = '';
},
@ -258,13 +276,13 @@ export default {
}
},
setOperation() {
if (this.condition.definition.criteria.length && this.condition.definition.criteria[0].operation) {
if (this.currentCriteria && this.currentCriteria.operation) {
for (let i=0, ii=this.operations.length; i < ii; i++) {
if (this.condition.definition.criteria[0].operation === this.operations[i].name) {
if (this.currentCriteria.operation === 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[0];
this.operationValue = this.currentCriteria.input[0];
}
}
}
@ -272,11 +290,11 @@ export default {
},
updateTelemetry() {
if (this.hasTelemetry()) {
this.openmct.objects.get(this.condition.definition.criteria[0].key).then((obj) => {
this.openmct.objects.get(this.currentCriteria.key).then((obj) => {
this.telemetryObject = obj;
this.telemetryMetadata = this.openmct.telemetry.getMetadata(this.telemetryObject).values();
this.selectedMetaDataKey = this.getTelemetryMetadataKey();
this.selectedTelemetryKey = this.getTelemetryKey();
this.selectedTelemetryKey[this.currentCriteria.key] = this.getTelemetryKey();
});
} else {
this.telemetryObject = null;
@ -284,33 +302,33 @@ export default {
},
getTelemetryMetadataKey() {
let index = -1;
if (this.condition.definition.criteria[0].metaDataKey) {
if (this.currentCriteria.metaDataKey) {
index = _.findIndex(this.telemetryMetadata, (metadata) => {
return metadata.key === this.condition.definition.criteria[0].metaDataKey;
return metadata.key === this.currentCriteria.metaDataKey;
});
}
return this.telemetryMetadata.length && index > -1 ? this.telemetryMetadata[index].key : '';
},
getTelemetryKey() {
let index = -1;
if (this.condition.definition.criteria[0].key) {
if (this.currentCriteria.key) {
index = _.findIndex(this.telemetry, (obj) => {
let key = this.openmct.objects.makeKeyString(obj.identifier);
let conditionKey = this.openmct.objects.makeKeyString(this.condition.definition.criteria[0].key);
let conditionKey = this.openmct.objects.makeKeyString(this.currentCriteria.key);
return key === conditionKey;
});
}
return this.telemetry.length && index > -1 ? this.telemetry[index].identifier : '';
},
hasTelemetry() {
return this.condition.definition.criteria.length && this.condition.definition.criteria[0].key;
return this.currentCriteria && this.currentCriteria.key;
},
updateConditionCriteria() {
if (this.condition.definition.criteria.length) {
this.condition.definition.criteria[0].key = this.selectedTelemetryKey;
this.condition.definition.criteria[0].metaDataKey = this.selectedMetaDataKey;
this.condition.definition.criteria[0].operation = this.selectedOperationKey;
this.condition.definition.criteria[0].input = [this.operationValue];
if (this.currentCriteria) {
this.currentCriteria.key = this.selectedTelemetryKey;
this.currentCriteria.metaDataKey = this.selectedMetaDataKey;
this.currentCriteria.operation = this.selectedOperationKey;
this.currentCriteria.input = [this.operationValue];
}
},
persist() {