Migrate indentation settings to a settings subobject

This commit is contained in:
yflory
2017-08-30 17:19:50 +02:00
parent 0893bcc0e5
commit f54dc7505c
4 changed files with 74 additions and 4 deletions

View File

@@ -81,7 +81,7 @@ define([
}; };
var andThen = function (editor, CodeMirror, common) { var andThen = function (editor, CodeMirror, common) {
var readOnly = false; // TODO var readOnly = false;
var cpNfInner; var cpNfInner;
var metadataMgr; var metadataMgr;
var onLocal; var onLocal;
@@ -113,8 +113,6 @@ define([
var indentKey = 'cryptpad.indentUnit'; var indentKey = 'cryptpad.indentUnit';
var useTabsKey = 'cryptpad.indentWithTabs'; var useTabsKey = 'cryptpad.indentWithTabs';
//var proxy = Cryptpad.getProxy();
var updateIndentSettings = function () { var updateIndentSettings = function () {
var indentUnit = proxy[indentKey]; var indentUnit = proxy[indentKey];
var useTabs = proxy[useTabsKey]; var useTabs = proxy[useTabsKey];

View File

@@ -4,7 +4,8 @@ define([
'/bower_components/chainpad-crypto/crypto.js?v=0.1.5', '/bower_components/chainpad-crypto/crypto.js?v=0.1.5',
'/bower_components/textpatcher/TextPatcher.amd.js', '/bower_components/textpatcher/TextPatcher.amd.js',
'/common/userObject.js', '/common/userObject.js',
], function ($, Listmap, Crypto, TextPatcher, FO) { '/common/migrate-user-object.js'
], function ($, Listmap, Crypto, TextPatcher, FO, Migrate) {
/* /*
This module uses localStorage, which is synchronous, but exposes an This module uses localStorage, which is synchronous, but exposes an
asyncronous API. This is so that we can substitute other storage asyncronous API. This is so that we can substitute other storage
@@ -154,6 +155,8 @@ define([
var todo = function () { var todo = function () {
fo.fixFiles(); fo.fixFiles();
Migrate(proxy, Cryptpad);
//storeObj = proxy; //storeObj = proxy;
store = initStore(fo, proxy, exp); store = initStore(fo, proxy, exp);
if (typeof(f) === 'function') { if (typeof(f) === 'function') {

View File

@@ -0,0 +1,68 @@
define([], function () {
// Start migration check
// Versions:
// 1: migrate pad attributes
// 2: migrate indent settings (codemirror)
return function (userObject, Cryptpad) {
var version = userObject.version || 0;
// Migration 1: pad attributes moved to filesData
var migrateAttributes = function () {
var files = userObject && userObject.drive;
if (!files) { return; }
var migratePadAttributes = function (el, id, parsed) {
// Migrate old pad attributes
['userid', 'previewMode'].forEach(function (attr) {
var key = parsed.hash + '.' + attr;
var key2 = parsed.hash.slice(0,-1) + '.' + attr;// old pads not ending with /
if (typeof(files[key]) !== "undefined" || typeof(files[key2]) !== "undefined") {
debug("Migrating pad attribute", attr, "for pad", id);
el[attr] = files[key] || files[key2];
delete files[key];
delete files[key2];
}
});
};
var filesData = files.filesData;
if (!filesData) { return; }
var el, id, parsed;
for (var id in filesData) {
id = Number(id);
el = filesData[id];
parsed = el.href && Cryptpad.parsePadUrl(el.href);
if (!parsed) { continue; }
migratePadAttributes(el, id, parsed);
}
// Migration done
};
if (version < 1) {
migrateAttributes();
Cryptpad.feedback('Migrate-1', true);
userObject.version = version = 1;
}
// Migration 2: indentation settings for CodeMirror moved from root to 'settings'
var migrateIndent = function () {
var indentKey = 'cryptpad.indentUnit';
var useTabsKey = 'cryptpad.indentWithTabs';
userObject.settings = userObject.settings || {};
if (userObject[indentKey]) {
userObject.settings.indentUnit = userObject[indentKey];
delete userObject[indentKey];
}
if (userObject[useTabsKey]) {
userObject.settings.indentWithTabs = userObject[useTabsKey];
delete userObject[useTabsKey];
}
};
if (version < 2) {
migrateIndent();
Cryptpad.feedback('Migrate-2', true);
userObject.version = version = 2;
}
};
});

View File

@@ -816,6 +816,7 @@ define([
} }
try { try {
debug("Migrating file system..."); debug("Migrating file system...");
Cryptpad.feedback('Migrate-oldFilesData', true);
files.migrate = 1; files.migrate = 1;
var next = function () { var next = function () {
var oldData = files[OLD_FILES_DATA].slice(); var oldData = files[OLD_FILES_DATA].slice();