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.

135 lines
3.3 KiB

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