wip: make sure we do not add an invalid overpass URL

This commit is contained in:
Yohan Boniface 2024-06-11 11:49:00 +02:00
parent a70307ea29
commit 115130083d
2 changed files with 8 additions and 4 deletions

View file

@ -35,7 +35,7 @@ class Autocomplete extends SingleMixin(BaseAjax) {
export class Importer { export class Importer {
constructor(map, options) { constructor(map, options) {
this.map = map this.map = map
this.name = 'Overpass' this.name = options.name || 'Overpass'
this.baseUrl = options?.url || 'https://overpass-api.de/api/interpreter' this.baseUrl = options?.url || 'https://overpass-api.de/api/interpreter'
} }
@ -57,8 +57,12 @@ export class Importer {
this.map.help.parse(container) this.map.help.parse(container)
const confirm = () => { const confirm = () => {
const outMode = container.querySelector('[name=out-mode]').value
let tags = container.querySelector('[name=tags]').value let tags = container.querySelector('[name=tags]').value
if (!tags) {
this.map.alert.open({content: translate('Please define an expression for the query first')})
return
}
const outMode = container.querySelector('[name=out-mode]').value
if (!tags.startsWith('[')) tags = `[${tags}]` if (!tags.startsWith('[')) tags = `[${tags}]`
let area = '{south},{west},{north},{east}' let area = '{south},{west},{north},{east}'
if (boundary) area = `area:${boundary}` if (boundary) area = `area:${boundary}`
@ -68,7 +72,7 @@ export class Importer {
importer.format = 'osm' importer.format = 'osm'
importer.dialog.close() importer.dialog.close()
} }
L.DomUtil.createButton('', container, 'OK', confirm) L.DomUtil.createButton('', container, translate('Choose this data'), confirm)
importer.dialog.open({ importer.dialog.open({
content: container, content: container,

View file

@ -534,7 +534,7 @@ def test_overpass_import_with_bbox(page, live_server, tilelayer, settings):
page.get_by_role("link", name="Import data (Ctrl+I)").click() page.get_by_role("link", name="Import data (Ctrl+I)").click()
page.get_by_role("button", name="Overpass").click() page.get_by_role("button", name="Overpass").click()
page.get_by_placeholder("amenity=drinking_water").fill("building") page.get_by_placeholder("amenity=drinking_water").fill("building")
page.get_by_role("button", name="OK").click() page.get_by_role("button", name="Choose this data").click()
expect(page.get_by_placeholder("Provide an URL here")).to_have_value( expect(page.get_by_placeholder("Provide an URL here")).to_have_value(
"https://my.overpass.io/interpreter?data=[out:json];nwr[building]({south},{west},{north},{east});out geom;" "https://my.overpass.io/interpreter?data=[out:json];nwr[building]({south},{west},{north},{east});out geom;"
) )