]> git.openstreetmap.org Git - nominatim-ui.git/commitdiff
new config option -Reverse_Only- (#166)
authormtmail <mtmail@gmx.net>
Wed, 27 Oct 2021 16:33:10 +0000 (18:33 +0200)
committerGitHub <noreply@github.com>
Wed, 27 Oct 2021 16:33:10 +0000 (18:33 +0200)
12 files changed:
.github/workflows/ci.yml
dist/config.defaults.js
dist/search.html
src/components/DetailsOneRow.svelte
src/components/Error.svelte
src/components/Header.svelte
src/lib/stores.js
src/pages/DetailsPage.svelte
test/_bootstrap.js
test/config_reverse_only.js [new file with mode: 0644]
test/details.js
test/search.js

index 58331309b7932bca59a9f0c5c4291133b0589de6..a8c25aca7a3776c61d116f26a6e2add1222de575 100644 (file)
@@ -26,6 +26,10 @@ jobs:
         run: yarn build
       
       - name: Testing
-        run: |
-          yarn test
-          API_ON_SAME_PORT=1 yarn test
+        run: yarn test
+
+      - name: Testing API_ON_SAME_PORT
+        run: API_ON_SAME_PORT=1 yarn test
+
+      - name: Testing REVERSE_ONLY
+        run: REVERSE_ONLY=1 yarn test
index ccbddfc362b3c6d19263098579c8b8046aaee769..1ab8bd938a7b25a4e5b2866cb8233bfd24f67757 100644 (file)
@@ -12,6 +12,9 @@ let Nominatim_Config = {
   // Additional query parameters for Nominatim API.
   Nominatim_API_Endpoint_Params: {},
 
+  // If database has no search index, then hide search page
+  Reverse_Only: false,
+
   // relative path or full URL
   Images_Base_Url: 'mapicons/',
 
index 99aa904a971efe3bc8dd458cf6882623ce4e9013..5e19ab7e1bee041cedac061913f08e7d17377ee3 100644 (file)
 
   <script src='config.defaults.js'></script>
   <script src='theme/config.theme.js'></script>
+
+  <script>
+    if (Nominatim_Config.Reverse_Only) {
+      window.location.pathname = window.location.pathname.replace('search.html', 'reverse.html');
+    }
+  </script>
   <script defer src='build/bundle.js'></script>
 </head>
 
index 1d63d7513be89a3f6ceed24397a48c72d9cfdd14..ccc38cf01c9d8c51b22064d2676bf3021180f684 100644 (file)
@@ -10,7 +10,7 @@
   export let bMarkUnusedLines = false;
 
   $: bAddressLineUsed = addressLine.isaddress;
-
+  $: reverse_only = Nominatim_Config.Reverse_Only;
 </script>
 
 <tr class:notused={bMarkUnusedLines && !bAddressLineUsed}>
@@ -29,9 +29,9 @@
   <td>
     {#if addressLine.osm_id}
       <DetailsLink feature={addressLine}>details</DetailsLink>
-    {:else if addressLine.type.match(/^country/)}
+    {:else if !reverse_only && addressLine.type.match(/^country/)}
       <PageLink page='search' params_hash={{ country: addressLine.localname }}>search by name</PageLink>
-    {:else if addressLine.type === 'postcode'}
+    {:else if !reverse_only && addressLine.type === 'postcode'}
       <PageLink page='search' params_hash={{ postalcode: addressLine.localname }}>search by name</PageLink>
     {/if}
   </td>
index 92679632d7a5669a499ab43fce9d7f1b407f0fcf..e8702b9098bd1a2fb11874807d75f10acaaa98b9 100644 (file)
@@ -14,6 +14,6 @@
   <div id="error" class="container-fluid alert-danger py-3 px-4">
     {error_message}
 
-    <button type="button" class="btn-close" aria-label="dismiss" on:click={dismiss_message}></button>
+    <button type="button" class="btn-close float-end" aria-label="dismiss" on:click={dismiss_message}></button>
   </div>
 {/if}
index a93d6c5ec6b42289795b07869090687edf49a6e0..0fbead9ae9839ca7f20bf77dabcdfa4ffff33323 100644 (file)
@@ -8,6 +8,7 @@
 
   $: view = $page.tab;
   $: page_title = Nominatim_Config.Page_Title;
+  $: reverse_only = Nominatim_Config.Reverse_Only;
 
   let map_lat;
   let map_lon;
@@ -67,7 +68,7 @@
     <div class="container-fluid">
       <!-- Brand -->
       <div class="navbar-brand">
-        <PageLink page="search">
+        <PageLink page={reverse_only ? 'reverse' : 'search'}>
           <img alt="logo" id="theme-logo" src="theme/logo.png" />
           <h1>{page_title}</h1>
         </PageLink>
       <div class="collapse navbar-collapse" id="navbarSupportedContent">
         <!-- Left-aligned links -->
         <ul class="navbar-nav me-auto">
-          <li class="nav-item">
-            <PageLink page="search" extra_classes="nav-link {view === 'search' ? 'active' : ''}">Search</PageLink>
-          </li>
+          {#if !reverse_only}
+            <li class="nav-item">
+              <PageLink page="search" extra_classes="nav-link {view === 'search' ? 'active' : ''}">Search</PageLink>
+            </li>
+          {/if}
           <li class="nav-item">
             <ReverseLink lat={map_lat} lon={map_lon} extra_classes="nav-link {view === 'reverse' ? 'active' : ''}">Reverse</ReverseLink>
           </li>
index 03f32cc9a03ef1791b1aa164c1172e64ed1eb2ea..35344ce7cf97c2473886743c4b3b90dcc60ede69 100644 (file)
@@ -16,16 +16,27 @@ export const page = writable();
  * the requested query parameters. It may also be omitted completely for a
  * link without query parameters.
  */
-const pagenames = ['search', 'reverse', 'details', 'deletable', 'polygons', 'status', 'about'];
+const default_pagename = Nominatim_Config.Reverse_Only ? 'reverse' : 'search';
+const pagenames = [
+  default_pagename,
+  'reverse',
+  'details',
+  'deletable',
+  'polygons',
+  'status',
+  'about'
+];
 
 export function refresh_page(pagename, params) {
   if (typeof pagename === 'undefined') {
     pagename = window.location.pathname.replace('.html', '').replace(/^.*\//, '');
 
-    if (!pagenames.includes(pagename)) pagename = 'search';
+    if (!pagenames.includes(pagename)) pagename = default_pagename;
 
     params = new URLSearchParams(window.location.search);
   } else {
+    if (!pagenames.includes(pagename)) pagename = default_pagename;
+
     if (typeof params === 'undefined') {
       params = new URLSearchParams();
     }
index 2c7f8ba6d16534fab44270af6fecdecdbf326cd5..33fb94d44be853025c695dca7091ba1920745f34 100644 (file)
@@ -69,6 +69,7 @@
       base_url = window.location.search;
     }
   }
+  $: reverse_only = Nominatim_Config.Reverse_Only;
 </script>
 
 <Header>
               {/each}
             {/if}
 
-            <tr class="all-columns"><td colspan="6"><h2>Keywords</h2></td></tr>
-            {#if api_request_params.keywords}
+            {#if !reverse_only}
+              <tr class="all-columns"><td colspan="6"><h2>Keywords</h2></td></tr>
+              {#if api_request_params.keywords}
 
-              {#if place_has_keywords(aPlace)}
-                <tr class="all-columns"><td colspan="6"><h3>Name Keywords</h3></td></tr>
-                {#each aPlace.keywords.name as keyword}
-                  <tr>
-                    <td>{formatKeywordToken(keyword.token)}</td>
-                    {#if keyword.id}
-                      <td>word id: {keyword.id}</td>
-                    {/if}
-                  </tr>
-                {/each}
-
-                {#if aPlace.keywords.address}
-                  <tr class="all-columns"><td colspan="6"><h3>Address Keywords</h3></td></tr>
-                  {#each aPlace.keywords.address as keyword}
+                {#if place_has_keywords(aPlace)}
+                  <tr class="all-columns"><td colspan="6"><h3>Name Keywords</h3></td></tr>
+                  {#each aPlace.keywords.name as keyword}
                     <tr>
                       <td>{formatKeywordToken(keyword.token)}</td>
                       {#if keyword.id}
                       {/if}
                     </tr>
                   {/each}
+
+                  {#if aPlace.keywords.address}
+                    <tr class="all-columns"><td colspan="6"><h3>Address Keywords</h3></td></tr>
+                    {#each aPlace.keywords.address as keyword}
+                      <tr>
+                        <td>{formatKeywordToken(keyword.token)}</td>
+                        {#if keyword.id}
+                          <td>word id: {keyword.id}</td>
+                        {/if}
+                      </tr>
+                    {/each}
+                  {/if}
+                {:else}
+                  <tr><td>Place has no keywords</td></tr>
                 {/if}
               {:else}
-                <tr><td>Place has no keywords</td></tr>
+                <tr>
+                  <td>
+                     <a class="btn btn-outline-secondary btn-sm"
+                      href="{base_url}&keywords=1">display keywords</a>
+                  </td>
+                </tr>
               {/if}
-            {:else}
-              <tr>
-                <td>
-                   <a class="btn btn-outline-secondary btn-sm"
-                    href="{base_url}&keywords=1">display keywords</a>
-                </td>
-              </tr>
             {/if}
 
             <tr class="all-columns"><td colspan="6"><h2>Parent Of</h2></td></tr>
index c74de5b4819b7835b4e967dd667df3197a3599a6..b538f5c2c89eb9142e8d13ea8ba49696f2ef435c 100644 (file)
@@ -13,7 +13,7 @@ const testing_port = 9999; // this is the port all tests expect nominatim-ui to
 // We can simulate that with a proxy.
 const use_proxy = !!process.env.API_ON_SAME_PORT;
 const static_port = use_proxy ? 9998 : 9999;
-
+const reverse_only = !!process.env.REVERSE_ONLY;
 
 // Methods to run at the start and end of the mocha testsuite run
 // https://mochajs.org/#global-setup-fixtures
@@ -28,6 +28,7 @@ exports.mochaGlobalSetup = async function () {
 
   fse.outputFile(workdir + '/theme/config.theme.js', `
 Nominatim_Config.Nominatim_API_Endpoint = '${api_endpoint}';
+Nominatim_Config.Reverse_Only = ${reverse_only};
   `);
 
 
diff --git a/test/config_reverse_only.js b/test/config_reverse_only.js
new file mode 100644 (file)
index 0000000..5e14312
--- /dev/null
@@ -0,0 +1,31 @@
+const assert = require('assert');
+
+describe('Reverse Only', function () {
+  let page;
+
+  // eslint-disable-next-line mocha/no-setup-in-describe
+  if (!process.env.REVERSE_ONLY) return;
+
+  describe('Redirect default pages', function () {
+    before(async function () {
+      page = await browser.newPage();
+      await page.goto('http://localhost:9999/search.html');
+    });
+
+    after(async function () {
+      await page.close();
+    });
+
+    it('should redirect to /reverse', async function () {
+      // await page.waitForSelector('footer');
+
+      let current_url = new URL(await page.url());
+      assert.deepStrictEqual(current_url.pathname, '/reverse.html');
+    });
+
+    it('no navigation link', async function () {
+      let nav_item = await page.$('nav ul li a[href="search.html"]');
+      assert.equal(nav_item, null);
+    });
+  });
+});
index 4a137617e8c82c60b41f931629381fd3a08db924..e5434963a63f24f4ff219d2ea293144165bec42d 100644 (file)
@@ -1,5 +1,7 @@
 const assert = require('assert');
 
+const reverse_only = !!process.env.REVERSE_ONLY;
+
 describe('Details Page', function () {
   let page;
 
@@ -63,24 +65,27 @@ describe('Details Page', function () {
       assert.strictEqual((await page.$$('a[href="https://www.openstreetmap.org/relation/1155956"]')).length, 2);
     });
 
-    it('should change page url and add new header on clicking display keywords', async function () {
-      let current_url;
-      let display_headers;
-      let [display_keywords_btn] = await page.$x("//a[contains(text(), 'display keywords')]");
+    // Reverse-only installation have no search index, therefor no keywords
+    if (!reverse_only) {
+      it('should change url and add new header on clicking display keywords', async function () {
+        let current_url;
+        let display_headers;
+        let [display_keywords_btn] = await page.$x("//a[contains(text(), 'display keywords')]");
 
-      await display_keywords_btn.evaluate(node => node.click());
-      await page.waitForNavigation();
+        await display_keywords_btn.evaluate(node => node.click());
+        await page.waitForNavigation();
 
-      current_url = new URL(await page.url());
-      assert.strictEqual(current_url.searchParams.get('keywords'), '1');
+        current_url = new URL(await page.url());
+        assert.strictEqual(current_url.searchParams.get('keywords'), '1');
 
-      await page.waitForSelector('h3');
-      display_headers = await page.$$eval('h3', elements => elements.map(el => el.textContent));
-      assert.deepStrictEqual(display_headers, ['Name Keywords', 'Address Keywords']);
+        await page.waitForSelector('h3');
+        display_headers = await page.$$eval('h3', elements => elements.map(el => el.textContent));
+        assert.deepStrictEqual(display_headers, ['Name Keywords', 'Address Keywords']);
 
-      let page_content = await page.$eval('body', el => el.textContent);
-      assert.ok(page_content.includes('qwaansshe')); // one of the name keywords
-    });
+        let page_content = await page.$eval('body', el => el.textContent);
+        assert.ok(page_content.includes('qwaansshe')); // one of the name keywords
+      });
+    }
 
     it('should change page url on clicking display child places', async function () {
       let current_url;
@@ -124,7 +129,9 @@ describe('Details Page', function () {
       let page_content = await page.$eval('body', el => el.textContent);
 
       assert.ok(page_content.includes('Name No Name'));
-      assert.ok(page_content.includes('Place has no keywords'));
+      if (!process.env.REVERSE_ONLY) {
+        assert.ok(page_content.includes('Place has no keywords'));
+      }
       assert.ok(page_content.includes('Place is not parent of other places'));
     });
   });
index db16dbd806d7a22f230a96ba7271a8d15c7b99df..59fc2eb9779c2fdabf26857cd9daec1f36d61f7f 100644 (file)
@@ -3,6 +3,9 @@ const assert = require('assert');
 describe('Search Page', function () {
   let page;
 
+  // eslint-disable-next-line mocha/no-setup-in-describe
+  if (process.env.REVERSE_ONLY) return;
+
   describe('No search', function () {
     before(async function () {
       page = await browser.newPage();