Settings.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. <!--
  2. - @copyright Copyright (c) 2023 John Molakvoæ <skjnldsv@protonmail.com>
  3. -
  4. - @author John Molakvoæ <skjnldsv@protonmail.com>
  5. -
  6. - @license GNU AGPL version 3 or any later version
  7. -
  8. - This program is free software: you can redistribute it and/or modify
  9. - it under the terms of the GNU Affero General Public License as
  10. - published by the Free Software Foundation, either version 3 of the
  11. - License, or (at your option) any later version.
  12. -
  13. - This program is distributed in the hope that it will be useful,
  14. - but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. - GNU Affero General Public License for more details.
  17. -
  18. - You should have received a copy of the GNU Affero General Public License
  19. - along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. -
  21. -->
  22. <template>
  23. <NcAppSettingsDialog :open="open"
  24. :show-navigation="true"
  25. :name="t('files', 'Files settings')"
  26. @update:open="onClose">
  27. <!-- Settings API-->
  28. <NcAppSettingsSection id="settings" :name="t('files', 'Files settings')">
  29. <NcCheckboxRadioSwitch :checked="userConfig.sort_favorites_first"
  30. @update:checked="setConfig('sort_favorites_first', $event)">
  31. {{ t('files', 'Sort favorites first') }}
  32. </NcCheckboxRadioSwitch>
  33. <NcCheckboxRadioSwitch :checked="userConfig.show_hidden"
  34. @update:checked="setConfig('show_hidden', $event)">
  35. {{ t('files', 'Show hidden files') }}
  36. </NcCheckboxRadioSwitch>
  37. <NcCheckboxRadioSwitch :checked="userConfig.crop_image_previews"
  38. @update:checked="setConfig('crop_image_previews', $event)">
  39. {{ t('files', 'Crop image previews') }}
  40. </NcCheckboxRadioSwitch>
  41. </NcAppSettingsSection>
  42. <!-- Settings API-->
  43. <NcAppSettingsSection v-if="settings.length !== 0"
  44. id="more-settings"
  45. :name="t('files', 'Additional settings')">
  46. <template v-for="setting in settings">
  47. <Setting :key="setting.name" :el="setting.el" />
  48. </template>
  49. </NcAppSettingsSection>
  50. <!-- Webdav URL-->
  51. <NcAppSettingsSection id="webdav" :name="t('files', 'WebDAV')">
  52. <NcInputField id="webdav-url-input"
  53. :show-trailing-button="true"
  54. :success="webdavUrlCopied"
  55. :trailing-button-label="t('files', 'Copy to clipboard')"
  56. :value="webdavUrl"
  57. readonly="readonly"
  58. type="url"
  59. @focus="$event.target.select()"
  60. @trailing-button-click="copyCloudId">
  61. <template #trailing-button-icon>
  62. <Clipboard :size="20" />
  63. </template>
  64. </NcInputField>
  65. <em>
  66. <a class="setting-link"
  67. :href="webdavDocs"
  68. target="_blank"
  69. rel="noreferrer noopener">
  70. {{ t('files', 'Use this address to access your Files via WebDAV') }} ↗
  71. </a>
  72. </em>
  73. <br>
  74. <em>
  75. <a class="setting-link" :href="appPasswordUrl">
  76. {{ t('files', 'If you have enabled 2FA, you must create and use a new app password by clicking here.') }} ↗
  77. </a>
  78. </em>
  79. </NcAppSettingsSection>
  80. </NcAppSettingsDialog>
  81. </template>
  82. <script>
  83. import NcAppSettingsDialog from '@nextcloud/vue/dist/Components/NcAppSettingsDialog.js'
  84. import NcAppSettingsSection from '@nextcloud/vue/dist/Components/NcAppSettingsSection.js'
  85. import NcCheckboxRadioSwitch from '@nextcloud/vue/dist/Components/NcCheckboxRadioSwitch.js'
  86. import Clipboard from 'vue-material-design-icons/Clipboard.vue'
  87. import NcInputField from '@nextcloud/vue/dist/Components/NcInputField.js'
  88. import Setting from '../components/Setting.vue'
  89. import { generateRemoteUrl, generateUrl } from '@nextcloud/router'
  90. import { getCurrentUser } from '@nextcloud/auth'
  91. import { showError, showSuccess } from '@nextcloud/dialogs'
  92. import { translate } from '@nextcloud/l10n'
  93. import { useUserConfigStore } from '../store/userconfig.ts'
  94. export default {
  95. name: 'Settings',
  96. components: {
  97. Clipboard,
  98. NcAppSettingsDialog,
  99. NcAppSettingsSection,
  100. NcCheckboxRadioSwitch,
  101. NcInputField,
  102. Setting,
  103. },
  104. props: {
  105. open: {
  106. type: Boolean,
  107. default: false,
  108. },
  109. },
  110. setup() {
  111. const userConfigStore = useUserConfigStore()
  112. return {
  113. userConfigStore,
  114. }
  115. },
  116. data() {
  117. return {
  118. // Settings API
  119. settings: window.OCA?.Files?.Settings?.settings || [],
  120. // Webdav infos
  121. webdavUrl: generateRemoteUrl('dav/files/' + encodeURIComponent(getCurrentUser()?.uid)),
  122. webdavDocs: 'https://docs.nextcloud.com/server/stable/go.php?to=user-webdav',
  123. appPasswordUrl: generateUrl('/settings/user/security#generate-app-token-section'),
  124. webdavUrlCopied: false,
  125. }
  126. },
  127. computed: {
  128. userConfig() {
  129. return this.userConfigStore.userConfig
  130. },
  131. },
  132. beforeMount() {
  133. // Update the settings API entries state
  134. this.settings.forEach(setting => setting.open())
  135. },
  136. beforeDestroy() {
  137. // Update the settings API entries state
  138. this.settings.forEach(setting => setting.close())
  139. },
  140. methods: {
  141. onClose() {
  142. this.$emit('close')
  143. },
  144. setConfig(key, value) {
  145. this.userConfigStore.update(key, value)
  146. },
  147. async copyCloudId() {
  148. document.querySelector('input#webdav-url-input').select()
  149. if (!navigator.clipboard) {
  150. // Clipboard API not available
  151. showError(t('files', 'Clipboard is not available'))
  152. return
  153. }
  154. await navigator.clipboard.writeText(this.webdavUrl)
  155. this.webdavUrlCopied = true
  156. showSuccess(t('files', 'WebDAV URL copied to clipboard'))
  157. setTimeout(() => {
  158. this.webdavUrlCopied = false
  159. }, 5000)
  160. },
  161. t: translate,
  162. },
  163. }
  164. </script>
  165. <style lang="scss" scoped>
  166. .setting-link:hover {
  167. text-decoration: underline;
  168. }
  169. </style>