Skip to content

Commit b0a28d3

Browse files
authored
🐛 [Frontend] Reload folder after deleting file (#6025)
1 parent 5a4391e commit b0a28d3

File tree

6 files changed

+324
-269
lines changed

6 files changed

+324
-269
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,13 @@ qx.Class.define("osparc.dashboard.CardBase", {
108108
} else if (sharedWith === "shared-with-me") {
109109
return totalAccess;
110110
} else if (sharedWith === "shared-with-everyone") {
111-
return !Object.keys(checks).includes("1");
111+
const store = osparc.store.Store.getInstance();
112+
const everyoneGroupIds = [
113+
store.getEveryoneProductGroup()["gid"],
114+
store.getEveryoneGroup()["gid"]
115+
];
116+
const found = Object.keys(checks).some(gId => everyoneGroupIds.includes(parseInt(gId)));
117+
return !found;
112118
}
113119
return false;
114120
}

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

Lines changed: 45 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -39,57 +39,15 @@ qx.Class.define("osparc.dashboard.DataBrowser", {
3939
},
4040

4141
members: {
42-
__filesTree: null,
43-
__folderViewer: null,
44-
__selectedFileLayout: null,
45-
4642
_createChildControlImpl: function(id) {
4743
let control;
4844
switch (id) {
49-
case "reload-button":
50-
control = new qx.ui.form.Button().set({
51-
label: this.tr("Reload"),
52-
font: "text-14",
53-
icon: "@FontAwesome5Solid/sync-alt/14",
54-
allowGrowX: false
55-
});
56-
this._addToLayout(control);
57-
break;
58-
case "tree-folder-layout":
59-
control = new qx.ui.splitpane.Pane("horizontal");
60-
control.getChildControl("splitter").set({
61-
width: 2,
62-
backgroundColor: "scrollbar-passive"
63-
});
45+
case "tree-folder-view":
46+
control = new osparc.file.TreeFolderView();
6447
this._addToLayout(control, {
6548
flex: 1
6649
});
6750
break;
68-
case "files-tree": {
69-
const treeFolderLayout = this.getChildControl("tree-folder-layout");
70-
control = new osparc.file.FilesTree().set({
71-
showLeafs: false,
72-
minWidth: 150,
73-
width: 250
74-
});
75-
treeFolderLayout.add(control, 0);
76-
break;
77-
}
78-
case "folder-viewer": {
79-
const treeFolderLayout = this.getChildControl("tree-folder-layout");
80-
control = new osparc.file.FolderViewer();
81-
treeFolderLayout.add(control, 1);
82-
break;
83-
}
84-
case "selected-file-layout":
85-
control = new osparc.file.FileLabelWithActions().set({
86-
alignY: "middle"
87-
});
88-
break;
89-
case "actions-toolbar":
90-
control = new qx.ui.toolbar.ToolBar();
91-
this._addToLayout(control);
92-
break;
9351
}
9452

9553
return control || this.base(arguments, id);
@@ -101,8 +59,9 @@ qx.Class.define("osparc.dashboard.DataBrowser", {
10159
this.__buildLayout();
10260

10361
this.addListener("appear", () => {
104-
this.getChildControl("files-tree").populateTree();
105-
this.getChildControl("folder-viewer").setFolder(this.getChildControl("files-tree").getModel());
62+
const treeFolderView = this.getChildControl("tree-folder-view");
63+
treeFolderView.getChildControl("folder-tree").populateTree();
64+
treeFolderView.getChildControl("folder-viewer").setFolder(treeFolderView.getChildControl("folder-tree").getModel());
10665
}, this);
10766
},
10867

@@ -111,64 +70,53 @@ qx.Class.define("osparc.dashboard.DataBrowser", {
11170
marginTop: 20
11271
});
11372

114-
// button for refetching data
115-
const reloadBtn = this.getChildControl("reload-button");
116-
reloadBtn.addListener("execute", () => {
117-
this.getChildControl("files-tree").resetCache();
118-
this.getChildControl("files-tree").populateTree();
119-
}, this);
73+
const treeFolderView = this.getChildControl("tree-folder-view");
12074

121-
const filesTree = this.getChildControl("files-tree");
122-
const folderViewer = this.getChildControl("folder-viewer");
75+
const reloadButton = treeFolderView.getChildControl("reload-button");
76+
reloadButton.addListener("execute", () => this.__reloadTree(), this);
12377

124-
const actionsToolbar = this.getChildControl("actions-toolbar");
125-
const fileActions = new qx.ui.toolbar.Part();
126-
const addFile = new qx.ui.toolbar.Part();
127-
actionsToolbar.add(fileActions);
128-
actionsToolbar.addSpacer();
129-
actionsToolbar.add(addFile);
78+
const selectedFileLayout = treeFolderView.getChildControl("selected-file-layout");
79+
selectedFileLayout.addListener("fileDeleted", e => this.__fileDeleted(e.getData()), this);
80+
},
13081

131-
const selectedFileLayout = this.__selectedFileLayout = this.getChildControl("selected-file-layout");
82+
__reloadTree: function() {
83+
const treeFolderView = this.getChildControl("tree-folder-view");
13284

133-
filesTree.addListener("selectionChanged", () => {
134-
const selectionData = filesTree.getSelectedItem();
135-
this.__selectionChanged(selectionData);
136-
if (osparc.file.FilesTree.isDir(selectionData) || (selectionData.getChildren && selectionData.getChildren().length)) {
137-
folderViewer.setFolder(selectionData);
138-
}
139-
}, this);
85+
const foldersTree = treeFolderView.getChildControl("folder-tree");
86+
foldersTree.resetCache();
87+
foldersTree.populateTree();
14088

141-
folderViewer.addListener("selectionChanged", e => {
142-
const selectionData = e.getData();
143-
this.__selectionChanged(selectionData);
144-
}, this);
145-
folderViewer.addListener("itemSelected", e => {
146-
const data = e.getData();
147-
filesTree.openNodeAndParents(data);
148-
filesTree.setSelection(new qx.data.Array([data]));
149-
}, this);
150-
folderViewer.addListener("folderUp", e => {
151-
const currentFolder = e.getData();
152-
const parent = filesTree.getParent(currentFolder);
153-
if (parent) {
154-
filesTree.setSelection(new qx.data.Array([parent]));
155-
folderViewer.setFolder(parent);
156-
}
157-
}, this);
158-
folderViewer.addListener("requestDatasetFiles", e => {
159-
const data = e.getData();
160-
filesTree.requestDatasetFiles(data.locationId, data.datasetId);
161-
}, this);
162-
163-
selectedFileLayout.addListener("fileDeleted", e => {
164-
const fileMetadata = e.getData();
165-
this.getChildControl("files-tree").populateTree(fileMetadata["locationId"]);
166-
}, this);
167-
fileActions.add(selectedFileLayout);
89+
const folderViewer = treeFolderView.getChildControl("folder-viewer");
90+
folderViewer.resetFolder();
16891
},
16992

170-
__selectionChanged: function(selectedItem) {
171-
this.__selectedFileLayout.setItemSelected(selectedItem);
93+
__fileDeleted: function(fileMetadata) {
94+
// After deleting a file, try to keep the user in the same folder.
95+
// If the folder doesn't longer exist, open the closest available parent
96+
97+
const path = fileMetadata["fileUuid"].split("/");
98+
99+
const treeFolderView = this.getChildControl("tree-folder-view");
100+
const foldersTree = treeFolderView.getChildControl("folder-tree");
101+
const folderViewer = treeFolderView.getChildControl("folder-viewer");
102+
103+
const openSameFolder = () => {
104+
// drop last, which is the file
105+
path.pop();
106+
treeFolderView.openPath(path);
107+
};
108+
109+
folderViewer.resetFolder();
110+
const locationId = fileMetadata["locationId"];
111+
const datasetId = path[0];
112+
foldersTree.resetCache();
113+
foldersTree.populateTree()
114+
.then(datasetPromises => {
115+
Promise.all(datasetPromises)
116+
.then(() => foldersTree.requestDatasetFiles(locationId, datasetId))
117+
.then(() => openSameFolder());
118+
})
119+
.catch(err => console.error(err));
172120
}
173121
}
174122
});

services/static-webserver/client/source/class/osparc/file/FilesTree.js

Lines changed: 64 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -145,24 +145,61 @@ qx.Class.define("osparc.file.FilesTree", {
145145
dataStore.resetCache();
146146
},
147147

148-
populateStudyTree(studyId) {
149-
if (studyId) {
150-
this.__populateStudyFiles(studyId);
151-
}
148+
populateStudyTree: function(studyId) {
149+
const treeName = osparc.product.Utils.getStudyAlias({firstUpperCase: true}) + " Files";
150+
this.__resetTree(treeName);
151+
let studyModel = this.getModel();
152+
this.self().addLoadingChild(studyModel);
153+
154+
const dataStore = osparc.store.Data.getInstance();
155+
return dataStore.getFilesByLocationAndDataset("0", studyId)
156+
.then(data => {
157+
const {
158+
files
159+
} = data;
160+
161+
if (files.length && "project_name" in files[0]) {
162+
this.__resetTree(files[0]["project_name"]);
163+
}
164+
studyModel = this.getModel();
165+
this.__filesToDataset("0", studyId, files, studyModel);
166+
});
152167
},
153168

154169
populateNodeTree(nodeId) {
155-
if (nodeId) {
156-
this.__populateNodeFiles(nodeId);
157-
}
170+
const treeName = "Node Files";
171+
this.__resetTree(treeName);
172+
const rootModel = this.getModel();
173+
this.self().addLoadingChild(rootModel);
174+
175+
const dataStore = osparc.store.Data.getInstance();
176+
return dataStore.getNodeFiles(nodeId)
177+
.then(files => {
178+
const newChildren = osparc.data.Converters.fromDSMToVirtualTreeModel(null, files);
179+
if (newChildren.length && // location
180+
newChildren[0].children.length && // study
181+
newChildren[0].children[0].children.length) { // node
182+
const nodeData = newChildren[0].children[0].children[0];
183+
const nodeTreeName = nodeData.label;
184+
this.__resetTree(nodeTreeName);
185+
const rootNodeModel = this.getModel();
186+
if (nodeData.children.length) {
187+
const nodeItemsOnly = nodeData.children;
188+
this.__itemsToNode(nodeItemsOnly);
189+
}
190+
this.openNode(rootNodeModel);
191+
192+
const selected = new qx.data.Array([rootNodeModel]);
193+
this.setSelection(selected);
194+
this.__selectionChanged();
195+
} else {
196+
rootModel.getChildren().removeAll();
197+
}
198+
});
158199
},
159200

160-
populateTree: function(locationId = null) {
161-
if (locationId) {
162-
this.__populateLocation(locationId);
163-
} else {
164-
this.__populateLocations();
165-
}
201+
populateTree: function() {
202+
return this.__populateLocations();
166203
},
167204

168205
loadFilePath: function(outFileVal) {
@@ -275,16 +312,18 @@ qx.Class.define("osparc.file.FilesTree", {
275312
hideRoot: true
276313
});
277314
const dataStore = osparc.store.Data.getInstance();
278-
dataStore.getLocations()
315+
return dataStore.getLocations()
279316
.then(locations => {
317+
const datasetPromises = [];
280318
if (this.__locations.size === 0) {
281319
this.resetChecks();
282320
this.__locationsToRoot(locations);
283321
for (let i=0; i<locations.length; i++) {
284322
const locationId = locations[i]["id"];
285-
this.__populateLocation(locationId);
323+
datasetPromises.push(this.__populateLocation(locationId));
286324
}
287325
}
326+
return datasetPromises;
288327
});
289328
},
290329

@@ -321,7 +360,7 @@ qx.Class.define("osparc.file.FilesTree", {
321360
}
322361

323362
const dataStore = osparc.store.Data.getInstance();
324-
dataStore.getDatasetsByLocation(locationId)
363+
return dataStore.getDatasetsByLocation(locationId)
325364
.then(data => {
326365
const {
327366
location,
@@ -333,66 +372,13 @@ qx.Class.define("osparc.file.FilesTree", {
333372
});
334373
},
335374

336-
__populateStudyFiles: function(studyId) {
337-
const treeName = osparc.product.Utils.getStudyAlias({firstUpperCase: true}) + " Files";
338-
this.__resetTree(treeName);
339-
let studyModel = this.getModel();
340-
this.self().addLoadingChild(studyModel);
341-
342-
const dataStore = osparc.store.Data.getInstance();
343-
dataStore.getFilesByLocationAndDataset("0", studyId)
344-
.then(data => {
345-
const {
346-
files
347-
} = data;
348-
349-
if (files.length && "project_name" in files[0]) {
350-
this.__resetTree(files[0]["project_name"]);
351-
}
352-
studyModel = this.getModel();
353-
this.__filesToDataset("0", studyId, files, studyModel);
354-
});
355-
},
356-
357-
__populateNodeFiles: function(nodeId) {
358-
const treeName = "Node Files";
359-
this.__resetTree(treeName);
360-
const rootModel = this.getModel();
361-
this.self().addLoadingChild(rootModel);
362-
363-
const dataStore = osparc.store.Data.getInstance();
364-
dataStore.getNodeFiles(nodeId)
365-
.then(files => {
366-
const newChildren = osparc.data.Converters.fromDSMToVirtualTreeModel(null, files);
367-
if (newChildren.length && // location
368-
newChildren[0].children.length && // study
369-
newChildren[0].children[0].children.length) { // node
370-
const nodeData = newChildren[0].children[0].children[0];
371-
const nodeTreeName = nodeData.label;
372-
this.__resetTree(nodeTreeName);
373-
const rootNodeModel = this.getModel();
374-
if (nodeData.children.length) {
375-
const nodeItemsOnly = nodeData.children;
376-
this.__itemsToNode(nodeItemsOnly);
377-
}
378-
this.openNode(rootNodeModel);
379-
380-
const selected = new qx.data.Array([rootNodeModel]);
381-
this.setSelection(selected);
382-
this.__selectionChanged();
383-
} else {
384-
rootModel.getChildren().removeAll();
385-
}
386-
});
387-
},
388-
389375
requestDatasetFiles: function(locationId, datasetId) {
390376
if (this.__datasets.has(datasetId)) {
391-
return;
377+
return null;
392378
}
393379

394380
const dataStore = osparc.store.Data.getInstance();
395-
dataStore.getFilesByLocationAndDataset(locationId, datasetId)
381+
return dataStore.getFilesByLocationAndDataset(locationId, datasetId)
396382
.then(data => {
397383
const {
398384
location,
@@ -531,6 +517,13 @@ qx.Class.define("osparc.file.FilesTree", {
531517
return list.find(element => element.getChildren && element.getChildren().contains(childItem));
532518
},
533519

520+
findItemId: function(itemId) {
521+
const root = this.getModel();
522+
const items = [];
523+
this.__getItemsInTree(root, items);
524+
return items.find(element => "getItemId" in element && element.getItemId() === itemId);
525+
},
526+
534527
__getItemsInTree: function(item, items) {
535528
items.push(item);
536529
if (item.getChildren) {

0 commit comments

Comments
 (0)