index.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595
  1. <!-- Search for member structures -->
  2. <template>
  3. <LayoutContainer>
  4. <!-- Header -->
  5. <v-row>
  6. <v-layout>
  7. <h2 class="flex">
  8. {{ $t("member_companies") }}
  9. </h2>
  10. <v-btn-toggle mandatory dense :value="mapview ? 0 : 1" @change="viewChanged">
  11. <v-btn>
  12. {{ $t("map") }}
  13. </v-btn>
  14. <v-btn>
  15. {{ $t("list") }}
  16. </v-btn>
  17. </v-btn-toggle>
  18. </v-layout>
  19. </v-row>
  20. <v-row>
  21. <!-- Map Column (hidden in 'list-view' mode)-->
  22. <v-col
  23. v-show="mapview"
  24. cols="12"
  25. sm="6"
  26. >
  27. <no-ssr>
  28. <UiMapStructures
  29. ref="map"
  30. :structures="filteredStructures"
  31. @boundsUpdated="mapBoundsFilterChanged"
  32. />
  33. </no-ssr>
  34. </v-col>
  35. <!-- Results column -->
  36. <v-col
  37. cols="12"
  38. :sm="mapview ? 6 : 12"
  39. >
  40. <!-- Search form -->
  41. <v-row>
  42. <v-form method="get" class="mt-8 w100">
  43. <v-container>
  44. <v-row>
  45. <v-col cols="12" md="6" class="py-2 px-1">
  46. <v-text-field
  47. v-model="textFilter"
  48. type="text"
  49. outlined
  50. clearable
  51. hide-details
  52. append-icon="mdi-magnify"
  53. :label="$t('what') + ' ?'"
  54. @click:append="search"
  55. @keydown.enter="search"
  56. />
  57. </v-col>
  58. <v-col cols="12" md="6" class="py-2 px-1">
  59. <UiSearchAddress
  60. ref="addressSearch"
  61. type="municipality"
  62. @change="locationFilterChanged"
  63. />
  64. </v-col>
  65. </v-row>
  66. <v-row>
  67. <v-col v-if="listview && $vuetify.breakpoint.mdAndUp" cols="2" class="py-2 px-1">
  68. <v-btn class="h100" @click="reinitializeFilters">
  69. {{ $t('reinitialize') }}
  70. </v-btn>
  71. </v-col>
  72. <v-col :cols="(listview && $vuetify.breakpoint.mdAndUp) ? 8 : 12">
  73. <v-row class="filters">
  74. <v-col lg="3" :md="listview ? 3 : 6" sm="6" cols="12" class="py-2 px-1">
  75. <v-autocomplete
  76. v-model="practicesFilter"
  77. :label="$t('type')"
  78. :items="translatedPractices"
  79. item-value="id"
  80. item-text="label"
  81. filled
  82. hide-details
  83. hide-no-data
  84. :filter="enhancedAutocompleteFilter"
  85. @change="search"
  86. />
  87. </v-col>
  88. <v-col lg="3" :md="listview ? 3 : 6" sm="6" cols="12" class="py-2 px-1">
  89. <v-autocomplete
  90. v-model="departmentFilter"
  91. :items="departments"
  92. item-value="code"
  93. item-text="label"
  94. :label="$t('department')"
  95. filled
  96. hide-details
  97. hide-no-data
  98. :filter="enhancedAutocompleteFilter"
  99. @change="search"
  100. />
  101. </v-col>
  102. <v-col lg="3" :md="listview ? 3 : 6" sm="6" cols="12" class="py-2 px-1">
  103. <v-autocomplete
  104. v-model="federationFilter"
  105. :items="federations"
  106. item-value="id"
  107. item-text="name"
  108. :label="$t('federation')"
  109. filled
  110. hide-details
  111. hide-no-data
  112. :filter="enhancedAutocompleteFilter"
  113. @change="search"
  114. />
  115. </v-col>
  116. <v-col lg="3" :md="listview ? 3 : 6" sm="6" cols="12" class="py-2 px-1">
  117. <v-select
  118. v-model="distanceFilter"
  119. :label="$t('distance')"
  120. :items="[
  121. {distance: 10, label: '10km'},
  122. {distance: 30, label: '30km'},
  123. {distance: 100, label: '100km'},
  124. {distance: 200, label: '200km'}
  125. ]"
  126. item-value="distance"
  127. item-text="label"
  128. filled
  129. hide-details
  130. @change="search"
  131. />
  132. </v-col>
  133. </v-row>
  134. </v-col>
  135. <v-col v-if="listview && $vuetify.breakpoint.mdAndUp" cols="2" class="py-2 px-1 d-flex justify-end">
  136. <v-btn class="h100">
  137. {{ $t('search') }}
  138. </v-btn>
  139. </v-col>
  140. </v-row>
  141. <v-row v-show="mapview || $vuetify.breakpoint.smAndDown" class="px-2 pt-2">
  142. <v-btn @click="reinitializeFilters">
  143. {{ $t('reinitialize') }}
  144. </v-btn>
  145. <v-spacer />
  146. <v-btn @click="search">
  147. {{ $t('search') }}
  148. </v-btn>
  149. </v-row>
  150. </v-container>
  151. </v-form>
  152. </v-row>
  153. <div class="pt-4 mt-6">
  154. <!-- loading skeleton -->
  155. <v-container v-if="$fetchState.pending">
  156. <v-row v-for="i in 3" :key="i" justify="space-between" class="mt-1 mb-3">
  157. <v-col v-for="j in 2" :key="j" cols="12" :md="mapview ? 6 : 12" class="py-2 px-1">
  158. <v-skeleton-loader type="card" :loading="true" />
  159. </v-col>
  160. </v-row>
  161. </v-container>
  162. <!-- Results -->
  163. <v-data-iterator
  164. v-else
  165. :items="onMapFilteredStructures"
  166. :page.sync="page"
  167. :items-per-page="itemsPerPage"
  168. sort-by="name"
  169. hide-default-footer
  170. no-data-text=""
  171. >
  172. <template #header>
  173. <i class="results-count">{{ totalRecords }} {{ $t('results') }}</i>
  174. </template>
  175. <template #default="props">
  176. <v-row justify="space-between" class="mt-1 mb-3">
  177. <v-col
  178. v-for="structure in props.items"
  179. :key="structure.name"
  180. cols="12"
  181. sm="12"
  182. :lg="mapview ? 6 : 12"
  183. class="py-2 px-1"
  184. >
  185. <v-card
  186. elevation="1"
  187. outlined
  188. :class="'structure-card pa-3 d-flex ' + ((mapview || $vuetify.breakpoint.smAndDown) ? 'flex-column' : 'flex-row align-items-center')"
  189. >
  190. <div class="d-flex justify-center max-w100" >
  191. <v-img
  192. v-if="structure.logoId"
  193. :src="'https://api.opentalent.fr/app.php/_internal/secure/files/' + structure.logoId"
  194. alt="poster"
  195. height="80"
  196. width="240"
  197. max-height="100%"
  198. :contain="true"
  199. style="margin: 12px;"
  200. />
  201. <div v-else style="height: 104px; width: 264px"></div>
  202. </div>
  203. <div :class="'d-flex flex-column' + (listview ? ' flex-grow-1' : '')">
  204. <v-card-title class="title">
  205. {{ structure.name }}
  206. </v-card-title>
  207. <v-card-text class="infos">
  208. <table>
  209. <tr>
  210. <td>
  211. <font-awesome-icon class="icon" :icon="['fas', 'map-marker-alt']" />
  212. </td>
  213. <td>
  214. <span v-if="structure.streetAddress">{{ structure.streetAddress }}<br></span>
  215. <span v-if="structure.postalCode" class="postalCode">{{ structure.postalCode }} </span>
  216. {{ structure.addressCity }}
  217. </td>
  218. </tr>
  219. <tr>
  220. <td>
  221. <font-awesome-icon class="icon" :icon="['fas', 'project-diagram']" />
  222. </td>
  223. <td>
  224. <NuxtLink
  225. v-if="structure.n1Id !== parent"
  226. class="neutral"
  227. :to="{path: '/structures/' + structure.n1Id, query: { parent: parent, view: view, theme: theme }}"
  228. nuxt
  229. >
  230. {{ structure.n1Name }}
  231. </NuxtLink>
  232. <div v-else>
  233. {{ structure.n1Name }}
  234. </div>
  235. </td>
  236. </tr>
  237. </table>
  238. </v-card-text>
  239. </div>
  240. <v-chip-group
  241. v-if="structure.practices"
  242. column
  243. active-class="primary--text"
  244. class="d-flex flex-row align-start"
  245. :style="listview ? 'width: 25%;min-width: 25%;' : ''"
  246. >
  247. <v-chip v-for="practice in structure.practices" :key="practice" outlined small pill>
  248. {{ $t(practice) }}
  249. </v-chip>
  250. </v-chip-group>
  251. <span v-if="mapview" class="flex-fill" />
  252. <v-card-actions :class="listview ? 'align-self-end' : ''">
  253. <v-btn
  254. class="see"
  255. :to="{path: '/structures/' + structure.id, query: { parent: parent, view: view, theme: theme }}"
  256. nuxt
  257. >
  258. <span style="margin-right: 6px;">{{ $t("see_more") }}</span>
  259. <font-awesome-icon :icon="['fa', 'caret-right']" />
  260. </v-btn>
  261. </v-card-actions>
  262. </v-card>
  263. </v-col>
  264. </v-row>
  265. </template>
  266. <template #footer>
  267. <v-pagination
  268. v-model="page"
  269. :length="pageCount"
  270. total-visible="9"
  271. color="#e4611b"
  272. />
  273. </template>
  274. </v-data-iterator>
  275. </div>
  276. </v-col>
  277. </v-row>
  278. </LayoutContainer>
  279. </template>
  280. <script lang="ts">
  281. import Vue from 'vue'
  282. import { LatLngBounds } from 'leaflet'
  283. import departments from '@/enums/departments'
  284. import practices from '@/enums/practices'
  285. import sphericDistance from '@/services/utils/geo'
  286. import StructuresProvider from '~/services/data/StructuresProvider'
  287. const CMF_ID = 12097
  288. export default Vue.extend({
  289. validate ({ query }) {
  290. if (!/^\d+$/.test(query.parent as string ?? '')) {
  291. // eslint-disable-next-line no-console
  292. console.error('Missing parameter: parent')
  293. return false
  294. }
  295. if (query.view && !['map', 'list'].includes(query.view as string)) {
  296. // eslint-disable-next-line no-console
  297. console.error('Invalid parameter: view')
  298. return false
  299. }
  300. return true
  301. },
  302. data () {
  303. return {
  304. parent: parseInt(this.$route.query.parent as string),
  305. view: this.$route.query.view ?? 'map',
  306. theme: this.$route.query.theme ?? 'orange',
  307. structures: [] as Array<Structure>,
  308. filteredStructures: [] as Array<Structure>,
  309. federations: [] as Array<{ id: number | null, name: string | null }>,
  310. loading: true,
  311. page: 1,
  312. itemsPerPage: 8,
  313. departments: departments as {code: string, label: string}[],
  314. practices: practices as {id: string}[],
  315. textFilter: null as string | null,
  316. locationFilter: null as Coordinates | null,
  317. practicesFilter: null as string | null,
  318. departmentFilter: null as string | null,
  319. federationFilter: null as number | null,
  320. distanceFilter: null as number | null,
  321. mapBoundsFilter: null as LatLngBounds | null,
  322. mapBoundsFilterStarted: false // map bounds filter is only activated when the map bounds are updated
  323. }
  324. },
  325. async fetch () {
  326. await new StructuresProvider(this.$axios).getAll(this.parent).then(
  327. (res) => {
  328. this.structures = res
  329. this.filteredStructures = res
  330. // populate federations filter
  331. for (const s of res) {
  332. const f = {
  333. id: s.n1Id,
  334. name: s.n1Name
  335. }
  336. if (!this.federations.includes(f)) {
  337. this.federations.push(f)
  338. }
  339. }
  340. // zoom on map markers (except if the parent structure is the CMF)
  341. if (this.parent !== CMF_ID) {
  342. this.fitMapToResults()
  343. }
  344. })
  345. },
  346. computed: {
  347. onMapFilteredStructures (): Array<Structure> {
  348. if (this.mapview && this.mapBoundsFilterStarted) {
  349. return this.filteredStructures.filter((s) => {
  350. return this.matchMapBounds(s)
  351. })
  352. } else {
  353. return this.filteredStructures
  354. }
  355. },
  356. totalRecords (): number {
  357. return this.onMapFilteredStructures.length
  358. },
  359. pageCount (): number {
  360. return Math.floor(this.totalRecords / this.itemsPerPage) + 1
  361. },
  362. mapview (): boolean {
  363. return this.view === 'map'
  364. },
  365. listview (): boolean {
  366. return this.view === 'list'
  367. },
  368. translatedPractices (): Array<{ id: string, label: string }> {
  369. const tPractices = []
  370. for (const practice of this.practices) {
  371. tPractices.push({ id: practice.id, label: this.$t(practice.id) as string })
  372. }
  373. return tPractices
  374. }
  375. },
  376. methods: {
  377. viewChanged (e: number) {
  378. this.view = (e === 0) ? 'map' : 'list'
  379. if (this.mapview) {
  380. this.fitMapToResults()
  381. }
  382. },
  383. textFilterChanged (newVal: string) {
  384. this.textFilter = newVal
  385. },
  386. locationFilterChanged (newVal: Coordinates) {
  387. this.locationFilter = newVal
  388. if (this.distanceFilter === null) {
  389. this.distanceFilter = 10
  390. }
  391. this.search()
  392. },
  393. resetMap (): void {
  394. const map = this.$refs.map as any
  395. map.resetBounds()
  396. if (this.parent !== CMF_ID) {
  397. this.fitMapToResults()
  398. }
  399. this.mapBoundsFilterStarted = false
  400. },
  401. fitMapToResults (): void {
  402. (this.$refs.map as any).zoomOnResults()
  403. },
  404. mapBoundsFilterChanged (newBounds: LatLngBounds) {
  405. this.mapBoundsFilterStarted = true
  406. this.mapBoundsFilter = newBounds
  407. },
  408. reinitializeFilters (): void {
  409. this.textFilter = null
  410. this.locationFilter = null
  411. this.practicesFilter = null
  412. this.departmentFilter = null
  413. this.federationFilter = null
  414. this.distanceFilter = null
  415. this.mapBoundsFilter = null
  416. const addressSearch = this.$refs.addressSearch as any
  417. addressSearch.clear()
  418. this.resetMap()
  419. this.filteredStructures = this.structures
  420. },
  421. /**
  422. * Does the structure match the current textFilter
  423. * @param structure
  424. * @returns {boolean}
  425. */
  426. matchTextFilter (structure: Structure): boolean {
  427. if (!this.textFilter) { return true }
  428. return structure.name.toLowerCase().includes(this.textFilter.toLowerCase())
  429. },
  430. /**
  431. * Does the structure match the current locationFilter
  432. * @param structure
  433. * @returns {boolean}
  434. */
  435. matchLocationFilter (structure: Structure): boolean {
  436. if (!this.locationFilter) { return true }
  437. if (!structure.latitude || !structure.longitude) { return false }
  438. const radius = Number(this.distanceFilter) ?? 5
  439. return sphericDistance(
  440. this.locationFilter.latitude, this.locationFilter.longitude, structure.latitude, structure.longitude
  441. ) <= radius
  442. },
  443. /**
  444. * Does the structure match the current practicesFilter
  445. * @param structure
  446. * @returns {boolean}
  447. */
  448. matchPracticesFilter (structure: Structure): boolean {
  449. if (!this.practicesFilter) { return true }
  450. return structure.practices && structure.practices.includes(this.practicesFilter)
  451. },
  452. /**
  453. * Does the structure match the current departmentFilter
  454. * @param structure
  455. * @returns {boolean}
  456. */
  457. matchDepartmentFilter (structure: Structure): boolean {
  458. if (!this.departmentFilter) { return true }
  459. return structure.postalCode !== null &&
  460. (
  461. structure.postalCode.startsWith(this.departmentFilter) ||
  462. (['2A', '2B'].includes(this.departmentFilter) && structure.postalCode.startsWith('20'))
  463. )
  464. },
  465. /**
  466. * Does the structure match the current federationFilter
  467. * @param structure
  468. * @returns {boolean}
  469. */
  470. matchFederationFilter (structure: Structure): boolean {
  471. if (!this.federationFilter) { return true }
  472. return structure.parents.includes(this.federationFilter)
  473. },
  474. /**
  475. * Does the structure match the current federationFilter
  476. * @param structure
  477. * @returns {boolean}
  478. */
  479. matchMapBounds (structure: Structure): boolean {
  480. if (!this.mapBoundsFilter) { return true }
  481. if (!(structure.latitude && structure.longitude)) { return false }
  482. return this.mapBoundsFilter.getSouth() <= structure.latitude &&
  483. structure.latitude <= this.mapBoundsFilter.getNorth() &&
  484. this.mapBoundsFilter.getWest() <= structure.longitude &&
  485. structure.longitude <= this.mapBoundsFilter.getEast()
  486. },
  487. /**
  488. * Does the structure match each of the page filters
  489. * @param structure
  490. * @returns {boolean}
  491. */
  492. matchFilters (structure: Structure): boolean {
  493. return this.matchTextFilter(structure) &&
  494. this.matchLocationFilter(structure) &&
  495. this.matchPracticesFilter(structure) &&
  496. this.matchDepartmentFilter(structure) &&
  497. this.matchFederationFilter(structure)
  498. },
  499. /**
  500. * Update the filteredStructures array
  501. */
  502. search (): void {
  503. this.filteredStructures = this.structures.filter((s) => { return this.matchFilters(s) })
  504. this.fitMapToResults()
  505. },
  506. autocompleteSearchNormalize (s: string): string {
  507. return s
  508. .toLowerCase()
  509. .replace(/[éèẽëê]/g, 'e')
  510. .replace(/[ç]/g, 'c')
  511. .replace(/[îïĩ]/g, 'i')
  512. .replace(/[àã]/g, 'a')
  513. .replace(/[öôõ]/g, 'o')
  514. .replace(/[ûüũ]/g, 'u')
  515. .replace(/[-]/g, ' ')
  516. .trim()
  517. },
  518. /**
  519. * Enhanced filter for v-autocomplete components
  520. *
  521. * @param _
  522. * @param queryText
  523. * @param itemText
  524. */
  525. enhancedAutocompleteFilter (_: any, queryText: string, itemText: string): boolean {
  526. return this.autocompleteSearchNormalize(itemText).includes(this.autocompleteSearchNormalize(queryText))
  527. }
  528. }
  529. })
  530. </script>
  531. <style scoped lang="scss">
  532. @import 'assets/style/variables.scss';
  533. h2 {
  534. color: var(--v-primary-base);
  535. }
  536. .structure-card {
  537. height: 100%;
  538. color: #666666;
  539. }
  540. .infos .col {
  541. padding: 6px 12px;
  542. }
  543. .infos td {
  544. padding: 4px;
  545. vertical-align: top;
  546. }
  547. .infos td:first-child {
  548. padding-top: 6px;
  549. text-align: center;
  550. }
  551. .title {
  552. word-break: normal;
  553. color: var(--v-primary-base);
  554. font-size: 18px;
  555. font-weight: 500;
  556. line-height: 1.6rem;
  557. }
  558. .icon {
  559. color: var(--v-primary-base);
  560. }
  561. .results-count {
  562. font-size: .8em;
  563. color: #666;
  564. }
  565. </style>