From 76726997b1dbe983bc6a9956472935c174c7b6e7 Mon Sep 17 00:00:00 2001 From: Raphael Odini Date: Sun, 7 Jan 2024 23:51:51 +0100 Subject: [PATCH 1/3] New api getLocationByOSMTypeAndId --- src/services/api.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/services/api.js b/src/services/api.js index 0cfd560a7d2..66896a4eb1b 100644 --- a/src/services/api.js +++ b/src/services/api.js @@ -103,6 +103,17 @@ export default { .then((response) => response.json()) }, + getLocationByOSMTypeAndId(locationOSMType, locationOSMId) { + const url = `${import.meta.env.VITE_OPEN_PRICES_API_URL}/locations/osm/${locationOSMType}/${locationOSMId}` + return fetch(url, { + method: 'GET', + headers: { + 'Content-Type': 'application/json', + }, + }) + .then((response) => response.json()) + }, + openfoodfactsProductSearch(code) { return fetch(`${OPENFOODFACTS_PRODUCT_URL}/${code}.json`, { method: 'GET', From 275fbb6024bcd3ee49a5c1f82f9f3900968a355d Mon Sep 17 00:00:00 2001 From: Raphael Odini Date: Sun, 7 Jan 2024 23:59:08 +0100 Subject: [PATCH 2/3] Update route from /id to /osmtype/osmid --- src/components/PriceCard.vue | 2 +- src/router.js | 2 +- src/views/LocationDetail.vue | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/components/PriceCard.vue b/src/components/PriceCard.vue index c87650cf561..63b4d04d4f1 100644 --- a/src/components/PriceCard.vue +++ b/src/components/PriceCard.vue @@ -213,7 +213,7 @@ export default { if (this.readonly) { return } - this.$router.push({ path: `/locations/${this.price.location_id}` }) + this.$router.push({ path: `/locations/${this.price.location_osm_type.toLowerCase()}/${this.price.location_osm_id}` }) }, goToUser() { if (this.readonly) { diff --git a/src/router.js b/src/router.js index f12ef33bc19..b85e2d547cc 100644 --- a/src/router.js +++ b/src/router.js @@ -21,7 +21,7 @@ const routes = [ { path: '/add/single', name: 'add-price-single', component: AddPriceSingle, meta: { title: 'Add a single price', requiresAuth: true }}, { path: '/prices', name: 'prices', component: PriceList, meta: { title: 'Latest prices', icon: 'mdi-tag-multiple-outline', drawerMenu: true }}, { path: '/products/:id', name: 'product-detail', component: ProductDetail, meta: { title: 'Product detail' }}, - { path: '/locations/:id', name: 'location-detail', component: LocationDetail, meta: { title: 'Location detail' }}, + { path: '/locations/:osmtype/:osmid', name: 'location-detail', component: LocationDetail, meta: { title: 'Location detail' }}, { path: '/users/:username', name: 'user-detail', component: UserDetail, meta: { title: 'User detail' }}, { path: '/stats', name: 'stats', component: Stats, meta: { title: 'Stats' }}, { path: '/:path(.*)', component: NotFound }, diff --git a/src/views/LocationDetail.vue b/src/views/LocationDetail.vue index 0a7abb17e00..283d63904fa 100644 --- a/src/views/LocationDetail.vue +++ b/src/views/LocationDetail.vue @@ -65,7 +65,7 @@ export default { }, methods: { getLocation() { - return api.getLocationById(this.$route.params.id) + return api.getLocationByOSMTypeAndId(this.$route.params.osmtype, this.$route.params.osmid) .then((data) => { if (data.id) { this.location = data @@ -75,7 +75,7 @@ export default { getLocationPrices() { this.loading = true this.locationPricePage += 1 - return api.getPrices({ location_id: this.$route.params.id, page: this.locationPricePage }) + return api.getPrices({ location_osm_type: this.$route.params.osmtype.toUpperCase(), location_osm_id: this.$route.params.osmid, page: this.locationPricePage }) .then((data) => { this.locationPriceList.push(...data.items) this.locationPriceTotal = data.total @@ -86,7 +86,7 @@ export default { if (location) { return utils.getLocationTitle(location, true) } - return this.$route.params.id + return `${this.$route.params.osmtype} ${this.$route.params.osmid}` }, getLocationOSMUrl(location) { return `https://www.openstreetmap.org/${location.osm_type.toLowerCase()}/${location.osm_id}` From 1d04fca3e366ed11df068b603d6ca4f5e5741541 Mon Sep 17 00:00:00 2001 From: Raphael Odini Date: Mon, 8 Jan 2024 00:08:32 +0100 Subject: [PATCH 3/3] Improve display when location not found --- src/views/LocationDetail.vue | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/views/LocationDetail.vue b/src/views/LocationDetail.vue index 283d63904fa..12f9efdc3c5 100644 --- a/src/views/LocationDetail.vue +++ b/src/views/LocationDetail.vue @@ -9,13 +9,18 @@ - - - + + + OpenStreetMap -

- Location not found in OpenStreetMap... Don't hesitate to add it :) + + + + + +

+ Location not found in our database...

@@ -88,8 +93,11 @@ export default { } return `${this.$route.params.osmtype} ${this.$route.params.osmid}` }, - getLocationOSMUrl(location) { - return `https://www.openstreetmap.org/${location.osm_type.toLowerCase()}/${location.osm_id}` + getLocationOSMUrl() { + if (this.location) { + return `https://www.openstreetmap.org/${this.location.osm_type.toLowerCase()}/${this.location.osm_id}` + } + return `https://www.openstreetmap.org/${this.$route.params.osmtype.toLowerCase()}/${this.$route.params.osmid}` } } }