From fa6dd84945c8c7cc416577b82d5b2a974f28d1a9 Mon Sep 17 00:00:00 2001 From: Joel McKinnon Date: Thu, 20 Feb 2020 07:23:38 -0800 Subject: [PATCH 01/30] added controls for remove and duplicate criteria --- .../condition/components/Condition.vue | 3 ++- .../condition/components/Criterion.vue | 26 +++++++++++++++++++ .../condition/components/condition.scss | 9 +++++++ 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/plugins/condition/components/Condition.vue b/src/plugins/condition/components/Condition.vue index e469cd588e..3633e85656 100644 --- a/src/plugins/condition/components/Condition.vue +++ b/src/plugins/condition/components/Condition.vue @@ -96,6 +96,7 @@ :criterion="criterion" :index="index" :trigger="trigger" + :is-default="domainObject.configuration.criteria.length === 1" @persist="persist" /> @@ -214,7 +215,7 @@ export default { this.domainObject.configuration.criteria.push(criteriaObject); }, dragStart(e) { - this.$emit('set-move-index', Number(e.target.getAttribute('data-condition-index'))); + this.$emit('setMoveIndex', Number(e.target.getAttribute('data-condition-index'))); }, destroy() { if (this.conditionClass) { diff --git a/src/plugins/condition/components/Criterion.vue b/src/plugins/condition/components/Criterion.vue index 0bd865f828..046ca4a19e 100644 --- a/src/plugins/condition/components/Criterion.vue +++ b/src/plugins/condition/components/Criterion.vue @@ -46,6 +46,15 @@ > +
+ + +
@@ -72,6 +81,10 @@ export default { trigger: { type: String, required: true + }, + isDefault: { + type: Boolean, + default: false } }, data() { @@ -91,6 +104,7 @@ export default { mounted() { this.updateMetadataOptions(); this.updateOperationInputVisibility(); + console.log('this.isDefault', this.isDefault); }, methods: { updateMetadataOptions() { @@ -113,6 +127,18 @@ export default { updateMetadataSelection() { this.updateOperationInputVisibility(); }, + removeCriterion(ev) { + console.log('removeCriterion', this.index); + // this.$emit('removeCondition', this.conditionIdentifier); + }, + cloneCriterion(ev) { + console.log('cloneCriterion') + // this.$emit('cloneCondition', { + // identifier: this.conditionIdentifier, + // index: Number(ev.target.closest('.widget-condition').getAttribute('data-condition-index')) + // }); + }, + persist() { this.$emit('persist', this.criterion); } diff --git a/src/plugins/condition/components/condition.scss b/src/plugins/condition/components/condition.scss index b6e4e47bd2..d5503456db 100644 --- a/src/plugins/condition/components/condition.scss +++ b/src/plugins/condition/components/condition.scss @@ -197,3 +197,12 @@ border-radius: 2px; } } + +.temp { + width: 24px; + + .c-c__duplicate, + .c-c__trash { + display: inline-block; + } +} From 386fc7504782b463af39240d4faac5cdef87b5c5 Mon Sep 17 00:00:00 2001 From: Joel McKinnon Date: Thu, 20 Feb 2020 12:23:18 -0800 Subject: [PATCH 02/30] remove criterion working --- .../condition/components/Condition.vue | 41 ++++++++++++++----- .../components/ConditionCollection.vue | 1 - .../condition/components/Criterion.vue | 27 +----------- .../condition/components/condition.scss | 2 +- 4 files changed, 34 insertions(+), 37 deletions(-) diff --git a/src/plugins/condition/components/Condition.vue b/src/plugins/condition/components/Condition.vue index 3633e85656..c76e1db722 100644 --- a/src/plugins/condition/components/Condition.vue +++ b/src/plugins/condition/components/Condition.vue @@ -90,15 +90,27 @@
@@ -180,7 +192,8 @@ export default { trigger: 'all', selectedOutputKey: '', stringOutputField: false, - outputOptions: ['false', 'true', 'string'] + outputOptions: ['false', 'true', 'string'], + criterionIndex: 0 }; }, computed: { @@ -241,6 +254,14 @@ export default { index: Number(ev.target.closest('.widget-condition').getAttribute('data-condition-index')) }); }, + removeCriterion(index) { + this.domainObject.configuration.criteria.splice(index, 1); + this.persist() + }, + cloneCriterion(ev) { + // console.log('cloneCriterion') + }, + setOutput() { let conditionOutput = this.domainObject.configuration.output; if (conditionOutput) { diff --git a/src/plugins/condition/components/ConditionCollection.vue b/src/plugins/condition/components/ConditionCollection.vue index fc52c2251a..ddc9483296 100644 --- a/src/plugins/condition/components/ConditionCollection.vue +++ b/src/plugins/condition/components/ConditionCollection.vue @@ -83,7 +83,6 @@ import Condition from '../../condition/components/Condition.vue'; import uuid from 'uuid'; - export default { inject: ['openmct', 'domainObject'], components: { diff --git a/src/plugins/condition/components/Criterion.vue b/src/plugins/condition/components/Criterion.vue index 046ca4a19e..e04803faf0 100644 --- a/src/plugins/condition/components/Criterion.vue +++ b/src/plugins/condition/components/Criterion.vue @@ -1,5 +1,5 @@ From 5814d2a35eaa26b31f0aa4454efe1af9f49c9e36 Mon Sep 17 00:00:00 2001 From: Joshi Date: Mon, 24 Feb 2020 15:43:03 -0800 Subject: [PATCH 09/30] Updates conditionManager.js to emit the output of the winning condition instead of the identifier of that condition --- src/plugins/condition/ConditionManager.js | 62 +++++++++++++++---- .../components/ConditionCollection.vue | 23 ++----- .../condition/components/ConditionSet.vue | 21 +++---- .../condition/components/CurrentOutput.vue | 10 +-- 4 files changed, 65 insertions(+), 51 deletions(-) diff --git a/src/plugins/condition/ConditionManager.js b/src/plugins/condition/ConditionManager.js index 56e8a4fd9f..66fd392fc2 100644 --- a/src/plugins/condition/ConditionManager.js +++ b/src/plugins/condition/ConditionManager.js @@ -34,6 +34,7 @@ export default class ConditionManager extends EventEmitter { } initialize() { + this.conditionResults = {}; this.openmct.objects.get(this.domainObject.identifier).then((obj) => { this.observeForChanges(obj); this.conditionCollection = []; @@ -67,10 +68,7 @@ export default class ConditionManager extends EventEmitter { //check for removed conditions oldConditionIdentifiers.forEach((identifier, index) => { if (newConditionIdentifiers.indexOf(identifier) < 0) { - let condition = this.conditionCollection[index]; - if (condition) { - this.removeCondition(condition); - } + this.removeCondition(identifier); } }); @@ -157,19 +155,38 @@ export default class ConditionManager extends EventEmitter { this.persist(); } - removeCondition(condition, index) { - if (index !== undefined && index > -1) { - condition = this.conditionCollection[index]; - } - if (condition) { + removeCondition(identifier) { + let found = this.findConditionById(identifier); + if (found) { + let index = found.index; + let condition = this.conditionCollection[index]; + let conditionIdAsString = this.openmct.objects.makeKeyString(condition.identifier); condition.destroyCriteria(); condition.off('conditionResultUpdated', this.handleConditionResult.bind(this)); this.conditionCollection.splice(index, 1); this.domainObject.configuration.conditionCollection.splice(index, 1); + if (this.conditionResults[conditionIdAsString] !== undefined) { + delete this.conditionResults[conditionIdAsString]; + } this.persist(); } } + findConditionById(identifier) { + let found; + for (let i=0, ii=this.conditionCollection.length; i < ii; i++) { + if (this.conditionCollection[i].id === this.openmct.objects.makeKeyString(identifier)) { + found = { + item: this.conditionCollection[i], + index: i + } + break; + } + } + + return found; + } + //this.$set(this.conditionCollection, reorderEvent.newIndex, oldConditions[reorderEvent.oldIndex]); reorderConditions(reorderPlan) { let oldConditions = Array.from(this.domainObject.configuration.conditionCollection); @@ -185,10 +202,29 @@ export default class ConditionManager extends EventEmitter { } handleConditionResult(args) { - this.emit('conditionResultUpdated', { - id: args.id, - result: args.data.result - }) + let idAsString = this.openmct.objects.makeKeyString(args.id); + let found = this.findConditionById(idAsString); + let conditionCollection = this.domainObject.configuration.conditionCollection; + let currentConditionIdentifier = conditionCollection[conditionCollection.length-1]; + if (found) { + this.conditionResults[idAsString] = args.data.result; + + for (let i = 0, ii = conditionCollection.length - 1; i < ii; i++) { + let conditionIdAsString = this.openmct.objects.makeKeyString(conditionCollection[i]); + if (this.conditionResults[conditionIdAsString]) { + //first condition to be true wins + currentConditionIdentifier = conditionCollection[i]; + break; + } + } + } + + this.openmct.objects.get(currentConditionIdentifier).then((obj) => { + this.emit('conditionSetResultUpdated', { + id: this.domainObject.identifier, + output: obj.configuration.output + }) + }); } persist() { diff --git a/src/plugins/condition/components/ConditionCollection.vue b/src/plugins/condition/components/ConditionCollection.vue index 3a2ba0e388..be38bebfb4 100644 --- a/src/plugins/condition/components/ConditionCollection.vue +++ b/src/plugins/condition/components/ConditionCollection.vue @@ -67,7 +67,6 @@ :condition-index="index" :telemetry="telemetryObjs" :is-editing="isEditing" - @updateCurrentCondition="updateCurrentCondition" @removeCondition="removeCondition" @cloneCondition="cloneCondition" @setMoveIndex="setMoveIndex" @@ -110,7 +109,7 @@ export default { this.composition.off('add', this.addTelemetryObject); this.composition.off('remove', this.removeTelemetryObject); if(this.conditionManager) { - this.conditionManager.off('conditionResultUpdated', this.handleConditionResult); + this.conditionManager.off('conditionSetResultUpdated', this.handleOutputUpdated); } if (typeof this.stopObservingForChanges === 'function') { this.stopObservingForChanges(); @@ -123,7 +122,7 @@ export default { this.composition.load(); this.conditionCollection = this.domainObject.configuration.conditionCollection; this.conditionManager = new ConditionManager(this.domainObject, this.openmct); - this.conditionManager.on('conditionResultUpdated', this.handleConditionResult.bind(this)); + this.conditionManager.on('conditionSetResultUpdated', this.handleOutputUpdated.bind(this)); this.observeForChanges(); }, methods: { @@ -178,22 +177,8 @@ export default { dragLeave(e) { e.target.classList.remove("dragging"); }, - handleConditionResult(args) { - let idAsString = this.openmct.objects.makeKeyString(args.id); - this.conditionResults[idAsString] = args.result; - this.updateCurrentConditionId(); - }, - updateCurrentConditionId() { - let currentConditionIdentifier = this.conditionCollection[this.conditionCollection.length-1]; - for (let i = 0; i < this.conditionCollection.length - 1; i++) { - let conditionIdAsString = this.openmct.objects.makeKeyString(this.conditionCollection[i]); - if (this.conditionResults[conditionIdAsString]) { - //first condition to be true wins - currentConditionIdentifier = this.conditionCollection[i]; - break; - } - } - this.$emit('currentConditionUpdated', currentConditionIdentifier); + handleOutputUpdated(args) { + this.$emit('currentConditionSetOutputUpdated', args); }, addTelemetryObject(domainObject) { this.telemetryObjs.push(domainObject); diff --git a/src/plugins/condition/components/ConditionSet.vue b/src/plugins/condition/components/ConditionSet.vue index 19f0959076..cc5af46072 100644 --- a/src/plugins/condition/components/ConditionSet.vue +++ b/src/plugins/condition/components/ConditionSet.vue @@ -23,10 +23,10 @@