|
|
@@ -53,33 +53,37 @@
|
|
|
<v-row class="filters">
|
|
|
<v-col :cols="3" class="py-2 px-1">
|
|
|
<v-select
|
|
|
+ v-model="typeFilter"
|
|
|
:label="$t('type')"
|
|
|
- :value="textFilter"
|
|
|
+ :items="translatedPractices"
|
|
|
+ item-value="id"
|
|
|
+ item-text="label"
|
|
|
filled
|
|
|
- @change="typeFilterChanged"
|
|
|
/>
|
|
|
</v-col>
|
|
|
<v-col :cols="3" class="py-2 px-1">
|
|
|
<v-select
|
|
|
- :items="departmentsEnum"
|
|
|
+ v-model="departmentFilter"
|
|
|
+ :items="departments"
|
|
|
item-value="code"
|
|
|
item-text="label"
|
|
|
:label="$t('department')"
|
|
|
- :value="departmentFilter"
|
|
|
filled
|
|
|
- @change="departmentFilterChanged"
|
|
|
/>
|
|
|
</v-col>
|
|
|
<v-col :cols="3" class="py-2 px-1">
|
|
|
<v-select
|
|
|
+ v-model="federationFilter"
|
|
|
+ :items="federations"
|
|
|
+ item-value="id"
|
|
|
+ item-text="name"
|
|
|
:label="$t('federation')"
|
|
|
- :value="federationFilter"
|
|
|
filled
|
|
|
- @change="federationFilterChanged"
|
|
|
/>
|
|
|
</v-col>
|
|
|
<v-col :cols="3" class="py-2 px-1">
|
|
|
<v-select
|
|
|
+ v-model="distanceFilter"
|
|
|
:label="$t('distance')"
|
|
|
:items="[
|
|
|
{distance: 10, label: '10km'},
|
|
|
@@ -89,9 +93,7 @@
|
|
|
]"
|
|
|
item-value="distance"
|
|
|
item-text="label"
|
|
|
- :value="distanceFilter"
|
|
|
filled
|
|
|
- @change="distanceFilterChanged"
|
|
|
/>
|
|
|
</v-col>
|
|
|
</v-row>
|
|
|
@@ -215,7 +217,8 @@
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
-import departmentsEnum from '~/plugins/enums'
|
|
|
+import departments from '@/enums/departments'
|
|
|
+import practices from '@/enums/practices'
|
|
|
|
|
|
export default {
|
|
|
data () {
|
|
|
@@ -1799,9 +1802,10 @@ export default {
|
|
|
page: 1,
|
|
|
itemsPerPage: 8,
|
|
|
mapview: true,
|
|
|
- departmentsEnum,
|
|
|
+ departments,
|
|
|
+ practices,
|
|
|
textFilter: '',
|
|
|
- locationFilter: '',
|
|
|
+ locationFilter: null,
|
|
|
typeFilter: null,
|
|
|
departmentFilter: null,
|
|
|
federationFilter: null,
|
|
|
@@ -1821,6 +1825,23 @@ export default {
|
|
|
},
|
|
|
listview () {
|
|
|
return !this.mapview
|
|
|
+ },
|
|
|
+ translatedPractices () {
|
|
|
+ const tPractices = []
|
|
|
+ for (const practice of this.practices) {
|
|
|
+ tPractices.push({ id: practice.id, label: this.$t(practice.id) })
|
|
|
+ }
|
|
|
+ return tPractices
|
|
|
+ },
|
|
|
+ federations () {
|
|
|
+ const federations = []
|
|
|
+ for (const s of this.structures) {
|
|
|
+ const f = { id: s.n1Id, name: s.n1Name }
|
|
|
+ if (!federations.includes(f)) {
|
|
|
+ federations.push(f)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return federations
|
|
|
}
|
|
|
},
|
|
|
methods: {
|
|
|
@@ -1832,18 +1853,9 @@ export default {
|
|
|
},
|
|
|
locationFilterChanged (newVal) {
|
|
|
this.locationFilter = newVal
|
|
|
- },
|
|
|
- typeFilterChanged (newVal) {
|
|
|
- this.typeFilter = newVal
|
|
|
- },
|
|
|
- departmentFilterChanged (newVal) {
|
|
|
- this.departmentFilter = newVal
|
|
|
- },
|
|
|
- federationFilterChanged (newVal) {
|
|
|
- this.federationFilter = newVal
|
|
|
- },
|
|
|
- distanceFilterChanged (newVal) {
|
|
|
- this.distanceFilter = newVal
|
|
|
+ if (this.distanceFilter === null) {
|
|
|
+ this.distanceFilter = 10
|
|
|
+ }
|
|
|
},
|
|
|
mapBoundsFilterChanged (newBounds) {
|
|
|
this.mapBoundsFilter = newBounds
|
|
|
@@ -1857,6 +1869,23 @@ export default {
|
|
|
this.distanceFilter = null
|
|
|
this.mapBoundsFilter = null
|
|
|
},
|
|
|
+ toRad (val) {
|
|
|
+ // Converts numeric degrees to radians
|
|
|
+ return val * Math.PI / 180
|
|
|
+ },
|
|
|
+ sphericDistance (lat1, lon1, lat2, lon2) {
|
|
|
+ // This function takes in latitude and longitude of two location and returns the distance between them as the crow flies (in km)
|
|
|
+ const R = 6371 // km
|
|
|
+ const dLat = this.toRad(lat2 - lat1)
|
|
|
+ const dLon = this.toRad(lon2 - lon1)
|
|
|
+ lat1 = this.toRad(lat1)
|
|
|
+ lat2 = this.toRad(lat2)
|
|
|
+
|
|
|
+ const a = Math.sin(dLat / 2) * Math.sin(dLat / 2) +
|
|
|
+ Math.sin(dLon / 2) * Math.sin(dLon / 2) * Math.cos(lat1) * Math.cos(lat2)
|
|
|
+ const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a))
|
|
|
+ return R * c
|
|
|
+ },
|
|
|
matchFilters (structure) {
|
|
|
// Filter by name
|
|
|
if (this.textFilter && !structure.name.toLowerCase().includes(this.textFilter.toLowerCase())) {
|
|
|
@@ -1864,23 +1893,28 @@ export default {
|
|
|
}
|
|
|
|
|
|
// filter by geographical position
|
|
|
- // if (query['lat'] && query['long']) {
|
|
|
- // if (!structure.latitude || !structure.longitude) {
|
|
|
- // return false;
|
|
|
- // }
|
|
|
- //
|
|
|
- // let radius = Number(query['radius']) ?? 0;
|
|
|
- //
|
|
|
- // // radius is increased by 10km to approximate the city radius
|
|
|
- // radius += 10;
|
|
|
- //
|
|
|
- // if (sphericDistance(query['lat'], query['long'], structure.latitude, structure.longitude) > radius) {
|
|
|
- // return false;
|
|
|
- // }
|
|
|
- // }
|
|
|
+ if (this.locationFilter) {
|
|
|
+ if (!structure.latitude || !structure.longitude) {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+
|
|
|
+ let radius = Number(this.distanceFilter) ?? 0
|
|
|
+
|
|
|
+ // radius is always increased by 10km to approximate the city radius
|
|
|
+ radius += 10
|
|
|
+
|
|
|
+ if (this.sphericDistance(
|
|
|
+ this.locationFilter.latitude,
|
|
|
+ this.locationFilter.longitude,
|
|
|
+ Number.parseFloat(structure.latitude),
|
|
|
+ Number.parseFloat(structure.longitude)) > radius
|
|
|
+ ) {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
// filter by practice
|
|
|
- if (this.typeFilter && !structure.practices.split(',').includes(this.typeFilter)) {
|
|
|
+ if (this.typeFilter && (!structure.practices || !structure.practices.split(',').includes(this.typeFilter))) {
|
|
|
return false
|
|
|
}
|
|
|
|