index.vue 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. const { em } = useEntityManager()
  34. const page: Ref<number> = ref(1)
  35. let { data: collection, pending, refresh } = useLazyAsyncData(
  36. 'files',
  37. () => em.fetchCollection(File, null, { page: page.value })
  38. )
  39. const totalItems: ComputedRef<number | undefined> = computed(() => collection.value?.totalItems)
  40. const pagination: ComputedRef<Pagination | undefined> = computed(() => {
  41. return collection.value?.pagination
  42. })
  43. let files: ComputedRef<Array<ApiResource> | undefined> = computed(() => {
  44. return collection.value?.items
  45. })
  46. const goToPreviousPage = async function () {
  47. if (page.value > 1) {
  48. page.value--
  49. await refresh()
  50. }
  51. }
  52. const goToNextPage = async function () {
  53. page.value++
  54. await refresh()
  55. }
  56. </script>
  57. <style>
  58. a {
  59. color: blue; /* !color! */
  60. cursor: pointer;
  61. }
  62. a:hover {
  63. text-decoration: underline;
  64. }
  65. button {
  66. border: grey solid 1px; /* !color! */
  67. padding: 5px;
  68. margin: 5px;
  69. cursor: pointer;
  70. }
  71. button:hover {
  72. text-decoration: underline;
  73. }
  74. button:focus {
  75. background-color: lightgrey; /* !color! */
  76. }
  77. </style>