From 8842b961bd0995c6b8e541847b54ed984c7f8c2a Mon Sep 17 00:00:00 2001
From: Tamara Steinwender <tamara.steinwender@tugraz.at>
Date: Wed, 7 Jul 2021 10:09:09 +0200
Subject: [PATCH] Fix collapsing columns nextcloud

---
 packages/file-handling/src/clipboard.js       | 28 +++++++++-------
 packages/file-handling/src/file-source.js     |  7 +++-
 .../src/nextcloud-file-picker.js              | 33 ++++++++++++++++---
 packages/file-handling/src/styles.js          |  1 +
 4 files changed, 52 insertions(+), 17 deletions(-)

diff --git a/packages/file-handling/src/clipboard.js b/packages/file-handling/src/clipboard.js
index 8088f961..7f7fb3fa 100644
--- a/packages/file-handling/src/clipboard.js
+++ b/packages/file-handling/src/clipboard.js
@@ -239,7 +239,22 @@ export class Clipboard extends ScopedElementsMixin(AdapterLitElement) {
                     if (this._("#select_all_checkmark")) {
                         this._("#select_all_checkmark").title = this.checkAllSelected() ? i18n.t('clipboard.select-nothing') : i18n.t('clipboard.select-all');
                     }
-                }
+                },
+                renderComplete: () => {
+                    if (this.tabulatorTable !== null) {
+                        const that = this;
+                        setTimeout(function(){
+                            if (that._('.tabulator-responsive-collapse-toggle-open')) {
+                                that._a('.tabulator-responsive-collapse-toggle-open').forEach(element => element.addEventListener("click", that.toggleCollapse.bind(that)));
+                            }
+
+                            if (that._('.tabulator-responsive-collapse-toggle-close')) {
+                                that._a('.tabulator-responsive-collapse-toggle-close').forEach(element => element.addEventListener("click", that.toggleCollapse.bind(that)));
+                            }
+                        }, 0);
+                    }
+
+                },
             });
             that.generateClipboardTable();
 
@@ -337,17 +352,6 @@ export class Clipboard extends ScopedElementsMixin(AdapterLitElement) {
             if (this.tabulatorTable !== null) {
                 this.tabulatorTable.clearData();
                 this.tabulatorTable.setData(data);
-
-                const that = this;
-                setTimeout(function(){
-                    if (that._('.tabulator-responsive-collapse-toggle-open')) {
-                        that._a('.tabulator-responsive-collapse-toggle-open').forEach(element => element.addEventListener("click", that.toggleCollapse.bind(that)));
-                    }
-
-                    if (that._('.tabulator-responsive-collapse-toggle-close')) {
-                        that._a('.tabulator-responsive-collapse-toggle-close').forEach(element => element.addEventListener("click", that.toggleCollapse.bind(that)));
-                    }
-                }, 0);
             }
         }
         if (this._("#select_all")) {
diff --git a/packages/file-handling/src/file-source.js b/packages/file-handling/src/file-source.js
index b352500c..c0a8a7ba 100644
--- a/packages/file-handling/src/file-source.js
+++ b/packages/file-handling/src/file-source.js
@@ -118,7 +118,12 @@ export class FileSource extends ScopedElementsMixin(DbpFileHandlingLitElement) {
                     if (this.firstOpen) {
                         this.nextcloudPath = this.initialFileHandlingState.path;
                     }
-                  break;
+                    break;
+                case "activeTarget":
+                    if (this.activeTarget === "nextcloud") {
+                        this.loadWebdavDirectory();
+                    }
+                    break;
             }
         });
         super.update(changedProperties);
diff --git a/packages/file-handling/src/nextcloud-file-picker.js b/packages/file-handling/src/nextcloud-file-picker.js
index b37ab28e..8b149ed8 100644
--- a/packages/file-handling/src/nextcloud-file-picker.js
+++ b/packages/file-handling/src/nextcloud-file-picker.js
@@ -306,7 +306,22 @@ export class NextcloudFilePicker extends ScopedElementsMixin(DBPLitElement) {
                 },
                 rowAdded: (row) => {
                     row.getElement().classList.toggle("addRowAnimation");
-                }
+                },
+                renderComplete: () => {
+                    if (this.tabulatorTable !== null) {
+                        const that = this;
+                        setTimeout(function(){
+                            if (that._('.tabulator-responsive-collapse-toggle-open')) {
+                                that._a('.tabulator-responsive-collapse-toggle-open').forEach(element => element.addEventListener("click", that.toggleCollapse.bind(that)));
+                            }
+
+                            if (that._('.tabulator-responsive-collapse-toggle-close')) {
+                                that._a('.tabulator-responsive-collapse-toggle-close').forEach(element => element.addEventListener("click", that.toggleCollapse.bind(that)));
+                            }
+                        }, 0);
+                    }
+
+                },
             });
 
 
@@ -392,6 +407,10 @@ export class NextcloudFilePicker extends ScopedElementsMixin(DBPLitElement) {
         }
     }
 
+    _a(selector) {
+        return this.shadowRoot === null ? this.querySelectorAll(selector) : this.shadowRoot.querySelectorAll(selector);
+    }
+
     onReceiveWindowMessage(event) {
         if (this.webDavClient === null) {
             const data = event.data;
@@ -413,14 +432,19 @@ export class NextcloudFilePicker extends ScopedElementsMixin(DBPLitElement) {
                 if (this._("#remember-checkbox") && this._("#remember-checkbox").checked) {
                     sessionStorage.setItem('nextcloud-webdav-username', data.loginName);
                     sessionStorage.setItem('nextcloud-webdav-password', data.token);
-                    console.log("saved");
-
                 }
                 this.loadDirectory(this.directoryPath);
             }
         }
     }
 
+    toggleCollapse(e) {
+        const table = this.tabulatorTable;
+        setTimeout(function() {
+            table.redraw();
+        }, 0);
+    }
+
     /**
      * Loads the directory from WebDAV
      *
@@ -479,7 +503,7 @@ export class NextcloudFilePicker extends ScopedElementsMixin(DBPLitElement) {
                     "</d:propfind>"
             })
             .then(contents => {
-                //console.log("------", contents);
+
                 this.loading = false;
                 this.statusText = "";
                 this.tabulatorTable.setData(contents.data);
@@ -490,6 +514,7 @@ export class NextcloudFilePicker extends ScopedElementsMixin(DBPLitElement) {
                 } else {
                     this._("#download-button").removeAttribute("disabled");
                 }
+
             }).catch(error => {
             console.error(error.message);
 
diff --git a/packages/file-handling/src/styles.js b/packages/file-handling/src/styles.js
index 180643c9..70cd49b7 100644
--- a/packages/file-handling/src/styles.js
+++ b/packages/file-handling/src/styles.js
@@ -230,6 +230,7 @@ export function getFileHandlingCss() {
         .tabulator-responsive-collapse-toggle-open, .tabulator-responsive-collapse-toggle-close{
             width: 100%;
             height: 100%;
+            line-height: 37px;
         }
         
         .tabulator-row-handle{
-- 
GitLab