Updates conditionManager.js to emit the output of the winning condition instead of the identifier of that condition

This commit is contained in:
Joshi
2020-02-24 15:43:03 -08:00
parent 6ab84c0bc3
commit 5814d2a35e
4 changed files with 65 additions and 51 deletions

View File

@ -34,6 +34,7 @@ export default class ConditionManager extends EventEmitter {
} }
initialize() { initialize() {
this.conditionResults = {};
this.openmct.objects.get(this.domainObject.identifier).then((obj) => { this.openmct.objects.get(this.domainObject.identifier).then((obj) => {
this.observeForChanges(obj); this.observeForChanges(obj);
this.conditionCollection = []; this.conditionCollection = [];
@ -67,10 +68,7 @@ export default class ConditionManager extends EventEmitter {
//check for removed conditions //check for removed conditions
oldConditionIdentifiers.forEach((identifier, index) => { oldConditionIdentifiers.forEach((identifier, index) => {
if (newConditionIdentifiers.indexOf(identifier) < 0) { if (newConditionIdentifiers.indexOf(identifier) < 0) {
let condition = this.conditionCollection[index]; this.removeCondition(identifier);
if (condition) {
this.removeCondition(condition);
}
} }
}); });
@ -157,19 +155,38 @@ export default class ConditionManager extends EventEmitter {
this.persist(); this.persist();
} }
removeCondition(condition, index) { removeCondition(identifier) {
if (index !== undefined && index > -1) { let found = this.findConditionById(identifier);
condition = this.conditionCollection[index]; if (found) {
} let index = found.index;
if (condition) { let condition = this.conditionCollection[index];
let conditionIdAsString = this.openmct.objects.makeKeyString(condition.identifier);
condition.destroyCriteria(); condition.destroyCriteria();
condition.off('conditionResultUpdated', this.handleConditionResult.bind(this)); condition.off('conditionResultUpdated', this.handleConditionResult.bind(this));
this.conditionCollection.splice(index, 1); this.conditionCollection.splice(index, 1);
this.domainObject.configuration.conditionCollection.splice(index, 1); this.domainObject.configuration.conditionCollection.splice(index, 1);
if (this.conditionResults[conditionIdAsString] !== undefined) {
delete this.conditionResults[conditionIdAsString];
}
this.persist(); 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]); //this.$set(this.conditionCollection, reorderEvent.newIndex, oldConditions[reorderEvent.oldIndex]);
reorderConditions(reorderPlan) { reorderConditions(reorderPlan) {
let oldConditions = Array.from(this.domainObject.configuration.conditionCollection); let oldConditions = Array.from(this.domainObject.configuration.conditionCollection);
@ -185,10 +202,29 @@ export default class ConditionManager extends EventEmitter {
} }
handleConditionResult(args) { handleConditionResult(args) {
this.emit('conditionResultUpdated', { let idAsString = this.openmct.objects.makeKeyString(args.id);
id: args.id, let found = this.findConditionById(idAsString);
result: args.data.result 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() { persist() {

View File

@ -67,7 +67,6 @@
:condition-index="index" :condition-index="index"
:telemetry="telemetryObjs" :telemetry="telemetryObjs"
:is-editing="isEditing" :is-editing="isEditing"
@updateCurrentCondition="updateCurrentCondition"
@removeCondition="removeCondition" @removeCondition="removeCondition"
@cloneCondition="cloneCondition" @cloneCondition="cloneCondition"
@setMoveIndex="setMoveIndex" @setMoveIndex="setMoveIndex"
@ -110,7 +109,7 @@ export default {
this.composition.off('add', this.addTelemetryObject); this.composition.off('add', this.addTelemetryObject);
this.composition.off('remove', this.removeTelemetryObject); this.composition.off('remove', this.removeTelemetryObject);
if(this.conditionManager) { if(this.conditionManager) {
this.conditionManager.off('conditionResultUpdated', this.handleConditionResult); this.conditionManager.off('conditionSetResultUpdated', this.handleOutputUpdated);
} }
if (typeof this.stopObservingForChanges === 'function') { if (typeof this.stopObservingForChanges === 'function') {
this.stopObservingForChanges(); this.stopObservingForChanges();
@ -123,7 +122,7 @@ export default {
this.composition.load(); this.composition.load();
this.conditionCollection = this.domainObject.configuration.conditionCollection; this.conditionCollection = this.domainObject.configuration.conditionCollection;
this.conditionManager = new ConditionManager(this.domainObject, this.openmct); 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(); this.observeForChanges();
}, },
methods: { methods: {
@ -178,22 +177,8 @@ export default {
dragLeave(e) { dragLeave(e) {
e.target.classList.remove("dragging"); e.target.classList.remove("dragging");
}, },
handleConditionResult(args) { handleOutputUpdated(args) {
let idAsString = this.openmct.objects.makeKeyString(args.id); this.$emit('currentConditionSetOutputUpdated', args);
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);
}, },
addTelemetryObject(domainObject) { addTelemetryObject(domainObject) {
this.telemetryObjs.push(domainObject); this.telemetryObjs.push(domainObject);

View File

@ -23,10 +23,10 @@
<template> <template>
<div class="c-cs-edit w-condition-set"> <div class="c-cs-edit w-condition-set">
<div class="c-sw-edit__ui holder"> <div class="c-sw-edit__ui holder">
<CurrentOutput :condition="currentCondition" /> <CurrentOutput :output="currentConditionOutput" />
<TestData :is-editing="isEditing" /> <TestData :is-editing="isEditing" />
<ConditionCollection :is-editing="isEditing" <ConditionCollection :is-editing="isEditing"
@currentConditionUpdated="updateCurrentCondition" @currentConditionSetOutputUpdated="updateCurrentOutput"
/> />
</div> </div>
</div> </div>
@ -49,24 +49,17 @@ export default {
}, },
data() { data() {
return { return {
currentCondition: this.currentCondition currentConditionOutput: ''
} }
}, },
mounted() { mounted() {
let conditionCollection = this.domainObject.configuration.conditionCollection; this.conditionSetIdentifier = this.openmct.objects.makeKeyString(this.domainObject.identifier);
this.currentConditionIdentifier = conditionCollection.length ? this.updateCurrentCondition(conditionCollection[0]) : null;
}, },
methods: { methods: {
setCurrentCondition() { updateCurrentOutput(currentConditionResult) {
if (this.currentConditionIdentifier) { if (this.openmct.objects.makeKeyString(currentConditionResult.id) === this.conditionSetIdentifier) {
this.openmct.objects.get(this.currentConditionIdentifier).then((obj) => { this.currentConditionOutput = currentConditionResult.output;
this.currentCondition = obj;
});
} }
},
updateCurrentCondition(conditionIdentifier) {
this.currentConditionIdentifier = conditionIdentifier;
this.setCurrentCondition();
} }
} }
}; };

View File

@ -22,7 +22,7 @@
<template> <template>
<section id="current-output"> <section id="current-output">
<div v-if="condition" <div v-if="output"
class="c-cs__ui__header" class="c-cs__ui__header"
> >
<span class="c-cs__ui__header-label">Current Output</span> <span class="c-cs__ui__header-label">Current Output</span>
@ -32,11 +32,11 @@
@click="expanded = !expanded" @click="expanded = !expanded"
></span> ></span>
</div> </div>
<div v-if="expanded && condition" <div v-if="expanded && output"
class="c-cs__ui_content" class="c-cs__ui_content"
> >
<div> <div>
<span class="current-output">{{ condition.configuration.output }}</span> <span class="current-output">{{ output }}</span>
</div> </div>
</div> </div>
</section> </section>
@ -47,9 +47,9 @@ export default {
inject: ['openmct', 'domainObject'], inject: ['openmct', 'domainObject'],
props: { props: {
isEditing: Boolean, isEditing: Boolean,
condition: { output: {
default: () => {return null;}, default: () => {return null;},
type: Object type: String
} }
}, },
data() { data() {