From e2996988724403d0423d37979f9786fe832700c1 Mon Sep 17 00:00:00 2001
From: Tamara Steinwender <tamara.steinwender@tugraz.at>
Date: Thu, 11 Mar 2021 12:08:17 +0100
Subject: [PATCH] Add clipboard functionality in filehandling

---
 README.md                                 |  1 +
 packages/file-handling/src/file-sink.js   |  5 ++++
 packages/file-handling/src/file-source.js | 29 +++++++++++++++++++++--
 3 files changed, 33 insertions(+), 2 deletions(-)

diff --git a/README.md b/README.md
index b7f92105..2e4043e0 100644
--- a/README.md
+++ b/README.md
@@ -38,6 +38,7 @@ the version number in its `package.json` is higher than the version number on np
 | `entry-point-url`             | Entry point url for all api requests                                              |
 | `requested-login-status`      | Used by the login buttons to trigger a login in auth components                   |
 | `initial-file-handling-state` | Used by the file-handling component to sync file source/sink at first time open   |
+| `clipboard-files`             | Used by the file-handling component to use the clipboard source and sink          |
 | `analytics-event`             | Used to send analytics events to the Matomo component                             |
 
 ## Reserved events
diff --git a/packages/file-handling/src/file-sink.js b/packages/file-handling/src/file-sink.js
index 3f4b1098..1993bd30 100644
--- a/packages/file-handling/src/file-sink.js
+++ b/packages/file-handling/src/file-sink.js
@@ -217,6 +217,11 @@ export class FileSink extends ScopedElementsMixin(DBPLitElement) {
     saveFilesToClipboard()
     {
         //save it
+        let data = {};
+        if (this.files.length !== 0) {
+            data = {"files": this.files};
+            this.sendSetPropertyEvent('clipboard-files', data);
+        }
     }
 
     closeDialog(e) {
diff --git a/packages/file-handling/src/file-source.js b/packages/file-handling/src/file-source.js
index d5ac5c1a..75a739b2 100644
--- a/packages/file-handling/src/file-source.js
+++ b/packages/file-handling/src/file-source.js
@@ -55,6 +55,8 @@ export class FileSource extends ScopedElementsMixin(DBPLitElement) {
         this.firstOpen = true;
 
         this.initialFileHandlingState = {target: '', path: ''};
+        this.clipBoardFiles = {files: ''};
+
     }
 
     static get scopedElements() {
@@ -89,6 +91,8 @@ export class FileSource extends ScopedElementsMixin(DBPLitElement) {
             nextcloudPath: { type: String, attribute: false },
 
             initialFileHandlingState: {type: Object, attribute: 'initial-file-handling-state'},
+            clipBoardFiles: {type: Object, attribute: 'clipboard-files'},
+
         };
     }
 
@@ -400,11 +404,30 @@ export class FileSource extends ScopedElementsMixin(DBPLitElement) {
 
     getClipboardFiles() {
         let htmlpath = [];
-        htmlpath[0] =  html`ein file und danach select button`;
-
+        htmlpath[0] =  html`ein file und danach select button<br>`;
+        console.log("############################", this.clipBoardFiles );
+        for(let i = 0; i < this.clipBoardFiles.files.length; i ++)
+        {
+            console.log("--", this.clipBoardFiles.files[i].name);
+            console.log("++", i);
+
+            htmlpath[i+1] =  this.clipBoardFiles.files[i].name;
+            //htmlpath[i+1] +=  html`<br>`;
+        }
         return htmlpath;
     }
 
+
+    async sendClipboardFiles() {
+        for(let i = 0; i < this.clipBoardFiles.files.length; i ++)
+        {
+            await this.sendFileEvent(this.clipBoardFiles.files[i]);
+        }
+
+        this.closeDialog();
+
+    }
+
     static get styles() {
         // language=css
         return css`
@@ -536,6 +559,8 @@ export class FileSource extends ScopedElementsMixin(DBPLitElement) {
                                     <h2>Von der Zwischenablage auswählen</h2>
                                     <p>Hier können Sie aus der zuvor temporär abgelegte Dateien auswählen.<br><br></p>
                                     <p>${this.getClipboardFiles()}</p>
+                                    <button class="button select-button is-primary"
+                                            @click="${() => {this.sendClipboardFiles(); }}">Auswählen</button>
                                 </div>
                             </div>
                         </main>
-- 
GitLab