Skip to content

Commit d5d06ee

Browse files
authored
🐛 [Frontend] Folders tree: Fixes I (#6358)
1 parent 62765b6 commit d5d06ee

13 files changed

+112
-116
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ qx.Class.define("osparc.dashboard.ContainerHeader", {
106106
if (workspaceId === -1) {
107107
rootButton = new qx.ui.form.Button(this.tr("Shared Workspaces"), osparc.store.Workspaces.iconPath());
108108
} else {
109-
const workspace = osparc.store.Workspaces.getWorkspace(workspaceId);
109+
const workspace = osparc.store.Workspaces.getInstance().getWorkspace(workspaceId);
110110
rootButton = new qx.ui.form.Button(workspace.getName(), osparc.store.Workspaces.iconPath());
111111
}
112112
} else {

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ qx.Class.define("osparc.dashboard.FolderButtonItem", {
151151
},
152152

153153
__applyWorkspaceId: function(workspaceId) {
154-
const workspace = osparc.store.Workspaces.getWorkspace(workspaceId);
154+
const workspace = osparc.store.Workspaces.getInstance().getWorkspace(workspaceId);
155155
const accessRights = workspace ? workspace.getAccessRights() : {};
156156
if (accessRights && Object.keys(accessRights).length) {
157157
const shareIcon = this.getChildControl("icon").getChildControl("shared-icon");

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ qx.Class.define("osparc.dashboard.FoldersTree", {
2121
construct: function(currentWorkspaceId) {
2222
this.__currentWorkspaceId = currentWorkspaceId;
2323

24-
const workspace = osparc.store.Workspaces.getWorkspace(this.__currentWorkspaceId);
24+
const workspace = osparc.store.Workspaces.getInstance().getWorkspace(this.__currentWorkspaceId);
2525
const workspaceLabel = workspace ? workspace.getName() : "My Workspace";
2626
const rootData = {
2727
label: workspaceLabel,

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ qx.Class.define("osparc.dashboard.MoveResourceToWorkspace", {
5858
let control;
5959
switch (id) {
6060
case "current-workspace": {
61-
const workspace = osparc.store.Workspaces.getWorkspace(this.__currentWorkspaceId);
61+
const workspace = osparc.store.Workspaces.getInstance().getWorkspace(this.__currentWorkspaceId);
6262
const currentWorkspaceName = workspace ? workspace.getName() : "My Workspace";
6363
control = new qx.ui.basic.Label(this.tr("Current location: ") + currentWorkspaceName);
6464
this._add(control);

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

+7-59
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ qx.Class.define("osparc.dashboard.ResourceFilter", {
2626

2727
this.__resourceType = resourceType;
2828
this.__sharedWithButtons = [];
29-
this.__workspaceButtons = [];
3029
this.__tagButtons = [];
3130
this.__serviceTypeButtons = [];
3231

@@ -42,11 +41,8 @@ qx.Class.define("osparc.dashboard.ResourceFilter", {
4241

4342
members: {
4443
__resourceType: null,
45-
__contextLayout: null,
46-
__contextRadioGroup: null,
4744
__workspacesAndFoldersTree: null,
4845
__sharedWithButtons: null,
49-
__workspaceButtons: null,
5046
__tagButtons: null,
5147
__serviceTypeButtons: null,
5248

@@ -88,10 +84,10 @@ qx.Class.define("osparc.dashboard.ResourceFilter", {
8884

8985
/* SHARED WITH */
9086
__createSharedWithFilterLayout: function() {
91-
const layout = this.__contextLayout = new qx.ui.container.Composite(new qx.ui.layout.VBox(5));
87+
const sharedWithLayout = new qx.ui.container.Composite(new qx.ui.layout.VBox(5));
9288

93-
const radioGroup = this.__contextRadioGroup = new qx.ui.form.RadioGroup();
94-
radioGroup.setAllowEmptySelection(false);
89+
const sharedWithRadioGroup = new qx.ui.form.RadioGroup();
90+
sharedWithRadioGroup.setAllowEmptySelection(false);
9591

9692
const options = osparc.dashboard.SearchBarFilter.getSharedWithOptions(this.__resourceType);
9793
options.forEach(option => {
@@ -124,8 +120,8 @@ qx.Class.define("osparc.dashboard.ResourceFilter", {
124120
}
125121
button.id = option.id;
126122

127-
layout.add(button);
128-
radioGroup.add(button);
123+
sharedWithLayout.add(button);
124+
sharedWithRadioGroup.add(button);
129125

130126
button.addListener("execute", () => {
131127
this.fireDataEvent("changeSharedWith", {
@@ -137,61 +133,13 @@ qx.Class.define("osparc.dashboard.ResourceFilter", {
137133
this.__sharedWithButtons.push(button);
138134
});
139135

140-
return layout;
136+
return sharedWithLayout;
141137
},
142138
/* /SHARED WITH */
143139

144140
/* WORKSPACES */
145-
__addWorkspaceButtons: function() {
146-
this.__contextLayout.add(new qx.ui.core.Spacer());
147-
const workspacesButton = new qx.ui.toolbar.RadioButton(this.tr("Shared Workspaces"), osparc.store.Workspaces.iconPath(22));
148-
workspacesButton.workspaceId = -1;
149-
workspacesButton.set({
150-
appearance: "filter-toggle-button"
151-
});
152-
this.__contextLayout.add(workspacesButton);
153-
this.__contextRadioGroup.add(workspacesButton);
154-
workspacesButton.addListener("execute", () => {
155-
this.fireDataEvent("changeWorkspace", workspacesButton.workspaceId);
156-
});
157-
158-
this.reloadWorkspaceButtons();
159-
},
160-
161-
reloadWorkspaceButtons: function() {
162-
// remove first the workspaces
163-
for (let i=this.__workspaceButtons.length-1; i >= 0; i--) {
164-
const workspaceButton = this.__workspaceButtons[i];
165-
this.__contextLayout.remove(workspaceButton);
166-
this.__contextRadioGroup.remove(workspaceButton);
167-
}
168-
this.__workspaceButtons = [];
169-
osparc.store.Workspaces.fetchWorkspaces()
170-
.then(workspaces => {
171-
workspaces.forEach(workspace => {
172-
const workspaceButton = new qx.ui.toolbar.RadioButton(null, osparc.store.Workspaces.iconPath(22));
173-
workspace.bind("name", workspaceButton, "label");
174-
workspaceButton.workspaceId = workspace.getWorkspaceId();
175-
this.__workspaceButtons.push(workspaceButton);
176-
workspaceButton.set({
177-
appearance: "filter-toggle-button",
178-
marginLeft: 15,
179-
});
180-
this.__contextLayout.add(workspaceButton);
181-
this.__contextRadioGroup.add(workspaceButton);
182-
workspaceButton.addListener("execute", () => {
183-
this.fireDataEvent("changeWorkspace", workspaceButton.workspaceId);
184-
}, this);
185-
});
186-
})
187-
.catch(console.error);
188-
},
189-
190141
workspaceSelected: function(workspaceId) {
191-
const foundButton = this.__workspaceButtons.find(workspaceButton => workspaceButton.workspaceId === workspaceId);
192-
if (foundButton) {
193-
foundButton.execute();
194-
}
142+
// OM: select folder
195143
},
196144
/* /WORKSPACES */
197145

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

+3-4
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
163163
},
164164

165165
__reloadWorkspaces: function() {
166-
osparc.store.Workspaces.fetchWorkspaces()
166+
osparc.store.Workspaces.getInstance().fetchWorkspaces()
167167
.then(workspaces => {
168168
this.__workspacesList = workspaces;
169169
workspaces.forEach(workspace => workspace["resourceType"] = "workspace");
@@ -411,7 +411,6 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
411411
"updateWorkspace"
412412
].forEach(e => {
413413
newWorkspaceCard.addListener(e, () => {
414-
this._resourceFilter.reloadWorkspaceButtons();
415414
this.__reloadWorkspaces();
416415
});
417416
});
@@ -420,16 +419,16 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
420419

421420
_workspaceSelected: function(workspaceId) {
422421
this.setCurrentWorkspaceId(workspaceId);
422+
this._changeContext(this.getCurrentWorkspaceId(), null);
423423
},
424424

425425
_workspaceUpdated: function() {
426426
this.__reloadWorkspaceCards();
427427
},
428428

429429
_deleteWorkspaceRequested: function(workspaceId) {
430-
osparc.store.Workspaces.deleteWorkspace(workspaceId)
430+
osparc.store.Workspaces.getInstance().deleteWorkspace(workspaceId)
431431
.then(() => {
432-
this._resourceFilter.reloadWorkspaceButtons();
433432
this.__reloadWorkspaces();
434433
})
435434
.catch(err => console.error(err));

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ qx.Class.define("osparc.dashboard.WorkspaceHeader", {
171171
const title = this.getChildControl("title");
172172
this.getChildControl("edit-button").exclude();
173173

174-
const workspace = osparc.store.Workspaces.getWorkspace(workspaceId);
174+
const workspace = osparc.store.Workspaces.getInstance().getWorkspace(workspaceId);
175175
if (workspaceId === -1) {
176176
this.__setIcon(osparc.store.Workspaces.iconPath(32));
177177
title.setValue(this.tr("Shared Workspaces"));
@@ -273,7 +273,7 @@ qx.Class.define("osparc.dashboard.WorkspaceHeader", {
273273
},
274274

275275
__editWorkspace: function() {
276-
const workspace = osparc.store.Workspaces.getWorkspace(this.getCurrentWorkspaceId());
276+
const workspace = osparc.store.Workspaces.getInstance().getWorkspace(this.getCurrentWorkspaceId());
277277
const permissionsView = new osparc.editor.WorkspaceEditor(workspace);
278278
const title = this.tr("Edit Workspace");
279279
const win = osparc.ui.window.Window.popUpInWindow(permissionsView, title, 300, 200);
@@ -284,7 +284,7 @@ qx.Class.define("osparc.dashboard.WorkspaceHeader", {
284284
},
285285

286286
__openShareWith: function() {
287-
const workspace = osparc.store.Workspaces.getWorkspace(this.getCurrentWorkspaceId());
287+
const workspace = osparc.store.Workspaces.getInstance().getWorkspace(this.getCurrentWorkspaceId());
288288
const permissionsView = new osparc.share.CollaboratorsWorkspace(workspace);
289289
const title = this.tr("Share Workspace");
290290
const win = osparc.ui.window.Window.popUpInWindow(permissionsView, title, 500, 400);

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

+38-8
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,33 @@ qx.Class.define("osparc.dashboard.WorkspacesAndFoldersTree", {
4545
this.__initTree();
4646

4747
osparc.store.Folders.getInstance().addListener("folderAdded", e => {
48-
const folder = e.getData()
48+
const folder = e.getData();
4949
this.__folderAdded(folder);
5050
}, this);
5151

5252
osparc.store.Folders.getInstance().addListener("folderRemoved", e => {
53-
const folder = e.getData()
53+
const folder = e.getData();
5454
this.__folderRemoved(folder);
5555
}, this);
56+
57+
osparc.store.Folders.getInstance().addListener("folderMoved", e => {
58+
const {
59+
folder,
60+
oldParentFolderId,
61+
} = e.getData();
62+
this.__folderRemoved(folder, oldParentFolderId);
63+
this.__folderAdded(folder);
64+
}, this);
65+
66+
osparc.store.Workspaces.getInstance().addListener("workspaceAdded", e => {
67+
const workspace = e.getData();
68+
this.__addWorkspace(workspace);
69+
}, this);
70+
71+
osparc.store.Workspaces.getInstance().addListener("workspaceRemoved", e => {
72+
const workspace = e.getData();
73+
this.__removeWorkspace(workspace);
74+
}, this);
5675
},
5776

5877
events: {
@@ -159,16 +178,16 @@ qx.Class.define("osparc.dashboard.WorkspacesAndFoldersTree", {
159178
this.__models.push(sharedWorkspaceModel);
160179
rootModel.getChildren().append(sharedWorkspaceModel);
161180

162-
osparc.store.Workspaces.fetchWorkspaces()
181+
osparc.store.Workspaces.getInstance().fetchWorkspaces()
163182
.then(workspaces => {
164183
workspaces.forEach(workspace => {
165-
this.__addWorkspace(workspace, sharedWorkspaceModel);
184+
this.__addWorkspace(workspace);
166185
});
167186
})
168187
.catch(console.error);
169188
},
170189

171-
__addWorkspace: function(workspace, parentModel) {
190+
__addWorkspace: function(workspace) {
172191
const workspaceData = {
173192
label: "",
174193
icon: "shared",
@@ -182,7 +201,17 @@ qx.Class.define("osparc.dashboard.WorkspacesAndFoldersTree", {
182201
const workspaceModel = qx.data.marshal.Json.createModel(workspaceData, true);
183202
this.__models.push(workspaceModel);
184203
workspace.bind("name", workspaceModel, "label");
185-
parentModel.getChildren().append(workspaceModel);
204+
205+
const sharedWorkspaceModel = this.__getModel(-1, null);
206+
sharedWorkspaceModel.getChildren().append(workspaceModel);
207+
},
208+
209+
__removeWorkspace: function(workspace) {
210+
const sharedWorkspaceModel = this.__getModel(-1, null);
211+
const idx = sharedWorkspaceModel.getChildren().toArray().findIndex(w => workspace.getWorkspaceId() === w.getWorkspaceId());
212+
if (idx > -1) {
213+
sharedWorkspaceModel.getChildren().toArray().splice(idx, 1);
214+
}
186215
},
187216

188217
__addFolder: function(folder, parentModel) {
@@ -225,8 +254,9 @@ qx.Class.define("osparc.dashboard.WorkspacesAndFoldersTree", {
225254
}
226255
},
227256

228-
__folderRemoved: function(folder) {
229-
const parentModel = this.__getModel(folder.getWorkspaceId(), folder.getParentFolderId());
257+
__folderRemoved: function(folder, oldParentFolderId) {
258+
// eslint-disable-next-line no-negated-condition
259+
const parentModel = this.__getModel(folder.getWorkspaceId(), oldParentFolderId !== undefined ? oldParentFolderId : folder.getParentFolderId());
230260
if (parentModel) {
231261
const idx = parentModel.getChildren().toArray().findIndex(c => folder.getWorkspaceId() === c.getWorkspaceId() && folder.getFolderId() === c.getFolderId());
232262
if (idx > -1) {

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ qx.Class.define("osparc.dashboard.WorkspacesTree", {
9595
const myWorkspaceModel = qx.data.marshal.Json.createModel(myWorkspaceData, true);
9696
parent.getChildren().append(myWorkspaceModel);
9797

98-
osparc.store.Workspaces.fetchWorkspaces()
98+
osparc.store.Workspaces.getInstance().fetchWorkspaces()
9999
.then(workspaces => {
100100
workspaces.forEach(workspace => {
101101
const workspaceData = {

services/static-webserver/client/source/class/osparc/editor/WorkspaceEditor.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ qx.Class.define("osparc.editor.WorkspaceEditor", {
176176
description: this.getDescription(),
177177
thumbnail: this.getThumbnail(),
178178
};
179-
osparc.store.Workspaces.postWorkspace(newWorkspaceData)
179+
osparc.store.Workspaces.getInstance().postWorkspace(newWorkspaceData)
180180
.then(newWorkspace => this.fireDataEvent("workspaceCreated", newWorkspace))
181181
.catch(console.error)
182182
.finally(() => createButton.setFetching(false));
@@ -189,7 +189,7 @@ qx.Class.define("osparc.editor.WorkspaceEditor", {
189189
description: this.getDescription(),
190190
thumbnail: this.getThumbnail(),
191191
};
192-
osparc.store.Workspaces.putWorkspace(this.__workspaceId, updateData)
192+
osparc.store.Workspaces.getInstance().putWorkspace(this.__workspaceId, updateData)
193193
.then(() => this.fireEvent("workspaceUpdated"))
194194
.catch(console.error)
195195
.finally(() => editButton.setFetching(false));

services/static-webserver/client/source/class/osparc/share/CollaboratorsWorkspace.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ qx.Class.define("osparc.share.CollaboratorsWorkspace", {
7070

7171
const newCollaborators = {};
7272
gids.forEach(gid => newCollaborators[gid] = this.self().getCollaboratorAccessRight());
73-
osparc.store.Workspaces.addCollaborators(this.__workspace.getWorkspaceId(), newCollaborators)
73+
osparc.store.Workspaces.getInstance().addCollaborators(this.__workspace.getWorkspaceId(), newCollaborators)
7474
.then(() => {
7575
this.fireDataEvent("updateAccessRights", this.__workspace.serialize());
7676
const text = this.tr("User(s) successfully added.");
@@ -88,7 +88,7 @@ qx.Class.define("osparc.share.CollaboratorsWorkspace", {
8888
item.setEnabled(false);
8989
}
9090

91-
osparc.store.Workspaces.removeCollaborator(this.__workspace.getWorkspaceId(), collaborator["gid"])
91+
osparc.store.Workspaces.getInstance().removeCollaborator(this.__workspace.getWorkspaceId(), collaborator["gid"])
9292
.then(() => {
9393
this.fireDataEvent("updateAccessRights", this.__workspace.serialize());
9494
osparc.FlashMessenger.getInstance().logAs(this.tr("Member successfully removed"));
@@ -108,7 +108,7 @@ qx.Class.define("osparc.share.CollaboratorsWorkspace", {
108108
__make: function(collaboratorGId, newAccessRights, successMsg, failureMsg, item) {
109109
item.setEnabled(false);
110110

111-
osparc.store.Workspaces.updateCollaborator(this.__workspace.getWorkspaceId(), collaboratorGId, newAccessRights)
111+
osparc.store.Workspaces.getInstance().updateCollaborator(this.__workspace.getWorkspaceId(), collaboratorGId, newAccessRights)
112112
.then(() => {
113113
this.fireDataEvent("updateAccessRights", this.__workspace.serialize());
114114
osparc.FlashMessenger.getInstance().logAs(successMsg);

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

+20-14
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ qx.Class.define("osparc.store.Folders", {
2828
events: {
2929
"folderAdded": "qx.event.type.Data",
3030
"folderRemoved": "qx.event.type.Data",
31+
"folderMoved": "qx.event.type.Data",
3132
},
3233

3334
members: {
@@ -92,20 +93,25 @@ qx.Class.define("osparc.store.Folders", {
9293
},
9394

9495
putFolder: function(folderId, updateData) {
95-
return new Promise((resolve, reject) => {
96-
const params = {
97-
"url": {
98-
folderId
99-
},
100-
data: updateData
101-
};
102-
osparc.data.Resources.getInstance().fetch("folders", "update", params)
103-
.then(folderData => {
104-
this.__addToCache(folderData);
105-
resolve();
106-
})
107-
.catch(err => reject(err));
108-
});
96+
const folder = this.getFolder(folderId);
97+
const oldParentFolderId = folder.getParentFolderId();
98+
const params = {
99+
"url": {
100+
folderId
101+
},
102+
data: updateData
103+
};
104+
return osparc.data.Resources.getInstance().fetch("folders", "update", params)
105+
.then(folderData => {
106+
this.__addToCache(folderData);
107+
if (updateData.parentFolderId !== oldParentFolderId) {
108+
this.fireDataEvent("folderMoved", {
109+
folder,
110+
oldParentFolderId,
111+
});
112+
}
113+
})
114+
.catch(console.error);
109115
},
110116

111117
getFolder: function(folderId = null) {

0 commit comments

Comments
 (0)