From: mtmail Date: Mon, 31 May 2021 12:09:31 +0000 (+0200) Subject: Helper check for details keywords (#160) X-Git-Url: https://git.openstreetmap.org/nominatim-ui.git/commitdiff_plain/7218a0c36c5b1e28ed46e1e1b133b5e5dd68b2ca?hp=84c511aaea6efd311518f97fcfd301569e247130 Helper check for details keywords (#160) * Details page helper to check if place has 1 or more keywords * add documentation hint how to run only one test file --- diff --git a/CONTRIBUTE.md b/CONTRIBUTE.md index 9c184e4..c910337 100644 --- a/CONTRIBUTE.md +++ b/CONTRIBUTE.md @@ -47,6 +47,12 @@ The `test/` setup uses [Mocha](https://mochajs.org/) to run tests. Tests use [Pu port. That's a rare setup but something https://nominatim.openstreetmap.org/ does so worth testing. + To run a single test file only + + ``` + yarn run rollup -c && yarn run mocha test/details.js + ``` + * Run syntax linter (configuration in `.eslint.js`) ``` diff --git a/src/pages/DetailsPage.svelte b/src/pages/DetailsPage.svelte index baac180..2c7f8ba 100644 --- a/src/pages/DetailsPage.svelte +++ b/src/pages/DetailsPage.svelte @@ -54,6 +54,14 @@ } } + function place_has_keywords(aThisPlace) { + // Return false if Nominatim API sends 'keywords: { name: [], address: [] }' + return ( + aThisPlace.keywords && aThisPlace.keywords.name && aThisPlace.keywords.address + && (aThisPlace.keywords.name.length > 0 || aThisPlace.keywords.address.length > 0) + ); + } + $: { let pageinfo = $page; if (pageinfo.tab === 'details') { @@ -165,7 +173,7 @@

Keywords

{#if api_request_params.keywords} - {#if aPlace.keywords && (aPlace.keywords.name || aPlace.keywords.address) } + {#if place_has_keywords(aPlace)}

Name Keywords

{#each aPlace.keywords.name as keyword}