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

Introduce more events (VPU/Apps/Signature#1)

parent 0e756e3f
No related branches found
No related tags found
No related merge requests found
...@@ -24,7 +24,7 @@ class FileUploadDemo extends LitElement { ...@@ -24,7 +24,7 @@ class FileUploadDemo extends LitElement {
this.updateComplete.then(() => { this.updateComplete.then(() => {
this.shadowRoot.querySelectorAll('vpu-fileupload') this.shadowRoot.querySelectorAll('vpu-fileupload')
.forEach(element => { .forEach(element => {
element.addEventListener('vpu-fileupload-finished', this.addLogEntry.bind(this)); element.addEventListener('vpu-fileupload-file-finished', this.addLogEntry.bind(this));
}); });
}); });
} }
......
...@@ -107,8 +107,14 @@ class VPUFileUpload extends VPULitElement { ...@@ -107,8 +107,14 @@ class VPUFileUpload extends VPULitElement {
async handleFiles(files) { async handleFiles(files) {
console.log('handleFiles: files.length = ' + files.length); console.log('handleFiles: files.length = ' + files.length);
this.dispatchEvent(new CustomEvent("vpu-fileupload-all-start",
{ "detail": {}, bubbles: true, composed: true }));
// we need to wait for each upload until we start the next one // we need to wait for each upload until we start the next one
await this.asyncForEach(files, async (file) => this.uploadFile(file)); await this.asyncForEach(files, async (file) => this.uploadFile(file));
this.dispatchEvent(new CustomEvent("vpu-fileupload-all-finished",
{ "detail": {}, bubbles: true, composed: true }));
} }
async sendFinishedEvent(response, file, sendFile = false) { async sendFinishedEvent(response, file, sendFile = false) {
...@@ -132,15 +138,25 @@ class VPUFileUpload extends VPULitElement { ...@@ -132,15 +138,25 @@ class VPUFileUpload extends VPULitElement {
data.file = file; data.file = file;
} }
const event = new CustomEvent("vpu-fileupload-finished", { "detail": data, bubbles: true, composed: true }); const event = new CustomEvent("vpu-fileupload-file-finished", { "detail": data, bubbles: true, composed: true });
this.dispatchEvent(event); this.dispatchEvent(event);
} }
sendStartEvent(file) {
let data = {
filename: file.name,
};
this.dispatchEvent(new CustomEvent("vpu-fileupload-file-start",
{ "detail": data, bubbles: true, composed: true }));
}
/** /**
* @param file * @param file
* @returns {Promise<void>} * @returns {Promise<void>}
*/ */
async uploadFile(file) { async uploadFile(file) {
this.sendStartEvent(file);
let url = this.url; let url = this.url;
let formData = new FormData(); let formData = new FormData();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment