index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  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="publicEvent in props.items"
  108. :key="publicEvent.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="publicEvent.imageId ? 'https://api.opentalent.fr/app.php/_internal/secure/files/' + publicEvent.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/' + publicEvent.uuid, query: { theme: theme }}">
  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: { 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 DatesUtils from "~/services/utils/dateUtils";
  194. const defaultDateRange: DateRange = { start: '', end: '' }
  195. export default Vue.extend({
  196. data () {
  197. return {
  198. theme: this.$route.query.theme ?? 'orange',
  199. hideTitle: this.$route.query.hideTitle === 'true',
  200. events: [] as Array<PublicEvent>,
  201. page: 1,
  202. itemsPerPage: 16,
  203. textFilter: null as string | null,
  204. locationFilter: null as Coordinates | null,
  205. dateRangeFilter: defaultDateRange,
  206. totalRecords: 0 as number,
  207. pagesCount: 1 as number | null,
  208. dateUtils: new DatesUtils(this.$dateFns, this.$t, this.$i18n)
  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. })
  227. },
  228. computed: {
  229. dateRangeMin(): string {
  230. return this.dateUtils.todayIso()
  231. },
  232. dateRangePresets(): Array<DateRangePreset> {
  233. // Today
  234. const today_preset: DateRangePreset = {
  235. label: this.$t('today').toString(),
  236. range: {start: this.dateUtils.todayIso(), end: this.dateUtils.todayIso()}
  237. }
  238. // Cette semaine
  239. const week_preset: DateRangePreset = {
  240. label: this.$t('next_week').toString(),
  241. range: {start: this.dateUtils.todayIso(), end: this.dateUtils.formatIso(this.$dateFns.addDays(this.dateUtils.today(), 7))}
  242. }
  243. // Ce week-end
  244. const sunday: Date = this.$dateFns.nextSunday(this.dateUtils.today())
  245. const weekend_preset: DateRangePreset = {
  246. label: this.$t('next_weekend').toString(),
  247. range: {start: this.dateUtils.formatIso(this.$dateFns.addDays(sunday, -2)), end: this.dateUtils.formatIso(sunday)}
  248. }
  249. // Ce mois
  250. const month_preset: DateRangePreset = {
  251. label: this.$t('next_month').toString(),
  252. range: {start: this.dateUtils.todayIso(), end: this.dateUtils.formatIso(this.$dateFns.addMonths(this.dateUtils.today(), 1))}
  253. }
  254. return [today_preset, week_preset, weekend_preset, month_preset]
  255. }
  256. },
  257. methods: {
  258. textFilterChanged (newVal: string) {
  259. this.textFilter = newVal
  260. },
  261. locationFilterChanged (newVal: Coordinates) {
  262. this.locationFilter = newVal
  263. this.search()
  264. },
  265. dateRangeFilterChanged (newVal: DateRange) {
  266. this.dateRangeFilter = newVal
  267. this.search()
  268. },
  269. reinitializeFilters (): void {
  270. this.textFilter = null
  271. this.locationFilter = null
  272. this.dateRangeFilter = defaultDateRange
  273. const addressSearch = this.$refs.addressSearch as any
  274. addressSearch.clear()
  275. this.search()
  276. },
  277. pageUpdated (page: number): void {
  278. this.page = page
  279. this.search()
  280. },
  281. /**
  282. * Update the filteredEvents array
  283. */
  284. search (): void {
  285. this.$fetch()
  286. },
  287. /**
  288. * Enhanced filter for v-autocomplete components
  289. *
  290. * @param _
  291. * @param queryText
  292. * @param itemText
  293. */
  294. enhancedAutocompleteFilter (_: any, queryText: string, itemText: string): boolean {
  295. return normalize(itemText).includes(normalize(queryText))
  296. }
  297. }
  298. })
  299. </script>
  300. <style scoped lang="scss">
  301. @import 'assets/style/variables.scss';
  302. h2 {
  303. color: var(--v-primary-base);
  304. }
  305. .event-card {
  306. height: 100%;
  307. width: 280px;
  308. min-width: 280px;
  309. color: #666666;
  310. }
  311. .event-card .title {
  312. text-transform: uppercase;
  313. }
  314. .event-card .title a {
  315. width: 100%;
  316. text-align: center;
  317. }
  318. .infos td {
  319. vertical-align: top;
  320. text-transform: capitalize;
  321. }
  322. .title {
  323. word-break: normal;
  324. color: var(--v-primary-base);
  325. font-size: 18px;
  326. font-weight: 500;
  327. line-height: 1.6rem;
  328. }
  329. .title a {
  330. text-decoration: none;
  331. }
  332. .icon {
  333. color: var(--v-primary-base);
  334. }
  335. .results-count {
  336. font-size: .8em;
  337. color: #666;
  338. }
  339. .search-actions button {
  340. width: 100%;
  341. height: 36px !important;
  342. }
  343. </style>