SharingEntryInternal.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <template>
  2. <SharingEntrySimple
  3. class="sharing-entry__internal"
  4. :title="t('files_sharing', 'Internal link')"
  5. :subtitle="internalLinkSubtitle">
  6. <template #avatar>
  7. <div class="avatar-external icon-external-white" />
  8. </template>
  9. <ActionLink ref="copyButton"
  10. :href="internalLink"
  11. target="_blank"
  12. :icon="copied && copySuccess ? 'icon-checkmark-color' : 'icon-clippy'"
  13. @click.prevent="copyLink">
  14. {{ clipboardTooltip }}
  15. </ActionLink>
  16. </SharingEntrySimple>
  17. </template>
  18. <script>
  19. import { generateUrl } from '@nextcloud/router'
  20. import ActionLink from 'nextcloud-vue/dist/Components/ActionLink'
  21. import SharingEntrySimple from './SharingEntrySimple'
  22. export default {
  23. name: 'SharingEntryInternal',
  24. components: {
  25. ActionLink,
  26. SharingEntrySimple
  27. },
  28. props: {
  29. fileInfo: {
  30. type: Object,
  31. default: () => {},
  32. required: true
  33. }
  34. },
  35. data() {
  36. return {
  37. copied: false,
  38. copySuccess: false
  39. }
  40. },
  41. computed: {
  42. /**
  43. * Get the internal link to this file id
  44. * @returns {string}
  45. */
  46. internalLink() {
  47. return window.location.protocol + '//' + window.location.host + generateUrl('/f/') + this.fileInfo.id
  48. },
  49. /**
  50. * Clipboard v-tooltip message
  51. * @returns {string}
  52. */
  53. clipboardTooltip() {
  54. if (this.copied) {
  55. return this.copySuccess
  56. ? t('files_sharing', 'Link copied')
  57. : t('files_sharing', 'Cannot copy, please copy the link manually')
  58. }
  59. return t('files_sharing', 'Copy to clipboard')
  60. },
  61. internalLinkSubtitle() {
  62. if (this.fileInfo.type === 'dir') {
  63. return t('files_sharing', 'Only works for users with access to this folder')
  64. }
  65. return t('files_sharing', 'Only works for users with access to this file')
  66. }
  67. },
  68. methods: {
  69. async copyLink() {
  70. try {
  71. await this.$copyText(this.internalLink)
  72. // focus and show the tooltip
  73. this.$refs.copyButton.$el.focus()
  74. this.copySuccess = true
  75. this.copied = true
  76. } catch (error) {
  77. this.copySuccess = false
  78. this.copied = true
  79. console.error(error)
  80. } finally {
  81. setTimeout(() => {
  82. this.copySuccess = false
  83. this.copied = false
  84. }, 4000)
  85. }
  86. }
  87. }
  88. }
  89. </script>
  90. <style lang="scss" scoped>
  91. .sharing-entry__internal {
  92. .avatar-external {
  93. width: 32px;
  94. height: 32px;
  95. line-height: 32px;
  96. font-size: 18px;
  97. background-color: var(--color-text-maxcontrast);
  98. border-radius: 50%;
  99. flex-shrink: 0;
  100. }
  101. .icon-checkmark-color {
  102. opacity: 1;
  103. }
  104. }
  105. </style>