feat(admin): add searchable cloud image catalog
parent
b6df7b14fd
commit
3479a2a362
@ -0,0 +1,70 @@
|
||||
const runningStates = new Set(['preparing', 'validating', 'distributing', 'importing',
|
||||
'syncing', 'pending', 'deleting', 'retiring', 'fetching', 'uploading']);
|
||||
const attentionStates = new Set(['degraded', 'error', 'failed', 'source_failed',
|
||||
'source_unknown', 'unknown', 'delete_failed', 'delete_unknown', 'delete_attention',
|
||||
'uncertain', 'missing', 'stale']);
|
||||
|
||||
function matches(entry, query, status) {
|
||||
const replicas = Array.isArray(entry.replicas) ? entry.replicas : [];
|
||||
const states = [entry.state, entry.artifact?.state,
|
||||
...replicas.filter(replica => replica.host_eligible === true).map(replica => replica.state)]
|
||||
.filter(Boolean).map(value => String(value).toLowerCase());
|
||||
const running = states.some(value => runningStates.has(value));
|
||||
const attention = states.some(value => attentionStates.has(value))
|
||||
|| Boolean(entry.cleanup_reason || entry.artifact?.error_code)
|
||||
|| replicas.some(replica => replica.host_record_present === false
|
||||
|| replica.repair_reason === 'content_divergent');
|
||||
if (status === 'running' && !running) return false;
|
||||
if (status === 'attention' && !attention) return false;
|
||||
const searchable = [entry.name, entry.id, entry.catalog_key, entry.os_family,
|
||||
entry.os_version, entry.version_label,
|
||||
...replicas.flatMap(replica => [replica.host_name, replica.host_region])]
|
||||
.filter(Boolean).join(' ').normalize('NFKC').toLowerCase();
|
||||
return searchable.includes(query.normalize('NFKC').toLowerCase());
|
||||
}
|
||||
|
||||
/** Filter a complete catalog without changing entries or their action policy. */
|
||||
export function mountAdminCatalogFilter({ form, count, onChange,
|
||||
locationImpl = globalThis.location, historyImpl = globalThis.history } = {}) {
|
||||
const query = form.elements.namedItem('catalog_q');
|
||||
const status = form.elements.namedItem('catalog_status');
|
||||
function restore() {
|
||||
const params = new URLSearchParams(locationImpl?.search || '');
|
||||
query.value = (params.get('catalog_q') || '').slice(0, 80);
|
||||
const value = params.get('catalog_status');
|
||||
status.value = ['running', 'attention'].includes(value) ? value : 'all';
|
||||
}
|
||||
function changed(event) {
|
||||
event?.preventDefault();
|
||||
if (locationImpl?.href && historyImpl?.replaceState) {
|
||||
const url = new URL(locationImpl.href);
|
||||
for (const [key, value] of [['catalog_q', query.value.trim()],
|
||||
['catalog_status', status.value === 'all' ? '' : status.value]]) {
|
||||
if (value) url.searchParams.set(key, value); else url.searchParams.delete(key);
|
||||
}
|
||||
historyImpl.replaceState(historyImpl.state, '', url);
|
||||
}
|
||||
onChange();
|
||||
}
|
||||
function reset(event) {
|
||||
query.value = ''; status.value = 'all'; changed(event);
|
||||
}
|
||||
restore();
|
||||
form.addEventListener('input', changed);
|
||||
form.addEventListener('change', changed);
|
||||
form.addEventListener('submit', changed);
|
||||
form.addEventListener('reset', reset);
|
||||
return Object.freeze({
|
||||
apply(entries) {
|
||||
const filtered = entries.filter(entry => matches(entry, query.value.trim(), status.value));
|
||||
count.textContent = `显示 ${filtered.length} / ${entries.length} 条记录`;
|
||||
return filtered;
|
||||
},
|
||||
destroy() {
|
||||
form.removeEventListener('input', changed);
|
||||
form.removeEventListener('change', changed);
|
||||
form.removeEventListener('submit', changed);
|
||||
form.removeEventListener('reset', reset);
|
||||
},
|
||||
});
|
||||
}
|
||||
@ -1,2 +1,2 @@
|
||||
{* Shared Venix CSS/JS cache key. Increment whenever a shared browser asset changes. *}
|
||||
{assign var=venix_asset_version value='2026103127' scope='global'}
|
||||
{assign var=venix_asset_version value='2026103128' scope='global'}
|
||||
|
||||
Loading…
Reference in New Issue