index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  1. <!-- Search for events -->
  2. <template>
  3. <LayoutContainer>
  4. <!-- Header -->
  5. <v-row>
  6. <v-layout>
  7. <h2 v-if="!hideTitle">
  8. {{ $t("events") }}
  9. </h2>
  10. </v-layout>
  11. </v-row>
  12. <!-- Search form -->
  13. <v-row>
  14. <v-form method="get" class="mt-8 w100">
  15. <v-container>
  16. <v-row>
  17. <v-col cols="12" md="6" class="py-2 px-1">
  18. <UiSearchDateRangePicker
  19. ref="dateSearch"
  20. v-model="dateRangeFilter"
  21. :start-label="$t('start_date')"
  22. :end-label="$t('end_date')"
  23. preset-label=""
  24. separator-label="~"
  25. :presets="dateRangePresets"
  26. :min="dateRangeMin"
  27. locale="fr-FR"
  28. no-title
  29. display-format="dd/MM/yyyy"
  30. :inputProps="{outlined: true}"
  31. :menuProps="{offsetY: true, closeOnContentClick: false}"
  32. :actionLabels="{apply: $t('apply'), cancel: $t('cancel'), reset: $t('reset')}"
  33. >
  34. </UiSearchDateRangePicker>
  35. </v-col>
  36. <v-col cols="12" md="6" class="py-2 px-1">
  37. <UiSearchAddress
  38. ref="addressSearch"
  39. type="municipality"
  40. @change="locationFilterChanged"
  41. />
  42. </v-col>
  43. <v-col cols="12" md="6" class="py-2 px-1">
  44. <v-text-field
  45. v-model="textFilter"
  46. type="text"
  47. outlined
  48. clearable
  49. hide-details
  50. append-icon="mdi-magnify"
  51. :label="$t('what') + ' ?'"
  52. @click:append="search"
  53. @keydown.enter="search"
  54. />
  55. </v-col>
  56. </v-row>
  57. <v-row>
  58. <v-col cols="2" class="py-2 px-1">
  59. <v-btn class="h100" @click="reinitializeFilters">
  60. {{ $t('reinitialize') }}
  61. </v-btn>
  62. </v-col>
  63. <v-col cols="2" class="py-2 px-1 d-flex justify-end">
  64. <v-btn class="h100" @click="search()">
  65. {{ $t('search') }}
  66. </v-btn>
  67. </v-col>
  68. </v-row>
  69. </v-container>
  70. </v-form>
  71. </v-row>
  72. <v-row>
  73. <!-- loading skeleton -->
  74. <v-container v-if="$fetchState.pending">
  75. <v-row v-for="i in 4" :key="i" justify="space-between" class="mt-1 mb-3">
  76. <v-col v-for="j in 4" :key="j" cols="3" :md="6" class="py-2 px-1">
  77. <v-skeleton-loader type="card-avatar, text, button" :loading="true" />
  78. </v-col>
  79. </v-row>
  80. </v-container>
  81. <!-- Results -->
  82. <v-data-iterator
  83. v-else
  84. :items="events"
  85. :page.sync="page"
  86. :items-per-page="itemsPerPage"
  87. sort-by="name"
  88. hide-default-footer
  89. no-data-text=""
  90. >
  91. <template #header>
  92. <i class="results-count">{{ totalRecords }} {{ $t('results') }}</i>
  93. </template>
  94. <template #default="props">
  95. <v-row justify="space-between" class="mt-3 mb-3">
  96. <v-col
  97. v-for="event in props.items"
  98. :key="event.uuid"
  99. cols="3"
  100. sm="6"
  101. :lg="3"
  102. class="py-2 px-1"
  103. >
  104. <v-card
  105. elevation="1"
  106. outlined
  107. class="event-card pa-0 d-flex flex-column"
  108. >
  109. <div class="d-flex justify-center max-w100">
  110. <v-img
  111. v-if="event.imageId"
  112. :src="'https://api.opentalent.fr/app.php/_internal/secure/files/' + event.imageId"
  113. alt="poster"
  114. height="320"
  115. width="100%"
  116. max-height="100%"
  117. :contain="true"
  118. style="margin: 12px;"
  119. />
  120. <div v-else style="height: 344px; width: 264px" />
  121. </div>
  122. <div class="d-flex flex-column flex-grow-1">
  123. <v-card-title class="title">
  124. <nuxt-link :to="{path: '/events/' + event.uuid, query: { theme: theme }}">
  125. {{ event.name }}
  126. </nuxt-link>
  127. </v-card-title>
  128. <v-card-text class="infos">
  129. <table>
  130. <tr v-if="event.datetimeStart">
  131. <td>
  132. <font-awesome-icon :icon="['fas', 'calendar']" class="icon mr-2" />
  133. </td>
  134. <td>
  135. <span v-if="event.datetimeStart && event.datetimeEnd">
  136. {{ new Date(event.datetimeStart).toLocaleString() }} ~ {{ new Date(event.datetimeEnd).toLocaleString() }}
  137. </span>
  138. <span v-else>{{ new Date(event.datetimeStart).toLocaleString() }}</span>
  139. </td>
  140. </tr>
  141. <tr v-if="event.address.addressCity">
  142. <td>
  143. <font-awesome-icon class="icon" :icon="['fas', 'map-marker-alt']" />
  144. </td>
  145. <td>
  146. <span v-if="event.address.streetAddress" style="white-space: pre-line;">{{ event.address.streetAddress }}<br></span>
  147. <span v-if="event.address.postalCode" class="postalCode">{{ event.address.postalCode }} </span>
  148. <span>{{ event.address.addressCity }}</span>
  149. </td>
  150. </tr>
  151. </table>
  152. </v-card-text>
  153. </div>
  154. <v-card-actions class="align-self-end">
  155. <v-btn
  156. class="see"
  157. :to="{path: '/event/' + event.uuid, query: { theme: theme, hideTitle: hideTitle }}"
  158. nuxt
  159. >
  160. <span style="margin-right: 6px;">{{ $t("see_more") }}</span>
  161. <font-awesome-icon :icon="['fa', 'caret-right']" />
  162. </v-btn>
  163. </v-card-actions>
  164. </v-card>
  165. </v-col>
  166. </v-row>
  167. </template>
  168. <template #footer>
  169. <v-pagination
  170. v-model="page"
  171. :length="pagesCount"
  172. total-visible="9"
  173. color="primary"
  174. @input="pageUpdated"
  175. />
  176. </template>
  177. </v-data-iterator>
  178. </v-row>
  179. </LayoutContainer>
  180. </template>
  181. <script lang="ts">
  182. import Vue from 'vue'
  183. import EventsProvider from "~/services/data/EventsProvider"
  184. import {today, todayIso, formatIso, formatIsoDate} from '@/services/utils/date'
  185. import { reformatDate, addDays, nextSunday, addMonths } from "date-fns";
  186. const defaultDateRange: DateRange = { start: '', end: '' }
  187. export default Vue.extend({
  188. data () {
  189. return {
  190. theme: this.$route.query.theme ?? 'orange',
  191. hideTitle: this.$route.query.hideTitle === 'true',
  192. events: [] as Array<PublicEvent>,
  193. page: 1,
  194. itemsPerPage: 16,
  195. textFilter: null as string | null,
  196. locationFilter: null as Coordinates | null,
  197. dateRangeFilter: defaultDateRange,
  198. totalRecords: 0 as number,
  199. pagesCount: 1 as number | null,
  200. }
  201. },
  202. async fetch () {
  203. await new EventsProvider(this.$axios).getBy(
  204. this.textFilter,
  205. null,
  206. this.dateRangeFilter.start,
  207. this.dateRangeFilter.end,
  208. null,
  209. this.page,
  210. this.itemsPerPage
  211. ).then(
  212. (collection: HydraCollection<PublicEvent>) => {
  213. this.events = collection.items
  214. this.totalRecords = collection.totalItems
  215. this.page = collection.page ?? 1
  216. this.pagesCount = collection.lastPage ?? 1
  217. console.log(this.events)
  218. })
  219. },
  220. computed: {
  221. dateRangeMin(): string {
  222. return todayIso()
  223. },
  224. dateRangePresets(): Array<DateRangePreset> {
  225. // Today
  226. const today_preset: DateRangePreset = {
  227. label: this.$t('today').toString(),
  228. range: {start: todayIso(), end: todayIso()}
  229. }
  230. // Cette semaine
  231. const week_preset: DateRangePreset = {
  232. label: this.$t('next_week').toString(),
  233. range: {start: todayIso(), end: formatIso(addDays(today(), 7))}
  234. }
  235. // Ce week-end
  236. const sunday: Date = nextSunday(today())
  237. const weekend_preset: DateRangePreset = {
  238. label: this.$t('next_weekend').toString(),
  239. range: {start: formatIso(addDays(sunday, -2)), end: formatIso(sunday)}
  240. }
  241. // Ce mois
  242. const month_preset: DateRangePreset = {
  243. label: this.$t('next_month').toString(),
  244. range: {start: todayIso(), end: formatIso(addMonths(today(), 1))}
  245. }
  246. return [today_preset, week_preset, weekend_preset, month_preset]
  247. }
  248. },
  249. methods: {
  250. textFilterChanged (newVal: string) {
  251. this.textFilter = newVal
  252. },
  253. locationFilterChanged (newVal: Coordinates) {
  254. this.locationFilter = newVal
  255. this.search()
  256. },
  257. dateRangeFilterChanged (newVal: DateRange) {
  258. this.dateRangeFilter = newVal
  259. this.search()
  260. },
  261. reinitializeFilters (): void {
  262. this.textFilter = null
  263. this.locationFilter = null
  264. this.dateRangeFilter = defaultDateRange
  265. const addressSearch = this.$refs.addressSearch as any
  266. addressSearch.clear()
  267. this.search()
  268. },
  269. pageUpdated (page: number): void {
  270. this.page = page
  271. this.search()
  272. },
  273. /**
  274. * Update the filteredEvents array
  275. */
  276. search (): void {
  277. this.$fetch()
  278. },
  279. /**
  280. * Enhanced filter for v-autocomplete components
  281. *
  282. * @param _
  283. * @param queryText
  284. * @param itemText
  285. */
  286. enhancedAutocompleteFilter (_: any, queryText: string, itemText: string): boolean {
  287. return normalize(itemText).includes(normalize(queryText))
  288. },
  289. formatDatetime(date: string): string {
  290. console.log(date)
  291. return reformatDate(date, 'yyyy-MM-DD[T]HH:mm:ssZZ', 'dd/MM/yyyy hh:mm')
  292. }
  293. }
  294. })
  295. </script>
  296. <style scoped lang="scss">
  297. @import 'assets/style/variables.scss';
  298. h2 {
  299. color: var(--v-primary-base);
  300. }
  301. .event-card {
  302. height: 100%;
  303. color: #666666;
  304. }
  305. .infos .col {
  306. padding: 6px 12px;
  307. }
  308. .infos td {
  309. padding: 4px;
  310. vertical-align: top;
  311. }
  312. .infos td:first-child {
  313. padding-top: 6px;
  314. text-align: center;
  315. }
  316. .title {
  317. word-break: normal;
  318. color: var(--v-primary-base);
  319. font-size: 18px;
  320. font-weight: 500;
  321. line-height: 1.6rem;
  322. }
  323. .title a {
  324. text-decoration: none;
  325. }
  326. .icon {
  327. color: var(--v-primary-base);
  328. }
  329. .results-count {
  330. font-size: .8em;
  331. color: #666;
  332. }
  333. </style>