Skip to content

Commit 268298d

Browse files
authored
πŸ›πŸŽ¨ [Frontend] Load folders after going back to the dashboard (ITISFoundation#6543)
1 parent b25439b commit 268298d

File tree

4 files changed

+97
-38
lines changed

4 files changed

+97
-38
lines changed

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

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ qx.Class.define("osparc.dashboard.Dashboard", {
9797
const permissions = osparc.data.Permissions.getInstance();
9898
const tabIconSize = 20;
9999
const tabs = [{
100-
id: "studiesTabBtn",
100+
id: "studiesTab",
101+
buttonId: "studiesTabBtn",
101102
label: osparc.product.Utils.getStudyAlias({
102103
plural: true,
103104
allUpperCase: true
@@ -107,7 +108,8 @@ qx.Class.define("osparc.dashboard.Dashboard", {
107108
}];
108109
if (permissions.canDo("dashboard.templates.read")) {
109110
tabs.push({
110-
id: "templatesTabBtn",
111+
id: "templatesTab",
112+
buttonId: "templatesTabBtn",
111113
label: osparc.product.Utils.getTemplateAlias({
112114
plural: true,
113115
allUpperCase: true
@@ -118,24 +120,27 @@ qx.Class.define("osparc.dashboard.Dashboard", {
118120
}
119121
if (permissions.canDo("dashboard.services.read")) {
120122
tabs.push({
121-
id: "servicesTabBtn",
123+
id: "servicesTab",
124+
buttonId: "servicesTabBtn",
122125
label: this.tr("SERVICES"),
123126
icon: "@FontAwesome5Solid/cogs/"+tabIconSize,
124127
buildLayout: this.__createServiceBrowser
125128
});
126129
}
127130
if (permissions.canDo("dashboard.data.read") && osparc.product.Utils.isProduct("osparc")) {
128131
tabs.push({
129-
id: "dataTabBtn",
132+
id: "dataTab",
133+
buttonId: "dataTabBtn",
130134
label: this.tr("DATA"),
131135
icon: "@FontAwesome5Solid/folder/"+tabIconSize,
132136
buildLayout: this.__createDataBrowser
133137
});
134138
}
135-
tabs.forEach(({id, label, icon, buildLayout}) => {
139+
tabs.forEach(({id, buttonId, label, icon, buildLayout}) => {
136140
const tabPage = new qx.ui.tabview.Page(label, icon).set({
137141
appearance: "dashboard-page"
138142
});
143+
tabPage.id = id;
139144
const tabButton = tabPage.getChildControl("button");
140145
tabButton.set({
141146
minWidth: 50,
@@ -149,7 +154,7 @@ qx.Class.define("osparc.dashboard.Dashboard", {
149154
visibility: "excluded"
150155
});
151156
osparc.utils.Utils.centerTabIcon(tabPage);
152-
osparc.utils.Utils.setIdToWidget(tabButton, id);
157+
osparc.utils.Utils.setIdToWidget(tabButton, buttonId);
153158
tabPage.setLayout(new qx.ui.layout.Grow());
154159

155160
const viewLayout = buildLayout.call(this);
@@ -158,6 +163,13 @@ qx.Class.define("osparc.dashboard.Dashboard", {
158163
viewLayout.resetSelection();
159164
}
160165
}, this);
166+
viewLayout.addListener("changeTab", e => {
167+
const activeTab = e.getData();
168+
const tabFound = this.getSelectables().find(s => s.id === activeTab);
169+
if (tabFound) {
170+
this.setSelection([tabFound]);
171+
}
172+
}, this);
161173
const scrollerMainView = new qx.ui.container.Scroll();
162174
scrollerMainView.add(viewLayout);
163175
tabPage.add(scrollerMainView);

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ qx.Class.define("osparc.dashboard.ResourceBrowserBase", {
7777
},
7878

7979
events: {
80+
"changeTab": "qx.event.type.Data",
8081
"publishTemplate": "qx.event.type.Data"
8182
},
8283

@@ -222,7 +223,7 @@ qx.Class.define("osparc.dashboard.ResourceBrowserBase", {
222223
throw new Error("Abstract method called!");
223224
},
224225

225-
reloadResources: function() {
226+
reloadMoreResources: function() {
226227
throw new Error("Abstract method called!");
227228
},
228229

@@ -431,7 +432,7 @@ qx.Class.define("osparc.dashboard.ResourceBrowserBase", {
431432

432433
_moreResourcesRequired: function() {
433434
if (this._resourcesContainer && this._resourcesContainer.areMoreResourcesRequired(this._loadingResourcesBtn)) {
434-
this.reloadResources();
435+
this.reloadMoreResources();
435436
}
436437
},
437438

@@ -456,6 +457,9 @@ qx.Class.define("osparc.dashboard.ResourceBrowserBase", {
456457
},
457458

458459
_startStudyById: function(studyId, openCB, cancelCB, isStudyCreation = false) {
460+
if (isStudyCreation) {
461+
this.fireDataEvent("changeTab", "studiesTab");
462+
}
459463
this.self().startStudyById(studyId, openCB, cancelCB, isStudyCreation);
460464
},
461465

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

Lines changed: 64 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
119119
const isStudyCreation = false;
120120
this._startStudyById(loadStudyId, null, cancelCB, isStudyCreation);
121121
} else {
122-
this.__reloadFolders();
123122
this.reloadResources();
124123
}
125124
// "Starting..." page
@@ -151,12 +150,17 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
151150
osparc.data.Permissions.getInstance().canDo("studies.user.read") &&
152151
osparc.auth.Manager.getInstance().isLoggedIn()
153152
) {
153+
this.__reloadFolders();
154154
this.__reloadStudies();
155155
} else {
156156
this.__resetStudiesList();
157157
}
158158
},
159159

160+
reloadMoreResources: function() {
161+
this.__reloadStudies();
162+
},
163+
160164
__reloadWorkspaces: function() {
161165
this.__setWorkspacesToList([]);
162166
osparc.store.Workspaces.getInstance().fetchWorkspaces()
@@ -223,21 +227,11 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
223227
this._loadingResourcesBtn.setVisibility("visible");
224228
this.__getNextStudiesRequest()
225229
.then(resp => {
226-
const urlParams = resp["params"]["url"];
227230
// Context might have been changed while waiting for the response.
228231
// The new call is on the way, therefore this response can be ignored.
229-
if ("workspaceId" in urlParams) {
230-
if (
231-
urlParams.workspaceId !== this.getCurrentWorkspaceId() ||
232-
urlParams.folderId !== this.getCurrentFolderId()
233-
) {
234-
return;
235-
}
236-
} else if ("text" in urlParams) {
237-
const currentFilterData = this._searchBarFilter.getFilterData();
238-
if (currentFilterData.text && urlParams.text !== encodeURIComponent(currentFilterData.text)) {
239-
return;
240-
}
232+
const contextChanged = this.__didContextChange(resp["params"]["url"]);
233+
if (contextChanged) {
234+
return;
241235
}
242236

243237
const studies = resp["data"];
@@ -615,26 +609,67 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
615609
}, this);
616610
},
617611

612+
__didContextChange: function(reqParams) {
613+
// not needed for the comparison
614+
delete reqParams["type"];
615+
delete reqParams["limit"];
616+
delete reqParams["offset"];
617+
618+
// check the entries in currentParams are the same as the reqParams
619+
const currentParams = this.__getRequestParams();
620+
let sameContext = true;
621+
Object.entries(currentParams).forEach(([key, value]) => {
622+
sameContext &= key in reqParams && reqParams[key] === value;
623+
});
624+
return !sameContext;
625+
},
626+
618627
__getNextPageParams: function() {
619-
if ("nextRequest" in this._resourcesContainer.getFlatList() &&
620-
this._resourcesContainer.getFlatList().nextRequest !== null &&
621-
osparc.utils.Utils.hasParamFromURL(this._resourcesContainer.getFlatList().nextRequest, "offset") &&
622-
osparc.utils.Utils.hasParamFromURL(this._resourcesContainer.getFlatList().nextRequest, "limit")
623-
) {
624-
return {
625-
offset: osparc.utils.Utils.getParamFromURL(this._resourcesContainer.getFlatList().nextRequest, "offset"),
626-
limit: osparc.utils.Utils.getParamFromURL(this._resourcesContainer.getFlatList().nextRequest, "limit")
627-
};
628+
if (this._resourcesContainer.getFlatList() && this._resourcesContainer.getFlatList().nextRequest) {
629+
// Context might have been changed while waiting for the response.
630+
// The new call is on the way, therefore this response can be ignored.
631+
const url = new URL(this._resourcesContainer.getFlatList().nextRequest);
632+
const urlSearchParams = new URLSearchParams(url.search);
633+
const urlParams = {};
634+
for (const [snakeKey, value] of urlSearchParams.entries()) {
635+
const key = osparc.utils.Utils.snakeToCamel(snakeKey);
636+
urlParams[key] = value === "null" ? null : value;
637+
}
638+
const contextChanged = this.__didContextChange(urlParams);
639+
if (
640+
!contextChanged &&
641+
osparc.utils.Utils.hasParamFromURL(this._resourcesContainer.getFlatList().nextRequest, "offset") &&
642+
osparc.utils.Utils.hasParamFromURL(this._resourcesContainer.getFlatList().nextRequest, "limit")
643+
) {
644+
return {
645+
offset: osparc.utils.Utils.getParamFromURL(this._resourcesContainer.getFlatList().nextRequest, "offset"),
646+
limit: osparc.utils.Utils.getParamFromURL(this._resourcesContainer.getFlatList().nextRequest, "limit")
647+
};
648+
}
628649
}
629650
return null;
630651
},
631652

653+
__getRequestParams: function() {
654+
const requestParams = {};
655+
requestParams.orderBy = JSON.stringify(this.getOrderBy());
656+
657+
const filterData = this._searchBarFilter.getFilterData();
658+
if (filterData.text) {
659+
requestParams.text = encodeURIComponent(filterData.text); // name, description and uuid
660+
return requestParams;
661+
}
662+
663+
requestParams.workspaceId = this.getCurrentWorkspaceId();
664+
requestParams.folderId = this.getCurrentFolderId();
665+
return requestParams;
666+
},
667+
632668
__getNextStudiesRequest: function() {
633669
const params = {
634670
url: {
635671
offset: 0,
636672
limit: osparc.dashboard.ResourceBrowserBase.PAGINATED_STUDIES,
637-
orderBy: JSON.stringify(this.getOrderBy()),
638673
}
639674
};
640675

@@ -647,14 +682,13 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
647682
resolveWResponse: true
648683
};
649684

650-
const filterData = this._searchBarFilter.getFilterData();
651-
if (filterData.text) {
652-
params.url.text = encodeURIComponent(filterData.text); // name, description and uuid
685+
const requestParams = this.__getRequestParams();
686+
Object.entries(requestParams).forEach(([key, value]) => {
687+
params.url[key] = value;
688+
});
689+
if ("text" in requestParams) {
653690
return osparc.data.Resources.fetch("studies", "getPageSearch", params, undefined, options);
654691
}
655-
656-
params.url.workspaceId = this.getCurrentWorkspaceId();
657-
params.url.folderId = this.getCurrentFolderId();
658692
return osparc.data.Resources.fetch("studies", "getPage", params, undefined, options);
659693
},
660694

β€Žservices/static-webserver/client/source/class/osparc/utils/Utils.jsβ€Ž

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,6 +1009,15 @@ qx.Class.define("osparc.utils.Utils", {
10091009

10101010
isUrl: url => /^(http:\/\/www\.|https:\/\/www\.|http:\/\/|https:\/\/)?[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$/gm.test(url),
10111011

1012+
snakeToCamel: str => {
1013+
return str.toLowerCase().replace(/([-_][a-z])/g, group =>
1014+
group
1015+
.toUpperCase()
1016+
.replace("-", "")
1017+
.replace("_", "")
1018+
);
1019+
},
1020+
10121021
setIdToWidget: (qWidget, id) => {
10131022
if (qWidget.getContentElement) {
10141023
qWidget.getContentElement().setAttribute("osparc-test-id", id);

0 commit comments

Comments
Β (0)