From e95b919c1e3c443f995d92d0d2c65154b0d301c8 Mon Sep 17 00:00:00 2001 From: the-djmaze <> Date: Wed, 4 Jan 2023 16:11:10 +0100 Subject: [PATCH] Resolve #825 --- plugins/nextcloud/index.php | 4 +- plugins/nextcloud/js/message.js | 1 + plugins/nextcloud/js/webdav.js | 87 +++++++++++-------- plugins/nextcloud/style.css | 1 + .../templates/PopupsNextcloudFiles.html | 5 ++ 5 files changed, 59 insertions(+), 39 deletions(-) diff --git a/plugins/nextcloud/index.php b/plugins/nextcloud/index.php index 71f23ab63..e91d91ef1 100644 --- a/plugins/nextcloud/index.php +++ b/plugins/nextcloud/index.php @@ -4,8 +4,8 @@ class NextcloudPlugin extends \RainLoop\Plugins\AbstractPlugin { const NAME = 'Nextcloud', - VERSION = '2.13', - RELEASE = '2022-12-16', + VERSION = '2.14', + RELEASE = '2023-01-04', CATEGORY = 'Integrations', DESCRIPTION = 'Integrate with Nextcloud v20+', REQUIRED = '2.23.0'; diff --git a/plugins/nextcloud/js/message.js b/plugins/nextcloud/js/message.js index 37f2956df..922fa8781 100644 --- a/plugins/nextcloud/js/message.js +++ b/plugins/nextcloud/js/message.js @@ -120,6 +120,7 @@ view.message.subscribe(msg => { view.nextcloudICS(null); if (msg && cfg.CalDAV) { +// let ics = msg.attachments.find(attachment => 'application/ics' == attachment.mimeType); let ics = msg.attachments.find(attachment => 'text/calendar' == attachment.mimeType); if (ics && ics.download) { // fetch it and parse the VEVENT diff --git a/plugins/nextcloud/js/webdav.js b/plugins/nextcloud/js/webdav.js index 9915dd2b8..d5c77da61 100644 --- a/plugins/nextcloud/js/webdav.js +++ b/plugins/nextcloud/js/webdav.js @@ -149,31 +149,14 @@ const items.forEach(item => { if (item.isFile) { let li = document.createElement('li'), - btn = document.createElement('button'); + cb = document.createElement('input'); li.item = item; li.textContent = item.name.replace(/^.*\/([^/]+)$/, '$1'); li.dataset.icon = '🗎'; - btn.name = 'select'; - btn.dataset.icon = '📎'; - btn.textContent = 'attach'; - btn.className = 'button-vue'; - li.append(btn); - - btn = document.createElement('button'); - btn.name = 'share-internal'; - btn.dataset.icon = '🔗'; - btn.textContent = 'internal'; - btn.className = 'button-vue'; - li.append(btn); - - btn = document.createElement('button'); - btn.name = 'share-public'; - btn.dataset.icon = '🔗'; - btn.textContent = 'public'; - btn.className = 'button-vue'; - li.append(btn); + cb.type = 'checkbox'; + li.append(cb); parent.append(li); } @@ -203,28 +186,42 @@ class NextcloudFilesPopupView extends rl.pluginPopupView { }); } - onBuild(dom) { - this.tree = dom.querySelector('#sm-nc-files-tree'); - this.tree.addEventListener('click', event => { - let el = event.target; - if (el.matches('button')) { - let parent = el.parentNode, - item = parent.item; - if ('select' == el.name) { - this.select = this.files() ? [item] : parent.item_name; + attach() { + this.select = []; + this.tree.querySelectorAll('input').forEach(input => + input.checked && this.select.push(input.parentNode.item) + ); + this.close(); + } + + shareInternal() { + this.select = []; + this.tree.querySelectorAll('input').forEach(input => + input.checked && this.select.push({url:generateRemoteUrl(`/f/${input.parentNode.item.id}`)}) + ); + this.close(); + } + + sharePublic() { + const inputs = [...this.tree.querySelectorAll('input')], + loop = () => { + if (!inputs.length) { this.close(); - } else if ('share-internal' == el.name) { - this.select = [{url:generateRemoteUrl(`/f/${item.id}`)}]; - this.close(); - } else if ('share-public' == el.name) { + return; + } + const input = inputs.pop(); + if (!input.checked) { + loop(); + } else { + const item = input.parentNode.item; if (item.shared) { ncFetch( shareUrl() + `?format=json&path=${encodeURIComponent(item.name)}&reshares=true` ) .then(response => (response.status < 400) ? response.json() : Promise.reject(new Error({ response }))) .then(json => { - this.select = [{url:json.ocs.data[0].url}]; - this.close(); + this.select.push({url:json.ocs.data[0].url}); + loop(); // json.data[0].password }); } else { @@ -246,10 +243,26 @@ class NextcloudFilesPopupView extends rl.pluginPopupView { .then(response => (response.status < 400) ? response.json() : Promise.reject(new Error({ response }))) .then(json => { // PUT /ocs/v2.php/apps/files_sharing/api/v1/shares/2 {"password":"ABC09"} - this.select = [{url:json.ocs.data.url}]; - this.close(); + this.select.push({url:json.ocs.data.url}); + loop(); }); } + } + }; + + this.select = []; + loop(); + } + + onBuild(dom) { + this.tree = dom.querySelector('#sm-nc-files-tree'); + this.tree.addEventListener('click', event => { + let el = event.target; + if (el.matches('button')) { + let parent = el.parentNode; + if ('select' == el.name) { + this.select = parent.item_name; + this.close(); } else if ('create' == el.name) { let name = el.input.value.replace(/[|\\?*<":>+[]\/&\s]/g, ''); if (name.length) { diff --git a/plugins/nextcloud/style.css b/plugins/nextcloud/style.css index e99ac0767..4dd142992 100644 --- a/plugins/nextcloud/style.css +++ b/plugins/nextcloud/style.css @@ -5,6 +5,7 @@ clear: right; line-height: 2.5em; } +#V-PopupsNextcloudFiles li input, #V-PopupsNextcloudFiles li button { cursor: pointer; float: right; diff --git a/plugins/nextcloud/templates/PopupsNextcloudFiles.html b/plugins/nextcloud/templates/PopupsNextcloudFiles.html index f63656034..1be321dae 100644 --- a/plugins/nextcloud/templates/PopupsNextcloudFiles.html +++ b/plugins/nextcloud/templates/PopupsNextcloudFiles.html @@ -11,3 +11,8 @@ -->