From 971e362a6c6b00fd0dbdde018802ac7943ae81ee Mon Sep 17 00:00:00 2001 From: sdirollo Date: Tue, 17 Oct 2023 12:20:19 +0200 Subject: [PATCH 1/5] Use qwant_id param for poi --- @types/idunn.ts | 2 ++ src/adapters/poi/idunn_poi.ts | 15 ++++++++++++--- src/adapters/poi/latlon_poi.ts | 2 +- src/adapters/poi/map_poi.js | 10 ++++++++-- src/adapters/poi/poi.ts | 8 ++++++-- src/adapters/poi_popup.js | 5 ++++- src/adapters/scene.js | 1 - src/libs/pois.js | 2 +- 8 files changed, 34 insertions(+), 11 deletions(-) diff --git a/@types/idunn.ts b/@types/idunn.ts index 4dce12de..6f4aa9e8 100644 --- a/@types/idunn.ts +++ b/@types/idunn.ts @@ -1178,6 +1178,8 @@ export interface components { type: string; /** Id */ id?: string; + /** Qwant Id */ + qwant_id?: string; /** Name */ name?: string; /** Local Name */ diff --git a/src/adapters/poi/idunn_poi.ts b/src/adapters/poi/idunn_poi.ts index 8d4d4593..28aac59c 100644 --- a/src/adapters/poi/idunn_poi.ts +++ b/src/adapters/poi/idunn_poi.ts @@ -34,7 +34,15 @@ export default class IdunnPoi extends Poi { lng: (rawPoi?.geometry?.coordinates as number[])[0], } as TPoi['latLon']; - super(rawPoi.id, rawPoi.name, rawPoi.type, latLng, rawPoi.class_name, rawPoi.subclass_name); + super( + rawPoi.id, + rawPoi.id, + rawPoi.name, + rawPoi.type, + latLng, + rawPoi.class_name, + rawPoi.subclass_name + ); this.blocks = rawPoi.blocks; this.localName = rawPoi.local_name; this.bbox = rawPoi?.geometry?.bbox as [number, number, number, number]; // TODO: Check if there is always a bbox on Idunn Place @@ -115,11 +123,12 @@ export default class IdunnPoi extends Poi { static async poiApiLoad( obj: { id?: string; + qwant_id?: string; queryContext?: TQueryContext; }, options: { simple?: boolean } = {} ) { - const url = `${serviceConfig.idunn.url}/v1/places/${obj.id}`; + const url = `${serviceConfig.idunn.url}/v1/places/${obj.qwant_id}`; let requestParams = {}; if (options.simple) { requestParams = { verbosity: 'list' }; @@ -140,7 +149,7 @@ export default class IdunnPoi extends Poi { // When the OPTIONS request is rejected, the error is 0 and not 405 console.warn("Headers aren't allowed, sending query without them..."); obj.queryContext = undefined; - return this.poiApiLoad(obj); + // return this.poiApiLoad(obj); } const s_requestParams = JSON.stringify(requestParams); Error.sendOnce( diff --git a/src/adapters/poi/latlon_poi.ts b/src/adapters/poi/latlon_poi.ts index 3f055431..096fee32 100644 --- a/src/adapters/poi/latlon_poi.ts +++ b/src/adapters/poi/latlon_poi.ts @@ -14,7 +14,7 @@ export default class LatLonPoi extends Poi { if (!label) { label = `${lnglat.lat.toFixed(5)} : ${lnglat.lng.toFixed(5)}`; } - super(id, label, undefined, lnglat, undefined, undefined); + super(id, undefined, label, undefined, lnglat, undefined, undefined); this.type = 'latlon'; } } diff --git a/src/adapters/poi/map_poi.js b/src/adapters/poi/map_poi.js index 2cc9c411..4ee4c4f4 100644 --- a/src/adapters/poi/map_poi.js +++ b/src/adapters/poi/map_poi.js @@ -3,8 +3,14 @@ import Poi, { POI_TYPE } from './poi'; export default class MapPoi extends Poi { constructor(feature) { - const { global_id, ['class']: className, subclass: subClassName, name } = feature.properties; + const { + global_id, + ['class']: className, + subclass: subClassName, + name, + qwant_id, + } = feature.properties; const ll = LngLat.convert(feature.geometry.coordinates); - super(global_id || feature.id, name, POI_TYPE, ll, className, subClassName); + super(global_id || feature.id, qwant_id, name, POI_TYPE, ll, className, subClassName); } } diff --git a/src/adapters/poi/poi.ts b/src/adapters/poi/poi.ts index 26f15f16..6c610494 100644 --- a/src/adapters/poi/poi.ts +++ b/src/adapters/poi/poi.ts @@ -7,6 +7,7 @@ export const POI_TYPE = 'poi'; export type TPoi = { id?: string; + qwant_id?: string; name?: string; type?: string; latLon?: LngLat; @@ -17,6 +18,7 @@ export type TPoi = { export default class Poi { id: TPoi['id']; + qwant_id: TPoi['qwant_id']; name: TPoi['name']; type: TPoi['type']; latLon: TPoi['latLon']; @@ -26,6 +28,7 @@ export default class Poi { constructor( id: TPoi['id'], + qwant_id: TPoi['qwant_id'], name: TPoi['name'], type: TPoi['type'], latLon: TPoi['latLon'], @@ -34,6 +37,7 @@ export default class Poi { bbox?: TPoi['bbox'] ) { this.id = id; + this.qwant_id = qwant_id; this.name = name; this.type = type; this.latLon = latLon; @@ -43,7 +47,7 @@ export default class Poi { } static deserialize(raw: TPoi) { - const { id, name, type, latLon, className, subClassName, bbox } = raw; - return new Poi(id, name, type, latLon, className, subClassName, bbox); + const { id, qwant_id, name, type, latLon, className, subClassName, bbox } = raw; + return new Poi(id, qwant_id, name, type, latLon, className, subClassName, bbox); } } diff --git a/src/adapters/poi_popup.js b/src/adapters/poi_popup.js index f4d20444..bcf6f330 100644 --- a/src/adapters/poi_popup.js +++ b/src/adapters/poi_popup.js @@ -67,7 +67,10 @@ PoiPopup.prototype.addListener = function (layer) { }; PoiPopup.prototype.createOSMPopup = async function (layerPoi, event) { - const poi = await ApiPoi.poiApiLoad({ id: layerPoi.properties.global_id }, { simple: true }); + const poi = await ApiPoi.poiApiLoad( + { id: layerPoi.properties.global_id, qwant_id: layerPoi.properties.qwant_id }, + { simple: true } + ); if (poi) { this.showPopup(poi, event); } diff --git a/src/adapters/scene.js b/src/adapters/scene.js index 086600db..026b1320 100644 --- a/src/adapters/scene.js +++ b/src/adapters/scene.js @@ -321,7 +321,6 @@ Scene.prototype.initMapBox = function ({ locationHash, bbox }) { Scene.prototype.clickOnMap = function (lngLat, clickedFeature, { longTouch = false } = {}) { // Instantiate the place clicked as a PoI const poi = clickedFeature ? new MapPoi(clickedFeature) : new LatLonPoi(lngLat); - if (document.querySelector('.directions-open')) { // If Direction panel is open, tell it to fill its fields with this PoI fire('set_direction_point', poi); diff --git a/src/libs/pois.js b/src/libs/pois.js index c240eb9d..7281e86f 100644 --- a/src/libs/pois.js +++ b/src/libs/pois.js @@ -9,7 +9,7 @@ export function toUrl(poi) { if (poi.id === 'geolocalisation' || poi.type === 'latlon') { return `latlon:${poi.latLon.lat.toFixed(5)}:${poi.latLon.lng.toFixed(5)}`; } - return poi.name ? `${poi.id}@${slug(poi.name)}` : poi.id; + return poi.name ? `${poi.qwant_id}@${slug(poi.name)}` : poi.qwant_id; } export function toAbsoluteUrl(poi) { From cf29dd7c526892d5dbc07c9f78b3bf0b129540b9 Mon Sep 17 00:00:00 2001 From: sdirollo Date: Tue, 17 Oct 2023 12:22:10 +0200 Subject: [PATCH 2/5] remove comment --- src/adapters/poi/idunn_poi.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/adapters/poi/idunn_poi.ts b/src/adapters/poi/idunn_poi.ts index 28aac59c..17c0398a 100644 --- a/src/adapters/poi/idunn_poi.ts +++ b/src/adapters/poi/idunn_poi.ts @@ -149,7 +149,7 @@ export default class IdunnPoi extends Poi { // When the OPTIONS request is rejected, the error is 0 and not 405 console.warn("Headers aren't allowed, sending query without them..."); obj.queryContext = undefined; - // return this.poiApiLoad(obj); + return this.poiApiLoad(obj); } const s_requestParams = JSON.stringify(requestParams); Error.sendOnce( From a285038f35b4109fcfec83e0a0cddcbba0c30ff7 Mon Sep 17 00:00:00 2001 From: sdirollo Date: Tue, 17 Oct 2023 12:28:47 +0200 Subject: [PATCH 3/5] fix latlon call --- src/adapters/poi/latlon_poi.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/adapters/poi/latlon_poi.ts b/src/adapters/poi/latlon_poi.ts index 096fee32..afc215fd 100644 --- a/src/adapters/poi/latlon_poi.ts +++ b/src/adapters/poi/latlon_poi.ts @@ -14,7 +14,7 @@ export default class LatLonPoi extends Poi { if (!label) { label = `${lnglat.lat.toFixed(5)} : ${lnglat.lng.toFixed(5)}`; } - super(id, undefined, label, undefined, lnglat, undefined, undefined); + super(id, id, label, undefined, lnglat, undefined, undefined); this.type = 'latlon'; } } From 53ef8821fdab926098c38f5dcc5ea72b5f37802a Mon Sep 17 00:00:00 2001 From: sdirollo Date: Tue, 17 Oct 2023 14:05:28 +0200 Subject: [PATCH 4/5] fix bragi poi autocomplete --- src/adapters/poi/bragi_poi.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/adapters/poi/bragi_poi.js b/src/adapters/poi/bragi_poi.js index e0c0644c..d35badf0 100644 --- a/src/adapters/poi/bragi_poi.js +++ b/src/adapters/poi/bragi_poi.js @@ -45,6 +45,7 @@ export default class BragiPoi extends Poi { } super( + id, id, name, type, From f962c045e99079220021ef15cf9df93c15d15119 Mon Sep 17 00:00:00 2001 From: sdirollo Date: Tue, 17 Oct 2023 14:38:55 +0200 Subject: [PATCH 5/5] fix tests --- src/adapters/poi/specials/navigator_geolocalisation_poi.js | 2 +- src/libs/pois.js | 2 +- tests/integration/favorites_tools.js | 4 ++-- tests/integration/tools.js | 1 + 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/adapters/poi/specials/navigator_geolocalisation_poi.js b/src/adapters/poi/specials/navigator_geolocalisation_poi.js index 39f102cf..ffe0e718 100644 --- a/src/adapters/poi/specials/navigator_geolocalisation_poi.js +++ b/src/adapters/poi/specials/navigator_geolocalisation_poi.js @@ -12,7 +12,7 @@ export const navigatorGeolocationStatus = { }; export default class NavigatorGeolocalisationPoi extends Poi { constructor() { - super('geolocalisation', _('Your position', 'direction'), 'geoloc'); + super('geolocalisation', 'geolocalisation', _('Your position', 'direction'), 'geoloc'); this.status = navigatorGeolocationStatus.UNKNOWN; } diff --git a/src/libs/pois.js b/src/libs/pois.js index 7281e86f..7840ba9f 100644 --- a/src/libs/pois.js +++ b/src/libs/pois.js @@ -36,7 +36,7 @@ export function fromUrl(urlParam) { urlData = urlParam.match(/^(.*?)(@(.*))?$/); if (urlData) { const idunnId = urlData[1]; - return IdunnPoi.poiApiLoad({ id: idunnId }); + return IdunnPoi.poiApiLoad({ id: idunnId, qwant_id: idunnId }); } return Promise.reject(); } diff --git a/tests/integration/favorites_tools.js b/tests/integration/favorites_tools.js index 73a154c5..4a8dbf6d 100644 --- a/tests/integration/favorites_tools.js +++ b/tests/integration/favorites_tools.js @@ -38,9 +38,9 @@ export async function toggleFavoritePanel(page) { export async function storePoi( page, - { id = 'A', title = 'poi', coords = { lat: 43, lng: 2 } } = {} + { id = 'A', qwant_id = 'A', title = 'poi', coords = { lat: 43, lng: 2 } } = {} ) { - const poi = new Poi(id, title, 'poi', coords, '', ''); + const poi = new Poi(id, qwant_id, title, 'poi', coords, '', ''); await page.evaluate( (storageKey, serializedPoi) => { window.localStorage.setItem(storageKey, serializedPoi); diff --git a/tests/integration/tools.js b/tests/integration/tools.js index 3752419e..df861040 100644 --- a/tests/integration/tools.js +++ b/tests/integration/tools.js @@ -63,6 +63,7 @@ export async function simulateClickOnMapPoi(page, poi) { const mapPoiMock = { properties: { global_id: poi.id, + qwant_id: poi.id, name: poi.name, }, geometry: poi.geometry,