|
|
@@ -266,31 +266,33 @@
|
|
|
</LayoutContainer>
|
|
|
</template>
|
|
|
|
|
|
-<script>
|
|
|
+<script lang="ts">
|
|
|
+import Vue from 'vue'
|
|
|
import departments from '@/enums/departments'
|
|
|
import practices from '@/enums/practices'
|
|
|
import sphericDistance from '@/services/utils/geo'
|
|
|
import StructuresProvider from '~/services/data/StructuresProvider'
|
|
|
+import { LatLngBoundsExpression } from 'leaflet'
|
|
|
|
|
|
-export default {
|
|
|
+export default Vue.extend({
|
|
|
data () {
|
|
|
return {
|
|
|
- structures: [],
|
|
|
- filteredStructures: [],
|
|
|
- federations: [],
|
|
|
+ structures: [] as Array<Structure>,
|
|
|
+ filteredStructures: [] as Array<Structure>,
|
|
|
+ federations: [] as Array<{ id: number | null, name: string | null }>,
|
|
|
loading: true,
|
|
|
page: 1,
|
|
|
itemsPerPage: 8,
|
|
|
mapview: true,
|
|
|
- departments,
|
|
|
- practices,
|
|
|
- textFilter: '',
|
|
|
- locationFilter: null,
|
|
|
- practicesFilter: null,
|
|
|
- departmentFilter: null,
|
|
|
- federationFilter: null,
|
|
|
- distanceFilter: null,
|
|
|
- mapBoundsFilter: null,
|
|
|
+ departments: departments as {code: string, label: string}[],
|
|
|
+ practices: practices as {id: string}[],
|
|
|
+ textFilter: null as string | null,
|
|
|
+ locationFilter: null as Address | null,
|
|
|
+ practicesFilter: null as string | null,
|
|
|
+ departmentFilter: null as string | null,
|
|
|
+ federationFilter: null as number | null,
|
|
|
+ distanceFilter: null as number | null,
|
|
|
+ mapBoundsFilter: null as LatLngBoundsExpression | null,
|
|
|
mapBoundsFilterStarted: false // map bounds filter is only activated when the map bounds are updated
|
|
|
}
|
|
|
},
|
|
|
@@ -313,54 +315,54 @@ export default {
|
|
|
})
|
|
|
},
|
|
|
computed: {
|
|
|
- totalRecords () {
|
|
|
+ onMapFilteredStructures (): Array<Structure> {
|
|
|
+ if (this.mapBoundsFilterStarted) {
|
|
|
+ return this.filteredStructures.filter((s) => {
|
|
|
+ return this.matchMapBounds(s)
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ return this.filteredStructures
|
|
|
+ }
|
|
|
+ },
|
|
|
+ totalRecords (): number {
|
|
|
return this.onMapFilteredStructures.length
|
|
|
},
|
|
|
- pageCount () {
|
|
|
+ pageCount (): number {
|
|
|
return Math.floor(this.totalRecords / this.itemsPerPage) + 1
|
|
|
},
|
|
|
- listview () {
|
|
|
+ listview (): boolean {
|
|
|
return !this.mapview
|
|
|
},
|
|
|
- translatedPractices () {
|
|
|
+ translatedPractices (): Array<{ id: string, label: string }> {
|
|
|
const tPractices = []
|
|
|
for (const practice of this.practices) {
|
|
|
- tPractices.push({ id: practice.id, label: this.$t(practice.id) })
|
|
|
+ tPractices.push({ id: practice.id, label: this.$t(practice.id) as string })
|
|
|
}
|
|
|
return tPractices
|
|
|
- },
|
|
|
- onMapFilteredStructures () {
|
|
|
- if (this.mapBoundsFilterStarted) {
|
|
|
- return this.filteredStructures.filter((s) => {
|
|
|
- return this.matchMapBounds(s)
|
|
|
- })
|
|
|
- } else {
|
|
|
- return this.filteredStructures
|
|
|
- }
|
|
|
}
|
|
|
},
|
|
|
methods: {
|
|
|
- viewChanged (e) {
|
|
|
+ viewChanged (e: number) {
|
|
|
this.mapview = (e === 0)
|
|
|
},
|
|
|
- textFilterChanged (newVal) {
|
|
|
+ textFilterChanged (newVal: string) {
|
|
|
this.textFilter = newVal
|
|
|
},
|
|
|
- locationFilterChanged (newVal) {
|
|
|
+ locationFilterChanged (newVal: Address) {
|
|
|
this.locationFilter = newVal
|
|
|
if (this.distanceFilter === null) {
|
|
|
this.distanceFilter = 10
|
|
|
}
|
|
|
this.search()
|
|
|
},
|
|
|
- fitMapToResults () {
|
|
|
- this.$refs.map.zoomOnResults()
|
|
|
+ fitMapToResults (): void {
|
|
|
+ (this.$refs.map as any).zoomOnResults()
|
|
|
},
|
|
|
- mapBoundsFilterChanged (newBounds) {
|
|
|
+ mapBoundsFilterChanged (newBounds: LatLngBoundsExpression) {
|
|
|
this.mapBoundsFilterStarted = true
|
|
|
this.mapBoundsFilter = newBounds
|
|
|
},
|
|
|
- reinitializeFilters () {
|
|
|
+ reinitializeFilters (): void {
|
|
|
this.textFilter = null
|
|
|
this.locationFilter = null
|
|
|
this.practicesFilter = null
|
|
|
@@ -377,7 +379,7 @@ export default {
|
|
|
* @param structure
|
|
|
* @returns {boolean}
|
|
|
*/
|
|
|
- matchTextFilter (structure) {
|
|
|
+ matchTextFilter (structure: Structure): boolean {
|
|
|
if (!this.textFilter) { return true }
|
|
|
|
|
|
return structure.name.toLowerCase().includes(this.textFilter.toLowerCase())
|
|
|
@@ -387,7 +389,7 @@ export default {
|
|
|
* @param structure
|
|
|
* @returns {boolean}
|
|
|
*/
|
|
|
- matchLocationFilter (structure) {
|
|
|
+ matchLocationFilter (structure: Structure): boolean {
|
|
|
if (!this.locationFilter) { return true }
|
|
|
if (!structure.latitude || !structure.longitude) { return false }
|
|
|
|
|
|
@@ -402,7 +404,7 @@ export default {
|
|
|
* @param structure
|
|
|
* @returns {boolean}
|
|
|
*/
|
|
|
- matchPracticesFilter (structure) {
|
|
|
+ matchPracticesFilter (structure: Structure): boolean {
|
|
|
if (!this.practicesFilter) { return true }
|
|
|
return structure.practices && structure.practices.includes(this.practicesFilter)
|
|
|
},
|
|
|
@@ -411,7 +413,7 @@ export default {
|
|
|
* @param structure
|
|
|
* @returns {boolean}
|
|
|
*/
|
|
|
- matchDepartmentFilter (structure) {
|
|
|
+ matchDepartmentFilter (structure: Structure): boolean {
|
|
|
if (!this.departmentFilter) { return true }
|
|
|
return structure.postalCode.startsWith(this.departmentFilter)
|
|
|
},
|
|
|
@@ -420,7 +422,7 @@ export default {
|
|
|
* @param structure
|
|
|
* @returns {boolean}
|
|
|
*/
|
|
|
- matchFederationFilter (structure) {
|
|
|
+ matchFederationFilter (structure: Structure): boolean {
|
|
|
if (!this.federationFilter) { return true }
|
|
|
return structure.parents.includes(Number(this.federationFilter))
|
|
|
},
|
|
|
@@ -429,9 +431,12 @@ export default {
|
|
|
* @param structure
|
|
|
* @returns {boolean}
|
|
|
*/
|
|
|
- matchMapBounds (structure) {
|
|
|
+ matchMapBounds (structure: Structure): boolean {
|
|
|
if (!this.mapBoundsFilter) { return true }
|
|
|
- return this.mapBoundsFilter.getSouth() <= structure.latitude &&
|
|
|
+ return structure.latitude && structure.longitude &&
|
|
|
+ typeof structure.latitude !== 'undefined' &&
|
|
|
+ typeof structure.longitude !== 'undefined' &&
|
|
|
+ this.mapBoundsFilter.getSouth() <= structure.latitude &&
|
|
|
structure.latitude <= this.mapBoundsFilter.getNorth() &&
|
|
|
this.mapBoundsFilter.getWest() <= structure.longitude &&
|
|
|
structure.longitude <= this.mapBoundsFilter.getEast()
|
|
|
@@ -441,7 +446,7 @@ export default {
|
|
|
* @param structure
|
|
|
* @returns {boolean}
|
|
|
*/
|
|
|
- matchFilters (structure) {
|
|
|
+ matchFilters (structure: Structure): boolean {
|
|
|
return this.matchTextFilter(structure) &&
|
|
|
this.matchLocationFilter(structure) &&
|
|
|
this.matchPracticesFilter(structure) &&
|
|
|
@@ -452,12 +457,12 @@ export default {
|
|
|
/**
|
|
|
* Update the filteredStructures array
|
|
|
*/
|
|
|
- search () {
|
|
|
+ search (): void {
|
|
|
this.filteredStructures = this.structures.filter((s) => { return this.matchFilters(s) })
|
|
|
this.fitMapToResults()
|
|
|
}
|
|
|
}
|
|
|
-}
|
|
|
+})
|
|
|
</script>
|
|
|
|
|
|
<style scoped lang="scss">
|