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.

143 lines
3.6 KiB

2 years ago
3 years ago
3 years ago
2 years ago
2 years ago
3 years ago
2 years ago
  1. <template>
  2. <v-data-table
  3. :value="value"
  4. :headers="headers"
  5. :items="items"
  6. :options.sync="options"
  7. :server-items-length="total"
  8. :search="search"
  9. :loading="isLoading"
  10. :loading-text="$t('generic.loading')"
  11. :no-data-text="$t('vuetify.noDataAvailable')"
  12. :footer-props="{
  13. showFirstLastPage: true,
  14. 'items-per-page-options': [10, 50, 100],
  15. 'items-per-page-text': $t('vuetify.itemsPerPageText'),
  16. 'page-text': $t('dataset.pageText')
  17. }"
  18. item-key="id"
  19. show-select
  20. @input="$emit('input', $event)"
  21. >
  22. <template #top>
  23. <v-text-field
  24. v-model="search"
  25. :prepend-inner-icon="mdiMagnify"
  26. :label="$t('generic.search')"
  27. single-line
  28. hide-details
  29. filled
  30. />
  31. </template>
  32. <template #[`item.name`]="{ item }">
  33. <nuxt-link :to="localePath(`/projects/${item.id}`)">
  34. <span>{{ item.name }}</span>
  35. </nuxt-link>
  36. </template>
  37. <template #[`item.createdAt`]="{ item }">
  38. <span>{{
  39. dateFormat(dateParse(item.createdAt, 'YYYY-MM-DDTHH:mm:ss'), 'YYYY/MM/DD HH:mm')
  40. }}</span>
  41. </template>
  42. <template #[`item.tags`]="{ item }">
  43. <v-chip v-for="tag in item.tags" :key="tag.id" outlined v-text="tag.text" />
  44. </template>
  45. </v-data-table>
  46. </template>
  47. <script lang="ts">
  48. import { mdiMagnify } from '@mdi/js'
  49. import { dateFormat } from '@vuejs-community/vue-filter-date-format'
  50. import { dateParse } from '@vuejs-community/vue-filter-date-parse'
  51. import type { PropType } from 'vue'
  52. import Vue from 'vue'
  53. import { DataOptions } from 'vuetify/types'
  54. import { Project } from '~/domain/models/project/project'
  55. export default Vue.extend({
  56. props: {
  57. isLoading: {
  58. type: Boolean,
  59. default: false,
  60. required: true
  61. },
  62. items: {
  63. type: Array as PropType<Project[]>,
  64. default: () => [],
  65. required: true
  66. },
  67. value: {
  68. type: Array as PropType<Project[]>,
  69. default: () => [],
  70. required: true
  71. },
  72. total: {
  73. type: Number,
  74. default: 0,
  75. required: true
  76. }
  77. },
  78. data() {
  79. return {
  80. search: this.$route.query.q,
  81. options: {} as DataOptions,
  82. mdiMagnify,
  83. dateFormat,
  84. dateParse
  85. }
  86. },
  87. computed: {
  88. headers(): { text: any; value: string; sortable?: boolean }[] {
  89. return [
  90. { text: this.$t('generic.name'), value: 'name' },
  91. { text: this.$t('generic.description'), value: 'description', sortable: false },
  92. { text: this.$t('generic.type'), value: 'projectType' },
  93. { text: 'Created', value: 'createdAt' },
  94. { text: 'Author', value: 'author' },
  95. { text: 'Tags', value: 'tags', sortable: false }
  96. ]
  97. }
  98. },
  99. watch: {
  100. options: {
  101. handler() {
  102. this.updateQuery({
  103. query: {
  104. limit: this.options.itemsPerPage.toString(),
  105. offset: ((this.options.page - 1) * this.options.itemsPerPage).toString(),
  106. q: this.search
  107. }
  108. })
  109. },
  110. deep: true
  111. },
  112. search() {
  113. this.updateQuery({
  114. query: {
  115. limit: this.options.itemsPerPage.toString(),
  116. offset: '0',
  117. q: this.search
  118. }
  119. })
  120. this.options.page = 1
  121. }
  122. },
  123. methods: {
  124. updateQuery(payload: any) {
  125. const { sortBy, sortDesc } = this.options
  126. if (sortBy.length === 1 && sortDesc.length === 1) {
  127. payload.query.sortBy = sortBy[0]
  128. payload.query.sortDesc = sortDesc[0]
  129. } else {
  130. payload.query.sortBy = 'createdAt'
  131. payload.query.sortDesc = true
  132. }
  133. this.$emit('update:query', payload)
  134. }
  135. }
  136. })
  137. </script>