From 31a99604c3ec97feeda38dd3be0467cd45f0f9ad Mon Sep 17 00:00:00 2001 From: dbauszus-glx Date: Mon, 30 Oct 2023 18:04:26 +0000 Subject: [PATCH 1/4] review sqlfilter json as url param encoding --- api/api.js | 7 ------- lib/utils/paramString.mjs | 12 +++++------- mod/utils/sqlFilter.js | 9 +++------ 3 files changed, 8 insertions(+), 20 deletions(-) diff --git a/api/api.js b/api/api.js index 58e24a793..cec0926d6 100644 --- a/api/api.js +++ b/api/api.js @@ -111,13 +111,6 @@ module.exports = async (req, res) => { req.params.template = req.params._template || req.params.template - // Decode string params. - Object.entries(req.params) - .filter(entry => typeof entry[1] === 'string') - .forEach(entry => { - req.params[entry[0]] = decodeURIComponent(entry[1]) - }) - // Short circuit login view or post request. if (req.params.login || req.body && req.body.login) return login(req, res) diff --git a/lib/utils/paramString.mjs b/lib/utils/paramString.mjs index f9466e469..b3e92e067 100644 --- a/lib/utils/paramString.mjs +++ b/lib/utils/paramString.mjs @@ -1,6 +1,10 @@ // Create param string for XHR request. export default params => Object.entries(params) + + // Value should be 0 or truthy .filter(entry => entry[1] === 0 || !!entry[1]) + + // Value must not be empty functional brackets. .filter(entry => entry[1] !== '{}') // Filter out zero length array and objects with empty object values. @@ -10,16 +14,10 @@ export default params => Object.entries(params) .map(entry => { - // if (Array.isArray(entry[1])) { - - // return entry[1].map(val => `${entry[0]}=${val}`).join('&') - // } - // Stringify non array objects. if (typeof entry[1] === 'object' && !Array.isArray(entry[1])) { - entry[1] = JSON.stringify(entry[1]) - + return `${entry[0]}=${encodeURIComponent(JSON.stringify(entry[1]))}` } return encodeURI(`${entry[0]}=${entry[1]}`) diff --git a/mod/utils/sqlFilter.js b/mod/utils/sqlFilter.js index 9f1d10373..259083e98 100644 --- a/mod/utils/sqlFilter.js +++ b/mod/utils/sqlFilter.js @@ -21,7 +21,7 @@ const filterTypes = { `(${val .split(',') .filter((val) => val.length > 0) - .map((val) => `"${col}" ILIKE \$${addValues(`${val}%`, true)}`) + .map((val) => `"${col}" ILIKE \$${addValues(`${val}%`)}`) .join(' OR ')})`, match: (col, val) => `"${col}"::text ILIKE \$${addValues(val)}` @@ -29,12 +29,9 @@ const filterTypes = { let SQLparams -function addValues(val, skip) { +function addValues(val) { - SQLparams.push(Array.isArray(val) - && val[0].map(v=>decodeURIComponent(v)) - || skip && val - || decodeURIComponent(val)) + SQLparams.push(val) return SQLparams.length } From 6887135d0a79d2023ab1ea3dc94e21f66172cff5 Mon Sep 17 00:00:00 2001 From: Simon Leech Date: Wed, 1 Nov 2023 10:03:34 +0000 Subject: [PATCH 2/4] Remove encode and decoding in filter --- lib/ui/elements/dropdown.mjs | 2 +- lib/ui/layers/filters.mjs | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/ui/elements/dropdown.mjs b/lib/ui/elements/dropdown.mjs index 39c5a2551..6fd5d7138 100644 --- a/lib/ui/elements/dropdown.mjs +++ b/lib/ui/elements/dropdown.mjs @@ -31,7 +31,7 @@ export default (params) => { // Set btn text to reflect selection or show placeholder. btn.querySelector('[data-id=header-span]') - .textContent = params.selectedTitles.size && Array.from(params.selectedTitles).map(v => decodeURIComponent(v)).join(', ') + .textContent = params.selectedTitles.size && Array.from(params.selectedTitles).map(v => v).join(', ') || params.span || params.placeholder // Execute callback method and pass array of current selection. diff --git a/lib/ui/layers/filters.mjs b/lib/ui/layers/filters.mjs index d32de5b12..97d442b8c 100644 --- a/lib/ui/layers/filters.mjs +++ b/lib/ui/layers/filters.mjs @@ -186,8 +186,8 @@ async function filter_in(layer, filter) { multi: true, placeholder: 'Select Multiple', entries: filter[filter.type].map(val => ({ - title: decodeURIComponent(val), - option: encodeURIComponent(val), + title: val, + option: val, selected: chkSet.has(val) })), callback: async (e, options) => { @@ -204,8 +204,8 @@ async function filter_in(layer, filter) { } return filter[filter.type].map(val => mapp.ui.elements.chkbox({ - val: encodeURIComponent(val), - label: decodeURIComponent(val), + val: val, + label: val, checked: chkSet.has(val), onchange: (checked, val) => { From 3dc63f67909d90012f75e7956f9c160a00c20b80 Mon Sep 17 00:00:00 2001 From: dbauszus-glx Date: Wed, 1 Nov 2023 10:39:08 +0000 Subject: [PATCH 3/4] update in filter for empty options array. --- lib/ui/layers/filters.mjs | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/lib/ui/layers/filters.mjs b/lib/ui/layers/filters.mjs index 97d442b8c..51ef15d57 100644 --- a/lib/ui/layers/filters.mjs +++ b/lib/ui/layers/filters.mjs @@ -13,16 +13,12 @@ export default { let timeout; -function applyFilter(layer, zoom) { - clearTimeout(timeout); +function applyFilter(layer) { - // enable zoomToExtent button. - let btn = layer.view.querySelector('[data-id=zoomToExtent]') - if (btn) btn.disabled = false; + clearTimeout(timeout); // Debounce layer reload by 500 timeout = setTimeout(() => { - timeout = null; layer.reload(); layer.mapview.Map.getTargetElement().dispatchEvent(new Event('changeEnd')) }, 500); @@ -192,11 +188,20 @@ async function filter_in(layer, filter) { })), callback: async (e, options) => { - Object.assign(layer.filter.current, { - [filter.field]:{ - [filter.type]: options - } - }) + if (!options.length) { + + // Remove empty array filter. + delete layer.filter.current[filter.field] + } else { + + // Set filter values array from options. + Object.assign(layer.filter.current, { + [filter.field]:{ + [filter.type]: options + } + }) + } + layer.reload() layer.mapview.Map.getTargetElement().dispatchEvent(new Event('changeEnd')) } From 1b610d64692e0f00d952bf6bf39241cc8486c8ec Mon Sep 17 00:00:00 2001 From: Robert Hurst Date: Thu, 2 Nov 2023 12:56:12 +0200 Subject: [PATCH 4/4] Remove encoding in tabulatorUtils --- lib/ui/utils/tabulatorUtils.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ui/utils/tabulatorUtils.mjs b/lib/ui/utils/tabulatorUtils.mjs index 83fe5af69..a75c7a806 100644 --- a/lib/ui/utils/tabulatorUtils.mjs +++ b/lib/ui/utils/tabulatorUtils.mjs @@ -62,7 +62,7 @@ function like(_this) { // Set filter _this.layer.filter.current[field] = { - [headerFilterParams.type || 'like']: encodeURIComponent(e.target.value) + [headerFilterParams.type || 'like']: e.target.value } } else {