Last cleanup commit

This commit is contained in:
Ian Keane 2026-08-07 17:25:32 -04:00
parent 46f2a303dc
commit 9dc16c6c63
2 changed files with 22 additions and 5 deletions

26
app.js
View file

@ -1589,7 +1589,7 @@ $('btn-refs-csv-import').addEventListener('click', async () => {
await loadAll();
let html = `<p class="csv-ok">✓ ${results.created} reference${results.created !== 1 ? 's' : ''} imported.</p>`;
if (results.warnings.length) {
html += `<p class="csv-error">${results.warnings.length} skipped — tune not found:</p><ul class="csv-errors">`;
html += `<p class="csv-error">${results.warnings.length} skipped:</p><ul class="csv-errors">`;
results.warnings.forEach(w => { html += `<li>${esc(w)}</li>`; });
html += '</ul>';
}
@ -1633,13 +1633,29 @@ async function importRefsCsvRows(rows) {
}
for (const row of rows) {
const tuneName = row.tune_name?.trim();
const tuneName = row.tune_name?.trim();
const sourceName = row.source?.trim();
if (!tuneName) continue;
const tune = allTunes.find(t => (t.name ?? '').toLowerCase() === tuneName.toLowerCase());
if (!tune) {
results.warnings.push(tuneName);
const matches = allTunes.filter(t => (t.name ?? '').toLowerCase() === tuneName.toLowerCase());
let tune;
if (matches.length === 0) {
results.warnings.push(`${tuneName} — not found`);
continue;
} else if (matches.length === 1) {
tune = matches[0];
} else {
// Multiple tunes with this name — need source to disambiguate
if (sourceName) {
tune = matches.find(t => (t.source?.name ?? '').toLowerCase() === sourceName.toLowerCase());
if (!tune) {
results.warnings.push(`${tuneName} (source: ${sourceName}) — no matching source found`);
continue;
}
} else {
results.warnings.push(`${tuneName} — ambiguous (${matches.length} tunes with this name; add a source column to disambiguate)`);
continue;
}
}
try {

View file

@ -266,6 +266,7 @@
<thead><tr><th>Column</th><th>Required</th><th>Notes</th></tr></thead>
<tbody>
<tr><td>tune_name</td><td>Yes</td><td>Must match an existing tune (case-insensitive)</td></tr>
<tr><td>source</td><td></td><td>Disambiguates when multiple tunes share a name</td></tr>
<tr><td>link</td><td></td><td>URL</td></tr>
<tr><td>site</td><td></td><td>Site name — created if new</td></tr>
<tr><td>musician1</td><td></td><td>Musician name — created if new</td></tr>