Versioned hash for onlyoffice
parent
68423f49bc
commit
16af013bce
|
@ -40,13 +40,16 @@ define([
|
|||
|
||||
if (endWithCp) { cpIndex = 0; }
|
||||
|
||||
var $version, $time;
|
||||
var $version, $time, $share;
|
||||
var $hist = $toolbar.find('.cp-toolbar-history');
|
||||
var $bottom = $toolbar.find('.cp-toolbar-bottom');
|
||||
|
||||
var showVersion = function (initial) {
|
||||
var getVersion = function () {
|
||||
var major = sortedCp.length - cpIndex;
|
||||
var v = major + '.' + msgIndex;
|
||||
return major + '.' + msgIndex;
|
||||
};
|
||||
var showVersion = function (initial) {
|
||||
var v = getVersion();
|
||||
if (initial) {
|
||||
v = "Latest"; // XXX
|
||||
}
|
||||
|
@ -113,6 +116,7 @@ define([
|
|||
fillOO(id, messages);
|
||||
loading = false;
|
||||
config.onCheckpoint(cp);
|
||||
$share.show();
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -199,10 +203,10 @@ define([
|
|||
$next.hide().appendTo($hist);
|
||||
$fastNext.hide().appendTo($hist);
|
||||
|
||||
var $share = $('<button>', {
|
||||
$share = $('<button>', {
|
||||
'class': 'fa fa-shhare-alt buttonPrimary',
|
||||
title: Messages.shareButton
|
||||
}).appendTo($hist);
|
||||
}).hide().appendTo($hist);
|
||||
$('<span>', {'class': 'cp-history-filler'}).appendTo($hist);
|
||||
$time = $(h('div')).appendTo($hist);
|
||||
var $close = $('<button>', {
|
||||
|
@ -247,6 +251,9 @@ define([
|
|||
// Versioned link
|
||||
$share.click(function () {
|
||||
// XXX
|
||||
common.getSframeChannel().event('EV_SHARE_OPEN', {
|
||||
versionHash: getVersion()
|
||||
});
|
||||
});
|
||||
|
||||
// Push one patch
|
||||
|
|
|
@ -409,7 +409,7 @@ define([
|
|||
}
|
||||
myUniqueOOId = undefined;
|
||||
setMyId();
|
||||
APP.docEditor.destroyEditor(); // Kill the old editor
|
||||
if (APP.docEditor) { APP.docEditor.destroyEditor(); } // Kill the old editor
|
||||
$('iframe[name="frameEditor"]').after(h('div#cp-app-oo-placeholder')).remove();
|
||||
ooLoaded = false;
|
||||
oldLocks = {};
|
||||
|
@ -546,6 +546,9 @@ define([
|
|||
return new Blob([newText], {type: 'text/plain'});
|
||||
};
|
||||
var loadLastDocument = function (lastCp, onCpError, cb) {
|
||||
if (!lastCp || !lastCp.file) {
|
||||
return void onCpError('EEMPTY');
|
||||
}
|
||||
ooChannel.cpIndex = lastCp.index || 0;
|
||||
ooChannel.lastHash = lastCp.hash;
|
||||
var parsed = Hash.parsePadUrl(lastCp.file);
|
||||
|
@ -611,6 +614,52 @@ define([
|
|||
});
|
||||
};
|
||||
|
||||
var openVersionHash = function (version) {
|
||||
readOnly = true;
|
||||
var hashes = content.hashes || {};
|
||||
var sortedCp = Object.keys(hashes).map(Number).sort(function (a, b) {
|
||||
return hashes[a].index - hashes[b].index;
|
||||
});
|
||||
var s = version.split('.');
|
||||
if (s.length !== 2) { return; }
|
||||
|
||||
var major = Number(s[0]);
|
||||
var cpId = sortedCp[major - 1];
|
||||
var nextCpId = sortedCp[major];
|
||||
var cp = hashes[cpId] || {};
|
||||
|
||||
var minor = Number(s[1]) + 1;
|
||||
|
||||
var toHash = cp.hash || 'NONE';
|
||||
var fromHash = nextCpId ? hashes[nextCpId].hash : 'NONE';
|
||||
|
||||
sframeChan.query('Q_GET_HISTORY_RANGE', {
|
||||
channel: content.channel,
|
||||
lastKnownHash: fromHash,
|
||||
toHash: toHash,
|
||||
}, function (err, data) {
|
||||
if (err) { return void console.error(err); }
|
||||
if (!Array.isArray(data.messages)) { return void console.error('Not an array!'); }
|
||||
|
||||
var messages = (data.messages || []).slice(1, minor).forEach(function (obj) {
|
||||
try { obj.msg = JSON.parse(obj.msg); } catch (e) { console.error(e); }
|
||||
});
|
||||
|
||||
loadLastDocument(cp, function () {
|
||||
var file = getFileType();
|
||||
var type = common.getMetadataMgr().getPrivateData().ooType;
|
||||
var blob = loadInitDocument(type, true);
|
||||
ooChannel.queue = messages;
|
||||
resetData(blob, file);
|
||||
UI.removeLoadingScreen();
|
||||
}, function (blob, file) {
|
||||
ooChannel.queue = messages;
|
||||
resetData(blob, file);
|
||||
UI.removeLoadingScreen();
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
var openRtChannel = function (cb) {
|
||||
if (rtChannel.ready) { return void cb(); }
|
||||
var chan = content.channel || Hash.createChannelId();
|
||||
|
@ -1763,75 +1812,75 @@ define([
|
|||
makeCheckpoint(true);
|
||||
});
|
||||
$save.appendTo(toolbar.$bottomM);
|
||||
|
||||
(function () {
|
||||
/* add a history button */
|
||||
// XXX move out of dev mode
|
||||
var commit = function () {
|
||||
APP.stopHistory = true;
|
||||
makeCheckpoint(true);
|
||||
};
|
||||
var loadCp = function (cp) {
|
||||
loadLastDocument(cp, function () {
|
||||
var file = getFileType();
|
||||
var type = common.getMetadataMgr().getPrivateData().ooType;
|
||||
var blob = loadInitDocument(type, true);
|
||||
ooChannel.queue = [];
|
||||
resetData(blob, file);
|
||||
}, function (blob, file) {
|
||||
ooChannel.queue = [];
|
||||
resetData(blob, file);
|
||||
});
|
||||
};
|
||||
var onPatch = function (patch) {
|
||||
// Patch on the current cp
|
||||
ooChannel.send(JSON.parse(patch.msg));
|
||||
};
|
||||
var onCheckpoint = function (cp) {
|
||||
// We want to load a checkpoint:
|
||||
loadCp(cp);
|
||||
};
|
||||
var setHistoryMode = function (bool) {
|
||||
if (bool) {
|
||||
APP.history = true;
|
||||
getEditor().setViewModeDisconnect();
|
||||
return;
|
||||
}
|
||||
// Cancel button: redraw from lastCp
|
||||
APP.history = false;
|
||||
ooChannel.queue = [];
|
||||
ooChannel.ready = false;
|
||||
rtChannel.getHistory(function () {
|
||||
var lastCp = getLastCp();
|
||||
loadCp(lastCp);
|
||||
});
|
||||
};
|
||||
|
||||
common.createButton('', true, {
|
||||
name: 'history',
|
||||
icon: 'fa-history',
|
||||
text: Messages.historyText,
|
||||
tippy: Messages.historyButton
|
||||
}).click(function () {
|
||||
ooChannel.historyLastHash = ooChannel.lastHash;
|
||||
ooChannel.currentIndex = ooChannel.cpIndex;
|
||||
//Feedback.send('OO_HISTORY'); // XXX pull Feedback from require
|
||||
var histConfig = {
|
||||
onPatch: onPatch,
|
||||
onCheckpoint: onCheckpoint,
|
||||
onRevert: commit,
|
||||
setHistory: setHistoryMode,
|
||||
onlyoffice: {
|
||||
hashes: content.hashes || {},
|
||||
channel: content.channel,
|
||||
lastHash: ooChannel.lastHash
|
||||
},
|
||||
$toolbar: $('.cp-toolbar-container')
|
||||
};
|
||||
History.create(common, histConfig);
|
||||
}).appendTo(toolbar.$drawer);
|
||||
})();
|
||||
}
|
||||
|
||||
(function () {
|
||||
/* add a history button */
|
||||
var commit = function () {
|
||||
APP.stopHistory = true;
|
||||
makeCheckpoint(true);
|
||||
};
|
||||
var loadCp = function (cp) {
|
||||
loadLastDocument(cp, function () {
|
||||
var file = getFileType();
|
||||
var type = common.getMetadataMgr().getPrivateData().ooType;
|
||||
var blob = loadInitDocument(type, true);
|
||||
ooChannel.queue = [];
|
||||
resetData(blob, file);
|
||||
}, function (blob, file) {
|
||||
ooChannel.queue = [];
|
||||
resetData(blob, file);
|
||||
});
|
||||
};
|
||||
var onPatch = function (patch) {
|
||||
// Patch on the current cp
|
||||
ooChannel.send(JSON.parse(patch.msg));
|
||||
};
|
||||
var onCheckpoint = function (cp) {
|
||||
// We want to load a checkpoint:
|
||||
loadCp(cp);
|
||||
};
|
||||
var setHistoryMode = function (bool) {
|
||||
if (bool) {
|
||||
APP.history = true;
|
||||
getEditor().setViewModeDisconnect();
|
||||
return;
|
||||
}
|
||||
// Cancel button: redraw from lastCp
|
||||
APP.history = false;
|
||||
ooChannel.queue = [];
|
||||
ooChannel.ready = false;
|
||||
rtChannel.getHistory(function () {
|
||||
var lastCp = getLastCp();
|
||||
loadCp(lastCp);
|
||||
});
|
||||
};
|
||||
|
||||
common.createButton('', true, {
|
||||
name: 'history',
|
||||
icon: 'fa-history',
|
||||
text: Messages.historyText,
|
||||
tippy: Messages.historyButton
|
||||
}).click(function () {
|
||||
ooChannel.historyLastHash = ooChannel.lastHash;
|
||||
ooChannel.currentIndex = ooChannel.cpIndex;
|
||||
//Feedback.send('OO_HISTORY'); // XXX pull Feedback from require
|
||||
var histConfig = {
|
||||
onPatch: onPatch,
|
||||
onCheckpoint: onCheckpoint,
|
||||
onRevert: commit,
|
||||
setHistory: setHistoryMode,
|
||||
onlyoffice: {
|
||||
hashes: content.hashes || {},
|
||||
channel: content.channel,
|
||||
lastHash: ooChannel.lastHash
|
||||
},
|
||||
$toolbar: $('.cp-toolbar-container')
|
||||
};
|
||||
History.create(common, histConfig);
|
||||
}).appendTo(toolbar.$drawer);
|
||||
})();
|
||||
|
||||
if (window.CP_DEV_MODE || DISPLAY_RESTORE_BUTTON) {
|
||||
common.createButton('', true, {
|
||||
name: 'delete',
|
||||
|
@ -1978,6 +2027,11 @@ define([
|
|||
sframeChan.event('EV_BURN_PAD', content.channel);
|
||||
}
|
||||
|
||||
if (privateData.ooVersionHash) {
|
||||
return void openVersionHash(privateData.ooVersionHash);
|
||||
}
|
||||
|
||||
|
||||
var useNewDefault = content.version && content.version >= 2;
|
||||
openRtChannel(function () {
|
||||
setMyId();
|
||||
|
|
|
@ -4,12 +4,13 @@ define([
|
|||
'/api/config',
|
||||
'/common/dom-ready.js',
|
||||
'/common/requireconfig.js',
|
||||
'/common/common-hash.js',
|
||||
'/common/sframe-common-outer.js'
|
||||
], function (nThen, ApiConfig, DomReady, RequireConfig, SFCommonO) {
|
||||
], function (nThen, ApiConfig, DomReady, RequireConfig, Hash, SFCommonO) {
|
||||
var requireConfig = RequireConfig();
|
||||
|
||||
// Loaded in load #2
|
||||
var hash, href;
|
||||
var hash, href, version;
|
||||
nThen(function (waitFor) {
|
||||
DomReady.onReady(waitFor());
|
||||
}).nThen(function (waitFor) {
|
||||
|
@ -27,6 +28,14 @@ define([
|
|||
if (window.history && window.history.replaceState && hash) {
|
||||
window.history.replaceState({}, window.document.title, '#');
|
||||
}
|
||||
|
||||
var parsed = Hash.parsePadUrl(href);
|
||||
var opts = parsed.getOptions();
|
||||
version = opts.versionHash;
|
||||
opts.versionHash = "";
|
||||
href = parsed.getUrl(opts);
|
||||
hash = parsed.hashData.getHash(opts);
|
||||
|
||||
document.getElementById('sbox-iframe').setAttribute('src',
|
||||
ApiConfig.httpSafeOrigin + window.location.pathname + 'inner.html?' +
|
||||
requireConfig.urlArgs + '#' + encodeURIComponent(JSON.stringify(req)));
|
||||
|
@ -46,6 +55,7 @@ define([
|
|||
}).nThen(function (/*waitFor*/) {
|
||||
var addData = function (obj) {
|
||||
obj.ooType = window.location.pathname.replace(/^\//, '').replace(/\/$/, '');
|
||||
obj.ooVersionHash = version;
|
||||
obj.ooForceVersion = localStorage.CryptPad_ooVersion || sessionStorage.CryptPad_ooVersion || "";
|
||||
};
|
||||
var addRpc = function (sframeChan, Cryptpad, Utils) {
|
||||
|
|
|
@ -2035,8 +2035,6 @@ define([
|
|||
var lastKnownHash;
|
||||
var txid = Util.uid();
|
||||
|
||||
console.error(data);
|
||||
|
||||
var onMsg = function (msg) {
|
||||
if (completed) { return; }
|
||||
var parsed = parse(msg);
|
||||
|
|
Loading…
Reference in New Issue