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

View File

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

View File

@ -85,17 +85,23 @@
</span> </span>
</li> </li>
</ul> </ul>
<<<<<<< HEAD
<ul v-if="telemetry.length" <ul v-if="telemetry.length"
class="t-widget-condition-config"> class="t-widget-condition-config">
<li v-for="(criteria, index) in condition.definition.criteria" <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" :key="criteria.key.key"
class="has-local-controls t-condition" class="has-local-controls t-condition"
> >
<label>{{ index === 0 ? 'when' : 'and when' }}</label> <label>{{ index === 0 ? 'when' : 'and when' }}</label>
<span class="t-configuration"> <span class="t-configuration">
<span class="controls"> <span class="controls">
<select v-model="selectedTelemetryKey" <select v-model="selectedTelemetryKey[criteria.key.key]"
@change="telemetryChange" @change="updateTelemetryMetaData"
> >
<option value="">- Select Telemetry -</option> <option value="">- Select Telemetry -</option>
<option v-for="telemetryOption in telemetry" <option v-for="telemetryOption in telemetry"
@ -119,7 +125,7 @@
</span> </span>
<span class="controls"> <span class="controls">
<select v-model="selectedOperationKey" <select v-model="selectedOperationKey"
@change="operationKeyChange" @change="setInputValueVisibility"
> >
<option value="">- Select Comparison -</option> <option value="">- Select Comparison -</option>
<option v-for="option in operations" <option v-for="option in operations"
@ -189,8 +195,8 @@ export default {
telemetryObject: this.telemetryObject, telemetryObject: this.telemetryObject,
telemetryMetadata: this.telemetryMetadata, telemetryMetadata: this.telemetryMetadata,
operations: OPERATIONS, operations: OPERATIONS,
selectedMetaDataKey: '', selectedMetaDataKey: {},
selectedTelemetryKey: '', selectedTelemetryKey: {},
selectedOperationKey: '', selectedOperationKey: '',
selectedOutputKey: '', selectedOutputKey: '',
stringOutputField: false, stringOutputField: false,
@ -247,12 +253,27 @@ export default {
this.$emit('set-move-index', Number(e.target.getAttribute('data-condition-index'))); this.$emit('set-move-index', Number(e.target.getAttribute('data-condition-index')));
}, },
initialize() { 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.setOutput();
this.setOperation(); this.setOperation();
this.updateTelemetry(); this.updateTelemetry();
this.conditionClass = new ConditionClass(this.condition, this.openmct); this.conditionClass = new ConditionClass(this.condition, this.openmct);
this.conditionClass.on('conditionResultUpdated', this.handleConditionResult.bind(this)); this.conditionClass.on('conditionResultUpdated', this.handleConditionResult.bind(this));
}, },
setCurrentCriterion(index) {
this.currentCriteria = this.condition.definition.criteria[index];
},
destroy() { destroy() {
this.conditionClass.off('conditionResultUpdated', this.handleConditionResult.bind(this)); this.conditionClass.off('conditionResultUpdated', this.handleConditionResult.bind(this));
if (this.conditionClass && typeof this.conditionClass.destroy === 'function') { if (this.conditionClass && typeof this.conditionClass.destroy === 'function') {
@ -261,8 +282,8 @@ export default {
} }
}, },
reset() { reset() {
this.selectedMetaDataKey = ''; this.selectedMetaDataKey = {};
this.selectedTelemetryKey = ''; this.selectedTelemetryKey = {};
this.selectedOperationKey = ''; this.selectedOperationKey = '';
this.operationValue = ''; this.operationValue = '';
}, },
@ -302,13 +323,13 @@ export default {
} }
}, },
setOperation() { 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++) { 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.selectedOperationKey = this.operations[i].name;
this.comparisonValueField = this.operations[i].inputCount > 0; this.comparisonValueField = this.operations[i].inputCount > 0;
if (this.comparisonValueField) { 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() { updateTelemetry() {
if (this.hasTelemetry()) { 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.telemetryObject = obj;
this.telemetryMetadata = this.openmct.telemetry.getMetadata(this.telemetryObject).values(); this.telemetryMetadata = this.openmct.telemetry.getMetadata(this.telemetryObject).values();
this.selectedMetaDataKey = this.getTelemetryMetadataKey(); this.selectedMetaDataKey = this.getTelemetryMetadataKey();
this.selectedTelemetryKey = this.getTelemetryKey(); this.selectedTelemetryKey[this.currentCriteria.key] = this.getTelemetryKey();
}); });
} else { } else {
this.telemetryObject = null; this.telemetryObject = null;
@ -328,33 +349,33 @@ export default {
}, },
getTelemetryMetadataKey() { getTelemetryMetadataKey() {
let index = -1; let index = -1;
if (this.condition.definition.criteria[0].metaDataKey) { if (this.currentCriteria.metaDataKey) {
index = _.findIndex(this.telemetryMetadata, (metadata) => { 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 : ''; return this.telemetryMetadata.length && index > -1 ? this.telemetryMetadata[index].key : '';
}, },
getTelemetryKey() { getTelemetryKey() {
let index = -1; let index = -1;
if (this.condition.definition.criteria[0].key) { if (this.currentCriteria.key) {
index = _.findIndex(this.telemetry, (obj) => { index = _.findIndex(this.telemetry, (obj) => {
let key = this.openmct.objects.makeKeyString(obj.identifier); 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 key === conditionKey;
}); });
} }
return this.telemetry.length && index > -1 ? this.telemetry[index].identifier : ''; return this.telemetry.length && index > -1 ? this.telemetry[index].identifier : '';
}, },
hasTelemetry() { hasTelemetry() {
return this.condition.definition.criteria.length && this.condition.definition.criteria[0].key; return this.currentCriteria && this.currentCriteria.key;
}, },
updateConditionCriteria() { updateConditionCriteria() {
if (this.condition.definition.criteria.length) { if (this.currentCriteria) {
this.condition.definition.criteria[0].key = this.selectedTelemetryKey; this.currentCriteria.key = this.selectedTelemetryKey;
this.condition.definition.criteria[0].metaDataKey = this.selectedMetaDataKey; this.currentCriteria.metaDataKey = this.selectedMetaDataKey;
this.condition.definition.criteria[0].operation = this.selectedOperationKey; this.currentCriteria.operation = this.selectedOperationKey;
this.condition.definition.criteria[0].input = [this.operationValue]; this.currentCriteria.input = [this.operationValue];
} }
}, },
persist() { persist() {
@ -368,7 +389,7 @@ export default {
this.condition.definition.output = this.selectedOutputKey; this.condition.definition.output = this.selectedOutputKey;
} }
}, },
operationKeyChange(ev) { setInputValueVisibility(ev) {
if (this.selectedOperationKey !== 'isUndefined' && this.selectedOperationKey !== 'isDefined') { if (this.selectedOperationKey !== 'isUndefined' && this.selectedOperationKey !== 'isDefined') {
this.comparisonValueField = true; this.comparisonValueField = true;
} else { } else {
@ -376,7 +397,7 @@ export default {
} }
//find the criterion being updated and set the operation property //find the criterion being updated and set the operation property
}, },
telemetryChange() { updateTelemetryMetaData() {
this.selectedMetaDataKey = ''; this.selectedMetaDataKey = '';
this.updateConditionCriteria(); this.updateConditionCriteria();
this.updateTelemetry(); this.updateTelemetry();

View File

@ -1,28 +1,13 @@
/** export const computeCondition = (resultMap, allMustBeTrue) => {
* Returns true only if at least one of the results is true
**/
export const computeConditionForAny = (resultMap) => {
let result = false; let result = false;
for (let key in resultMap) { for (let key in resultMap) {
if (resultMap.hasOwnProperty(key)) { if (resultMap.hasOwnProperty(key)) {
result = resultMap[key]; result = resultMap[key];
if (result) { if (allMustBeTrue && !result) {
break; //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.
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) {
break; break;
} }
} }