Skip to content

Commit 48fa854

Browse files
committed
more improvements
1 parent 303aec7 commit 48fa854

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ qx.Class.define("osparc.dashboard.TemplateBrowser", {
3636
}
3737
this._resourcesInitialized = true;
3838

39-
osparc.store.Templates.fetchAllTemplates()
39+
osparc.store.Templates.getTemplates()
4040
.then(() => {
4141
this._resourcesList = [];
4242
this.getChildControl("resources-layout");
@@ -88,7 +88,7 @@ qx.Class.define("osparc.dashboard.TemplateBrowser", {
8888
osparc.store.Templates.getTemplates()
8989
.then(templates => this.__setResourcesToList(templates));
9090
} else {
91-
osparc.store.Templates.fetchAllTemplates()
91+
osparc.store.Templates.getTemplates(useCache)
9292
.then(templates => this.__setResourcesToList(templates))
9393
.catch(() => this.__setResourcesToList([]));
9494
}

services/static-webserver/client/source/class/osparc/store/Templates.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ qx.Class.define("osparc.store.Templates", {
1919
type: "static",
2020

2121
statics: {
22-
__templates: [],
22+
__templates: null,
2323
__templatesPromisesCached: null,
2424

25-
fetchAllTemplates: function() {
25+
__fetchAllTemplates: function() {
2626
return this.__templatesPromisesCached = osparc.data.Resources.getInstance().getAllPages("templates")
2727
.then(templates => {
2828
this.__templates = templates;
@@ -36,12 +36,23 @@ qx.Class.define("osparc.store.Templates", {
3636
});
3737
},
3838

39-
getTemplates: function() {
39+
getTemplates: function(useCache = true) {
4040
if (this.__templatesPromisesCached) {
41+
// fetching templates already in progress
4142
return this.__templatesPromisesCached;
4243
}
4344

44-
return new Promise(resolve => resolve(this.__templates));
45+
if (this.__templates === null) {
46+
// no templates cached, fetch them
47+
return this.__fetchAllTemplates();
48+
}
49+
50+
if (useCache) {
51+
// templates already cached, return them
52+
return new Promise(resolve => resolve(this.__templates));
53+
}
54+
// templates cached but force a refresh
55+
return this.__fetchAllTemplates();
4556
},
4657

4758
getTemplatesHypertools: function() {

0 commit comments

Comments
 (0)