+ exportBoard()

This commit is contained in:
Alex Pankratov
2021-03-31 20:20:49 +02:00
parent 8517f1868d
commit 00254cb274

View File

@@ -1129,9 +1129,9 @@
<div class=boards> <div class=boards>
<!-- here'll be boards --> <!-- here'll be boards -->
</div> </div>
<a href=# class=imp-board>Import board...</a> <a href=# class=exp-board>Export current board...</a>
<a href=# class=imp-board>Import...</a>
<input class=imp-board-select type="file" accept=".nbx"> <input class=imp-board-select type="file" accept=".nbx">
<a href=# class=exp-board>Export board...</a>
<a href="#" class="switch-theme">Use <i>light</i><b>dark</b> theme</a> <a href="#" class="switch-theme">Use <i>light</i><b>dark</b> theme</a>
<a href="#" class="switch-fsize">Use <i>smaller</i><b>larger</b> font</a> <a href="#" class="switch-fsize">Use <i>smaller</i><b>larger</b> font</a>
</div> </div>
@@ -1328,7 +1328,7 @@
for (var rev of meta.history) for (var rev of meta.history)
{ {
if ( (rev_old < rev && rev < rev_new) || (keep.length >= this.conf.max_undo) ) if ( (rev_old < rev && rev < rev_new) || (rebuild.length >= this.conf.max_undo) )
{ {
this.delItem('board.' + board.id + '.' + rev); this.delItem('board.' + board.id + '.' + rev);
console.log( `Deleted revision ${rev} of ${board.id} (${board.title})` ); console.log( `Deleted revision ${rev} of ${board.id} (${board.title})` );
@@ -2063,6 +2063,38 @@
NB.storage.nukeBoard(NB.board.id, null); NB.storage.nukeBoard(NB.board.id, null);
} }
/*
* export / import
*/
function exportBoard()
{
var blob, file;
if (! NB.board)
{
var index = NB.storage.getBoardIndex();
var all = [];
boards.forEach(function(meta, board_id){
all.push( NB.storage.loadBoard(board_id, null) );
})
blob = JSON.stringify(all);
file = `Nullboard.nbx`;
}
else
{
var board = NB.board;
blob = JSON.stringify(board);
file = `Nullboard-${board.id}-${board.title}.nbx`;
}
blob = encodeURIComponent(blob);
blob = "data:application/octet-stream," + blob;
return { blob: blob, file: file };
}
function checkBoard(foo) function checkBoard(foo)
{ {
var props = [ 'format', 'id', 'revision', 'title', 'lists' ]; var props = [ 'format', 'id', 'revision', 'title', 'lists' ];
@@ -2545,8 +2577,15 @@
empty = false; empty = false;
}); });
if (id_now) $export.show(); if (! empty)
else $export.hide(); {
if (id_now) $export.html('Export this board...').show();
else $export.html('Export all boards...').show();
}
else
{
$export.hide();
}
if (! empty) $index.show(); if (! empty) $index.show();
} }
@@ -3103,15 +3142,9 @@
}); });
$('.config').on('click', '.exp-board', function(){ $('.config').on('click', '.exp-board', function(){
var board = NB.board; var pack = exportBoard();
var blob = JSON.stringify(board); $(this).attr('href', pack.blob);
var file = `Nullboard-${board.id}-${board.title}.nbx`; $(this).attr('download', pack.file);
blob = encodeURIComponent(blob);
blob = "data:application/octet-stream," + blob;
$(this).attr('href', blob);
$(this).attr('download', file);
return true; return true;
}); });