Skip to content
Snippets Groups Projects
Commit c975bdfb authored by Bekerle, Patrizio's avatar Bekerle, Patrizio :fire: Committed by Reiter, Christoph
Browse files

Improve sendFinishedEvent (VPU/Middleware/API#40)

parent f1911a1e
No related branches found
No related tags found
No related merge requests found
...@@ -95,13 +95,17 @@ class VPUFileUpload extends VPULitElement { ...@@ -95,13 +95,17 @@ class VPUFileUpload extends VPULitElement {
([...files]).forEach(this.uploadFile.bind(this)) ([...files]).forEach(this.uploadFile.bind(this))
} }
sendFinishedEvent(status, filename) { sendFinishedEvent(response, file) {
response.json().then((json) => {
const data = { const data = {
status: status, status: response.status,
filename: filename filename: file.name,
json: json
}; };
const event = new CustomEvent("vpu-fileupload-finished", { "detail": data, bubbles: true, composed: true }); const event = new CustomEvent("vpu-fileupload-finished", { "detail": data, bubbles: true, composed: true });
this.dispatchEvent(event); this.dispatchEvent(event);
});
} }
uploadFile(file) { uploadFile(file) {
...@@ -120,12 +124,12 @@ class VPUFileUpload extends VPULitElement { ...@@ -120,12 +124,12 @@ class VPUFileUpload extends VPULitElement {
.then((response) => { .then((response) => {
/* Done. Inform the user */ /* Done. Inform the user */
console.log(`Status: ${response.status} for file ${file.name}`); console.log(`Status: ${response.status} for file ${file.name}`);
this.sendFinishedEvent(response.status, file.name); this.sendFinishedEvent(response, file);
}) })
.catch((response) => { .catch((response) => {
/* Error. Inform the user */ /* Error. Inform the user */
console.log(`Status: ${response.status} for file ${file.name}`); console.log(`Error status: ${response.status} for file ${file.name}`);
this.sendFinishedEvent(response.status, file.name); this.sendFinishedEvent(response, file);
}) })
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment