index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  1. <!-- Search for events -->
  2. <template>
  3. <LayoutContainer>
  4. <!-- Search form -->
  5. <v-row class="my-3" id="searchBar">
  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. @input="dateRangeFilterChanged"
  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" style="width: 100%">
  73. <v-row v-for="i in 4" :key="i" justify="center" justify-sm="start">
  74. <v-col
  75. v-for="j in 4"
  76. :key="j"
  77. :cols="12"
  78. :sm="6"
  79. :md="4"
  80. :lg="3"
  81. class="py-2 px-2 my-2"
  82. >
  83. <v-skeleton-loader type="card-avatar, article, button" :loading="true" height="400px" />
  84. </v-col>
  85. </v-row>
  86. </v-container>
  87. <!-- Results -->
  88. <v-data-iterator
  89. v-else
  90. :items="events"
  91. :page.sync="page"
  92. :items-per-page="itemsPerPage"
  93. sort-by="name"
  94. hide-default-footer
  95. :no-data-text="$t('no_results')"
  96. style="width: 100%"
  97. >
  98. <template #header>
  99. <i class="results-count">{{ totalRecords }} {{ $t('results') }}</i>
  100. </template>
  101. <template #default="props">
  102. <v-container>
  103. <v-row
  104. justify="center"
  105. justify-sm="start"
  106. >
  107. <v-col
  108. v-for="publicEvent in events"
  109. :key="publicEvent.uuid"
  110. :cols="12"
  111. :sm="6"
  112. :md="4"
  113. :lg="3"
  114. class="py-2 px-2 my-2"
  115. >
  116. <v-card
  117. elevation="4"
  118. class="event-card pa-0 d-flex flex-column"
  119. >
  120. <div class="d-flex justify-center max-w100">
  121. <v-img
  122. :src="publicEvent.thumbnailUrl || '/images/event-default.jpg'"
  123. alt="poster"
  124. max-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/' + publicEvent.uuid, query: query}">
  133. {{ publicEvent.name }}
  134. </nuxt-link>
  135. </v-card-title>
  136. <v-card-text class="infos pb-0">
  137. <table>
  138. <tr v-if="publicEvent.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. {{ dateUtils.formatDateIntervalFor(new Date(publicEvent.datetimeStart), new Date(publicEvent.datetimeEnd)) }}
  145. </span>
  146. </td>
  147. </tr>
  148. <tr v-if="publicEvent.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="publicEvent.roomName" style="white-space: pre-line;">{{ publicEvent.roomName }}<br></span>
  154. <span v-if="publicEvent.address.streetAddress" style="white-space: pre-line;">{{ publicEvent.address.streetAddress }}<br></span>
  155. <span>{{ publicEvent.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: '/events/' + publicEvent.uuid, query: query}"
  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 DatesUtils from "~/services/utils/dateUtils";
  194. const defaultDateRange: DateRange = { start: '', end: '' }
  195. export default Vue.extend({
  196. scrollToTop: true,
  197. data () {
  198. return {
  199. theme: this.$route.query.theme as string ?? 'orange',
  200. organization: parseInt(this.$route.query.organization as string) ?? null,
  201. page: 1,
  202. events: [] as Array<PublicEvent>,
  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. dateUtils: new DatesUtils(this.$dateFns, this.$t, this.$i18n)
  210. }
  211. },
  212. async fetch () {
  213. await new EventsProvider(this.$axios).getBy(
  214. this.textFilter,
  215. this.organization,
  216. this.dateRangeFilter.start,
  217. this.dateRangeFilter.end,
  218. this.locationFilter,
  219. this.page,
  220. this.itemsPerPage
  221. ).then(
  222. (collection: HydraCollection<PublicEvent>) => {
  223. this.events = collection.items
  224. this.totalRecords = collection.totalItems
  225. this.page = collection.page ?? 1
  226. this.pagesCount = collection.lastPage ?? 1
  227. })
  228. },
  229. computed: {
  230. query (): object {
  231. const q: any = { theme: this.theme }
  232. if (this.organization > 0) {
  233. q.organization = this.organization
  234. }
  235. return q
  236. },
  237. dateRangeMin(): string {
  238. return this.dateUtils.todayIso()
  239. },
  240. dateRangePresets(): Array<DateRangePreset> {
  241. // Today
  242. const today_preset: DateRangePreset = {
  243. label: this.$t('today').toString(),
  244. range: {start: this.dateUtils.todayIso(), end: this.dateUtils.todayIso()}
  245. }
  246. // Cette semaine
  247. const week_preset: DateRangePreset = {
  248. label: this.$t('next_week').toString(),
  249. range: {start: this.dateUtils.todayIso(), end: this.dateUtils.formatIso(this.$dateFns.addDays(this.dateUtils.today(), 7))}
  250. }
  251. // Ce week-end
  252. const sunday: Date = this.$dateFns.nextSunday(this.dateUtils.today())
  253. const weekend_preset: DateRangePreset = {
  254. label: this.$t('next_weekend').toString(),
  255. range: {start: this.dateUtils.formatIso(this.$dateFns.addDays(sunday, -2)), end: this.dateUtils.formatIso(sunday)}
  256. }
  257. // Ce mois
  258. const month_preset: DateRangePreset = {
  259. label: this.$t('next_month').toString(),
  260. range: {start: this.dateUtils.todayIso(), end: this.dateUtils.formatIso(this.$dateFns.addMonths(this.dateUtils.today(), 1))}
  261. }
  262. return [today_preset, week_preset, weekend_preset, month_preset]
  263. }
  264. },
  265. methods: {
  266. textFilterChanged (newVal: string) {
  267. this.textFilter = newVal
  268. },
  269. locationFilterChanged (newVal: Coordinates) {
  270. this.locationFilter = newVal
  271. this.search()
  272. },
  273. dateRangeFilterChanged (newVal: DateRange) {
  274. this.dateRangeFilter = newVal
  275. this.search()
  276. },
  277. reinitializeFilters (): void {
  278. this.textFilter = null
  279. this.locationFilter = null
  280. this.dateRangeFilter = defaultDateRange
  281. const dateSearch = this.$refs.dateSearch as any
  282. dateSearch.reset()
  283. const addressSearch = this.$refs.addressSearch as any
  284. addressSearch.clear()
  285. this.page = 1
  286. this.search()
  287. },
  288. async pageUpdated (page: number): Promise<void> {
  289. await this.$vuetify.goTo(0, { duration: 400, offset: 0, easing: 'easeInOutCubic' })
  290. this.page = page
  291. this.search()
  292. },
  293. /**
  294. * Update the filteredEvents array
  295. */
  296. search (): void {
  297. this.$fetch()
  298. },
  299. /**
  300. * Enhanced filter for v-autocomplete components
  301. *
  302. * @param _
  303. * @param queryText
  304. * @param itemText
  305. */
  306. enhancedAutocompleteFilter (_: any, queryText: string, itemText: string): boolean {
  307. return normalize(itemText).includes(normalize(queryText))
  308. }
  309. }
  310. })
  311. </script>
  312. <style scoped lang="scss">
  313. @import 'assets/style/variables.scss';
  314. h2 {
  315. color: var(--v-primary-base);
  316. }
  317. .event-card {
  318. height: 100%;
  319. width: 280px;
  320. min-width: 280px;
  321. color: #666666;
  322. }
  323. .event-card .title {
  324. text-transform: uppercase;
  325. }
  326. .event-card .title a {
  327. width: 100%;
  328. text-align: center;
  329. }
  330. .infos td {
  331. vertical-align: top;
  332. text-transform: capitalize;
  333. }
  334. .title {
  335. word-break: normal;
  336. color: var(--v-primary-base);
  337. font-size: 18px;
  338. font-weight: 500;
  339. line-height: 1.6rem;
  340. }
  341. .title a {
  342. text-decoration: none;
  343. }
  344. .icon {
  345. color: var(--v-primary-base);
  346. }
  347. .results-count {
  348. font-size: .8em;
  349. color: #666;
  350. }
  351. .search-actions button {
  352. width: 100%;
  353. height: 36px !important;
  354. }
  355. </style>