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.

FilesListHeader.vue 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. <tr>
  24. <th class="files-list__row-checkbox">
  25. <NcCheckboxRadioSwitch v-bind="selectAllBind" @update:checked="onToggleAll" />
  26. </th>
  27. <!-- Icon or preview -->
  28. <th class="files-list__row-icon" />
  29. <!-- Link to file and -->
  30. <th class="files-list__row-name">
  31. {{ t('files', 'Name') }}
  32. </th>
  33. </tr>
  34. </template>
  35. <script lang="ts">
  36. import { translate } from '@nextcloud/l10n'
  37. import NcCheckboxRadioSwitch from '@nextcloud/vue/dist/Components/NcCheckboxRadioSwitch.js'
  38. import logger from '../logger'
  39. import { File, Folder } from '@nextcloud/files'
  40. export default {
  41. name: 'FilesListHeader',
  42. components: {
  43. NcCheckboxRadioSwitch,
  44. },
  45. props: {
  46. nodes: {
  47. type: [File, Folder],
  48. required: true,
  49. },
  50. },
  51. computed: {
  52. dir() {
  53. // Remove any trailing slash but leave root slash
  54. return (this.$route?.query?.dir || '/').replace(/^(.+)\/$/, '$1')
  55. },
  56. selectAllBind() {
  57. return {
  58. ariaLabel: this.isNoneSelected || this.isSomeSelected
  59. ? this.t('files', 'Select all')
  60. : this.t('files', 'Unselect all'),
  61. checked: this.isAllSelected,
  62. indeterminate: this.isSomeSelected,
  63. }
  64. },
  65. isAllSelected() {
  66. return this.selectedFiles.length === this.nodes.length
  67. },
  68. isNoneSelected() {
  69. return this.selectedFiles.length === 0
  70. },
  71. isSomeSelected() {
  72. return !this.isAllSelected && !this.isNoneSelected
  73. },
  74. selectedFiles() {
  75. return this.$store.state.selection.selected
  76. },
  77. },
  78. methods: {
  79. /**
  80. * Get a cached note from the store
  81. *
  82. * @param {number} fileId the file id to get
  83. * @return {Folder|File}
  84. */
  85. getNode(fileId) {
  86. return this.$store.getters['files/getNode'](fileId)
  87. },
  88. onToggleAll(selected) {
  89. if (selected) {
  90. const selection = this.nodes.map(node => node.attributes.fileid.toString())
  91. logger.debug('Added all nodes to selection', { selection })
  92. this.$store.dispatch('selection/set', selection)
  93. } else {
  94. logger.debug('Cleared selection')
  95. this.$store.dispatch('selection/reset')
  96. }
  97. },
  98. t: translate,
  99. },
  100. }
  101. </script>
  102. <style scoped lang="scss">
  103. @import '../mixins/fileslist-row.scss'
  104. </style>