index.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <template>
  2. <main>
  3. <div>
  4. <div v-if="pending">
  5. Pending...
  6. </div>
  7. <div v-else>
  8. <ul>
  9. <li v-for="file in files">
  10. <nuxt-link :to="'/poc/' + file.id" class="mr-3">{{ file.name }}</nuxt-link>
  11. </li>
  12. </ul>
  13. <div class="ma-3">{{ totalItems }} results</div>
  14. <!-- <div class="ma-3">-->
  15. <!-- <button @click="goToPreviousPage" class="mr-3">Previous page ({{ pagination.previous }})</button>-->
  16. <!-- <span class="mx-3">Page : {{ page }}</span>-->
  17. <!-- <button @click="goToNextPage">Next page ({{ pagination.next }})</button>-->
  18. <!-- <span class="mx-2"> (Last page : {{ pagination.last }})</span>-->
  19. <!-- </div>-->
  20. <div class="ma-3">
  21. <nuxt-link to="/poc/new">Create</nuxt-link>
  22. <p><nuxt-link to="/poc/1">Goto 1</nuxt-link></p>
  23. </div>
  24. </div>
  25. </div>
  26. </main>
  27. </template>
  28. <script setup lang="ts">
  29. import {useEntityManager} from "~/composables/data/useEntityManager";
  30. import {computed, ComputedRef, ref, Ref} from "@vue/reactivity";
  31. import ApiResource from "~/models/ApiResource";
  32. import File from "~/models/Core/File";
  33. import {Collection, Pagination} from "~/types/enum/data";
  34. import {useEntityFetch} from "~/composables/data/useEntityFetch";
  35. const { em } = useEntityManager()
  36. const page: Ref<number> = ref(1)
  37. let { data: collection, pending, refresh } = useLazyAsyncData(
  38. 'files',
  39. () => em.fetchCollection(File, null, { page: page.value })
  40. )
  41. const totalItems: ComputedRef<number | undefined> = computed(() => collection.value?.totalItems)
  42. const pagination: ComputedRef<Pagination | undefined> = computed(() => {
  43. return collection.value?.pagination
  44. })
  45. let files: ComputedRef<Array<ApiResource> | undefined> = computed(() => {
  46. return collection.value?.items
  47. })
  48. const goToPreviousPage = async function () {
  49. if (page.value > 1) {
  50. page.value--
  51. await refresh()
  52. }
  53. }
  54. const goToNextPage = async function () {
  55. page.value++
  56. await refresh()
  57. }
  58. </script>
  59. <style>
  60. a {
  61. color: blue; /* !color! */
  62. cursor: pointer;
  63. }
  64. a:hover {
  65. text-decoration: underline;
  66. }
  67. button {
  68. border: grey solid 1px; /* !color! */
  69. padding: 5px;
  70. margin: 5px;
  71. cursor: pointer;
  72. }
  73. button:hover {
  74. text-decoration: underline;
  75. }
  76. button:focus {
  77. background-color: lightgrey; /* !color! */
  78. }
  79. </style>