SharingInherited.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <!--
  2. - @copyright Copyright (c) 2019 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. <ul id="sharing-inherited-shares">
  24. <!-- Main collapsible entry -->
  25. <SharingEntrySimple
  26. class="sharing-entry__inherited"
  27. :title="mainTitle">
  28. <template #avatar>
  29. <div class="avatar-shared icon-more-white" />
  30. </template>
  31. <ActionButton :icon="showInheritedSharesIcon" @click.prevent.stop="toggleInheritedShares">
  32. {{ toggleTooltip }}
  33. </ActionButton>
  34. </SharingEntrySimple>
  35. <!-- Inherited shares list -->
  36. <SharingEntryInherited v-for="share in shares"
  37. :key="share.id"
  38. :share="share" />
  39. </ul>
  40. </template>
  41. <script>
  42. import { generateOcsUrl } from '@nextcloud/router'
  43. import ActionButton from 'nextcloud-vue/dist/Components/ActionButton'
  44. import axios from '@nextcloud/axios'
  45. import Share from '../models/Share'
  46. import SharingEntryInherited from '../components/SharingEntryInherited'
  47. import SharingEntrySimple from '../components/SharingEntrySimple'
  48. export default {
  49. name: 'SharingInherited',
  50. components: {
  51. ActionButton,
  52. SharingEntryInherited,
  53. SharingEntrySimple,
  54. },
  55. props: {
  56. fileInfo: {
  57. type: Object,
  58. default: () => {},
  59. required: true,
  60. },
  61. },
  62. data() {
  63. return {
  64. loaded: false,
  65. loading: false,
  66. showInheritedShares: false,
  67. shares: [],
  68. }
  69. },
  70. computed: {
  71. showInheritedSharesIcon() {
  72. if (this.loading) {
  73. return 'icon-loading-small'
  74. }
  75. if (this.showInheritedShares) {
  76. return 'icon-triangle-n'
  77. }
  78. return 'icon-triangle-s'
  79. },
  80. mainTitle() {
  81. return t('files_sharing', 'Others with access')
  82. },
  83. toggleTooltip() {
  84. return this.fileInfo.type === 'dir'
  85. ? t('files_sharing', 'Toggle list of others with access to this directory')
  86. : t('files_sharing', 'Toggle list of others with access to this file')
  87. },
  88. fullPath() {
  89. const path = `${this.fileInfo.path}/${this.fileInfo.name}`
  90. return path.replace('//', '/')
  91. },
  92. },
  93. watch: {
  94. fileInfo() {
  95. this.resetState()
  96. },
  97. },
  98. methods: {
  99. /**
  100. * Toggle the list view and fetch/reset the state
  101. */
  102. toggleInheritedShares() {
  103. this.showInheritedShares = !this.showInheritedShares
  104. if (this.showInheritedShares) {
  105. this.fetchInheritedShares()
  106. } else {
  107. this.resetState()
  108. }
  109. },
  110. /**
  111. * Fetch the Inherited Shares array
  112. */
  113. async fetchInheritedShares() {
  114. this.loading = true
  115. try {
  116. const url = generateOcsUrl(`apps/files_sharing/api/v1/shares/inherited?format=json&path=${this.fullPath}`, 2)
  117. const shares = await axios.get(url.replace(/\/$/, ''))
  118. this.shares = shares.data.ocs.data
  119. .map(share => new Share(share))
  120. .sort((a, b) => b.createdTime - a.createdTime)
  121. console.info(this.shares)
  122. this.loaded = true
  123. } catch (error) {
  124. OC.Notification.showTemporary(t('files_sharing', 'Unable to fetch inherited shares'), { type: 'error' })
  125. } finally {
  126. this.loading = false
  127. }
  128. },
  129. /**
  130. * Reset current component state
  131. */
  132. resetState() {
  133. this.loaded = false
  134. this.loading = false
  135. this.showInheritedShares = false
  136. this.shares = []
  137. },
  138. },
  139. }
  140. </script>
  141. <style lang="scss" scoped>
  142. .sharing-entry__inherited {
  143. .avatar-shared {
  144. width: 32px;
  145. height: 32px;
  146. line-height: 32px;
  147. font-size: 18px;
  148. background-color: var(--color-text-maxcontrast);
  149. border-radius: 50%;
  150. flex-shrink: 0;
  151. }
  152. }
  153. </style>