index.vue 9.2 KB

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