Skip to content

Commit ea2779e

Browse files
committed
more refactoring
1 parent d95e500 commit ea2779e

File tree

4 files changed

+22
-18
lines changed

4 files changed

+22
-18
lines changed

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

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,14 @@ qx.Class.define("osparc.dashboard.TemplateBrowser", {
3535
this._hideLoadingPage();
3636
},
3737

38-
reloadResources: function() {
38+
reloadResources: function(useCache = true) {
3939
if (osparc.data.Permissions.getInstance().canDo("studies.templates.read")) {
40-
this.__reloadTemplates();
40+
this.__reloadTemplates(useCache);
4141
} else {
4242
this.__setResourcesToList([]);
4343
}
4444
},
4545

46-
invalidateTemplates: function() {
47-
osparc.store.Store.getInstance().invalidate("templates");
48-
},
49-
5046
__attachEventHandlers: function() {
5147
const socket = osparc.wrapper.WebSocket.getInstance();
5248
socket.on("projectStateUpdated", data => {
@@ -74,15 +70,21 @@ qx.Class.define("osparc.dashboard.TemplateBrowser", {
7470
}
7571
},
7672

77-
__reloadTemplates: function() {
73+
__reloadTemplates: function(useCache) {
7874
this.__tasksToCards();
7975

80-
osparc.data.Resources.getInstance().getAllPages("templates")
81-
.then(templates => this.__setResourcesToList(templates))
82-
.catch(err => {
83-
console.error(err);
84-
this.__setResourcesToList([]);
85-
});
76+
const templatesStore = osparc.store.Templates.getInstance();
77+
if (useCache) {
78+
const templates = templatesStore.getTemplates();
79+
this.__setResourcesToList(templates);
80+
} else {
81+
templatesStore.fetchAllTemplates()
82+
.then(templates => this.__setResourcesToList(templates))
83+
.catch(err => {
84+
console.error(err);
85+
this.__setResourcesToList([]);
86+
});
87+
}
8688
},
8789

8890
_updateTemplateData: function(templateData) {

services/static-webserver/client/source/class/osparc/desktop/MainPage.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,9 @@ qx.Class.define("osparc.desktop.MainPage", {
158158
this.closeEditor();
159159
this.__showDashboard();
160160
// reset templates
161-
this.__dashboard.getTemplateBrowser().invalidateTemplates();
161+
// OM is this needed?
162+
// this.__dashboard.getTemplateBrowser().invalidateTemplates();
163+
osparc.store.Templates.getInstance().invalidateTemplates();
162164
this.__dashboard.getTemplateBrowser().reloadResources();
163165
// reset studies
164166
this.__dashboard.getStudyBrowser().invalidateStudies();

services/static-webserver/client/source/class/osparc/info/StudyLarge.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -310,10 +310,6 @@ qx.Class.define("osparc.info.StudyLarge", {
310310
studyData["resourceType"] = this.__isTemplate ? "template" : "study";
311311
this.fireDataEvent("updateStudy", studyData);
312312
qx.event.message.Bus.getInstance().dispatchByName("updateStudy", studyData);
313-
if (this.__isTemplate) {
314-
// reload templates
315-
osparc.data.Resources.get("templates", {}, false)
316-
}
317313
})
318314
.catch(err => {
319315
const msg = this.tr("An issue occurred while updating the information.");

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ qx.Class.define("osparc.store.Templates", {
4040
});
4141
},
4242

43+
invalidateTemplates: function() {
44+
this.__templates = [];
45+
},
46+
4347
getTemplates: function() {
4448
return this.__templates;
4549
},

0 commit comments

Comments
 (0)