Skip to content

Commit 34e848a

Browse files
odeimaizmrnicegyu11
authored andcommitted
πŸ› [Frontend] File Picker: complete upload (ITISFoundation#7299)
1 parent 52fa710 commit 34e848a

File tree

7 files changed

+42
-33
lines changed

7 files changed

+42
-33
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,8 @@ qx.Class.define("osparc.dashboard.TemplateBrowser", {
191191
const workbench = newStudyData["workbench"];
192192
const nodesIdsListed = [];
193193
Object.keys(workbench).forEach(nodeId => {
194-
const node = workbench[nodeId];
195-
if (osparc.study.StudyPricingUnits.includeInList(node)) {
194+
const nodeData = workbench[nodeId];
195+
if (osparc.study.StudyPricingUnits.includeInList(nodeData)) {
196196
nodesIdsListed.push(nodeId);
197197
}
198198
});

β€Žservices/static-webserver/client/source/class/osparc/data/model/Study.jsβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ qx.Class.define("osparc.data.model.Study", {
487487
// Do not listen to output related backend updates if the node is a frontend node.
488488
// The frontend controls its output values, progress and states.
489489
// If a File Picker is uploading a file, the backend could override the current state with some older state.
490-
if (node && nodeData && !osparc.data.model.Node.isFrontend(node)) {
490+
if (node && nodeData && !osparc.data.model.Node.isFrontend(node.getMetaData())) {
491491
node.setOutputData(nodeData.outputs);
492492
if ("progress" in nodeData) {
493493
const progress = Number.parseInt(nodeData["progress"]);

β€Žservices/static-webserver/client/source/class/osparc/file/FilePicker.jsβ€Ž

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,18 @@ qx.Class.define("osparc.file.FilePicker", {
414414
if (files.length === 1) {
415415
const fileUploader = new osparc.file.FileUploader(this.getNode());
416416
fileUploader.addListener("uploadAborted", () => this.__resetOutput());
417-
fileUploader.addListener("fileUploaded", () => {
417+
fileUploader.addListener("fileUploaded", e => {
418+
const fileMetadata = e.getData();
419+
if (
420+
"location" in fileMetadata &&
421+
"dataset" in fileMetadata &&
422+
"path" in fileMetadata &&
423+
"name" in fileMetadata
424+
) {
425+
osparc.file.FilePicker.setOutputValueFromStore(this.getNode(), fileMetadata["location"], fileMetadata["dataset"], fileMetadata["path"], fileMetadata["name"]);
426+
} else {
427+
console.error("metadata info missing", fileMetadata);
428+
}
418429
this.fireEvent("fileUploaded");
419430
this.getNode().fireEvent("fileUploaded");
420431
}, this);

β€Žservices/static-webserver/client/source/class/osparc/file/FileUploader.jsβ€Ž

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ qx.Class.define("osparc.file.FileUploader", {
3939

4040
events: {
4141
"uploadAborted": "qx.event.type.Event",
42-
"fileUploaded": "qx.event.type.Event"
42+
"fileUploaded": "qx.event.type.Data",
4343
},
4444

4545
statics: {
@@ -60,6 +60,7 @@ qx.Class.define("osparc.file.FileUploader", {
6060
members: {
6161
__presignedLinkData: null,
6262
__uploadedParts: null,
63+
__fileMetadata: null,
6364

6465
// Request to the server an upload URL.
6566
retrieveUrlAndUpload: function(file) {
@@ -80,6 +81,14 @@ qx.Class.define("osparc.file.FileUploader", {
8081
.then(presignedLinkData => {
8182
if (presignedLinkData.resp.urls) {
8283
this.__presignedLinkData = presignedLinkData;
84+
85+
this.__fileMetadata = {
86+
location: presignedLinkData.locationId,
87+
dataset: studyId,
88+
path: presignedLinkData.fileUuid,
89+
name: file.name
90+
};
91+
8392
try {
8493
this.__uploadFile(file);
8594
} catch (error) {
@@ -124,7 +133,7 @@ qx.Class.define("osparc.file.FileUploader", {
124133
const nProgress = Math.min(Math.max(100*progress-min, min), max);
125134
this.getNode().getStatus().setProgress(nProgress);
126135
if (this.__uploadedParts.every(uploadedPart => uploadedPart["e_tag"] !== null)) {
127-
this.__checkCompleteUpload(file);
136+
this.__checkCompleteUpload();
128137
}
129138
}
130139
} catch (err) {
@@ -153,7 +162,7 @@ qx.Class.define("osparc.file.FileUploader", {
153162
},
154163

155164
// Use XMLHttpRequest to complete the upload to S3
156-
__checkCompleteUpload: function(file) {
165+
__checkCompleteUpload: function() {
157166
if (this.getNode()["fileUploadAbortRequested"]) {
158167
this.__abortUpload();
159168
return;
@@ -162,29 +171,21 @@ qx.Class.define("osparc.file.FileUploader", {
162171
const presignedLinkData = this.__presignedLinkData;
163172
this.getNode().getStatus().setProgress(this.self().PROGRESS_VALUES.COMPLETING);
164173
const completeUrl = presignedLinkData.resp.links.complete_upload;
165-
const location = presignedLinkData.locationId;
166-
const path = presignedLinkData.fileUuid;
167174
const xhr = new XMLHttpRequest();
168175
xhr.onloadend = () => {
169-
const fileMetadata = {
170-
location,
171-
dataset: this.getNode().getStudy().getUuid(),
172-
path,
173-
name: file.name
174-
};
175176
const resp = JSON.parse(xhr.responseText);
176177
if ("error" in resp && resp["error"]) {
177178
console.error(resp["error"]);
178179
this.__abortUpload();
179180
} else if ("data" in resp) {
180181
if (xhr.status == 202) {
181-
console.log("waiting for completion", file.name);
182+
console.log("waiting for completion", this.__fileMetadata.name);
182183
// @odeimaiz: we need to poll the received new location in the response
183184
// we do have links.state -> poll that link until it says ok
184185
// right now this kind of work if files are small and this happens fast
185-
this.__pollFileUploadState(resp["data"]["links"]["state"], fileMetadata);
186+
this.__pollFileUploadState(resp["data"]["links"]["state"]);
186187
} else if (xhr.status == 200) {
187-
this.__completeUpload(fileMetadata);
188+
this.__completeUpload();
188189
}
189190
}
190191
};
@@ -196,30 +197,27 @@ qx.Class.define("osparc.file.FileUploader", {
196197
xhr.send(JSON.stringify(body));
197198
},
198199

199-
__pollFileUploadState: function(stateLink, fileMetadata) {
200+
__pollFileUploadState: function(stateLink) {
200201
const xhr = new XMLHttpRequest();
201202
xhr.open("POST", stateLink, true);
202203
xhr.setRequestHeader("Content-Type", "application/json");
203204
xhr.onloadend = () => {
204205
const resp = JSON.parse(xhr.responseText);
205206
if ("data" in resp && resp["data"] && resp["data"]["state"] === "ok") {
206-
this.__completeUpload(fileMetadata);
207+
this.__completeUpload();
207208
} else {
208209
const interval = 2000;
209-
qx.event.Timer.once(() => this.__pollFileUploadState(stateLink, fileMetadata), this, interval);
210+
qx.event.Timer.once(() => this.__pollFileUploadState(stateLink), this, interval);
210211
}
211212
};
212213
xhr.send();
213214
},
214215

215-
__completeUpload: function(fileMetadata) {
216+
__completeUpload: function() {
216217
this.getNode()["fileUploadAbortRequested"] = false;
217218

218-
if ("location" in fileMetadata && "dataset" in fileMetadata && "path" in fileMetadata && "name" in fileMetadata) {
219-
osparc.file.FilePicker.setOutputValueFromStore(this.getNode(), fileMetadata["location"], fileMetadata["dataset"], fileMetadata["path"], fileMetadata["name"]);
220-
}
221219
this.__presignedLinkData = null;
222-
this.fireEvent("fileUploaded");
220+
this.fireDataEvent("fileUploaded", this.__fileMetadata);
223221
},
224222

225223
__abortUpload: function() {

β€Žservices/static-webserver/client/source/class/osparc/study/StudyPricingUnits.jsβ€Ž

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ qx.Class.define("osparc.study.StudyPricingUnits", {
3838
},
3939

4040
statics: {
41-
includeInList: function(node) {
42-
return !osparc.data.model.Node.isFrontend(node);
41+
includeInList: function(nodeData) {
42+
return !osparc.data.model.Node.isFrontend(nodeData);
4343
},
4444
},
4545

@@ -61,9 +61,9 @@ qx.Class.define("osparc.study.StudyPricingUnits", {
6161
if ("workbench" in this.__studyData) {
6262
const workbench = this.__studyData["workbench"];
6363
Object.keys(workbench).forEach(nodeId => {
64-
const node = workbench[nodeId];
65-
if (this.self().includeInList(node)) {
66-
const nodePricingUnits = new osparc.study.NodePricingUnits(this.__studyData["uuid"], nodeId, node);
64+
const nodeData = workbench[nodeId];
65+
if (this.self().includeInList(nodeData)) {
66+
const nodePricingUnits = new osparc.study.NodePricingUnits(this.__studyData["uuid"], nodeId, nodeData);
6767
this.__nodePricingUnits.push(nodePricingUnits);
6868
this._add(nodePricingUnits);
6969
promises.push(nodePricingUnits.showPricingUnits());

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ qx.Class.define("osparc.study.Utils", {
359359
},
360360

361361
getNonFrontendNodes: function(studyData) {
362-
return Object.values(studyData["workbench"]).filter(node => !osparc.data.model.Node.isFrontend(node));
362+
return Object.values(studyData["workbench"]).filter(nodeData => !osparc.data.model.Node.isFrontend(nodeData));
363363
},
364364

365365
guessIcon: function(studyData) {

β€Žservices/static-webserver/client/source/class/osparc/ui/basic/NodeStatusUI.jsβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ qx.Class.define("osparc.ui.basic.NodeStatusUI", {
145145
this.getNode().getStatus().addListener("changeProgress", e => {
146146
const progress = e.getData();
147147
if (progress > 0 && progress < 100) {
148-
this.getChildControl("label").setValue(this.tr("Uploading"));
148+
this.getChildControl("label").setValue(this.tr("Uploading..."));
149149
}
150150
});
151151
}

0 commit comments

Comments
Β (0)