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.

FileEntry.vue 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <!--
  2. - @copyright Copyright (c) 2019 Gary Kim <gary@garykim.dev>
  3. -
  4. - @author Gary Kim <gary@garykim.dev>
  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. <Fragment>
  24. <td class="files-list__row-checkbox">
  25. <NcCheckboxRadioSwitch :aria-label="t('files', 'Select the row for {displayName}', { displayName })"
  26. :checked.sync="selectedFiles"
  27. :value="fileid.toString()"
  28. name="selectedFiles" />
  29. </td>
  30. <!-- Icon or preview -->
  31. <td class="files-list__row-icon">
  32. <FolderIcon v-if="source.type === 'folder'" />
  33. </td>
  34. <!-- Link to file and -->
  35. <td class="files-list__row-name">
  36. <a v-bind="linkTo">
  37. {{ displayName }}
  38. </a>
  39. </td>
  40. </Fragment>
  41. </template>
  42. <script lang="ts">
  43. import { Folder, File } from '@nextcloud/files'
  44. import { Fragment } from 'vue-fragment'
  45. import { join } from 'path'
  46. import { translate } from '@nextcloud/l10n'
  47. import NcCheckboxRadioSwitch from '@nextcloud/vue/dist/Components/NcCheckboxRadioSwitch.js'
  48. import FolderIcon from 'vue-material-design-icons/Folder.vue'
  49. import logger from '../logger'
  50. export default {
  51. name: 'FileEntry',
  52. components: {
  53. FolderIcon,
  54. Fragment,
  55. NcCheckboxRadioSwitch,
  56. },
  57. props: {
  58. index: {
  59. type: Number,
  60. required: true,
  61. },
  62. source: {
  63. type: [File, Folder],
  64. required: true,
  65. },
  66. },
  67. computed: {
  68. dir() {
  69. // Remove any trailing slash but leave root slash
  70. return (this.$route?.query?.dir || '/').replace(/^(.+)\/$/, '$1')
  71. },
  72. fileid() {
  73. return this.source.attributes.fileid
  74. },
  75. displayName() {
  76. return this.source.attributes.displayName
  77. || this.source.basename
  78. },
  79. linkTo() {
  80. if (this.source.type === 'folder') {
  81. const to = { ...this.$route, query: { dir: join(this.dir, this.source.basename) } }
  82. return {
  83. is: 'router-link',
  84. title: this.t('files', 'Open folder {name}', { name: this.displayName }),
  85. to,
  86. }
  87. }
  88. return {
  89. href: this.source.source,
  90. // TODO: Use first action title ?
  91. title: this.t('files', 'Download file {name}', { name: this.displayName }),
  92. }
  93. },
  94. selectedFiles: {
  95. get() {
  96. return this.$store.state.selection.selected
  97. },
  98. set(selection) {
  99. logger.debug('Added node to selection', { selection })
  100. this.$store.dispatch('selection/set', selection)
  101. },
  102. },
  103. },
  104. methods: {
  105. /**
  106. * Get a cached note from the store
  107. *
  108. * @param {number} fileId the file id to get
  109. * @return {Folder|File}
  110. */
  111. getNode(fileId) {
  112. return this.$store.getters['files/getNode'](fileId)
  113. },
  114. t: translate,
  115. },
  116. }
  117. </script>
  118. <style scoped lang="scss">
  119. @import '../mixins/fileslist-row.scss'
  120. </style>