Display the current output based on the first condition that has evaluated to true.

Fix remove condition
This commit is contained in:
Joshi 2020-01-22 21:35:22 -08:00
parent cfd9730055
commit 0bf3597147
4 changed files with 42 additions and 18 deletions

View File

@ -80,16 +80,35 @@ export default {
}, },
mounted() { mounted() {
this.telemetryObjs = []; this.telemetryObjs = [];
this.conditionResults = {};
this.instantiate = this.openmct.$injector.get('instantiate'); this.instantiate = this.openmct.$injector.get('instantiate');
this.composition = this.openmct.composition.get(this.domainObject); this.composition = this.openmct.composition.get(this.domainObject);
this.composition.on('add', this.addTelemetry); this.composition.on('add', this.addTelemetry);
this.composition.load(); this.composition.load();
this.conditionCollection = this.domainObject.configuration ? this.domainObject.configuration.conditionCollection : []; this.conditionCollection = this.domainObject.configuration ? this.domainObject.configuration.conditionCollection : [];
if (!this.conditionCollection.length) {this.addCondition(null, true)} if (!this.conditionCollection.length) {
this.addCondition(null, true);
}
}, },
methods: { methods: {
handleConditionResult(args) { handleConditionResult(args) {
console.log('ConditionCollection: ', args.result); console.log('ConditionCollection: ', args.result);
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, ii = this.conditionCollection.length-1; i< ii; 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('current-condition-updated', currentConditionIdentifier);
}, },
addTelemetry(telemetryDomainObject) { addTelemetry(telemetryDomainObject) {
this.telemetryObjs.push(telemetryDomainObject); this.telemetryObjs.push(telemetryDomainObject);
@ -135,12 +154,14 @@ export default {
this.conditions[index] = updatedCondition; this.conditions[index] = updatedCondition;
}, },
removeCondition(identifier) { removeCondition(identifier) {
console.log('this.conditions', this.conditions);
let index = _.findIndex(this.conditionCollection, (condition) => { let index = _.findIndex(this.conditionCollection, (condition) => {
identifier.key === condition.key let conditionId = this.openmct.objects.makeKeyString(condition);
let id = this.openmct.objects.makeKeyString(identifier);
return conditionId === id;
}); });
this.conditionCollection.splice(index + 1, 1); this.conditionCollection.splice(index, 1);
this.persist(); this.persist();
this.updateCurrentConditionId();
}, },
reorder(reorderPlan) { reorder(reorderPlan) {
let oldConditions = this.conditionCollection.slice(); let oldConditions = this.conditionCollection.slice();

View File

@ -256,6 +256,8 @@ export default {
checkInputValue() { checkInputValue() {
if (this.selectedOutputKey === this.outputOptions[2].key) { if (this.selectedOutputKey === this.outputOptions[2].key) {
this.condition.definition.output = ''; this.condition.definition.output = '';
} else {
this.condition.definition.output = this.selectedOutputKey;
} }
}, },
operationKeyChange(ev) { operationKeyChange(ev) {

View File

@ -5,7 +5,7 @@
<CurrentOutput :condition="currentCondition" /> <CurrentOutput :condition="currentCondition" />
<TestData :is-editing="isEditing" /> <TestData :is-editing="isEditing" />
<ConditionCollection :is-editing="isEditing" <ConditionCollection :is-editing="isEditing"
@update-current-condition="updateCurrentcondition" @current-condition-updated="updateCurrentCondition"
/> />
</div> </div>
</div> </div>
@ -17,7 +17,6 @@ import CurrentOutput from './CurrentOutput.vue';
import TestData from './TestData.vue'; import TestData from './TestData.vue';
import ConditionCollection from './ConditionCollection.vue'; import ConditionCollection from './ConditionCollection.vue';
export default { export default {
inject: ["openmct", "domainObject"], inject: ["openmct", "domainObject"],
components: { components: {
@ -35,20 +34,19 @@ export default {
}, },
mounted() { mounted() {
let conditionCollection = this.domainObject.configuration.conditionCollection; let conditionCollection = this.domainObject.configuration.conditionCollection;
this.currentConditionIdentifier = conditionCollection.length ? this.domainObject.configuration.conditionCollection[0] : null; this.currentConditionIdentifier = conditionCollection.length ? this.updateCurrentCondition(conditionCollection[0]) : null;
},
methods: {
setCurrentCondition() {
if (this.currentConditionIdentifier) { if (this.currentConditionIdentifier) {
this.openmct.objects.get(this.currentConditionIdentifier).then((obj) => { this.openmct.objects.get(this.currentConditionIdentifier).then((obj) => {
this.currentCondition = obj; this.currentCondition = obj;
}); });
} }
}, },
methods: { updateCurrentCondition(conditionIdentifier) {
updateCurrentcondition(identifier) { this.currentConditionIdentifier = conditionIdentifier;
this.currentConditionIdentifier = identifier; this.setCurrentCondition();
this.openmct.objects.get(this.currentConditionIdentifier).then((obj) => {
this.currentCondition = obj;
});
} }
} }
}; };

View File

@ -36,6 +36,9 @@ export default {
} }
}, },
mounted() { mounted() {
},
updated() {
}, },
methods: { methods: {