dashboard.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <template>
  2. <v-container fluid>
  3. <v-row>
  4. <!-- Bloc événements -->
  5. <v-col cols="12" md="8">
  6. <v-card>
  7. <v-tabs v-model="tab">
  8. <v-tab value="future">Mes événements à venir</v-tab>
  9. <v-tab value="past">Mes événements passés</v-tab>
  10. </v-tabs>
  11. <v-tabs-window v-model="tab">
  12. <v-tabs-window-item value="future">
  13. <UiEventList
  14. v-if="statusUpcomingEvents == FETCHING_STATUS.SUCCESS && upcomingEvents?.items"
  15. :events="upcomingEvents.items"
  16. :pagination="upcomingEvents.pagination"
  17. @load="loadUpcomingEvents"
  18. @edit="editEvent"
  19. />
  20. </v-tabs-window-item>
  21. <v-tabs-window-item value="past">
  22. <UiEventList
  23. v-if="statusPastEvents == FETCHING_STATUS.SUCCESS && pastEvents?.items"
  24. :events="pastEvents.items"
  25. :pagination="pastEvents.pagination"
  26. @load="loadPastEvents"
  27. @edit="editEvent"
  28. />
  29. </v-tabs-window-item>
  30. </v-tabs-window>
  31. <v-card-actions>
  32. <v-btn color="primary" to="events/new">Ajouter un événement</v-btn>
  33. </v-card-actions>
  34. </v-card>
  35. </v-col>
  36. <!-- Bloc structure -->
  37. <v-col cols="12" md="4">
  38. <v-card v-if="statusOrganization == FETCHING_STATUS.SUCCESS">
  39. <v-card-title>Structure</v-card-title>
  40. <v-card-text>
  41. <div><strong>Nom:</strong> {{ organization?.name }}</div>
  42. <div><strong>Email:</strong> {{ organization?.email }}</div>
  43. </v-card-text>
  44. <v-card-actions>
  45. <v-btn color="secondary" to="organization">Modifier la structure</v-btn>
  46. </v-card-actions>
  47. </v-card>
  48. </v-col>
  49. </v-row>
  50. </v-container>
  51. </template>
  52. <script setup lang="ts">
  53. import Query from "~/services/data/Query";
  54. definePageMeta({
  55. name: 'freemium_dashboard_page',
  56. })
  57. import { ref } from 'vue'
  58. import {useEntityFetch} from "~/composables/data/useEntityFetch";
  59. import Organization from "~/models/Freemium/Organization";
  60. import Event from "~/models/Freemium/Event";
  61. import type {AsyncData} from "#app";
  62. import OrderBy from "~/services/data/Filters/OrderBy";
  63. import {FETCHING_STATUS, ORDER_BY_DIRECTION, TIME_STRATEGY} from "~/types/enum/data";
  64. import PageFilter from "~/services/data/Filters/PageFilter";
  65. import TimeFilter from "~/services/data/Filters/TimeFilter";
  66. import Country from "~/models/Core/Country";
  67. import DateUtils from "~/services/utils/dateUtils";
  68. import UrlUtils from "~/services/utils/urlUtils";
  69. //Ref Définition
  70. const tab = ref(null)
  71. const { fetch, fetchCollection } = useEntityFetch()
  72. const upcomingPage = ref(1)
  73. const pastPage = ref(1)
  74. //Fetch
  75. const { data: organization, status:statusOrganization } = fetch(Organization)
  76. const { data: upcomingEvents, status: statusUpcomingEvents, refresh: refreshUpcomingEvents } = fetchEvents()
  77. const { data: pastEvents, status: statusPastEvents, refresh: refreshPastEvents } = fetchEvents(true)
  78. /**
  79. * Charge une page des événements à venir
  80. * @param pageNumber
  81. */
  82. function loadUpcomingEvents(pageNumber: number) {
  83. upcomingPage.value = pageNumber
  84. refreshPastEvents()
  85. }
  86. /**
  87. * Cahrge une page des événements passées
  88. * @param pageNumber
  89. */
  90. function loadPastEvents(pageNumber: number) {
  91. pastPage.value = pageNumber
  92. refreshPastEvents()
  93. }
  94. /**
  95. * Redirige vers la page d'édition d'un événement
  96. * @param eventId
  97. */
  98. function editEvent(eventId: number) {
  99. navigateTo(UrlUtils.join('events', eventId))
  100. }
  101. /**
  102. * Récupère la liste des événements
  103. * @param past
  104. */
  105. function fetchEvents(past:boolean = false){
  106. const today = computed(() => DateUtils.formatIsoShortDate(new Date()))
  107. const query =
  108. new Query(
  109. new OrderBy('datetimeStart', past ? ORDER_BY_DIRECTION.DESC : ORDER_BY_DIRECTION.ASC),
  110. new PageFilter(past ? pastPage : upcomingPage, ref(5)),
  111. new TimeFilter('datetimeStart', today, past ? TIME_STRATEGY.BEFORE : TIME_STRATEGY.AFTER)
  112. )
  113. return fetchCollection(Event, null, query)
  114. }
  115. /**
  116. * Nettoyage du store
  117. */
  118. onUnmounted(() => {
  119. useRepo(Organization).flush()
  120. useRepo(Event).flush()
  121. useRepo(Country).flush()
  122. })
  123. </script>
  124. <style scoped>
  125. .v-card {
  126. margin-bottom: 16px;
  127. }
  128. </style>