index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  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="test()">
  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="filteredEvents"
  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="pageCount"
  149. total-visible="9"
  150. color="primary"
  151. />
  152. </template>
  153. </v-data-iterator>
  154. </v-row>
  155. </LayoutContainer>
  156. </template>
  157. <script lang="ts">
  158. import Vue from 'vue'
  159. import sphericDistance from '@/services/utils/geo'
  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. filteredEvents: [] as Array<PublicEvent>,
  171. loading: true,
  172. page: 1,
  173. itemsPerPage: 8,
  174. textFilter: null as string | null,
  175. locationFilter: null as Coordinates | null,
  176. dateRangeFilter: defaultDateRange
  177. }
  178. },
  179. async fetch () {
  180. await new EventsProvider(this.$axios).getBy().then(
  181. (res) => {
  182. this.events = res
  183. this.filteredEvents = res
  184. })
  185. },
  186. computed: {
  187. totalRecords (): number {
  188. return this.filteredEvents.length
  189. },
  190. pageCount (): number {
  191. return Math.floor(this.totalRecords / this.itemsPerPage) + 1
  192. },
  193. dateRangeMin(): string {
  194. return todayIso()
  195. },
  196. dateRangePresets(): Array<DateRangePreset> {
  197. // Today
  198. const today_preset: DateRangePreset = {
  199. label: this.$t('today').toString(),
  200. range: {start: todayIso(), end: todayIso()}
  201. }
  202. // Cette semaine
  203. const week_preset: DateRangePreset = {
  204. label: this.$t('next_week').toString(),
  205. range: {start: todayIso(), end: formatIso(addDays(today(), 7))}
  206. }
  207. // Ce week-end
  208. const sunday: Date = nextSunday(today())
  209. const weekend_preset: DateRangePreset = {
  210. label: this.$t('next_weekend').toString(),
  211. range: {start: formatIso(addDays(sunday, -2)), end: formatIso(sunday)}
  212. }
  213. // Ce mois
  214. const month_preset: DateRangePreset = {
  215. label: this.$t('next_month').toString(),
  216. range: {start: todayIso(), end: formatIso(addMonths(today(), 1))}
  217. }
  218. return [today_preset, week_preset, weekend_preset, month_preset]
  219. }
  220. },
  221. methods: {
  222. test () {
  223. console.log(this.dateRangeFilter)
  224. },
  225. textFilterChanged (newVal: string) {
  226. this.textFilter = newVal
  227. },
  228. locationFilterChanged (newVal: Coordinates) {
  229. this.locationFilter = newVal
  230. this.search()
  231. },
  232. dateRangeFilterChanged (newVal: DateRange) {
  233. this.dateRangeFilter = newVal
  234. this.search()
  235. },
  236. reinitializeFilters (): void {
  237. this.textFilter = null
  238. this.locationFilter = null
  239. this.dateRangeFilter = defaultDateRange
  240. const addressSearch = this.$refs.addressSearch as any
  241. addressSearch.clear()
  242. this.filteredEvents = this.events
  243. },
  244. /**
  245. * Does the event match the current textFilter
  246. * @param event
  247. * @returns {boolean}
  248. */
  249. matchTextFilter (event: PublicEvent): boolean {
  250. if (!this.textFilter) { return true }
  251. return normalize(event.name).includes(normalize(this.textFilter))
  252. },
  253. /**
  254. * Does the event match the current locationFilter
  255. * @param event
  256. * @returns {boolean}
  257. */
  258. matchLocationFilter (event: PublicEvent): boolean {
  259. if (!this.locationFilter) { return true }
  260. if (event.address === null || !event.address.latitude || !event.address.longitude) { return false }
  261. const radius = 30
  262. return sphericDistance(
  263. this.locationFilter.latitude,
  264. this.locationFilter.longitude,
  265. event.address.latitude,
  266. event.address.longitude
  267. ) <= radius
  268. },
  269. /**
  270. * Does the event match each of the page filters
  271. * @param event
  272. * @returns {boolean}
  273. */
  274. matchFilters (event: PublicEvent): boolean {
  275. return this.matchTextFilter(event) &&
  276. this.matchLocationFilter(event)
  277. },
  278. /**
  279. * Update the filteredEvents array
  280. */
  281. search (): void {
  282. this.filteredEvents = this.events.filter((e) => { return this.matchFilters(e) })
  283. },
  284. /**
  285. * Enhanced filter for v-autocomplete components
  286. *
  287. * @param _
  288. * @param queryText
  289. * @param itemText
  290. */
  291. enhancedAutocompleteFilter (_: any, queryText: string, itemText: string): boolean {
  292. return normalize(itemText).includes(normalize(queryText))
  293. }
  294. }
  295. })
  296. </script>
  297. <style scoped lang="scss">
  298. @import 'assets/style/variables.scss';
  299. h2 {
  300. color: var(--v-primary-base);
  301. }
  302. .event-card {
  303. height: 100%;
  304. color: #666666;
  305. }
  306. .infos .col {
  307. padding: 6px 12px;
  308. }
  309. .infos td {
  310. padding: 4px;
  311. vertical-align: top;
  312. }
  313. .infos td:first-child {
  314. padding-top: 6px;
  315. text-align: center;
  316. }
  317. .title {
  318. word-break: normal;
  319. color: var(--v-primary-base);
  320. font-size: 18px;
  321. font-weight: 500;
  322. line-height: 1.6rem;
  323. }
  324. .title a {
  325. text-decoration: none;
  326. }
  327. .icon {
  328. color: var(--v-primary-base);
  329. }
  330. .results-count {
  331. font-size: .8em;
  332. color: #666;
  333. }
  334. </style>