Normalization of ä, ö,ü and ß in filters and search of duplicates
This commit is contained in:
@@ -47,7 +47,14 @@
|
||||
}
|
||||
|
||||
function normalize(value) {
|
||||
let result = value.trim().replace(/\s+/g, ' ');
|
||||
const sharedNormalize = window.AssetManagerNormalizeSearchText;
|
||||
if (typeof sharedNormalize === 'function') {
|
||||
return sharedNormalize(value, {
|
||||
caseSensitive: !caseInsensitive.checked,
|
||||
collapseWhitespace: true
|
||||
});
|
||||
}
|
||||
let result = String(value || '').trim().replace(/\s+/g, ' ');
|
||||
if (caseInsensitive.checked) result = result.toLocaleLowerCase();
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -11,9 +11,11 @@
|
||||
const table = document.getElementById('software-inventory-table');
|
||||
if (filter && table) {
|
||||
filter.addEventListener('input', () => {
|
||||
const needle = filter.value.trim().toLocaleLowerCase();
|
||||
const normalize = window.AssetManagerNormalizeSearchText ||
|
||||
((value) => String(value || '').toLocaleLowerCase());
|
||||
const needle = normalize(filter.value.trim());
|
||||
table.querySelectorAll('tbody tr').forEach((row) => {
|
||||
row.hidden = needle && !row.textContent.toLocaleLowerCase().includes(needle);
|
||||
row.hidden = Boolean(needle) && !normalize(row.textContent).includes(needle);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,4 +1,32 @@
|
||||
(() => {
|
||||
function normalizeSearchText(value, options = {}) {
|
||||
const caseSensitive = Boolean(options.caseSensitive);
|
||||
const collapseWhitespace = Boolean(options.collapseWhitespace);
|
||||
let text = String(value ?? '');
|
||||
|
||||
// Preserve the common German transliterations before Unicode accent
|
||||
// folding so searches treat umlauts and their ASCII spellings equally.
|
||||
text = text
|
||||
.replace(/Ä/g, 'Ae')
|
||||
.replace(/Ö/g, 'Oe')
|
||||
.replace(/Ü/g, 'Ue')
|
||||
.replace(/ä/g, 'ae')
|
||||
.replace(/ö/g, 'oe')
|
||||
.replace(/ü/g, 'ue')
|
||||
.replace(/ẞ/g, 'SS')
|
||||
.replace(/ß/g, 'ss')
|
||||
.normalize('NFKD')
|
||||
.replace(/[\u0300-\u036f]/g, '');
|
||||
|
||||
if (collapseWhitespace) text = text.trim().replace(/\s+/g, ' ');
|
||||
if (!caseSensitive) text = text.toLocaleLowerCase();
|
||||
return text;
|
||||
}
|
||||
|
||||
// Standalone filters and duplicate detection use the exact same comparison
|
||||
// rules as the generic table filters.
|
||||
window.AssetManagerNormalizeSearchText = normalizeSearchText;
|
||||
|
||||
const collator = new Intl.Collator(document.documentElement.lang || 'de', {
|
||||
numeric: true,
|
||||
sensitivity: 'base'
|
||||
@@ -322,7 +350,7 @@
|
||||
const active = filterDefinitions
|
||||
.map(definition => ({
|
||||
definition,
|
||||
term: definition.input?.value.trim().toLocaleLowerCase() || ''
|
||||
term: normalizeSearchText(definition.input?.value.trim() || '')
|
||||
}))
|
||||
.filter(item => item.term);
|
||||
|
||||
@@ -350,7 +378,7 @@
|
||||
if (definition.numericFilter) {
|
||||
return !numericFilterMatches(value, term);
|
||||
}
|
||||
return !value.toLocaleLowerCase().includes(term);
|
||||
return !normalizeSearchText(value).includes(term);
|
||||
});
|
||||
|
||||
row.hidden = hidden;
|
||||
|
||||
Reference in New Issue
Block a user