EntityInstancesTable.vue 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <template>
  2. <Table
  3. :data="tableRows"
  4. :headers="headers"
  5. :show-pagination="false"
  6. >
  7. <template #cell-title="{ row, value }">
  8. <router-link :to="entityDetailsRoute(row)">
  9. {{ value }}
  10. </router-link>
  11. </template>
  12. </Table>
  13. <div
  14. v-if="totalInstances > 0"
  15. class="padding"
  16. >
  17. <Pagination
  18. v-model:page="currentPageModel"
  19. v-model:page-size="pageSizeModel"
  20. :total="totalInstances"
  21. item-title="entities"
  22. />
  23. </div>
  24. </template>
  25. <script setup>
  26. import { computed } from 'vue'
  27. import Table from 'picocrank/vue/components/Table.vue'
  28. import Pagination from 'picocrank/vue/components/Pagination.vue'
  29. import { entityDetailsRoute } from '../utils/entityRoutes.js'
  30. const props = defineProps({
  31. instances: {
  32. type: Array,
  33. required: true
  34. },
  35. properties: {
  36. type: Array,
  37. required: true
  38. },
  39. totalInstances: {
  40. type: Number,
  41. default: 0
  42. },
  43. page: {
  44. type: Number,
  45. default: 1
  46. },
  47. pageSize: {
  48. type: Number,
  49. default: 10
  50. }
  51. })
  52. const emit = defineEmits(['update:page', 'update:pageSize'])
  53. const headers = computed(() => {
  54. const propertyHeaders = props.properties.map(property => ({
  55. key: property.name,
  56. label: property.title
  57. }))
  58. return [
  59. { key: 'title', label: 'Name' },
  60. ...propertyHeaders
  61. ]
  62. })
  63. const tableRows = computed(() =>
  64. props.instances.map(instance => ({
  65. ...instance.fields,
  66. title: instance.title,
  67. type: instance.type,
  68. uniqueKey: instance.uniqueKey
  69. }))
  70. )
  71. const currentPageModel = computed({
  72. get: () => props.page,
  73. set: value => emit('update:page', value)
  74. })
  75. const pageSizeModel = computed({
  76. get: () => props.pageSize,
  77. set: value => emit('update:pageSize', value)
  78. })
  79. </script>
  80. <style scoped>
  81. a {
  82. text-decoration: none;
  83. }
  84. a:hover {
  85. text-decoration: underline;
  86. }
  87. </style>