Last cleanup commit
This commit is contained in:
parent
46f2a303dc
commit
9dc16c6c63
2 changed files with 22 additions and 5 deletions
24
app.js
24
app.js
|
|
@ -1589,7 +1589,7 @@ $('btn-refs-csv-import').addEventListener('click', async () => {
|
||||||
await loadAll();
|
await loadAll();
|
||||||
let html = `<p class="csv-ok">✓ ${results.created} reference${results.created !== 1 ? 's' : ''} imported.</p>`;
|
let html = `<p class="csv-ok">✓ ${results.created} reference${results.created !== 1 ? 's' : ''} imported.</p>`;
|
||||||
if (results.warnings.length) {
|
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>`; });
|
results.warnings.forEach(w => { html += `<li>${esc(w)}</li>`; });
|
||||||
html += '</ul>';
|
html += '</ul>';
|
||||||
}
|
}
|
||||||
|
|
@ -1634,12 +1634,28 @@ async function importRefsCsvRows(rows) {
|
||||||
|
|
||||||
for (const row of 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;
|
if (!tuneName) continue;
|
||||||
|
|
||||||
const tune = allTunes.find(t => (t.name ?? '').toLowerCase() === tuneName.toLowerCase());
|
const matches = allTunes.filter(t => (t.name ?? '').toLowerCase() === tuneName.toLowerCase());
|
||||||
if (!tune) {
|
let tune;
|
||||||
results.warnings.push(tuneName);
|
if (matches.length === 0) {
|
||||||
|
results.warnings.push(`${tuneName} — not found`);
|
||||||
continue;
|
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 {
|
try {
|
||||||
|
|
|
||||||
|
|
@ -266,6 +266,7 @@
|
||||||
<thead><tr><th>Column</th><th>Required</th><th>Notes</th></tr></thead>
|
<thead><tr><th>Column</th><th>Required</th><th>Notes</th></tr></thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr><td>tune_name</td><td>Yes</td><td>Must match an existing tune (case-insensitive)</td></tr>
|
<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>link</td><td></td><td>URL</td></tr>
|
||||||
<tr><td>site</td><td></td><td>Site name — created if new</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>
|
<tr><td>musician1</td><td></td><td>Musician name — created if new</td></tr>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue