index.vue 12 KB

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