Skip to content

Commit 9d9a809

Browse files
authored
FE: Fix file path converter (#124)
* eslint * support nested folders * refactoring * cleanup
1 parent c9fde1c commit 9d9a809

File tree

2 files changed

+40
-64
lines changed

2 files changed

+40
-64
lines changed

services/static-webserver/client/source/class/osparc/data/Converters.js

Lines changed: 32 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -48,74 +48,43 @@ qx.Class.define("osparc.data.Converters", {
4848
file["location_id"],
4949
""
5050
);
51-
if (file["location_id"] === 0 || file["location_id"] === "0") {
52-
// simcore files
53-
let parent = fileInTree;
54-
const splitted = file["file_uuid"].split("/");
55-
if (splitted.length < 3) {
56-
continue;
57-
}
51+
const isSimcore = file["location_id"] === 0 || file["location_id"] === "0";
5852

59-
const prjId = splitted[0];
60-
const nodeId = splitted[1];
61-
const prjLabel = file["project_name"];
62-
const nodeLabel = file["node_name"];
63-
const prjItem = this.createDirEntry(
64-
prjLabel,
65-
file["location_id"],
66-
prjId
67-
);
68-
parent.children.push(prjItem);
69-
parent = prjItem
70-
const nodeItem = this.createDirEntry(
71-
nodeLabel,
72-
file["location_id"],
73-
nodeId
74-
);
75-
parent.children.push(nodeItem);
76-
parent = nodeItem
53+
const splitted = file["file_uuid"].split("/");
54+
if (isSimcore && splitted.length < 3) {
55+
continue;
56+
}
7757

78-
for (let j=2; j<splitted.length-1; j++) {
79-
const newItem = this.createDirEntry(
80-
splitted[j],
81-
file["location_id"],
82-
parent.path === "" ? splitted[j] : parent.path +"/"+ splitted[j]
83-
);
84-
parent.children.push(newItem);
85-
parent = newItem;
58+
// create directories
59+
let parent = fileInTree;
60+
for (let j=0; j<splitted.length-1; j++) {
61+
let label = "Unknown";
62+
if (isSimcore && j===0) {
63+
label = file["project_name"];
64+
} else if (isSimcore && j===1) {
65+
label = file["node_name"];
66+
} else {
67+
label = splitted[j];
8668
}
87-
let fileInfo = this.createFileEntry(
88-
splitted[splitted.length-1],
69+
const newItem = this.createDirEntry(
70+
label,
8971
file["location_id"],
90-
splitted[splitted.length-1],
91-
file["file_id"],
92-
file["last_modified"],
93-
file["file_size"]);
94-
parent.children.push(fileInfo);
95-
this.__mergeFileTreeChildren(children, fileInTree);
96-
} else if (file["location_id"] === 1 || file["location_id"] === "1") {
97-
// datcore files
98-
let parent = fileInTree;
99-
let splitted = file["file_uuid"].split("/");
100-
for (let j=0; j<splitted.length-1; j++) {
101-
const newItem = this.createDirEntry(
102-
splitted[j],
103-
file["location_id"],
104-
parent.path === "" ? splitted[j] : parent.path +"/"+ splitted[j]
105-
);
106-
parent.children.push(newItem);
107-
parent = newItem;
108-
}
109-
let fileInfo = this.createFileEntry(
110-
splitted[splitted.length-1],
111-
file["location_id"],
112-
datasetId,
113-
file["file_id"],
114-
file["last_modified"],
115-
file["file_size"]);
116-
parent.children.push(fileInfo);
117-
this.__mergeFileTreeChildren(children, fileInTree);
72+
parent.path === "" ? splitted[j] : parent.path +"/"+ splitted[j]
73+
);
74+
parent.children.push(newItem);
75+
parent = newItem;
11876
}
77+
78+
// create file
79+
const fileInfo = this.createFileEntry(
80+
splitted[splitted.length-1],
81+
file["location_id"],
82+
datasetId,
83+
file["file_id"],
84+
file["last_modified"],
85+
file["file_size"]);
86+
parent.children.push(fileInfo);
87+
this.__mergeFileTreeChildren(children, fileInTree);
11988
}
12089

12190
return children;

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,13 @@ qx.Class.define("osparc.file.FilesTree", {
118118
.splice(i, 1);
119119
}
120120
}
121+
},
122+
123+
attachPathLabel: function(srcPathLabel, data) {
124+
data["pathLabel"] = srcPathLabel.concat(data["label"]);
125+
if ("children" in data) {
126+
data.children.forEach(child => this.self().attachPathLabel(data["pathLabel"], child));
127+
}
121128
}
122129
},
123130

@@ -464,7 +471,7 @@ qx.Class.define("osparc.file.FilesTree", {
464471
const locationData = osparc.data.Converters.fromDSMToVirtualTreeModel(datasetId, files);
465472
const datasetData = locationData[0].children;
466473
datasetData[0].children.forEach(data => {
467-
data["pathLabel"] = datasetModel.getPathLabel().concat(data["label"]);
474+
this.self().attachPathLabel(datasetModel.getPathLabel(), data);
468475
const filesModel = qx.data.marshal.Json.createModel(data, true);
469476
datasetModel.getChildren().append(filesModel);
470477
});

0 commit comments

Comments
 (0)