Skip to content

Commit a254b72

Browse files
committed
feat(files): Add clipboard copy to webdav url in files settings
Signed-off-by: John Molakvoæ <skjnldsv@protonmail.com>
1 parent e20df01 commit a254b72

5 files changed

Lines changed: 42 additions & 9 deletions

File tree

apps/files/src/views/Settings.vue

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,19 @@
4747

4848
<!-- Webdav URL-->
4949
<NcAppSettingsSection id="webdav" :title="t('files', 'Webdav')">
50-
<NcInputField type="text" readonly="readonly" :value="webdavUrl" />
50+
<NcInputField id="webdav-url-input"
51+
:show-trailing-button="true"
52+
:success="webdavUrlCopied"
53+
:trailing-button-label="t('files', 'Copy to clipboard')"
54+
:value="webdavUrl"
55+
readonly="readonly"
56+
type="url"
57+
@focus="$event.target.select()"
58+
@trailing-button-click="copyCloudId">
59+
<template #trailing-button-icon>
60+
<Clipboard :size="20" />
61+
</template>
62+
</NcInputField>
5163
<em>
5264
<a :href="webdavDocs" target="_blank" rel="noreferrer noopener">
5365
{{ t('files', 'Use this address to access your Files via WebDAV') }} ↗
@@ -61,15 +73,17 @@
6173
import NcAppSettingsDialog from '@nextcloud/vue/dist/Components/NcAppSettingsDialog.js'
6274
import NcAppSettingsSection from '@nextcloud/vue/dist/Components/NcAppSettingsSection.js'
6375
import NcCheckboxRadioSwitch from '@nextcloud/vue/dist/Components/NcCheckboxRadioSwitch.js'
76+
import Clipboard from 'vue-material-design-icons/Clipboard.vue'
6477
import NcInputField from '@nextcloud/vue/dist/Components/NcInputField'
6578
import Setting from '../components/Setting.vue'
6679
80+
import { emit } from '@nextcloud/event-bus'
6781
import { generateRemoteUrl, generateUrl } from '@nextcloud/router'
6882
import { getCurrentUser } from '@nextcloud/auth'
6983
import { loadState } from '@nextcloud/initial-state'
70-
import { emit } from '@nextcloud/event-bus'
71-
import axios from '@nextcloud/axios'
84+
import { showError, showSuccess } from '@nextcloud/dialogs'
7285
import { translate } from '@nextcloud/l10n'
86+
import axios from '@nextcloud/axios'
7387
7488
const userConfig = loadState('files', 'config', {
7589
show_hidden: false,
@@ -79,6 +93,7 @@ const userConfig = loadState('files', 'config', {
7993
export default {
8094
name: 'Settings',
8195
components: {
96+
Clipboard,
8297
NcAppSettingsDialog,
8398
NcAppSettingsSection,
8499
NcCheckboxRadioSwitch,
@@ -104,6 +119,7 @@ export default {
104119
// Webdav infos
105120
webdavUrl: generateRemoteUrl('dav/files/' + encodeURIComponent(getCurrentUser()?.uid)),
106121
webdavDocs: 'https://docs.nextcloud.com/server/stable/go.php?to=user-webdav',
122+
webdavUrlCopied: false,
107123
}
108124
},
109125
@@ -129,6 +145,23 @@ export default {
129145
})
130146
},
131147
148+
async copyCloudId() {
149+
document.querySelector('input#webdav-url-input').select()
150+
151+
if (!navigator.clipboard) {
152+
// Clipboard API not available
153+
showError(t('files', 'Clipboard is not available'))
154+
return
155+
}
156+
157+
await navigator.clipboard.writeText(this.webdavUrl)
158+
this.webdavUrlCopied = true
159+
showSuccess(t('files', 'Webdav URL copied to clipboard'))
160+
setTimeout(() => {
161+
this.webdavUrlCopied = false
162+
}, 5000)
163+
},
164+
132165
t: translate,
133166
},
134167
}

dist/files-main.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/files-main.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/files-sidebar.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/files-sidebar.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)