You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SharingEntryInternal.vue 2.6KB

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