Files
furumi-ng/furumi-agent/src/web/admin.html
T

604 lines
26 KiB
HTML
Raw Normal View History

2026-03-18 02:21:00 +00:00
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Furumi Agent — Admin</title>
<style>
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
--bg-base: #0a0c12;
--bg-panel: #111520;
--bg-card: #161d2e;
--bg-hover: #1e2740;
--bg-active: #252f4a;
--border: #1f2c45;
--accent: #7c6af7;
--accent-dim: #5a4fcf;
--text: #e2e8f0;
--text-muted: #64748b;
--text-dim: #94a3b8;
--success: #34d399;
--danger: #f87171;
--warning: #fbbf24;
}
html, body { height: 100%; overflow: hidden; }
2026-03-18 04:05:47 +00:00
body { font-family: 'Inter', sans-serif; background: var(--bg-base); color: var(--text); display: flex; flex-direction: column; }
2026-03-18 02:21:00 +00:00
2026-03-18 04:05:47 +00:00
header { background: var(--bg-panel); border-bottom: 1px solid var(--border); padding: 10px 24px; display: flex; align-items: center; gap: 20px; flex-shrink: 0; }
header h1 { font-size: 15px; font-weight: 600; }
.stats { display: flex; gap: 14px; margin-left: auto; font-size: 12px; color: var(--text-dim); }
.stats .stat { display: flex; gap: 3px; align-items: center; }
2026-03-18 02:21:00 +00:00
.stats .stat-value { color: var(--text); font-weight: 600; }
2026-03-18 04:05:47 +00:00
.agent-status { font-size: 11px; padding: 3px 8px; border-radius: 4px; }
.agent-status.idle { background: #052e16; color: var(--success); }
.agent-status.busy { background: #1e1b4b; color: var(--accent); animation: pulse 1.5s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.6; } }
2026-03-18 02:21:00 +00:00
2026-03-18 04:05:47 +00:00
nav { display: flex; gap: 3px; }
nav button { background: none; border: none; color: var(--text-muted); padding: 5px 10px; border-radius: 5px; cursor: pointer; font-size: 12px; font-family: inherit; }
2026-03-18 02:21:00 +00:00
nav button:hover { background: var(--bg-hover); color: var(--text); }
nav button.active { background: var(--bg-active); color: var(--accent); }
2026-03-18 04:05:47 +00:00
/* Filter bar */
.filter-bar { display: flex; gap: 4px; padding: 10px 24px; border-bottom: 1px solid var(--border); flex-shrink: 0; align-items: center; flex-wrap: wrap; }
.filter-btn { font-size: 11px; padding: 4px 10px; background: var(--bg-card); border: 1px solid var(--border); border-radius: 5px; color: var(--text-muted); cursor: pointer; font-family: inherit; }
.filter-btn:hover { border-color: var(--accent); color: var(--text); }
.filter-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.filter-btn .count { font-weight: 600; margin-left: 3px; }
2026-03-18 02:21:00 +00:00
2026-03-18 04:05:47 +00:00
main { flex: 1; overflow-y: auto; }
2026-03-18 02:21:00 +00:00
2026-03-18 04:05:47 +00:00
/* Table */
table { width: 100%; border-collapse: collapse; font-size: 12px; }
th { text-align: left; padding: 6px 10px; color: var(--text-muted); font-weight: 500; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--bg-base); z-index: 2; font-size: 11px; }
td { padding: 5px 10px; border-bottom: 1px solid var(--border); max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
tr:hover td { background: var(--bg-hover); }
tr.selected td { background: var(--bg-active); }
2026-03-18 02:21:00 +00:00
2026-03-18 04:05:47 +00:00
/* Group header */
.group-header td { background: var(--bg-card); font-weight: 600; color: var(--text-dim); font-size: 11px; letter-spacing: 0.03em; padding: 8px 10px; border-bottom: 1px solid var(--border); }
.group-header:hover td { background: var(--bg-card); }
2026-03-18 02:21:00 +00:00
2026-03-18 04:05:47 +00:00
/* Inline edit */
td.editable { cursor: text; }
td.editable:hover { outline: 1px dashed var(--border); outline-offset: -2px; }
td .inline-input { background: var(--bg-card); border: 1px solid var(--accent); border-radius: 3px; padding: 2px 5px; color: var(--text); font-size: 12px; font-family: inherit; width: 100%; }
2026-03-18 02:21:00 +00:00
2026-03-18 04:05:47 +00:00
/* Checkbox */
.cb { width: 15px; height: 15px; accent-color: var(--accent); cursor: pointer; }
2026-03-18 02:21:00 +00:00
2026-03-18 04:05:47 +00:00
.status { padding: 2px 7px; border-radius: 3px; font-size: 10px; font-weight: 600; text-transform: uppercase; }
2026-03-18 02:21:00 +00:00
.status-pending { background: #1e293b; color: var(--text-muted); }
.status-processing { background: #1e1b4b; color: var(--accent); }
.status-review { background: #422006; color: var(--warning); }
.status-approved { background: #052e16; color: var(--success); }
.status-rejected { background: #450a0a; color: var(--danger); }
.status-error { background: #450a0a; color: var(--danger); }
2026-03-18 04:05:47 +00:00
.actions { display: flex; gap: 3px; }
.btn { border: none; padding: 3px 8px; border-radius: 3px; cursor: pointer; font-size: 11px; font-family: inherit; font-weight: 500; }
2026-03-18 02:21:00 +00:00
.btn-approve { background: #052e16; color: var(--success); }
.btn-approve:hover { background: #065f46; }
.btn-reject { background: #450a0a; color: var(--danger); }
.btn-reject:hover { background: #7f1d1d; }
2026-03-18 04:05:47 +00:00
.btn-retry { background: #1e1b4b; color: var(--accent); }
.btn-retry:hover { background: #312e81; }
2026-03-18 02:21:00 +00:00
.btn-edit { background: var(--bg-active); color: var(--text-dim); }
.btn-edit:hover { background: var(--bg-hover); color: var(--text); }
.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover { background: var(--accent-dim); }
.btn-cancel { background: var(--bg-card); color: var(--text-dim); }
.btn-cancel:hover { background: var(--bg-hover); }
2026-03-18 04:05:47 +00:00
.empty { text-align: center; padding: 48px; color: var(--text-muted); font-size: 13px; }
2026-03-18 02:21:00 +00:00
2026-03-18 04:05:47 +00:00
/* Floating batch toolbar */
.batch-bar { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--bg-panel); border: 1px solid var(--border); border-radius: 10px; padding: 10px 20px; display: flex; gap: 10px; align-items: center; box-shadow: 0 8px 32px rgba(0,0,0,0.6); z-index: 50; transition: opacity 0.2s, transform 0.2s; }
.batch-bar.hidden { opacity: 0; pointer-events: none; transform: translateX(-50%) translateY(20px); }
.batch-bar .batch-count { font-size: 13px; font-weight: 600; margin-right: 8px; color: var(--accent); }
.batch-bar .btn { padding: 6px 14px; font-size: 12px; }
2026-03-18 02:21:00 +00:00
2026-03-18 04:05:47 +00:00
/* Modal */
.modal-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.7); z-index: 100; align-items: center; justify-content: center; }
.modal-overlay.visible { display: flex; }
.modal { background: var(--bg-panel); border: 1px solid var(--border); border-radius: 12px; padding: 24px; min-width: 400px; max-width: 600px; max-height: 90vh; overflow-y: auto; }
.modal h2 { font-size: 15px; margin-bottom: 14px; }
.modal label { display: block; font-size: 11px; color: var(--text-muted); margin-bottom: 3px; margin-top: 10px; }
.modal input, .modal textarea { width: 100%; background: var(--bg-card); border: 1px solid var(--border); border-radius: 5px; padding: 7px 9px; color: var(--text); font-family: inherit; font-size: 12px; }
.modal textarea { resize: vertical; min-height: 50px; }
.modal-actions { margin-top: 16px; display: flex; gap: 6px; justify-content: flex-end; }
.modal-actions .btn { padding: 7px 14px; }
.detail-row { display: flex; gap: 10px; margin-top: 6px; }
.detail-row .field { flex: 1; }
.raw-value { font-size: 10px; color: var(--text-muted); margin-top: 1px; }
2026-03-18 02:21:00 +00:00
2026-03-18 04:05:47 +00:00
/* Featured artist tags */
.feat-tags { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 5px; min-height: 24px; }
.feat-tag { display: flex; align-items: center; gap: 3px; background: var(--bg-active); border: 1px solid var(--border); border-radius: 3px; padding: 1px 7px; font-size: 11px; }
.feat-tag .remove { cursor: pointer; color: var(--text-muted); font-size: 13px; line-height: 1; }
2026-03-18 02:21:00 +00:00
.feat-tag .remove:hover { color: var(--danger); }
2026-03-18 04:05:47 +00:00
.artist-search-wrap { position: relative; margin-top: 5px; }
.artist-dropdown { position: absolute; top: 100%; left: 0; right: 0; background: var(--bg-card); border: 1px solid var(--border); border-radius: 0 0 5px 5px; max-height: 140px; overflow-y: auto; z-index: 10; display: none; }
2026-03-18 02:21:00 +00:00
.artist-dropdown.open { display: block; }
2026-03-18 04:05:47 +00:00
.artist-option { padding: 5px 9px; cursor: pointer; font-size: 12px; }
2026-03-18 02:21:00 +00:00
.artist-option:hover { background: var(--bg-hover); }
</style>
</head>
<body>
<header>
<h1>Furumi Agent</h1>
<nav>
2026-03-18 04:05:47 +00:00
<button class="active" onclick="showTab('queue',this)">Queue</button>
<button onclick="showTab('artists',this)">Artists</button>
2026-03-18 02:21:00 +00:00
</nav>
2026-03-18 04:05:47 +00:00
<span class="agent-status idle" id="agentStatus">Idle</span>
2026-03-18 02:21:00 +00:00
<div class="stats" id="statsBar"></div>
</header>
2026-03-18 04:05:47 +00:00
<div class="filter-bar" id="filterBar"></div>
2026-03-18 02:21:00 +00:00
<main id="content"></main>
2026-03-18 04:05:47 +00:00
<div class="batch-bar hidden" id="batchBar">
<span class="batch-count" id="batchCount">0 selected</span>
<button class="btn btn-approve" onclick="batchAction('approve')">Approve</button>
<button class="btn btn-reject" onclick="batchAction('reject')">Reject</button>
<button class="btn btn-retry" onclick="batchAction('retry')">Retry</button>
<button class="btn btn-edit" onclick="batchAction('delete')">Delete</button>
<button class="btn btn-cancel" onclick="clearSelection()">Cancel</button>
</div>
2026-03-18 02:21:00 +00:00
<div class="modal-overlay" id="modalOverlay" onclick="if(event.target===this)closeModal()">
<div class="modal" id="modal"></div>
</div>
<script>
const _base = location.pathname.replace(/\/+$/, '');
const API = _base + '/api';
2026-03-18 02:21:00 +00:00
let currentTab = 'queue';
let currentFilter = null;
2026-03-18 04:05:47 +00:00
let queueItems = [];
let selected = new Set();
let searchTimer = null;
let editFeatured = [];
let statsCache = null;
2026-03-18 02:21:00 +00:00
async function api(path, opts) {
const r = await fetch(API + path, opts);
if (r.status === 204) return null;
const text = await r.text();
if (!text) return null;
try { return JSON.parse(text); }
2026-03-18 04:05:47 +00:00
catch(e) { console.error('API error:', r.status, text); return null; }
2026-03-18 02:21:00 +00:00
}
2026-03-18 04:05:47 +00:00
// --- Stats & polling ---
2026-03-18 02:21:00 +00:00
async function loadStats() {
const s = await api('/stats');
2026-03-18 04:05:47 +00:00
if (!s) return;
statsCache = s;
2026-03-18 02:21:00 +00:00
document.getElementById('statsBar').innerHTML = `
<div class="stat">Tracks: <span class="stat-value">${s.total_tracks}</span></div>
<div class="stat">Artists: <span class="stat-value">${s.total_artists}</span></div>
<div class="stat">Albums: <span class="stat-value">${s.total_albums}</span></div>
2026-03-18 04:05:47 +00:00
`;
// Agent status
const el = document.getElementById('agentStatus');
if (s.pending_count > 0) { el.textContent = 'Processing...'; el.className = 'agent-status busy'; }
else { el.textContent = 'Idle'; el.className = 'agent-status idle'; }
// Update filter counts if on queue tab
if (currentTab === 'queue') renderFilterBar(s);
}
function renderFilterBar(s) {
const bar = document.getElementById('filterBar');
if (currentTab !== 'queue') { bar.innerHTML = ''; return; }
const f = currentFilter;
bar.innerHTML = `
<button class="filter-btn ${!f?'active':''}" onclick="loadQueue()">All</button>
<button class="filter-btn ${f==='review'?'active':''}" onclick="loadQueue('review')">Review<span class="count">${s.review_count}</span></button>
<button class="filter-btn ${f==='pending'?'active':''}" onclick="loadQueue('pending')">Pending<span class="count">${s.pending_count}</span></button>
<button class="filter-btn ${f==='error'?'active':''}" onclick="loadQueue('error')">Errors<span class="count">${s.error_count}</span></button>
<button class="filter-btn ${f==='approved'?'active':''}" onclick="loadQueue('approved')">Approved</button>
<button class="filter-btn ${f==='rejected'?'active':''}" onclick="loadQueue('rejected')">Rejected</button>
2026-03-18 02:21:00 +00:00
`;
}
2026-03-18 04:05:47 +00:00
function showTab(tab, btn) {
2026-03-18 02:21:00 +00:00
currentTab = tab;
document.querySelectorAll('nav button').forEach(b => b.classList.remove('active'));
2026-03-18 04:05:47 +00:00
btn.classList.add('active');
clearSelection();
if (tab === 'queue') { loadQueue(); loadStats(); }
else if (tab === 'artists') { loadArtists(); document.getElementById('filterBar').innerHTML = ''; }
2026-03-18 02:21:00 +00:00
}
2026-03-18 04:05:47 +00:00
// --- Queue ---
async function loadQueue(status, keepSelection) {
2026-03-18 02:21:00 +00:00
currentFilter = status;
2026-03-18 04:05:47 +00:00
if (!keepSelection) clearSelection();
const qs = status ? `?status=${status}&limit=200` : '?limit=200';
queueItems = await api(`/queue${qs}`) || [];
// Prune selection: remove ids no longer in the list
const currentIds = new Set(queueItems.map(i => i.id));
for (const id of [...selected]) { if (!currentIds.has(id)) selected.delete(id); }
updateBatchBar();
renderQueue();
if (statsCache) renderFilterBar(statsCache);
}
function renderQueue() {
2026-03-18 02:21:00 +00:00
const el = document.getElementById('content');
2026-03-18 04:05:47 +00:00
if (!queueItems.length) { el.innerHTML = '<div class="empty">No items in queue</div>'; return; }
// Group by album
const groups = {};
const noAlbum = [];
for (const it of queueItems) {
const key = it.norm_album || it.raw_album || it.path_album;
if (key) { (groups[key] = groups[key] || []).push(it); }
else noAlbum.push(it);
2026-03-18 02:21:00 +00:00
}
2026-03-18 04:05:47 +00:00
let html = `<table><tr>
<th style="width:30px"><input type="checkbox" class="cb" onchange="toggleSelectAll(this.checked)"></th>
<th style="width:70px">Status</th>
<th>Artist</th>
<th>Title</th>
<th>Album</th>
<th style="width:40px">Yr</th>
<th style="width:30px">#</th>
<th style="width:40px">Conf</th>
<th style="width:130px">Actions</th>
</tr>`;
const renderRow = (it) => {
const sel = selected.has(it.id) ? ' selected' : '';
2026-03-18 02:21:00 +00:00
const conf = it.confidence != null ? it.confidence.toFixed(2) : '-';
2026-03-18 04:05:47 +00:00
const artist = it.norm_artist || it.raw_artist || '-';
const title = it.norm_title || it.raw_title || '-';
const album = it.norm_album || it.raw_album || '-';
const year = it.norm_year || it.raw_year || '';
const tnum = it.norm_track_number || it.raw_track_number || '';
const canApprove = it.status === 'review';
const canRetry = it.status === 'error';
return `<tr class="${sel}" data-id="${it.id}">
<td><input type="checkbox" class="cb" ${selected.has(it.id)?'checked':''} onchange="toggleSelect('${it.id}',this.checked)"></td>
2026-03-18 02:21:00 +00:00
<td><span class="status status-${it.status}">${it.status}</span></td>
2026-03-18 04:05:47 +00:00
<td class="editable" ondblclick="inlineEdit(this,'${it.id}','norm_artist')" title="${esc(it.raw_artist||'')}">${esc(artist)}</td>
<td class="editable" ondblclick="inlineEdit(this,'${it.id}','norm_title')" title="${esc(it.raw_title||'')}">${esc(title)}</td>
<td class="editable" ondblclick="inlineEdit(this,'${it.id}','norm_album')" title="${esc(it.raw_album||'')}">${esc(album)}</td>
<td>${year}</td>
<td>${tnum}</td>
2026-03-18 02:21:00 +00:00
<td>${conf}</td>
<td class="actions">
2026-03-18 04:05:47 +00:00
${canApprove ? `<button class="btn btn-approve" onclick="approveItem('${it.id}')">Approve</button>` : ''}
${canApprove ? `<button class="btn btn-reject" onclick="rejectItem('${it.id}')">Reject</button>` : ''}
${canRetry ? `<button class="btn btn-retry" onclick="retryItem('${it.id}')">Retry</button>` : ''}
2026-03-18 02:21:00 +00:00
<button class="btn btn-edit" onclick="editItem('${it.id}')">Edit</button>
</td>
</tr>`;
2026-03-18 04:05:47 +00:00
};
// Render grouped
for (const [albumName, items] of Object.entries(groups)) {
const artist = items[0].norm_artist || items[0].raw_artist || '?';
const year = items[0].norm_year || items[0].raw_year || '';
const yearStr = year ? ` (${year})` : '';
const albumIds = items.map(i => i.id);
html += `<tr class="group-header">
<td><input type="checkbox" class="cb" onchange="toggleSelectGroup(${JSON.stringify(albumIds).replace(/"/g,'&quot;')},this.checked)"></td>
<td colspan="8">${esc(artist)}${esc(albumName)}${yearStr} &nbsp; (${items.length} tracks)</td>
</tr>`;
for (const it of items) html += renderRow(it);
}
// Ungrouped
if (noAlbum.length) {
if (Object.keys(groups).length) {
html += `<tr class="group-header"><td></td><td colspan="8">Ungrouped</td></tr>`;
}
for (const it of noAlbum) html += renderRow(it);
2026-03-18 02:21:00 +00:00
}
html += '</table>';
el.innerHTML = html;
}
2026-03-18 04:05:47 +00:00
// --- Selection ---
function toggleSelect(id, checked) {
if (checked) selected.add(id); else selected.delete(id);
updateBatchBar();
// Update row style
const row = document.querySelector(`tr[data-id="${id}"]`);
if (row) row.classList.toggle('selected', checked);
}
2026-03-18 02:21:00 +00:00
2026-03-18 04:05:47 +00:00
function toggleSelectAll(checked) {
selected.clear();
if (checked) queueItems.forEach(it => selected.add(it.id));
updateBatchBar();
renderQueue();
}
2026-03-18 02:21:00 +00:00
2026-03-18 04:05:47 +00:00
function toggleSelectGroup(ids, checked) {
ids.forEach(id => { if (checked) selected.add(id); else selected.delete(id); });
updateBatchBar();
renderQueue();
2026-03-18 02:21:00 +00:00
}
2026-03-18 04:05:47 +00:00
function clearSelection() { selected.clear(); updateBatchBar(); }
function updateBatchBar() {
const bar = document.getElementById('batchBar');
if (selected.size > 0) {
bar.classList.remove('hidden');
document.getElementById('batchCount').textContent = selected.size + ' selected';
} else {
bar.classList.add('hidden');
}
2026-03-18 02:21:00 +00:00
}
2026-03-18 04:05:47 +00:00
async function batchAction(action) {
const ids = [...selected];
if (!ids.length) return;
if (action === 'delete' && !confirm(`Delete ${ids.length} item(s)?`)) return;
await api(`/queue/batch/${action}`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ ids }),
});
clearSelection();
2026-03-18 02:21:00 +00:00
loadStats();
loadQueue(currentFilter);
}
2026-03-18 04:05:47 +00:00
// --- Single actions ---
async function approveItem(id) { await api(`/queue/${id}/approve`, { method: 'POST' }); loadStats(); loadQueue(currentFilter); }
async function rejectItem(id) { await api(`/queue/${id}/reject`, { method: 'POST' }); loadStats(); loadQueue(currentFilter); }
async function retryItem(id) { await api(`/queue/${id}/retry`, { method: 'POST' }); loadStats(); loadQueue(currentFilter); }
// --- Inline editing ---
function inlineEdit(td, id, field) {
if (td.querySelector('.inline-input')) return;
const current = td.textContent.trim();
const input = document.createElement('input');
input.className = 'inline-input';
input.value = current === '-' ? '' : current;
td.textContent = '';
td.appendChild(input);
input.focus();
input.select();
const save = async () => {
const val = input.value.trim();
td.textContent = val || '-';
// Send update
const body = {};
body[field] = val || null;
await api(`/queue/${id}/update`, {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(body),
});
// Update local cache
const item = queueItems.find(i => i.id === id);
if (item) item[field] = val || null;
};
2026-03-18 02:21:00 +00:00
2026-03-18 04:05:47 +00:00
input.addEventListener('blur', save);
input.addEventListener('keydown', e => {
if (e.key === 'Enter') { e.preventDefault(); input.blur(); }
if (e.key === 'Escape') { td.textContent = current; }
});
}
// --- Full edit modal ---
2026-03-18 02:21:00 +00:00
async function editItem(id) {
const item = await api(`/queue/${id}`);
if (!item) return;
editFeatured = [];
if (item.norm_featured_artists) {
try { editFeatured = JSON.parse(item.norm_featured_artists); } catch(e) {}
}
document.getElementById('modal').innerHTML = `
<h2>Edit Metadata</h2>
<div class="detail-row">
<div class="field">
<label>Artist</label>
<input id="ed-artist" value="${esc(item.norm_artist || item.raw_artist || '')}">
<div class="raw-value">Raw: ${esc(item.raw_artist || '-')} | Path: ${esc(item.path_artist || '-')}</div>
</div>
</div>
<div class="detail-row">
<div class="field">
<label>Title</label>
<input id="ed-title" value="${esc(item.norm_title || item.raw_title || '')}">
<div class="raw-value">Raw: ${esc(item.raw_title || '-')} | Path: ${esc(item.path_title || '-')}</div>
</div>
</div>
<div class="detail-row">
<div class="field">
<label>Album</label>
<input id="ed-album" value="${esc(item.norm_album || item.raw_album || '')}">
<div class="raw-value">Raw: ${esc(item.raw_album || '-')} | Path: ${esc(item.path_album || '-')}</div>
</div>
<div class="field">
<label>Year</label>
<input id="ed-year" type="number" value="${item.norm_year || item.raw_year || ''}">
</div>
</div>
<div class="detail-row">
<div class="field">
<label>Track #</label>
<input id="ed-track" type="number" value="${item.norm_track_number || item.raw_track_number || ''}">
</div>
<div class="field">
<label>Genre</label>
<input id="ed-genre" value="${esc(item.norm_genre || item.raw_genre || '')}">
</div>
</div>
<label>Featured Artists</label>
<div class="feat-tags" id="feat-tags"></div>
<div class="artist-search-wrap">
<input id="feat-search" placeholder="Search artist to add..." autocomplete="off"
oninput="onFeatSearch(this.value)" onkeydown="onFeatKey(event)">
<div class="artist-dropdown" id="feat-dropdown"></div>
</div>
2026-03-18 04:05:47 +00:00
${item.llm_notes ? `<label>Agent Notes</label><div class="raw-value" style="margin-bottom:6px">${esc(item.llm_notes)}</div>` : ''}
2026-03-18 02:21:00 +00:00
${item.error_message ? `<label>Error</label><div class="raw-value" style="color:var(--danger)">${esc(item.error_message)}</div>` : ''}
<div class="modal-actions">
<button class="btn btn-cancel" onclick="closeModal()">Cancel</button>
<button class="btn btn-primary" onclick="saveEdit('${item.id}')">Save</button>
</div>
`;
renderFeatTags();
openModal();
}
2026-03-18 04:05:47 +00:00
async function saveEdit(id) {
const body = {
norm_artist: document.getElementById('ed-artist').value || null,
norm_title: document.getElementById('ed-title').value || null,
norm_album: document.getElementById('ed-album').value || null,
norm_year: parseInt(document.getElementById('ed-year').value) || null,
norm_track_number: parseInt(document.getElementById('ed-track').value) || null,
norm_genre: document.getElementById('ed-genre').value || null,
featured_artists: editFeatured,
};
await api(`/queue/${id}/update`, {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(body),
});
closeModal();
loadQueue(currentFilter);
}
// --- Featured artists ---
2026-03-18 02:21:00 +00:00
function renderFeatTags() {
const el = document.getElementById('feat-tags');
if (!el) return;
el.innerHTML = editFeatured.map((name, i) =>
`<span class="feat-tag">${esc(name)}<span class="remove" onclick="removeFeat(${i})">&times;</span></span>`
).join('');
}
2026-03-18 04:05:47 +00:00
function removeFeat(idx) { editFeatured.splice(idx, 1); renderFeatTags(); }
2026-03-18 02:21:00 +00:00
function addFeat(name) {
name = name.trim();
if (!name || editFeatured.includes(name)) return;
editFeatured.push(name);
renderFeatTags();
const input = document.getElementById('feat-search');
2026-03-18 04:05:47 +00:00
if (input) input.value = '';
2026-03-18 02:21:00 +00:00
closeFeatDropdown();
}
function onFeatSearch(q) {
clearTimeout(searchTimer);
if (q.length < 2) { closeFeatDropdown(); return; }
searchTimer = setTimeout(async () => {
const results = await api(`/artists/search?q=${encodeURIComponent(q)}&limit=8`);
const dd = document.getElementById('feat-dropdown');
if (!results || !results.length) {
2026-03-18 04:05:47 +00:00
dd.innerHTML = `<div class="artist-option" onclick="addFeat('${esc(q)}')">Add "${esc(q)}" as new</div>`;
2026-03-18 02:21:00 +00:00
dd.classList.add('open');
return;
}
2026-03-18 04:05:47 +00:00
let html = results.map(a => `<div class="artist-option" onclick="addFeat('${esc(a.name)}')">${esc(a.name)}</div>`).join('');
2026-03-18 02:21:00 +00:00
const typed = document.getElementById('feat-search').value.trim();
if (typed && !results.find(a => a.name.toLowerCase() === typed.toLowerCase())) {
2026-03-18 04:05:47 +00:00
html += `<div class="artist-option" onclick="addFeat('${esc(typed)}')">Add "${esc(typed)}" as new</div>`;
2026-03-18 02:21:00 +00:00
}
dd.innerHTML = html;
dd.classList.add('open');
}, 250);
}
function onFeatKey(e) {
2026-03-18 04:05:47 +00:00
if (e.key === 'Enter') { e.preventDefault(); addFeat(e.target.value); }
else if (e.key === 'Escape') closeFeatDropdown();
2026-03-18 02:21:00 +00:00
}
2026-03-18 04:05:47 +00:00
function closeFeatDropdown() { const dd = document.getElementById('feat-dropdown'); if (dd) dd.classList.remove('open'); }
2026-03-18 02:21:00 +00:00
2026-03-18 04:05:47 +00:00
// --- Artists tab ---
async function loadArtists() {
const artists = await api('/artists');
const el = document.getElementById('content');
if (!artists || !artists.length) { el.innerHTML = '<div class="empty">No artists yet</div>'; return; }
let html = '<table><tr><th>ID</th><th>Name</th><th>Actions</th></tr>';
for (const a of artists) {
html += `<tr>
<td>${a.id}</td>
<td class="editable" ondblclick="inlineEditArtist(this,${a.id})">${esc(a.name)}</td>
<td class="actions">
<button class="btn btn-edit" onclick="editArtist(${a.id},'${esc(a.name)}')">Rename</button>
</td>
</tr>`;
}
html += '</table>';
el.innerHTML = html;
2026-03-18 02:21:00 +00:00
}
2026-03-18 04:05:47 +00:00
function inlineEditArtist(td, id) {
if (td.querySelector('.inline-input')) return;
const current = td.textContent.trim();
const input = document.createElement('input');
input.className = 'inline-input';
input.value = current;
td.textContent = '';
td.appendChild(input);
input.focus();
input.select();
const save = async () => {
const val = input.value.trim();
if (!val || val === current) { td.textContent = current; return; }
td.textContent = val;
await api(`/artists/${id}`, {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ name: val }),
});
2026-03-18 02:21:00 +00:00
};
2026-03-18 04:05:47 +00:00
input.addEventListener('blur', save);
input.addEventListener('keydown', e => {
if (e.key === 'Enter') { e.preventDefault(); input.blur(); }
if (e.key === 'Escape') { td.textContent = current; }
2026-03-18 02:21:00 +00:00
});
}
async function editArtist(id, currentName) {
const name = prompt('New artist name:', currentName);
if (!name || name === currentName) return;
await api(`/artists/${id}`, {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ name }),
});
loadArtists();
}
2026-03-18 04:05:47 +00:00
// --- Helpers ---
2026-03-18 02:21:00 +00:00
function openModal() { document.getElementById('modalOverlay').classList.add('visible'); }
function closeModal() { document.getElementById('modalOverlay').classList.remove('visible'); }
function esc(s) {
if (s == null) return '';
return String(s).replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;').replace(/"/g,'&quot;').replace(/'/g,'&#39;');
}
2026-03-18 04:05:47 +00:00
// --- Init ---
2026-03-18 02:21:00 +00:00
loadStats();
loadQueue();
2026-03-18 04:05:47 +00:00
setInterval(loadStats, 5000);
// Auto-refresh queue when on queue tab
setInterval(() => { if (currentTab === 'queue') loadQueue(currentFilter, true); }, 5000);
2026-03-18 02:21:00 +00:00
</script>
</body>
</html>