From 01b1d66bea801df5e1bca386079021e149696e65 Mon Sep 17 00:00:00 2001 From: Joel McKinnon Date: Tue, 28 Jan 2020 10:05:58 -0800 Subject: [PATCH 1/5] duplicate condition complete --- .../components/ConditionCollection.vue | 42 ++++++++++++++----- .../condition/components/ConditionEdit.vue | 11 +++-- 2 files changed, 39 insertions(+), 14 deletions(-) diff --git a/src/plugins/condition/components/ConditionCollection.vue b/src/plugins/condition/components/ConditionCollection.vue index 6363426cf6..8dae3642c6 100644 --- a/src/plugins/condition/components/ConditionCollection.vue +++ b/src/plugins/condition/components/ConditionCollection.vue @@ -45,6 +45,7 @@ :condition-index="index" @update-current-condition="updateCurrentCondition" @remove-condition="removeCondition" + @clone-condition="cloneCondition" @condition-result-updated="handleConditionResult" @set-move-index="setMoveIndex" /> @@ -168,17 +169,36 @@ export default { addTelemetry(telemetryDomainObject) { this.telemetryObjs.push(telemetryDomainObject); }, - addCondition(event, isDefault) { - let conditionDO = this.getConditionDomainObject(!!isDefault); + /* + Adds a condition to list via programatic creation of default for initial list, manual + creation via Add Condition button, or duplication via button in title bar of condition. + Params: + event: always null, + idDefault (boolean): true if conditionList is empty + isClone (boolean): true if duplicating a condition + name (string): name of condition being duplicated + index (number): index of condition being duplicated + */ + addCondition(event, isDefault, isClone, name, index) { + let conditionDO = this.getConditionDomainObject(!!isDefault, isClone, name, index); //persist the condition DO so that we can do an openmct.objects.get on it and only persist the identifier in the conditionCollection of conditionSet this.openmct.objects.mutate(conditionDO, 'created', new Date()); - this.conditionCollection.unshift(conditionDO.identifier); + if (!isClone) { + this.conditionCollection.unshift(conditionDO.identifier); + } else { + this.conditionCollection.splice(index + 1, 0, conditionDO.identifier); + } this.persist(); }, updateCurrentCondition(identifier) { this.currentConditionIdentifier = identifier; }, - getConditionDomainObject(isDefault) { + getConditionDomainObject(isDefault, isClone, name) { + if (isClone) { + name = 'Copy of ' + name; + } else { + name = isDefault ? 'Default' : 'Unnamed Condition'; + } let conditionObj = { isDefault: isDefault, identifier: { @@ -186,7 +206,7 @@ export default { key: uuid() }, definition: { - name: isDefault ? 'Default' : 'Unnamed Condition', + name: name, output: 'false', trigger: 'any', criteria: isDefault ? [] : [{ @@ -203,11 +223,6 @@ export default { return newDO.useCapability('adapter'); }, - updateCondition(updatedCondition) { - //TODO: this should only happen for reordering - let index = _.findIndex(this.conditions, (condition) => condition.id === updatedCondition.id); - this.conditions[index] = updatedCondition; - }, removeCondition(identifier) { let index = _.findIndex(this.conditionCollection, (condition) => { let conditionId = this.openmct.objects.makeKeyString(condition); @@ -219,12 +234,17 @@ export default { this.updateCurrentConditionId(); }, reorder(reorderPlan) { - let oldConditions = this.conditionCollection.slice(); + let oldConditions = Array.from(this.conditionCollection); reorderPlan.forEach((reorderEvent) => { this.$set(this.conditionCollection, reorderEvent.newIndex, oldConditions[reorderEvent.oldIndex]); }); this.persist(); }, + cloneCondition(condition) { + this.openmct.objects.get(condition.identifier).then((obj) => { + this.addCondition(null, false, true, obj.definition.name, condition.index); + }); + }, persist() { this.openmct.objects.mutate(this.domainObject, 'configuration.conditionCollection', this.conditionCollection); } diff --git a/src/plugins/condition/components/ConditionEdit.vue b/src/plugins/condition/components/ConditionEdit.vue index 883fd135b7..447643a4e3 100644 --- a/src/plugins/condition/components/ConditionEdit.vue +++ b/src/plugins/condition/components/ConditionEdit.vue @@ -23,6 +23,7 @@ { this.telemetryObject = obj; this.telemetryMetadata = this.openmct.telemetry.getMetadata(this.telemetryObject).values(); - // this.selectedMetaDataKey = this.telemetryMetadata[0].key; this.selectedMetaDataKey = ''; this.selectedTelemetryKey = this.telemetryObject.identifier; }); From 3c5047df5edcef44cee4f01ba0d1e7211966592e Mon Sep 17 00:00:00 2001 From: Joel McKinnon Date: Tue, 28 Jan 2020 12:10:21 -0800 Subject: [PATCH 2/5] passed definition prop instead of just name --- .../components/ConditionCollection.vue | 37 +++++++++---------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/src/plugins/condition/components/ConditionCollection.vue b/src/plugins/condition/components/ConditionCollection.vue index 8dae3642c6..bd2f15f9c0 100644 --- a/src/plugins/condition/components/ConditionCollection.vue +++ b/src/plugins/condition/components/ConditionCollection.vue @@ -176,11 +176,11 @@ export default { event: always null, idDefault (boolean): true if conditionList is empty isClone (boolean): true if duplicating a condition - name (string): name of condition being duplicated + definition (string): definition property of condition being duplicated with new name index (number): index of condition being duplicated */ - addCondition(event, isDefault, isClone, name, index) { - let conditionDO = this.getConditionDomainObject(!!isDefault, isClone, name, index); + addCondition(event, isDefault, isClone, definition, index) { + let conditionDO = this.getConditionDomainObject(!!isDefault, isClone, definition); //persist the condition DO so that we can do an openmct.objects.get on it and only persist the identifier in the conditionCollection of conditionSet this.openmct.objects.mutate(conditionDO, 'created', new Date()); if (!isClone) { @@ -193,11 +193,17 @@ export default { updateCurrentCondition(identifier) { this.currentConditionIdentifier = identifier; }, - getConditionDomainObject(isDefault, isClone, name) { - if (isClone) { - name = 'Copy of ' + name; - } else { - name = isDefault ? 'Default' : 'Unnamed Condition'; + getConditionDomainObject(isDefault, isClone, definition) { + const definitionTemplate = { + name: isDefault ? 'Default' : 'Unnamed Condition', + output: 'false', + trigger: 'any', + criteria: isDefault ? [] : [{ + operation: '', + input: '', + metaDataKey: this.openmct.telemetry.getMetadata(this.telemetryObjs[0]).values()[0].key, + key: this.telemetryObjs.length ? this.openmct.objects.makeKeyString(this.telemetryObjs[0].identifier) : null + }] } let conditionObj = { isDefault: isDefault, @@ -205,17 +211,7 @@ export default { namespace: this.domainObject.identifier.namespace, key: uuid() }, - definition: { - name: name, - output: 'false', - trigger: 'any', - criteria: isDefault ? [] : [{ - operation: '', - input: '', - metaDataKey: this.openmct.telemetry.getMetadata(this.telemetryObjs[0]).values()[0].key, - key: this.telemetryObjs.length ? this.openmct.objects.makeKeyString(this.telemetryObjs[0].identifier) : null - }] - }, + definition: isClone ? definition: definitionTemplate, summary: 'summary description' }; let conditionDOKeyString = this.openmct.objects.makeKeyString(conditionObj.identifier); @@ -242,7 +238,8 @@ export default { }, cloneCondition(condition) { this.openmct.objects.get(condition.identifier).then((obj) => { - this.addCondition(null, false, true, obj.definition.name, condition.index); + obj.definition.name = 'Copy of ' + obj.definition.name; + this.addCondition(null, false, true, obj.definition, condition.index); }); }, persist() { From 03a6de55d6fde629580155ed0232325e5e286be2 Mon Sep 17 00:00:00 2001 From: Joel McKinnon Date: Tue, 28 Jan 2020 12:16:18 -0800 Subject: [PATCH 3/5] typo in comment --- src/plugins/condition/components/ConditionCollection.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/condition/components/ConditionCollection.vue b/src/plugins/condition/components/ConditionCollection.vue index bd2f15f9c0..e8b9620969 100644 --- a/src/plugins/condition/components/ConditionCollection.vue +++ b/src/plugins/condition/components/ConditionCollection.vue @@ -174,7 +174,7 @@ export default { creation via Add Condition button, or duplication via button in title bar of condition. Params: event: always null, - idDefault (boolean): true if conditionList is empty + isDefault (boolean): true if conditionList is empty isClone (boolean): true if duplicating a condition definition (string): definition property of condition being duplicated with new name index (number): index of condition being duplicated From 79811d6662a9413b23dbbf9f3d499c8a7aee938e Mon Sep 17 00:00:00 2001 From: Joshi Date: Tue, 4 Feb 2020 15:12:33 -0800 Subject: [PATCH 4/5] Merge condition-ui branch into this. --- src/plugins/condition/Condition.js | 8 +- .../condition/ConditionSetViewProvider.js | 2 +- src/plugins/condition/ConditionSpec.js | 1 - .../condition/components/Condition.vue | 19 ++ .../components/ConditionCollection.vue | 79 +++++-- .../condition/components/ConditionEdit.vue | 192 +++++++++++++----- .../condition/components/ConditionSet.vue | 38 +++- .../condition/components/CurrentOutput.vue | 22 ++ src/plugins/condition/components/DropHint.vue | 83 -------- src/plugins/condition/components/TestData.vue | 22 ++ .../condition/components/condition.scss | 13 +- src/plugins/condition/utils/evaluator.js | 27 +-- src/plugins/condition/utils/eventbus.js | 2 - 13 files changed, 309 insertions(+), 199 deletions(-) delete mode 100644 src/plugins/condition/components/DropHint.vue delete mode 100644 src/plugins/condition/utils/eventbus.js diff --git a/src/plugins/condition/Condition.js b/src/plugins/condition/Condition.js index 6ff4a41b56..ab3bc0858d 100644 --- a/src/plugins/condition/Condition.js +++ b/src/plugins/condition/Condition.js @@ -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) { diff --git a/src/plugins/condition/ConditionSetViewProvider.js b/src/plugins/condition/ConditionSetViewProvider.js index 38a3d65726..267f10718c 100644 --- a/src/plugins/condition/ConditionSetViewProvider.js +++ b/src/plugins/condition/ConditionSetViewProvider.js @@ -58,7 +58,7 @@ export default class ConditionSetViewProvider { isEditing } }, - template: '' + template: '' }); }, onEditModeChange: (isEditing) => { diff --git a/src/plugins/condition/ConditionSpec.js b/src/plugins/condition/ConditionSpec.js index 2f58676cef..18334bcada 100644 --- a/src/plugins/condition/ConditionSpec.js +++ b/src/plugins/condition/ConditionSpec.js @@ -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); diff --git a/src/plugins/condition/components/Condition.vue b/src/plugins/condition/components/Condition.vue index ae041c6ed2..1e37bc6479 100644 --- a/src/plugins/condition/components/Condition.vue +++ b/src/plugins/condition/components/Condition.vue @@ -1,4 +1,5 @@