Add a way to restore broken spreadsheets

pull/1/head
yflory 5 years ago
parent f5444e5d3d
commit 16549f40bb

@ -48,6 +48,7 @@ define([
}; };
var CHECKPOINT_INTERVAL = 50; var CHECKPOINT_INTERVAL = 50;
var DISPLAY_RESTORE_BUTTON = false;
var debug = function (x) { var debug = function (x) {
if (!window.CP_DEV_MODE) { return; } if (!window.CP_DEV_MODE) { return; }
@ -237,13 +238,7 @@ define([
} }
}; };
var fmConfig = { var onUploaded = function (ev, data, err) {
noHandlers: true,
noStore: true,
body: $('body'),
onUploaded: function (ev, data) {
if (!data || !data.url) { return; }
sframeChan.query('Q_OO_SAVE', data, function (err) {
if (err) { if (err) {
console.error(err); console.error(err);
return void UI.alert(Messages.oo_saveError); return void UI.alert(Messages.oo_saveError);
@ -270,6 +265,16 @@ define([
}, function (err, obj) { }, function (err, obj) {
if (err || (obj && obj.error)) { console.error(err || obj.error); } if (err || (obj && obj.error)) { console.error(err || obj.error); }
}); });
};
var fmConfig = {
noHandlers: true,
noStore: true,
body: $('body'),
onUploaded: function (ev, data) {
if (!data || !data.url) { return; }
sframeChan.query('Q_OO_SAVE', data, function (err) {
onUploaded(ev, data, err);
}); });
} }
}; };
@ -307,6 +312,19 @@ define([
} }
}, to); }, to);
}; };
var restoreLastCp = function () {
content.saveLock = myOOId;
APP.onLocal();
APP.realtime.onSettle(function () {
onUploaded({
hash: ooChannel.lastHash,
index: ooChannel.cpIndex
}, {
url: getLastCp().file,
});
});
};
var openRtChannel = function (cb) { var openRtChannel = function (cb) {
if (rtChannel.ready) { return void cb(); } if (rtChannel.ready) { return void cb(); }
@ -880,6 +898,16 @@ define([
}); });
$save.appendTo($rightside); $save.appendTo($rightside);
} }
if (window.CP_DEV_MODE || DISPLAY_RESTORE_BUTTON) {
common.createButton('', true, {
name: 'restore',
icon: 'fa-history',
hiddenReadOnly: true
}).click(function () {
if (initializing) { return void console.error('initializing'); }
restoreLastCp();
}).attr('title', 'Restore last checkpoint').appendTo($rightside);
}
var $export = common.createButton('export', true, {}, exportFile); var $export = common.createButton('export', true, {}, exportFile);
$export.appendTo($rightside); $export.appendTo($rightside);

Loading…
Cancel
Save