Skip to content

Commit a2a4746

Browse files
committed
lazy load templates
1 parent b6cf15a commit a2a4746

File tree

6 files changed

+48
-15
lines changed

6 files changed

+48
-15
lines changed

services/static-webserver/client/source/class/osparc/dashboard/Dashboard.js

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ qx.Class.define("osparc.dashboard.Dashboard", {
128128
buttonId: "hypertoolsTabBtn",
129129
label: this.tr("HYPERTOOLS"),
130130
icon: "@FontAwesome5Solid/copy/"+tabIconSize,
131-
initVisibility: "excluded",
131+
// initVisibility: "excluded",
132132
buildLayout: this.__createHypertoolsBrowser
133133
});
134134
}
@@ -172,26 +172,25 @@ qx.Class.define("osparc.dashboard.Dashboard", {
172172
osparc.utils.Utils.setIdToWidget(tabButton, buttonId);
173173
tabPage.setLayout(new qx.ui.layout.Grow());
174174

175-
const viewLayout = buildLayout.call(this);
175+
const resourceBrowser = buildLayout.call(this);
176176
tabButton.addListener("execute", () => {
177-
if (viewLayout.resetSelection) {
178-
viewLayout.resetSelection();
177+
if (resourceBrowser.resetSelection) {
178+
resourceBrowser.resetSelection();
179179
}
180180
}, this);
181-
viewLayout.addListener("changeTab", e => {
181+
182+
resourceBrowser.addListener("changeTab", e => {
182183
const activeTab = e.getData();
183184
const tabFound = this.getSelectables().find(s => s.id === activeTab);
184185
if (tabFound) {
185186
this.setSelection([tabFound]);
186187
}
187188
}, this);
188-
viewLayout.addListener("showTab", e => {
189-
const showTab = e.getData();
190-
tabButton.setVisibility(showTab ? "visible" : "excluded");
191-
})
189+
192190
const scrollerMainView = new qx.ui.container.Scroll();
193-
scrollerMainView.add(viewLayout);
191+
scrollerMainView.add(resourceBrowser);
194192
tabPage.add(scrollerMainView);
193+
tabPage.resourceBrowser = resourceBrowser;
195194

196195
this.add(tabPage);
197196
}, this);
@@ -202,9 +201,22 @@ qx.Class.define("osparc.dashboard.Dashboard", {
202201
preResourcePromises.push(osparc.store.Services.getServicesLatest(false));
203202
Promise.all(preResourcePromises)
204203
.then(() => {
205-
this.__studyBrowser.initResources();
206-
this.__serviceBrowser.initResources();
207-
this.__dataBrowser.initResources();
204+
if (this.__studyBrowser) {
205+
this.__studyBrowser.initResources();
206+
}
207+
if (this.__serviceBrowser) {
208+
this.__serviceBrowser.initResources();
209+
}
210+
if (this.__dataBrowser) {
211+
this.__dataBrowser.initResources();
212+
}
213+
214+
this.addListener("changeSelection", e => {
215+
const selectedTab = e.getData()[0];
216+
if (selectedTab && selectedTab.resourceBrowser) {
217+
selectedTab.resourceBrowser.initResources();
218+
}
219+
}, this);
208220
})
209221
.catch(err => console.error(err));
210222
},

services/static-webserver/client/source/class/osparc/dashboard/DataBrowser.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ qx.Class.define("osparc.dashboard.DataBrowser", {
5555

5656
// overridden
5757
initResources: function() {
58+
if (this._resourcesInitialized) {
59+
return;
60+
}
61+
this._resourcesInitialized = true;
62+
5863
this._hideLoadingPage();
5964
this.__buildLayout();
6065

services/static-webserver/client/source/class/osparc/dashboard/ResourceBrowserBase.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ qx.Class.define("osparc.dashboard.ResourceBrowserBase", {
3131
construct: function() {
3232
this.base(arguments);
3333

34+
this._resourcesInitialized = false;
35+
3436
this._showLoadingPage(this.tr("Starting") + " " + osparc.store.StaticInfo.getInstance().getDisplayName());
3537

3638
const padding = osparc.dashboard.Dashboard.PADDING;
@@ -88,7 +90,6 @@ qx.Class.define("osparc.dashboard.ResourceBrowserBase", {
8890

8991
events: {
9092
"changeTab": "qx.event.type.Data",
91-
"showTab": "qx.event.type.Data",
9293
"publishTemplate": "qx.event.type.Data",
9394
},
9495

@@ -210,6 +211,7 @@ qx.Class.define("osparc.dashboard.ResourceBrowserBase", {
210211
__centerLayout: null,
211212
_resourceType: null,
212213
_resourcesList: null,
214+
_resourcesInitialized: null,
213215
_toolbar: null,
214216
_searchBarFilter: null,
215217
__viewModeLayout: null,

services/static-webserver/client/source/class/osparc/dashboard/ServiceBrowser.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ qx.Class.define("osparc.dashboard.ServiceBrowser", {
3737

3838
// overridden
3939
initResources: function() {
40+
if (this._resourcesInitialized) {
41+
return;
42+
}
43+
this._resourcesInitialized = true;
44+
4045
this._resourcesList = [];
4146
osparc.store.Services.getServicesLatest()
4247
.then(services => {

services/static-webserver/client/source/class/osparc/dashboard/StudyBrowser.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,11 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
9292

9393
// overridden
9494
initResources: function() {
95+
if (this._resourcesInitialized) {
96+
return;
97+
}
98+
this._resourcesInitialized = true;
99+
95100
this._resourcesList = [];
96101
this.__getActiveStudy()
97102
.then(() => {

services/static-webserver/client/source/class/osparc/dashboard/TemplateBrowser.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ qx.Class.define("osparc.dashboard.TemplateBrowser", {
3131

3232
// overridden
3333
initResources: function() {
34+
if (this._resourcesInitialized) {
35+
return;
36+
}
37+
this._resourcesInitialized = true;
38+
3439
osparc.store.Templates.getInstance().fetchAllTemplates()
3540
.then(() => {
3641
this._resourcesList = [];
@@ -106,7 +111,6 @@ qx.Class.define("osparc.dashboard.TemplateBrowser", {
106111
__setResourcesToList: function(templatesList) {
107112
templatesList.forEach(template => template["resourceType"] = "template");
108113
this._resourcesList = templatesList.filter(template => osparc.study.Utils.extractTemplateType(template) === this.__templateType);
109-
this.fireDataEvent("showTab", Boolean(this._resourcesList.length));
110114
this._reloadCards();
111115
},
112116

0 commit comments

Comments
 (0)