keep backupStatus of the app's config

This commit is contained in:
Alex Pankratov
2021-04-25 16:04:11 +02:00
parent 850a16acfd
commit 438d3ef39f

View File

@@ -1685,7 +1685,6 @@
function AppConfig() function AppConfig()
{ {
this.format = NB.confVersion;
this.verLast = null; // last used codeVersion this.verLast = null; // last used codeVersion
this.verSeen = null; // latest codeVersion they saw the changelog for this.verSeen = null; // latest codeVersion they saw the changelog for
@@ -1703,6 +1702,8 @@
agents : [ ], // [ { type, id, enabled, conf } ]; agents : [ ], // [ { type, id, enabled, conf } ];
nextId : 1 nextId : 1
}; };
this.backupStatus = new Map(); // agentId => [ 'conf' ]
} }
function BoardMeta() function BoardMeta()
@@ -1711,7 +1712,7 @@
this.current = 1; // revision this.current = 1; // revision
this.ui_spot = 0; // 0 = not set this.ui_spot = 0; // 0 = not set
this.history = [ ]; // revision IDs this.history = [ ]; // revision IDs
this.backups = [ ]; // agents that this board is backed up with this.backupStatus = new Map(); // agentId => [ what's backed up ]
} }
class Storage class Storage
@@ -1881,8 +1882,6 @@
meta.history = rebuild; meta.history = rebuild;
} }
meta.backups = [];
/* /*
* save meta * save meta
*/ */
@@ -2001,6 +2000,8 @@
meta.ui_spot = ui_spot; meta.ui_spot = ui_spot;
this.backupBoard(board_id, null, meta);
return this.setJson('board.' + board_id + '.meta', meta); return this.setJson('board.' + board_id + '.meta', meta);
} }
@@ -2076,7 +2077,7 @@
conf: { base: '', auth: '' } conf: { base: '', auth: '' }
}) })
NB.storage.saveConfig(); self.saveConfig();
} }
} }
@@ -2118,26 +2119,40 @@
backupBoard(board_id, board, meta) backupBoard(board_id, board, meta)
{ {
var self = this; var self = this;
var was = meta.backups || new Map();
meta.backupStatus = new Map();
if (! this.backups.agents.length) if (! this.backups.agents.length)
{ {
meta.backups = []; if (was.size)
self.setJson('board.' + board_id + '.meta', meta);
return; return;
} }
meta.backups = [];
console.log( `Backing up ${board_id}...` ); console.log( `Backing up ${board_id}...` );
this.backups.agents.forEach(function(agent){ this.backups.agents.forEach(function(agent){
var fields = was.get(agent.id) || { };
if (board) delete fields.data;
if (meta) delete fields.meta;
meta.backupStatus.set(agent.id, fields);
agent.saveBoard(board_id, board, meta, function(){ agent.saveBoard(board_id, board, meta, function(){
var what = 'Backup of ' + board_id + (board ? '' : ' (meta)'); var what = 'Backup of ' + board_id + (board ? '' : ' (meta)');
console.log( `${what} to '${agent.id}' -> ${agent.status}` ); console.log( `${what} to '${agent.id}' -> ${agent.status}` );
if (agent.status == 'ready') if (agent.status == 'ready')
meta.backups.push(agent.id); {
if (board) fields.data = + new Date();
if (meta) fields.meta = + new Date();
meta.backupStatus.set(agent.id, fields);
}
self.setJson('board.' + board_id + '.meta', meta); self.setJson('board.' + board_id + '.meta', meta);
}); });
@@ -2147,12 +2162,33 @@
backupConfig() backupConfig()
{ {
var self = this; var self = this;
var was = self.conf.backupStatus || new Map();
self.conf.backupStatus = new Map();
if (! this.backups.agents.length) if (! this.backups.agents.length)
{
if (was.size)
this.setJson('config', this.conf);
return; return;
}
this.backups.agents.forEach(function(agent){ this.backups.agents.forEach(function(agent){
agent.saveConfig(self.conf, function(){});
var fields = { };
self.conf.backupStatus.set(agent.id, fields);
agent.saveConfig(self.conf, function(){
if (agent.status == 'ready')
{
fields.conf = + new Date()
self.conf.backupStatus.set(agent.id, fields);
}
self.setJson('config', this.conf);
});
}); });
} }
}; };
@@ -2187,13 +2223,13 @@
var conf = this.getJson('config'); var conf = this.getJson('config');
var newInstall = true; var newInstall = true;
if (conf && (conf.format != NB.confVersion)) // if (conf && (conf.format != NB.confVersion))
{ // {
if (! confirm('Preferences are stored in an unsupported format. Reset them?')) // if (! confirm('Preferences are stored in an unsupported format. Reset them?'))
return false; // return false;
//
conf = null; // conf = null;
} // }
if (conf) if (conf)
{ {