Last cleanup commit
This commit is contained in:
parent
46f2a303dc
commit
9dc16c6c63
2 changed files with 22 additions and 5 deletions
26
app.js
26
app.js
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue