index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  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>
  136. {{ formatDateIntervalFor(new Date(event.datetimeStart), new Date(event.datetimeEnd)) }}
  137. </span>
  138. </td>
  139. </tr>
  140. <tr v-if="event.address.addressCity">
  141. <td>
  142. <font-awesome-icon class="icon" :icon="['fas', 'map-marker-alt']" />
  143. </td>
  144. <td>
  145. <span v-if="event.address.streetAddress" style="white-space: pre-line;">{{ event.address.streetAddress }}<br></span>
  146. <span v-if="event.address.postalCode" class="postalCode">{{ event.address.postalCode }} </span>
  147. <span>{{ event.address.addressCity }}</span>
  148. </td>
  149. </tr>
  150. </table>
  151. </v-card-text>
  152. </div>
  153. <v-card-actions class="align-self-end">
  154. <v-btn
  155. class="see"
  156. :to="{path: '/event/' + event.uuid, query: { theme: theme, hideTitle: hideTitle }}"
  157. nuxt
  158. >
  159. <span style="margin-right: 6px;">{{ $t("see_more") }}</span>
  160. <font-awesome-icon :icon="['fa', 'caret-right']" />
  161. </v-btn>
  162. </v-card-actions>
  163. </v-card>
  164. </v-col>
  165. </v-row>
  166. </template>
  167. <template #footer>
  168. <v-pagination
  169. v-model="page"
  170. :length="pagesCount"
  171. total-visible="9"
  172. color="primary"
  173. @input="pageUpdated"
  174. />
  175. </template>
  176. </v-data-iterator>
  177. </v-row>
  178. </LayoutContainer>
  179. </template>
  180. <script lang="ts">
  181. import Vue from 'vue'
  182. import EventsProvider from "~/services/data/EventsProvider"
  183. import {today, todayIso, formatIso} from '@/services/utils/date'
  184. import locale from 'date-fns/locale/fr'
  185. const defaultDateRange: DateRange = { start: '', end: '' }
  186. export default Vue.extend({
  187. data () {
  188. return {
  189. theme: this.$route.query.theme ?? 'orange',
  190. hideTitle: this.$route.query.hideTitle === 'true',
  191. events: [] as Array<PublicEvent>,
  192. page: 1,
  193. itemsPerPage: 16,
  194. textFilter: null as string | null,
  195. locationFilter: null as Coordinates | null,
  196. dateRangeFilter: defaultDateRange,
  197. totalRecords: 0 as number,
  198. pagesCount: 1 as number | null,
  199. }
  200. },
  201. async fetch () {
  202. await new EventsProvider(this.$axios).getBy(
  203. this.textFilter,
  204. null,
  205. this.dateRangeFilter.start,
  206. this.dateRangeFilter.end,
  207. this.locationFilter,
  208. this.page,
  209. this.itemsPerPage
  210. ).then(
  211. (collection: HydraCollection<PublicEvent>) => {
  212. this.events = collection.items
  213. this.totalRecords = collection.totalItems
  214. this.page = collection.page ?? 1
  215. this.pagesCount = collection.lastPage ?? 1
  216. console.log(this.events)
  217. })
  218. },
  219. computed: {
  220. dateRangeMin(): string {
  221. return todayIso()
  222. },
  223. dateRangePresets(): Array<DateRangePreset> {
  224. // Today
  225. const today_preset: DateRangePreset = {
  226. label: this.$t('today').toString(),
  227. range: {start: todayIso(), end: todayIso()}
  228. }
  229. // Cette semaine
  230. const week_preset: DateRangePreset = {
  231. label: this.$t('next_week').toString(),
  232. range: {start: todayIso(), end: formatIso(this.$dateFns.addDays(today(), 7))}
  233. }
  234. // Ce week-end
  235. const sunday: Date = this.$dateFns.nextSunday(today())
  236. const weekend_preset: DateRangePreset = {
  237. label: this.$t('next_weekend').toString(),
  238. range: {start: formatIso(this.$dateFns.addDays(sunday, -2)), end: formatIso(sunday)}
  239. }
  240. // Ce mois
  241. const month_preset: DateRangePreset = {
  242. label: this.$t('next_month').toString(),
  243. range: {start: todayIso(), end: formatIso(this.$dateFns.addMonths(today(), 1))}
  244. }
  245. return [today_preset, week_preset, weekend_preset, month_preset]
  246. }
  247. },
  248. methods: {
  249. textFilterChanged (newVal: string) {
  250. this.textFilter = newVal
  251. },
  252. locationFilterChanged (newVal: Coordinates) {
  253. this.locationFilter = newVal
  254. this.search()
  255. },
  256. dateRangeFilterChanged (newVal: DateRange) {
  257. this.dateRangeFilter = newVal
  258. this.search()
  259. },
  260. reinitializeFilters (): void {
  261. this.textFilter = null
  262. this.locationFilter = null
  263. this.dateRangeFilter = defaultDateRange
  264. const addressSearch = this.$refs.addressSearch as any
  265. addressSearch.clear()
  266. this.search()
  267. },
  268. pageUpdated (page: number): void {
  269. this.page = page
  270. this.search()
  271. },
  272. /**
  273. * Update the filteredEvents array
  274. */
  275. search (): void {
  276. this.$fetch()
  277. },
  278. /**
  279. * Enhanced filter for v-autocomplete components
  280. *
  281. * @param _
  282. * @param queryText
  283. * @param itemText
  284. */
  285. enhancedAutocompleteFilter (_: any, queryText: string, itemText: string): boolean {
  286. return normalize(itemText).includes(normalize(queryText))
  287. },
  288. formatDate(date: Date, short = true): string {
  289. return short ? this.$dateFns.format(date, 'dd/MM/yyyy') : this.$dateFns.format(date, 'dd MMM yyyy', {locale: locale})
  290. },
  291. formatTime(date: Date): string {
  292. return this.$dateFns.format(date, 'HH:mm')
  293. },
  294. formatDateTime(date: Date): string {
  295. return this.formatDate(date) + ' ' + this.$t('on_hour') + ' ' + this.formatTime(date)
  296. },
  297. formatDateIntervalFor(dateStart: Date | null = null, dateEnd: Date | null = null): string {
  298. if (dateStart === null && dateEnd !== null)
  299. {
  300. return this.formatDateTime(dateEnd)
  301. }
  302. else if (dateEnd === null && dateStart !== null) {
  303. return this.formatDateTime(dateStart)
  304. }
  305. else if (dateStart !== null && dateEnd !== null) {
  306. if (dateStart === dateEnd) {
  307. return this.formatDateTime(dateStart)
  308. }
  309. else if (this.$dateFns.isSameDay(dateStart, dateEnd)) {
  310. return this.$t('on_day') + ' ' + this.formatDate(dateStart, false) + ', ' +
  311. this.$t('from_hour') + ' ' + this.formatTime(dateStart) + ' ' + this.$t('to_hour') + ' ' + this.formatTime(dateEnd)
  312. }
  313. else {
  314. return this.$t('from_day') + ' ' + this.formatDateTime(dateStart) + ' ' + this.$t('to_day') + ' ' + this.formatDateTime(dateEnd)
  315. }
  316. }
  317. return ""
  318. }
  319. }
  320. })
  321. </script>
  322. <style scoped lang="scss">
  323. @import 'assets/style/variables.scss';
  324. h2 {
  325. color: var(--v-primary-base);
  326. }
  327. .event-card {
  328. height: 100%;
  329. color: #666666;
  330. }
  331. .infos .col {
  332. padding: 6px 12px;
  333. }
  334. .infos td {
  335. padding: 4px;
  336. vertical-align: top;
  337. }
  338. .infos td:first-child {
  339. padding-top: 6px;
  340. text-align: center;
  341. }
  342. .title {
  343. word-break: normal;
  344. color: var(--v-primary-base);
  345. font-size: 18px;
  346. font-weight: 500;
  347. line-height: 1.6rem;
  348. }
  349. .title a {
  350. text-decoration: none;
  351. }
  352. .icon {
  353. color: var(--v-primary-base);
  354. }
  355. .results-count {
  356. font-size: .8em;
  357. color: #666;
  358. }
  359. </style>