From 0f037e00846ca27d1da71960349237dcdb1cb29c Mon Sep 17 00:00:00 2001 From: Patrizio Bekerle <patrizio@bekerle.com> Date: Tue, 23 Jun 2020 14:50:04 +0200 Subject: [PATCH] Send downloaded file via event (#26) --- src/vpu-nextcloud-file-picker.js | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/src/vpu-nextcloud-file-picker.js b/src/vpu-nextcloud-file-picker.js index 0efd6a0..ec84c83 100644 --- a/src/vpu-nextcloud-file-picker.js +++ b/src/vpu-nextcloud-file-picker.js @@ -169,23 +169,31 @@ export class NextcloudFilePicker extends ScopedElementsMixin(VPULitElement) { } downloadFiles(files) { - files.forEach((file) => this.downloadFile(file)); + files.forEach((fileData) => this.downloadFile(fileData)); } - downloadFile(file) { - this.statusText = "Loading " + file.filename + "..."; + downloadFile(fileData) { + this.statusText = "Loading " + fileData.filename + "..."; // https://github.com/perry-mitchell/webdav-client#getfilecontents this.webDavClient - .getFileContents(file.filename) + .getFileContents(fileData.filename) .then(contents => { - console.log("contents", contents); - // TODO: Generate file and send event + // create file to send via event + const file = new File([contents], fileData.basename, { type: fileData.mime }); + console.log("binaryFile", file); + + // send event + const data = {"file": file, "data": fileData}; + const event = new CustomEvent("vpu-nextcloud-file-picker-file-downloaded", + { "detail": data, bubbles: true, composed: true }); + this.dispatchEvent(event); + this.statusText = ""; }).catch(error => { - console.error(error.message); - this.statusText = error.message; - }); + console.error(error.message); + this.statusText = error.message; + }); } /** @@ -215,7 +223,6 @@ export class NextcloudFilePicker extends ScopedElementsMixin(VPULitElement) { render() { commonUtils.initAssetBaseURL('vpu-tabulator-table'); const tabulatorCss = commonUtils.getAssetURL('local/vpu-signature/tabulator-tables/css/tabulator.min.css'); - console.log("tabulatorCss", tabulatorCss); return html` <link rel="stylesheet" href="${tabulatorCss}"> -- GitLab