index.vue 12 KB

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