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.

137 lines
3.3 KiB

3 years ago
3 years ago
3 years ago
3 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.updatedAt`]="{ item }">
  38. <span>{{ item.updatedAt | dateParse('YYYY-MM-DDTHH:mm:ss') | dateFormat('DD/MM/YYYY HH:mm') }}</span>
  39. </template>
  40. <template #[`item.tags`]="{ item }">
  41. <v-chip
  42. v-for="tag in item.tags"
  43. :key="tag.id"
  44. outlined v-text="tag.text"
  45. />
  46. </template>
  47. </v-data-table>
  48. </template>
  49. <script lang="ts">
  50. import Vue, { PropType } from 'vue'
  51. import { mdiMagnify } from '@mdi/js'
  52. import { DataOptions } from 'vuetify/types'
  53. import VueFilterDateFormat from '@vuejs-community/vue-filter-date-format'
  54. import VueFilterDateParse from '@vuejs-community/vue-filter-date-parse'
  55. import { ProjectDTO } from '~/services/application/project/projectData'
  56. Vue.use(VueFilterDateFormat)
  57. Vue.use(VueFilterDateParse)
  58. export default Vue.extend({
  59. props: {
  60. isLoading: {
  61. type: Boolean,
  62. default: false,
  63. required: true
  64. },
  65. items: {
  66. type: Array as PropType<ProjectDTO[]>,
  67. default: () => [],
  68. required: true
  69. },
  70. value: {
  71. type: Array as PropType<ProjectDTO[]>,
  72. default: () => [],
  73. required: true
  74. },
  75. total: {
  76. type: Number,
  77. default: 0,
  78. required: true
  79. }
  80. },
  81. data() {
  82. return {
  83. search: this.$route.query.q,
  84. options: {} as DataOptions,
  85. mdiMagnify
  86. }
  87. },
  88. computed: {
  89. headers() {
  90. return [
  91. { text: this.$t('generic.name'), value: 'name' },
  92. { text: this.$t('generic.description'), value: 'description' },
  93. { text: this.$t('generic.type'), value: 'projectType' },
  94. { text: 'Updated', value: 'updatedAt' },
  95. { text: 'Tags', value: 'tags'}
  96. ]
  97. }
  98. },
  99. watch: {
  100. options: {
  101. handler() {
  102. const self: any = this
  103. self.updateQuery({
  104. query: {
  105. limit: self.options.itemsPerPage.toString(),
  106. offset: ((self.options.page - 1) * self.options.itemsPerPage).toString(),
  107. q: self.search
  108. }
  109. })
  110. },
  111. deep: true
  112. },
  113. search() {
  114. const self: any = this
  115. self.updateQuery({
  116. query: {
  117. limit: self.options.itemsPerPage.toString(),
  118. offset: '0',
  119. q: self.search
  120. }
  121. })
  122. self.options.page = 1
  123. }
  124. },
  125. methods: {
  126. updateQuery(payload: any) {
  127. this.$emit('update:query', payload)
  128. }
  129. }
  130. })
  131. </script>