reworked logic for add/remove unit detection

This commit is contained in:
Jamie Vigliotta 2020-07-15 16:12:24 -07:00
parent 551364ad8c
commit 70125afa9d
2 changed files with 15 additions and 11 deletions

View File

@ -76,14 +76,13 @@ export default {
item.key = this.openmct.objects.makeKeyString(domainObject.identifier);
this.items.push(item);
if(!this.hasUnits) {
this.checkForUnits(domainObject);
}
this.checkForUnits();
},
removeItem(identifier) {
let index = this.items.findIndex(item => this.openmct.objects.makeKeyString(identifier) === item.key);
this.items.splice(index, 1);
this.checkForUnits();
},
reorder(reorderPlan) {
let oldItems = this.items.slice();
@ -91,14 +90,20 @@ export default {
this.$set(this.items, reorderEvent.newIndex, oldItems[reorderEvent.oldIndex]);
});
},
checkForUnits(domainObject) {
let metadata = this.openmct.telemetry.getMetadata(domainObject);
metadata.valueMetadatas.forEach((metadatum) => {
if(metadatum.unit) {
this.hasUnits = true;
return;
}
checkForUnits() {
let metadatas = [];
let hasUnits = false;
this.items.forEach((item) => {
let metadata = this.openmct.telemetry.getMetadata(item.domainObject);
metadatas = metadatas.concat(metadata.valueMetadatas);
});
for(let metadatum of metadatas) {
if(metadatum.unit) {
hasUnits = true;
break;
}
};
this.hasUnits = hasUnits;
}
}
}

View File

@ -549,7 +549,6 @@ define(['lodash'], function (_) {
.valueMetadatas
.filter((metadatum) => metadatum.unit)
.length;
console.log('hasUnits', hasUnits);
return hasUnits > 0;
});
return results;