]> git.openstreetmap.org Git - nominatim-ui.git/blob - src/components/SearchSectionDetails.svelte
Update dependencies, second try (#287)
[nominatim-ui.git] / src / components / SearchSectionDetails.svelte
1 <script>
2   import { refresh_page } from '../lib/stores.js';
3   import { SvelteURLSearchParams } from 'svelte/reactivity';
4
5   export let api_request_params = {};
6
7   function handleFormSubmit(event) {
8     let form_el = event.target;
9     let val = form_el.querySelector('input[type=edit]').value.trim();
10     let type_and_id_match = val.match(/^\s*([NWR])(-?\d+)\s*$/i)
11                             || val.match(/\/(relation|way|node)\/(-?\d+)\s*$/);
12
13     var params = new SvelteURLSearchParams();
14     if (type_and_id_match) {
15       params.set('osmtype', type_and_id_match[1].charAt(0).toUpperCase());
16       params.set('osmid', type_and_id_match[2]);
17     } else if (val.match(/^\d+$/)) {
18       params.set('place_id', val);
19     } else {
20       alert('invalid input');
21       return;
22     }
23
24     refresh_page('details', params);
25   }
26 </script>
27
28 <form on:submit|preventDefault={handleFormSubmit} class="form-inline" action="details.html">
29   <div class="row g-1">
30     <div class="col-auto">
31       <!-- eslint-disable-next-line max-len -->
32       <input type="edit"
33              class="form-control form-control-sm me-1"
34              pattern="^[1-9][0-9]*$|^[NWRnwr]-?[1-9][0-9]*$|.*openstreetmap.*"
35              value="{
36               (api_request_params.osmtype || '')
37               + (api_request_params.osmid || '')
38               + (api_request_params.place_id || '')
39             }" />
40       </div>
41     <div class="col-auto">
42       <button type="submit" class="btn btn-primary btn-sm">Show</button>
43     </div>
44   </div>
45 </form>
46 <small class="form-text text-muted">
47   OSM type+id (<em>N123</em>,
48                <em>n123</em>,
49                <em>W123</em>,
50                <em>w123</em>,
51                <em>R123</em>,
52                <em>r123</em>),
53   Place id (<em>1234</em>) or
54   URL (<em>https://openstreetmap.org/way/123</em>)
55 </small>
56
57 <style>
58   form .form-control{
59     width: 500px;
60     max-width: 100%;
61   }
62   .form-text em {
63     font-family: monospace;
64     font-style: normal;
65   }
66 </style>