Allow * as wildcard in filter, re #2070

No UI but edit the URL to provide a filter with * in it
and the query gets changed to LIKE and the * to %.

Works in MySQL at least!

fix regex
This commit is contained in:
Rich Lott / Artful Robot 2023-07-03 17:05:51 +01:00
parent 71bb012cab
commit 2257ad7b70

View file

@ -111,9 +111,16 @@ function getFilterQuery(filters = {}, params = []): string {
const filter = filters[key]; const filter = filters[key];
if (filter !== undefined) { if (filter !== undefined) {
let filterValue = decodeURIComponent(filter),
op = '=';
const column = FILTER_COLUMNS[key] || key; const column = FILTER_COLUMNS[key] || key;
arr.push(`and ${column}=$${params.length + 1}`);
params.push(decodeURIComponent(filter)); if (filterValue.indexOf('*') > -1) {
op = 'LIKE';
filterValue = filterValue.replaceAll(/\*+/g, '%');
}
arr.push(`and ${column} ${op} $${params.length + 1}`);
params.push(filterValue);
} }
return arr; return arr;