Compare commits

...

1 Commits

Author SHA1 Message Date
Deep Tailor
93d321aa8e improve tab loading logic and fix delete tab issue 2021-02-08 11:08:03 -08:00
2 changed files with 28 additions and 15 deletions

View File

@@ -53,7 +53,7 @@
:class="{'c-tabs-view__object-holder--hidden': !isCurrent(tab)}" :class="{'c-tabs-view__object-holder--hidden': !isCurrent(tab)}"
> >
<object-view <object-view
v-if="internalDomainObject.keep_alive ? currentTab : isCurrent(tab)" v-if="isTabLoaded(tab)"
class="c-tabs-view__object" class="c-tabs-view__object"
:default-object="tab.domainObject" :default-object="tab.domainObject"
:object-path="tab.objectPath" :object-path="tab.objectPath"
@@ -100,7 +100,8 @@ export default {
setCurrentTab: true, setCurrentTab: true,
isDragging: false, isDragging: false,
allowDrop: false, allowDrop: false,
searchTabKey: `tabs.pos.${keyString}` searchTabKey: `tabs.pos.${keyString}`,
loadedTabs: {}
}; };
}, },
computed: { computed: {
@@ -151,9 +152,12 @@ export default {
document.removeEventListener('dragend', this.dragend); document.removeEventListener('dragend', this.dragend);
}, },
methods: { methods: {
addTabToLoaded(tab) {
this.loadedTabs[tab.keyString] = true;
},
setCurrentTabByIndex(index) { setCurrentTabByIndex(index) {
if (this.tabsList[index]) { if (this.tabsList[index]) {
this.currentTab = this.tabsList[index]; this.showTab(this.tabsList[index]);
} }
}, },
showTab(tab, index) { showTab(tab, index) {
@@ -162,6 +166,7 @@ export default {
} }
this.currentTab = tab; this.currentTab = tab;
this.addTabToLoaded(tab);
}, },
showRemoveDialog(index) { showRemoveDialog(index) {
if (!this.tabsList[index]) { if (!this.tabsList[index]) {
@@ -179,7 +184,7 @@ export default {
label: 'Ok', label: 'Ok',
emphasis: 'true', emphasis: 'true',
callback: () => { callback: () => {
this.removeFromComposition(childDomainObject); this.composition.remove(childDomainObject);
prompt.dismiss(); prompt.dismiss();
} }
}, },
@@ -192,9 +197,6 @@ export default {
] ]
}); });
}, },
removeFromComposition(childDomainObject) {
this.composition.remove(childDomainObject);
},
addItem(domainObject) { addItem(domainObject) {
let type = this.openmct.types.get(domainObject.type) || unknownObjectType; let type = this.openmct.types.get(domainObject.type) || unknownObjectType;
let keyString = this.openmct.objects.makeKeyString(domainObject.identifier); let keyString = this.openmct.objects.makeKeyString(domainObject.identifier);
@@ -215,7 +217,7 @@ export default {
this.tabsList.push(tabItem); this.tabsList.push(tabItem);
if (this.setCurrentTab) { if (this.setCurrentTab) {
this.currentTab = tabItem; this.showTab(tabItem);
this.setCurrentTab = false; this.setCurrentTab = false;
} }
}, },
@@ -224,15 +226,21 @@ export default {
this.setCurrentTab = true; this.setCurrentTab = true;
}, },
removeItem(identifier) { removeItem(identifier) {
let pos = this.tabsList.findIndex(tab => let keyStringToBeRemoved = this.openmct.objects.makeKeyString(identifier);
tab.domainObject.identifier.namespace === identifier.namespace && tab.domainObject.identifier.keyString === identifier.keyString
); let pos = this.tabsList.findIndex(tab => {
return tab.keyString === keyStringToBeRemoved;
});
let tabToBeRemoved = this.tabsList[pos]; let tabToBeRemoved = this.tabsList[pos];
tabToBeRemoved.statusUnsubscribe(); tabToBeRemoved.statusUnsubscribe();
this.tabsList.splice(pos, 1); this.tabsList.splice(pos, 1);
this.loadedTabs[keyStringToBeRemoved] = undefined;
delete this.loadedTabs[keyStringToBeRemoved];
if (this.isCurrent(tabToBeRemoved)) { if (this.isCurrent(tabToBeRemoved)) {
this.showTab(this.tabsList[this.tabsList.length - 1], this.tabsList.length - 1); this.showTab(this.tabsList[this.tabsList.length - 1], this.tabsList.length - 1);
} }
@@ -291,10 +299,15 @@ export default {
let tabPos = this.tabsList.findIndex((tab) => { let tabPos = this.tabsList.findIndex((tab) => {
return tab.keyString === keyString; return tab.keyString === keyString;
}); });
let tab = this.tabsList[tabPos];
if (tabPos !== -1) { this.$set(tab, 'status', status);
let tab = this.tabsList[tabPos]; },
this.$set(tab, 'status', status); isTabLoaded(tab) {
if (this.internalDomainObject.keep_alive) {
return true;
} else {
return this.loadedTabs[tab.keyString];
} }
} }
} }

View File

@@ -41,7 +41,7 @@ define([
form: [ form: [
{ {
"key": "keep_alive", "key": "keep_alive",
"name": "Keep Tabs Alive", "name": "Eager Load Tabs",
"control": "select", "control": "select",
"options": [ "options": [
{ {