Skip to content

Commit

Permalink
Improve board import flow in case of duplicate board.id or title
Browse files Browse the repository at this point in the history
  • Loading branch information
apankrat committed Aug 10, 2022
1 parent d2fa350 commit a456a76
Showing 1 changed file with 38 additions and 3 deletions.
41 changes: 38 additions & 3 deletions nullboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -3501,26 +3501,61 @@ <h3>Auto-backup</h3>
if (! confirm(msg))
return false;

var to_open = '';

for (var i=0; i<data.length; i++)
{
var board = data[i];
var check_title = true;

// check ID

if (index.has(board.id))
{
console.log(`Import: board ${board.id} (${board.title}) will be assigned new ID`);
board.id = +new Date();
var which = (data.length == 1) ? "with the same ID" : board.id;

if (confirm(`Board ${which} already exists. Overwrite it?`) &&
confirm(`OVERWRITE for sure?`))
{
console.log(`Import: ${board.id} (${board.title} - will overwrite existing one`);
check_title = false;
}
else
if (confirm(`Import the board under a new ID?`))
{
var new_id = +new Date();
console.log(`Import: ${board.id} (${board.title} - will import as ${new_id}`);
board.id = new_id;
}
else
{
console.log(`Import: ${board.id} (${board.title} - ID conflict, will not import`);
continue;
}
}

if (check_title)
{
var retitle = false;
index.forEach( have => { retitle |= (have.title == board.title) } );

if (retitle) board.title += ' (imported)';
}

// ok, do the deed

board.revision--; // save will ++ it back

if (! NB.storage.saveBoard(board)) // this updates 'index'
{
alert(`Failed to save board ${board.id}. Import failed.`);
return false;
}

if (! to_open) to_open = data[0].id;
}

openBoard(data[0].id);
if (to_open) openBoard(to_open);
}

/*
Expand Down

0 comments on commit a456a76

Please sign in to comment.