Version 0.5.5.94: field type conversion, exclusion filters and value lists

- Change the data type of custom fields with stored values via a preview:
  values that cannot be converted need an explicit decision, the
  conversion runs in one transaction with row locks and a stale-preview
  check, old values are saved to data/backups and recorded in history.
- Table filters: "!value" excludes rows, "=value" compares exactly;
  Excel-like value list (▾) per column in all tables. The software job
  list computes its value list on the server over the full job history.
- Bulk edit offers custom fields with type-specific input and validation.
- MeshCentral mappings: optional "value if empty" with a guard path;
  fallbacks are skipped when only basic data was delivered.
- Deleting a field removes its translations (same name can be reused);
  one confirmation with the value count replaces the checkbox.
- Job list filters recognize the "reinstall" action and the
  "software deployment" job type.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
RolandandClaude Opus 5.5 committed 2026-11-18 21:14:21 +01:00
1 parent 261b4f2029
commit 40cd88871f
20 files changed
+1400 -187

No files matched your search

+335 -20
View File
@@ -117,6 +117,51 @@
return `${explicitFilterValue} ${cell.textContent || ''}`.trim();
}
// The value a user sees in a cell (selected option text, input value or
// plain text). Used by the value list and by exact "=value" filters.
function listValue(cell) {
if (!cell) return '';
const controls = [...cell.querySelectorAll('input, select, textarea')]
.filter(control => control.type !== 'hidden');
let text;
if (controls.length) {
const yes = document.body.dataset.valueListYes || 'Yes';
const no = document.body.dataset.valueListNo || 'No';
const parts = controls.map(control => {
if (control.tagName === 'SELECT') return control.options?.[control.selectedIndex]?.textContent || '';
if (control.type === 'checkbox' || control.type === 'radio') return control.checked ? yes : no;
return control.value || '';
});
text = [...parts, textOutsideControls(cell)].join(' ');
} else {
text = cell.textContent || '';
}
return text.replace(/\s+/g, ' ').trim();
}
function exactValueKey(value) {
return normalizeSearchText(value, { collapseWhitespace: true });
}
// "!term" excludes, everything else includes (OR). "==x" keeps a literal "=x" search.
function splitFilterTerms(text) {
const includes = [];
const excludes = [];
String(text || '')
.split(/\r?\n/)
.map(term => term.trim())
.filter(Boolean)
.forEach(term => {
if (term.startsWith('!')) {
const excluded = term.slice(1).trim();
if (excluded) excludes.push(excluded);
} else {
includes.push(term);
}
});
return { includes, excludes };
}
function parsedValue(value) {
const text = value.trim();
if (!text) return { type: 'empty', value: '' };
@@ -793,6 +838,21 @@
if (neutralTerm === '@empty') return !String(comparable || '').trim();
if (neutralTerm === '@notempty') return !!String(comparable || '').trim();
// "=value": the whole visible cell value must match (value list, exact search).
// Numeric/date columns additionally keep their "=5" / "=18.11.2026" comparison.
const trimmedTerm = String(term || '').trim();
const exact = trimmedTerm.startsWith('=') && !trimmedTerm.startsWith('==');
if (exact) {
const expected = exactValueKey(trimmedTerm.slice(1));
if (exactValueKey(listValue(cell)) === expected) return true;
const numericExact = numericFilterMatches(comparable, trimmedTerm, false);
if (numericExact !== null) return numericExact;
const dateExact = dateFilterMatches(comparable, trimmedTerm);
if (dateExact !== null) return dateExact;
return false;
}
if (trimmedTerm.startsWith('==')) term = trimmedTerm.slice(1);
// Preserve the pre-existing software-summary numeric behavior exactly:
// plain numeric input is an exact match in columns explicitly marked as numeric.
if (definition.numericFilter) {
@@ -1009,6 +1069,255 @@
});
}
// Excel-like value list: every distinct value of the column among the rows
// that pass the filters of all OTHER columns, with checkboxes. The result is
// written into the normal filter field ("=a" lines or "!=b" lines), so saved
// filters, the filter status and "reset filters" keep working unchanged.
function createValueListButton(filterCell, definition) {
const button = document.createElement('button');
button.type = 'button';
button.className = 'value-list-button';
button.textContent = '▾';
button.title = document.body.dataset.valueListOpen || 'Select values';
button.setAttribute('aria-label', `${button.title}: ${definition.title}`);
button.setAttribute('aria-haspopup', 'dialog');
filterCell.classList.add('value-list-filter-cell');
filterCell.appendChild(button);
button.addEventListener('click', event => {
event.stopPropagation();
const open = document.querySelector('.value-list-popup');
if (open && open._anchor === button) { open._close(); return; }
openValueList(definition, button);
});
}
function collectColumnValues(definition) {
const others = activeFilterItems().filter(item => item.definition !== definition);
const own = activeFilterItems().find(item => item.definition === definition) || null;
const values = new Map();
[...tbody.rows].forEach(row => {
if (row.querySelector('.empty-state')) return;
if (others.some(item => !rowPassesFilter(row, item))) return;
const cell = cellForDefinition(row, definition);
let label = listValue(cell);
if (!label) label = comparableCellValue(cell);
const key = label ? exactValueKey(label) : '@empty';
let entry = values.get(key);
if (!entry) {
entry = { key, label, count: 0, checked: own ? rowPassesFilter(row, own) : true };
values.set(key, entry);
}
entry.count += 1;
});
const entries = [...values.values()];
entries.sort((a, b) => {
if (a.key === '@empty') return -1;
if (b.key === '@empty') return 1;
return compareValues(a.label, b.label);
});
return entries;
}
// Server tables (software jobs) only contain the current page of rows, so
// their value list is computed on the server with the other column filters.
async function serverColumnValues(definition) {
const target = new URL(table.dataset.valueListUrl, window.location.origin);
target.searchParams.set('column', definition.serverName);
filterDefinitions.forEach(item => {
const value = item.input.value.trim();
if (item.serverName && value) target.searchParams.set(`job_filter_${item.serverName}`, value);
});
const response = await fetch(target.toString(), { cache: 'no-store', headers: { 'X-Requested-With': 'AssetManagerValueList' } });
if (!response.ok) throw new Error(`HTTP ${response.status}`);
const data = await response.json();
const entries = (data.values || []).map(item => ({
key: item.label ? exactValueKey(item.label) : '@empty',
label: item.label,
count: item.count,
checked: Boolean(item.checked)
}));
entries.sort((a, b) => {
if (a.key === '@empty') return -1;
if (b.key === '@empty') return 1;
return compareValues(a.label, b.label);
});
entries.truncated = Boolean(data.truncated);
entries.scanLimit = data.scan_limit;
return entries;
}
async function openValueList(definition, anchor) {
document.querySelectorAll('.value-list-popup').forEach(popup => popup._close?.());
let entries;
if (usesServerFilters) {
anchor.classList.add('is-loading');
try {
entries = await serverColumnValues(definition);
} catch (error) {
console.error('[AssetManager] value list failed', error);
window.AssetManagerToast?.error?.(document.body.dataset.valueListError || 'The value list could not be loaded.');
return;
} finally {
anchor.classList.remove('is-loading');
}
} else {
entries = collectColumnValues(definition);
}
const maxRendered = 500;
const popup = document.createElement('div');
popup.className = 'advanced-filter-popup advanced-filter-popup-portal value-list-popup';
popup.setAttribute('role', 'dialog');
popup.setAttribute('aria-label', definition.title);
const title = document.createElement('strong');
title.className = 'advanced-filter-title';
title.textContent = definition.title;
const search = document.createElement('input');
search.type = 'search';
search.className = 'value-list-search';
search.placeholder = document.body.dataset.valueListSearch || 'Search';
search.autocomplete = 'off';
const list = document.createElement('div');
list.className = 'value-list-items';
const info = document.createElement('p');
info.className = 'value-list-info muted';
const actions = document.createElement('div');
actions.className = 'advanced-filter-actions';
const apply = document.createElement('button');
apply.type = 'button';
apply.className = 'button button-primary';
apply.textContent = document.body.dataset.advancedFilterApply || 'Apply';
const cancel = document.createElement('button');
cancel.type = 'button';
cancel.className = 'button button-secondary';
cancel.textContent = document.body.dataset.valueListCancel || 'Cancel';
actions.append(apply, cancel);
popup.append(title, search, list, info, actions);
document.body.appendChild(popup);
const emptyLabel = document.body.dataset.valueListEmpty || '(Empty)';
const visibleEntries = () => {
const term = search.value.trim();
return term ? entries.filter(entry => searchTextMatches(entry.key === '@empty' ? emptyLabel : entry.label, term)) : entries;
};
const render = () => {
const shown = visibleEntries();
list.replaceChildren();
const allLabel = document.createElement('label');
allLabel.className = 'value-list-item value-list-all';
const all = document.createElement('input');
all.type = 'checkbox';
const checkedShown = shown.filter(entry => entry.checked).length;
all.checked = shown.length > 0 && checkedShown === shown.length;
all.indeterminate = checkedShown > 0 && checkedShown < shown.length;
all.addEventListener('change', () => {
shown.forEach(entry => { entry.checked = all.checked; });
render();
});
allLabel.append(all, document.createTextNode(` ${document.body.dataset.valueListSelectAll || '(Select all)'}`));
list.appendChild(allLabel);
shown.slice(0, maxRendered).forEach(entry => {
const label = document.createElement('label');
label.className = 'value-list-item';
const checkbox = document.createElement('input');
checkbox.type = 'checkbox';
checkbox.checked = entry.checked;
checkbox.addEventListener('change', () => {
entry.checked = checkbox.checked;
const checkedNow = shown.filter(item => item.checked).length;
all.checked = checkedNow === shown.length;
all.indeterminate = checkedNow > 0 && checkedNow < shown.length;
updateApply();
});
const text = document.createElement('span');
text.className = 'value-list-label';
text.textContent = entry.key === '@empty' ? emptyLabel : entry.label;
text.title = text.textContent;
const count = document.createElement('span');
count.className = 'value-list-count';
count.textContent = String(entry.count);
label.append(checkbox, text, count);
list.appendChild(label);
});
const notes = [];
if (shown.length > maxRendered) {
notes.push((document.body.dataset.valueListLimited || 'Showing {shown} of {total} values, use the search field.')
.replace('{shown}', String(maxRendered)).replace('{total}', String(shown.length)));
}
if (entries.truncated) {
notes.push((document.body.dataset.valueListScanLimited || 'Only the newest {count} jobs were evaluated.')
.replace('{count}', String(entries.scanLimit)));
}
info.textContent = notes.join(' ');
info.hidden = !info.textContent;
updateApply();
};
const updateApply = () => {
apply.disabled = !entries.some(entry => entry.checked);
};
const position = () => {
const rect = anchor.closest('th').getBoundingClientRect();
const margin = 6;
const popupRect = popup.getBoundingClientRect();
let left = Math.min(rect.left, window.innerWidth - popupRect.width - margin);
left = Math.max(margin, left);
let top = rect.bottom + 4;
if (top + popupRect.height > window.innerHeight - margin && rect.top > popupRect.height + margin) {
top = rect.top - popupRect.height - 4;
}
popup.style.left = `${Math.round(left)}px`;
popup.style.top = `${Math.round(Math.max(margin, top))}px`;
};
const onDocumentClick = event => {
if (!popup.contains(event.target) && event.target !== anchor) close();
};
const onKey = event => {
if (event.key === 'Escape') { close(); anchor.focus(); }
};
function close() {
popup.remove();
document.removeEventListener('click', onDocumentClick, true);
document.removeEventListener('keydown', onKey, true);
window.removeEventListener('resize', position);
window.removeEventListener('scroll', position, true);
}
popup._close = close;
popup._anchor = anchor;
apply.addEventListener('click', () => {
const checked = entries.filter(entry => entry.checked);
const unchecked = entries.filter(entry => !entry.checked);
const term = entry => (entry.key === '@empty' ? '@empty' : `=${entry.label}`);
let lines = [];
if (!unchecked.length) lines = [];
else if (checked.length <= unchecked.length) lines = checked.map(term);
else lines = unchecked.map(entry => `!${term(entry)}`);
definition.input.value = lines.join('\n');
definition.input.dispatchEvent(new Event('input', { bubbles: true }));
if (usesServerFilters) submitServerFilters(true);
close();
});
cancel.addEventListener('click', close);
search.addEventListener('input', render);
search.addEventListener('keydown', event => {
if (event.key === 'Enter') { event.preventDefault(); if (!apply.disabled) apply.click(); }
});
render();
position();
document.addEventListener('click', onDocumentClick, true);
document.addEventListener('keydown', onKey, true);
window.addEventListener('resize', position);
window.addEventListener('scroll', position, true);
search.focus();
}
function submitServerFilters(immediate = false) {
if (!usesServerFilters) return;
if (serverFilterTimer) window.clearTimeout(serverFilterTimer);
@@ -1090,18 +1399,26 @@
});
}
function activeFilterItems() {
return filterDefinitions
.map(definition => ({ definition, ...splitFilterTerms(definition.input?.value) }))
.filter(item => item.includes.length || item.excludes.length);
}
// A row passes one column filter when it matches at least one include line
// (if there are any) and none of the "!" exclude lines.
function rowPassesFilter(row, item) {
const cell = cellForDefinition(row, item.definition);
const value = textValue(cell);
const matches = term => advancedFilterMatches(cell, value, term, item.definition);
if (item.includes.length && !item.includes.some(matches)) return false;
return !item.excludes.some(matches);
}
function applyFilters() {
rebuildMissingCellKeys();
const active = filterDefinitions
.map(definition => ({
definition,
terms: String(definition.input?.value || '')
.split(/\r?\n/)
.map(term => term.trim())
.filter(Boolean)
}))
.filter(item => item.terms.length);
const active = activeFilterItems();
if (usesServerFilters) {
const serverTotal = Number.parseInt(table.dataset.serverFilterTotal || '', 10);
@@ -1122,14 +1439,7 @@
let visibleRows = 0;
[...tbody.rows].forEach(row => {
const hidden = active.some(({ definition, terms }) => {
const cell = cellForDefinition(row, definition);
const value = textValue(cell);
const matchesAnyTerm = terms.some(term =>
advancedFilterMatches(cell, value, term, definition)
);
return !matchesAnyTerm;
});
const hidden = active.some(item => !rowPassesFilter(row, item));
row.hidden = hidden;
if (!hidden) visibleRows += 1;
@@ -1230,14 +1540,19 @@
filterCell.appendChild(input);
const advancedFilterType = inferredAdvancedFilterType(header, columnIndex, serverName);
createAdvancedFilterHelper(filterCell, input, advancedFilterType);
filterDefinitions.push({
const definition = {
field,
columnIndex,
input,
serverName,
numericFilter: header.dataset.numericFilter === '1',
advancedFilterType
});
advancedFilterType,
title: textValue(header)
};
filterDefinitions.push(definition);
if (!header.dataset.noValueList && (!usesServerFilters || header.dataset.valueList === 'server')) {
createValueListButton(filterCell, definition);
}
}
filterRow.appendChild(filterCell);
+7
View File
@@ -36,6 +36,13 @@
}, seconds * 1000);
}
// Small API for scripts that need to report an error without a page reload.
window.AssetManagerToast = {
error: message => showToast(message, 'error'),
warning: message => showToast(message, 'warning'),
success: message => showToast(message, 'success')
};
let changed = false;
entries.forEach(([key, level]) => {
const values = params.getAll(key);