index.vue 12 KB

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