From 44fdf3f55d252eff38e0bcd22debedcd8caee28c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20B=C3=B6sch-Plepelits?= Date: Tue, 18 Aug 2020 06:45:48 +0200 Subject: [PATCH 1/5] CategoryOverpassFilter: translate placeholder --- doc/Filters.md | 1 + src/CategoryOverpassFilter.js | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/doc/Filters.md b/doc/Filters.md index c7e75ee5..582fe21c 100644 --- a/doc/Filters.md +++ b/doc/Filters.md @@ -36,6 +36,7 @@ Each filter can define the following values: * 'has_key_value' query object with a tag with this key * 'strsearch' query string parts (e.g. "kai keb" would match "Kaiser Kebap") and query character variants (e.g. "cafe" would match "café"). * show_default: if true, this filter will be shown by default, others need to be added via the select box. +* placeholder: a text which is shown as placeholder (Twig enabled) ### Values #### Array diff --git a/src/CategoryOverpassFilter.js b/src/CategoryOverpassFilter.js index 104c6189..e79daf43 100644 --- a/src/CategoryOverpassFilter.js +++ b/src/CategoryOverpassFilter.js @@ -121,6 +121,11 @@ class CategoryOverpassFilter { f.values = v } } + + if ('placeholder' in f && typeof f.placeholder === 'string') { + let t = OverpassLayer.twig.twig({ data: f.placeholder, autoescape: true }) + f.placeholder = decodeHTML(t.render({}).toString()) + } } let masterOptions = { From b472af6290f65696917ee669a4e9930fad8aa2bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20B=C3=B6sch-Plepelits?= Date: Tue, 18 Aug 2020 06:46:25 +0200 Subject: [PATCH 2/5] CategoryOverpassFilter: add defaultQuery option --- doc/Filters.md | 1 + src/CategoryOverpassFilter.js | 24 +++++++++++++++++++++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/doc/Filters.md b/doc/Filters.md index 582fe21c..4e857465 100644 --- a/doc/Filters.md +++ b/doc/Filters.md @@ -37,6 +37,7 @@ Each filter can define the following values: * 'strsearch' query string parts (e.g. "kai keb" would match "Kaiser Kebap") and query character variants (e.g. "cafe" would match "café"). * show_default: if true, this filter will be shown by default, others need to be added via the select box. * placeholder: a text which is shown as placeholder (Twig enabled) +* defaultQuery: A filter query which is added when no value is selected. ### Values #### Array diff --git a/src/CategoryOverpassFilter.js b/src/CategoryOverpassFilter.js index e79daf43..568f4c40 100644 --- a/src/CategoryOverpassFilter.js +++ b/src/CategoryOverpassFilter.js @@ -139,16 +139,22 @@ class CategoryOverpassFilter { this.formFilter = new form('filter-' + this.master.id, this.data, masterOptions) this.formFilter.show(this.domFilter) - this.formFilter.onchange = function () { + this.formFilter.onchange = () => { let param = JSON.parse(JSON.stringify(this.formFilter.get_data())) this.applyParam(param) state.update() - }.bind(this) + } this.master.on('setParam', this.setParam.bind(this)) - this.master.on('applyParam', this.applyParam.bind(this)) + this.master.on('applyParam', (param) => { + this.applyParam(param) + + if (!this.tabFilter.isSelected()) { + this.tabFilter.select() + } + }) this.master.on('open', this.openCategory.bind(this)) this.master.on('stateGet', this.stateGet.bind(this)) } @@ -227,6 +233,15 @@ class CategoryOverpassFilter { } }).filter(f => f) // remove null values + const defaultQueries = Object.keys(this.data) + .map(k => { + if (!param[k]) { + return this.data[k].defaultQuery + } + }) + .filter(f => f) + this.additionalFilter = this.additionalFilter.concat(defaultQueries) + if (this.additionalFilter.length === 0) { this.additionalFilter = [] } else if (this.additionalFilter.length === 1) { @@ -244,6 +259,9 @@ class CategoryOverpassFilter { openCategory () { this.formFilter.resize() + + let param = JSON.parse(JSON.stringify(this.formFilter.get_data())) + this.applyParam(param) } stateGet (param) { From 7b7aad625bf38bffe7be51815ecb6b06d9ccc1be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20B=C3=B6sch-Plepelits?= Date: Wed, 19 Aug 2020 19:26:26 +0200 Subject: [PATCH 3/5] CategoryOverpassFilter: replace 'defaultQuery' by 'emptyQuery' --- doc/Filters.md | 2 +- src/CategoryOverpassFilter.js | 11 +---------- 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/doc/Filters.md b/doc/Filters.md index 4e857465..c424ee4f 100644 --- a/doc/Filters.md +++ b/doc/Filters.md @@ -37,7 +37,7 @@ Each filter can define the following values: * 'strsearch' query string parts (e.g. "kai keb" would match "Kaiser Kebap") and query character variants (e.g. "cafe" would match "café"). * show_default: if true, this filter will be shown by default, others need to be added via the select box. * placeholder: a text which is shown as placeholder (Twig enabled) -* defaultQuery: A filter query which is added when no value is selected. +* emptyQuery: A Overpass filter query which is added, when no value is selected. ### Values #### Array diff --git a/src/CategoryOverpassFilter.js b/src/CategoryOverpassFilter.js index 568f4c40..7e9914bc 100644 --- a/src/CategoryOverpassFilter.js +++ b/src/CategoryOverpassFilter.js @@ -169,7 +169,7 @@ class CategoryOverpassFilter { let d = this.data[k] if (values === null) { - return null + return d.emptyQuery } if (!Array.isArray(values)) { @@ -233,15 +233,6 @@ class CategoryOverpassFilter { } }).filter(f => f) // remove null values - const defaultQueries = Object.keys(this.data) - .map(k => { - if (!param[k]) { - return this.data[k].defaultQuery - } - }) - .filter(f => f) - this.additionalFilter = this.additionalFilter.concat(defaultQueries) - if (this.additionalFilter.length === 0) { this.additionalFilter = [] } else if (this.additionalFilter.length === 1) { From 54f47f532ee2c56670d733979cf1b51954885200 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20B=C3=B6sch-Plepelits?= Date: Wed, 19 Aug 2020 19:31:14 +0200 Subject: [PATCH 4/5] CategoryOverpassFilter: bugfix (on open, show filters only when param exist) --- src/CategoryOverpassFilter.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/CategoryOverpassFilter.js b/src/CategoryOverpassFilter.js index 7e9914bc..36bd7f7f 100644 --- a/src/CategoryOverpassFilter.js +++ b/src/CategoryOverpassFilter.js @@ -242,10 +242,6 @@ class CategoryOverpassFilter { } this.master.layer.setFilter(this.additionalFilter) - - if (!this.tabFilter.isSelected()) { - this.tabFilter.select() - } } openCategory () { From 894e25cead5dac64d3c440f5164729d2899649b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20B=C3=B6sch-Plepelits?= Date: Sat, 5 Sep 2020 09:08:40 +0200 Subject: [PATCH 5/5] translate 'empty value' --- lang/en.json | 1 + 1 file changed, 1 insertion(+) diff --git a/lang/en.json b/lang/en.json index 879fc3a8..a02708b6 100644 --- a/lang/en.json +++ b/lang/en.json @@ -13,6 +13,7 @@ "editor:remote": "Remote Control (JOSM or Merkaator)", "editor:remote:help": "You have to enable remote control in JOSM or Merkaator.", "error": "Error", + "empty value": "empty value", "export-all": "Export all visible map features", "export-prepare": "Prepare download", "export:GeoJSON": "Download as GeoJSON",