PersonalSettings.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. <!--
  2. SPDX-FileLicenseText: 2022 Carl Schwan <carl@carlschwan.eu>
  3. SPDX-License-Identifier: AGPL-3.0-or-later
  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU Affero General Public License as
  6. published by the Free Software Foundation, either version 3 of the
  7. License, or (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU Affero General Public License for more details.
  12. You should have received a copy of the GNU Affero General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. -->
  15. <template>
  16. <NcSettingsSection :name="t('federatedfilesharing', 'Federated Cloud')"
  17. :description="t('federatedfilesharing', 'You can share with anyone who uses a Nextcloud server or other Open Cloud Mesh (OCM) compatible servers and services! Just put their Federated Cloud ID in the share dialog. It looks like person@cloud.example.com')"
  18. :doc-url="docUrlFederated">
  19. <p class="cloud-id-text">
  20. {{ t('federatedfilesharing', 'Your Federated Cloud ID:') }}
  21. <strong id="cloudid">{{ cloudId }}</strong>
  22. <NcButton ref="clipboard"
  23. :title="copyLinkTooltip"
  24. :aria-label="copyLinkTooltip"
  25. class="clipboard"
  26. type="tertiary-no-background"
  27. @click.prevent="copyCloudId">
  28. <template #icon>
  29. <Clipboard :size="20" />
  30. </template>
  31. </NcButton>
  32. </p>
  33. <p class="social-button">
  34. {{ t('federatedfilesharing', 'Share it so your friends can share files with you:') }}<br>
  35. <NcButton @click="goTo(shareFacebookUrl)">
  36. {{ t('federatedfilesharing', 'Facebook') }}
  37. <template #icon>
  38. <Facebook :size="20" />
  39. </template>
  40. </NcButton>
  41. <NcButton @click="goTo(shareTwitterUrl)">
  42. {{ t('federatedfilesharing', 'Twitter') }}
  43. <template #icon>
  44. <Twitter :size="20" />
  45. </template>
  46. </NcButton>
  47. <NcButton @click="goTo(shareDiasporaUrl)">
  48. {{ t('federatedfilesharing', 'Diaspora') }}
  49. <template #icon>
  50. <svg width="20"
  51. height="20"
  52. viewBox="-10 -5 1034 1034"
  53. xmlns="http://www.w3.org/2000/svg"><path fill="currentColor" d="M502 197q-96 0-96.5 1.5t-1.5 137-1.5 138-2 2.5T266 432.5 132.5 390t-30 94T74 578l232 77q21 8 21 10t-79.5 117.5T168 899t79.5 56.5T328 1011t81-110 82-110 41 55l83 115q43 60 44 60t79.5-58 79-59-76-112.5-76-113.5T795 632.5t129.5-44-28-94T867 400t-128 42-128.5 43-2.5-7.5-1-38.5l-3-108q-4-133-5-133.5t-97-.5z" /></svg>
  54. </template>
  55. </NcButton>
  56. <NcButton @click="showHtml = !showHtml">
  57. <template #icon>
  58. <Web :size="20" />
  59. </template>
  60. {{ t('federatedfilesharing', 'Add to your website') }}
  61. </NcButton>
  62. </p>
  63. <template v-if="showHtml">
  64. <p style="margin: 10px 0">
  65. <a target="_blank"
  66. rel="noreferrer noopener"
  67. :href="reference"
  68. :style="backgroundStyle">
  69. <span :style="linkStyle" />
  70. {{ t('federatedfilesharing', 'Share with me via Nextcloud') }}
  71. </a>
  72. </p>
  73. <p>
  74. {{ t('federatedfilesharing', 'HTML Code:') }}
  75. <br>
  76. <pre>{{ htmlCode }}</pre>
  77. </p>
  78. </template>
  79. </NcSettingsSection>
  80. </template>
  81. <script>
  82. import { showError, showSuccess } from '@nextcloud/dialogs'
  83. import { loadState } from '@nextcloud/initial-state'
  84. import NcSettingsSection from '@nextcloud/vue/dist/Components/NcSettingsSection.js'
  85. import NcButton from '@nextcloud/vue/dist/Components/NcButton.js'
  86. import Twitter from 'vue-material-design-icons/Twitter.vue'
  87. import Facebook from 'vue-material-design-icons/Facebook.vue'
  88. import Web from 'vue-material-design-icons/Web.vue'
  89. import Clipboard from 'vue-material-design-icons/Clipboard.vue'
  90. export default {
  91. name: 'PersonalSettings',
  92. components: {
  93. NcButton,
  94. NcSettingsSection,
  95. Twitter,
  96. Facebook,
  97. Web,
  98. Clipboard,
  99. },
  100. data() {
  101. return {
  102. color: loadState('federatedfilesharing', 'color'),
  103. textColor: loadState('federatedfilesharing', 'textColor'),
  104. logoPath: loadState('federatedfilesharing', 'logoPath'),
  105. reference: loadState('federatedfilesharing', 'reference'),
  106. cloudId: loadState('federatedfilesharing', 'cloudId'),
  107. docUrlFederated: loadState('federatedfilesharing', 'docUrlFederated'),
  108. showHtml: false,
  109. isCopied: false,
  110. }
  111. },
  112. computed: {
  113. messageWithURL() {
  114. return t('federatedfilesharing', 'Share with me through my #Nextcloud Federated Cloud ID, see {url}', { url: this.reference })
  115. },
  116. messageWithoutURL() {
  117. return t('federatedfilesharing', 'Share with me through my #Nextcloud Federated Cloud ID')
  118. },
  119. shareDiasporaUrl() {
  120. return `https://share.diasporafoundation.org/?title=${encodeURIComponent(this.messageWithoutURL)}&url=${encodeURIComponent(this.reference)}`
  121. },
  122. shareTwitterUrl() {
  123. return `https://twitter.com/intent/tweet?text=${encodeURIComponent(this.messageWithURL)}`
  124. },
  125. shareFacebookUrl() {
  126. return `https://www.facebook.com/sharer/sharer.php?u=${encodeURIComponent(this.reference)}`
  127. },
  128. logoPathAbsolute() {
  129. return window.location.protocol + '//' + window.location.host + this.logoPath
  130. },
  131. backgroundStyle() {
  132. return `padding:10px;background-color:${this.color};color:${this.textColor};border-radius:3px;padding-left:4px;`
  133. },
  134. linkStyle() {
  135. return `background-image:url(${this.logoPathAbsolute});width:50px;height:30px;position:relative;top:8px;background-size:contain;display:inline-block;background-repeat:no-repeat; background-position: center center;`
  136. },
  137. htmlCode() {
  138. return `<a target="_blank" rel="noreferrer noopener" href="${this.reference}" style="${this.backgroundStyle}">
  139. <span style="${this.linkStyle}"></span>
  140. ${t('federatedfilesharing', 'Share with me via Nextcloud')}
  141. </a>`
  142. },
  143. copyLinkTooltip() {
  144. return this.isCopied ? t('federatedfilesharing', 'Cloud ID copied to the clipboard') : t('federatedfilesharing', 'Copy to clipboard')
  145. },
  146. },
  147. methods: {
  148. async copyCloudId() {
  149. if (!navigator.clipboard) {
  150. // Clipboard API not available
  151. showError(t('federatedfilesharing', 'Clipboard is not available'))
  152. return
  153. }
  154. await navigator.clipboard.writeText(this.cloudId)
  155. this.isCopied = true
  156. showSuccess(t('federatedfilesharing', 'Copied!'))
  157. this.$refs.clipboard.$el.focus()
  158. },
  159. goTo(url) {
  160. window.location.href = url
  161. },
  162. },
  163. }
  164. </script>
  165. <style lang="scss" scoped>
  166. .social-button {
  167. margin-top: 0.5rem;
  168. button {
  169. display: inline-flex;
  170. margin-left: 0.5rem;
  171. margin-top: 1rem;
  172. }
  173. }
  174. .cloud-id-text {
  175. display: flex;
  176. align-items: center;
  177. button {
  178. display: inline-flex;
  179. }
  180. }
  181. pre {
  182. margin-top: 0;
  183. white-space: pre-wrap;
  184. }
  185. #cloudid {
  186. margin-left: 0.25rem;
  187. }
  188. </style>