fixed merge conflict

This commit is contained in:
Joel McKinnon 2020-01-29 14:48:22 -08:00
commit 8886a94a01
4 changed files with 54 additions and 53 deletions

View File

@ -24,7 +24,7 @@ import * as EventEmitter from 'eventemitter3';
import uuid from 'uuid';
import TelemetryCriterion from "@/plugins/condition/criterion/TelemetryCriterion";
import { TRIGGER } from "@/plugins/condition/utils/constants";
import {computeConditionForAll, computeConditionForAny} from "@/plugins/condition/utils/evaluator";
import {computeCondition} from "@/plugins/condition/utils/evaluator";
/*
* conditionDefinition = {
@ -228,11 +228,7 @@ export default class ConditionClass extends EventEmitter {
//TODO: implement as part of the evaluator class task.
evaluate() {
if (this.trigger === TRIGGER.ANY) {
this.result = computeConditionForAny(this.criteriaResults);
} else if (this.trigger === TRIGGER.ALL) {
this.result = computeConditionForAll(this.criteriaResults);
}
this.result = computeCondition(this.criteriaResults, this.trigger === TRIGGER.ALL);
}
emitEvent(eventName, data) {

View File

@ -65,7 +65,7 @@ describe("The condition", function () {
testConditionDefinition = {
definition: {
trigger: 'any',
trigger: TRIGGER.ANY,
criteria: [
{
operation: 'equalTo',
@ -103,7 +103,6 @@ describe("The condition", function () {
it("initializes with criteria from the condition definition", function () {
expect(conditionObj.criteria.length).toEqual(1);
let criterion = conditionObj.criteria[0];
console.log(criterion);
expect(criterion instanceof TelemetryCriterion).toBeTrue();
expect(criterion.operator).toEqual(testConditionDefinition.definition.criteria[0].operator);
expect(criterion.input).toEqual(testConditionDefinition.definition.criteria[0].input);

View File

@ -85,17 +85,23 @@
</span>
</li>
</ul>
<<<<<<< HEAD
<ul v-if="telemetry.length"
class="t-widget-condition-config">
<li v-for="(criteria, index) in condition.definition.criteria"
=======
<ul class="t-widget-rule-config"
v-if="telemetry.length">
<li v-for="criteria in condition.definition.criteria"
>>>>>>> f25eebdf3f51d50f1fd180e4350fb0566f02e39f
:key="criteria.key.key"
class="has-local-controls t-condition"
>
<label>{{ index === 0 ? 'when' : 'and when' }}</label>
<span class="t-configuration">
<span class="controls">
<select v-model="selectedTelemetryKey"
@change="telemetryChange"
<select v-model="selectedTelemetryKey[criteria.key.key]"
@change="updateTelemetryMetaData"
>
<option value="">- Select Telemetry -</option>
<option v-for="telemetryOption in telemetry"
@ -119,7 +125,7 @@
</span>
<span class="controls">
<select v-model="selectedOperationKey"
@change="operationKeyChange"
@change="setInputValueVisibility"
>
<option value="">- Select Comparison -</option>
<option v-for="option in operations"
@ -189,8 +195,8 @@ export default {
telemetryObject: this.telemetryObject,
telemetryMetadata: this.telemetryMetadata,
operations: OPERATIONS,
selectedMetaDataKey: '',
selectedTelemetryKey: '',
selectedMetaDataKey: {},
selectedTelemetryKey: {},
selectedOperationKey: '',
selectedOutputKey: '',
stringOutputField: false,
@ -247,12 +253,27 @@ export default {
this.$emit('set-move-index', Number(e.target.getAttribute('data-condition-index')));
},
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') {
@ -261,8 +282,8 @@ export default {
}
},
reset() {
this.selectedMetaDataKey = '';
this.selectedTelemetryKey = '';
this.selectedMetaDataKey = {};
this.selectedTelemetryKey = {};
this.selectedOperationKey = '';
this.operationValue = '';
},
@ -302,13 +323,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];
}
}
}
@ -316,11 +337,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;
@ -328,33 +349,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() {
@ -368,7 +389,7 @@ export default {
this.condition.definition.output = this.selectedOutputKey;
}
},
operationKeyChange(ev) {
setInputValueVisibility(ev) {
if (this.selectedOperationKey !== 'isUndefined' && this.selectedOperationKey !== 'isDefined') {
this.comparisonValueField = true;
} else {
@ -376,7 +397,7 @@ export default {
}
//find the criterion being updated and set the operation property
},
telemetryChange() {
updateTelemetryMetaData() {
this.selectedMetaDataKey = '';
this.updateConditionCriteria();
this.updateTelemetry();

View File

@ -1,28 +1,13 @@
/**
* Returns true only if at least one of the results is true
**/
export const computeConditionForAny = (resultMap) => {
export const computeCondition = (resultMap, allMustBeTrue) => {
let result = false;
for (let key in resultMap) {
if (resultMap.hasOwnProperty(key)) {
result = resultMap[key];
if (result) {
break;
}
}
}
return result;
};
/**
* Returns true only if all the results are true
**/
export const computeConditionForAll = (resultMap) => {
let result = false;
for (let key in resultMap) {
if (resultMap.hasOwnProperty(key)) {
result = resultMap[key];
if (!result) {
if (allMustBeTrue && !result) {
//If we want all conditions to be true, then even one negative result should break.
break;
} else if (!allMustBeTrue && result) {
//If we want at least one condition to be true, then even one positive result should break.
break;
}
}