Skip to content

Commit

Permalink
feat(files): Add clipboard copy to webdav url in files settings
Browse files Browse the repository at this point in the history
Signed-off-by: John Molakvoæ <[email protected]>
  • Loading branch information
skjnldsv committed Jan 4, 2023
1 parent 42ce36f commit c172ef3
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 6 deletions.
39 changes: 36 additions & 3 deletions apps/files/src/views/Settings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,19 @@

<!-- Webdav URL-->
<NcAppSettingsSection id="webdav" :title="t('files', 'Webdav')">
<NcInputField type="text" readonly="readonly" :value="webdavUrl" />
<NcInputField id="webdav-url-input"
:show-trailing-button="true"
:success="webdavUrlCopied"
:trailing-button-label="t('files', 'Copy to clipboard')"
:value="webdavUrl"
readonly="readonly"
type="url"
@focus="$event.target.select()"
@trailing-button-click="copyCloudId">
<template #trailing-button-icon>
<Clipboard :size="20" />
</template>
</NcInputField>
<em>
<a :href="webdavDocs" target="_blank" rel="noreferrer noopener">
{{ t('files', 'Use this address to access your Files via WebDAV') }} ↗
Expand All @@ -61,15 +73,17 @@
import NcAppSettingsDialog from '@nextcloud/vue/dist/Components/NcAppSettingsDialog.js'
import NcAppSettingsSection from '@nextcloud/vue/dist/Components/NcAppSettingsSection.js'
import NcCheckboxRadioSwitch from '@nextcloud/vue/dist/Components/NcCheckboxRadioSwitch.js'
import Clipboard from 'vue-material-design-icons/Clipboard.vue'
import NcInputField from '@nextcloud/vue/dist/Components/NcInputField'
import Setting from '../components/Setting.vue'
import { emit } from '@nextcloud/event-bus'
import { generateRemoteUrl, generateUrl } from '@nextcloud/router'
import { getCurrentUser } from '@nextcloud/auth'
import { loadState } from '@nextcloud/initial-state'
import { emit } from '@nextcloud/event-bus'
import axios from '@nextcloud/axios'
import { showError, showSuccess } from '@nextcloud/dialogs'
import { translate } from '@nextcloud/l10n'
import axios from '@nextcloud/axios'
const userConfig = loadState('files', 'config', {
show_hidden: false,
Expand All @@ -79,6 +93,7 @@ const userConfig = loadState('files', 'config', {
export default {
name: 'Settings',
components: {
Clipboard,
NcAppSettingsDialog,
NcAppSettingsSection,
NcCheckboxRadioSwitch,
Expand All @@ -104,6 +119,7 @@ export default {
// Webdav infos
webdavUrl: generateRemoteUrl('dav/files/' + encodeURIComponent(getCurrentUser()?.uid)),
webdavDocs: 'https://docs.nextcloud.com/server/stable/go.php?to=user-webdav',
webdavUrlCopied: false,
}
},
Expand All @@ -129,6 +145,23 @@ export default {
})
},
async copyCloudId() {
document.querySelector('input#webdav-url-input').select()
if (!navigator.clipboard) {
// Clipboard API not available
showError(t('files', 'Clipboard is not available'))
return
}
await navigator.clipboard.writeText(this.webdavUrl)
this.webdavUrlCopied = true
showSuccess(t('files', 'Webdav URL copied to clipboard'))
setTimeout(() => {
this.webdavUrlCopied = false
}, 5000)
},
t: translate,
},
}
Expand Down
4 changes: 2 additions & 2 deletions dist/files-main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/files-main.js.map

Large diffs are not rendered by default.

0 comments on commit c172ef3

Please sign in to comment.