Use the FS store as default store

This commit is contained in:
yflory
2016-11-17 18:27:55 +01:00
parent aa14ea7ac4
commit 118829617f
6 changed files with 282 additions and 67 deletions

View File

@@ -54,10 +54,12 @@ li {
border: 1px dotted #bbb;
background: #666;
color: #eee;
margin: -1px;
}
/* TREE */
#tree {
border: 2px solid blue;
box-sizing: border-box;
@@ -194,6 +196,10 @@ li {
flex: 1;
}
#content li * {
pointer-events: none;
}
#content li:hover:not(.header) .name {
text-decoration: underline;
}

View File

@@ -12,6 +12,7 @@ define([
var NEW_FOLDER_NAME = Messages.fm_newFolder;
var init = module.init = function (files, config) {
FILES_DATA = config.storageKey;
var DEBUG = config.DEBUG || false;
var logging = console.log;
var log = config.log || logging;
@@ -192,6 +193,16 @@ define([
return ret;
};
var getFilesDataFiles = function () {
var ret = [];
for (var el in files[FILES_DATA]) {
if (el.href && ret.indexOf(el.href) === -1) {
ret.push(el.href);
}
}
return ret;
};
var removeFileFromRoot = function (root, href) {
if (isFile(root)) { return; }
for (var e in root) {
@@ -536,18 +547,39 @@ define([
pushToTrash(key, href, [UNSORTED]);
};
var addPad = exp.addPad = function (href, data) {
if (!getFileData(href)) {
files[FILES_DATA].push(data);
}
var addUnsortedPad = exp.addPad = function (href) {
var unsortedFiles = getUnsortedFiles().slice();
var rootFiles = getRootFiles().slice();
//var trashFiles = getTrashFiles().slice();
if (unsortedFiles.indexOf(href) === -1 && rootFiles.indexOf(href) === -1) {
var trashFiles = getTrashFiles().slice();
if (unsortedFiles.indexOf(href) === -1 && rootFiles.indexOf(href) === -1 && trashFiles.indexOf(href) === -1) {
files[UNSORTED].push(href);
}
};
var checkNewPads = exp.checkNewPads = function () {
var fd = files[FILES_DATA];
var rootFiles = getRootFiles().slice();
var unsortedFiles = getUnsortedFiles().slice();
var trashFiles = getTrashFiles().slice();
fd.forEach(function (el, idx) {
if (!el.href) { return; }
if (rootFiles.indexOf(el.href) === -1
&& unsortedFiles.indexOf(el.href) === -1
&& trashFiles.indexOf(el.href) === -1) {
debug("An element in filesData was not in ROOT, UNSORTED or TRASH.", el);
files[UNSORTED].push(el.href);
}
});
};
var checkRemovedPads = exp.checkRemovedPads = function () {
var fd = files[FILES_DATA];
var rootFiles = getRootFiles().slice();
var unsortedFiles = getUnsortedFiles().slice();
var trashFiles = getTrashFiles().slice();
};
var fixFiles = exp.fixFiles = function () {
// Explore the tree and check that everything is correct:
// * 'root', 'trash' and 'filesData' exist and are objects

View File

@@ -21,17 +21,13 @@ define([
//var hash = Cryptpad.getAttribute('FS_hash', cb);
var hash = localStorage.FS_hash;
if (hash) {
window.location.hash = hash;
}
var secret = Cryptpad.getSecrets();
var secret = Cryptpad.getSecrets(hash);
var ROOT = "root";
var ROOT_NAME = Messages.fm_rootName;
var UNSORTED = "unsorted";
var UNSORTED_NAME = Messages.fm_unsortedName;
var FILES_DATA = "filesData";
var FILES_DATA = Cryptpad.storageKey;
var FILES_DATA_NAME = Messages.fm_filesDataName;
var TRASH = "trash";
var TRASH_NAME = Messages.fm_trashName;
@@ -44,6 +40,7 @@ define([
var NEW_FOLDER_NAME = Messages.fm_newFolder;
var config = {};
config.storageKey = FILES_DATA;
var DEBUG = config.DEBUG = true;
var debug = config.debug = DEBUG ? console.log : function() {return;};
var logError = config.logError = console.error;
@@ -55,7 +52,7 @@ define([
}
};
var filesObject = module.files = {
var filesObject = {
root: {
"Directory 1": {
"Dir A": {
@@ -213,7 +210,7 @@ define([
localStorage[LOCALSTORAGE_LAST] = JSON.stringify(path);
};
var initLSOpened = function () {
var initLocalStorage = function () {
try {
var store = JSON.parse(localStorage[LOCALSTORAGE_OPENED]);
if (!$.isArray(store)) {
@@ -562,14 +559,13 @@ define([
var addDragAndDropHandlers = function ($element, path, isFolder, droppable) {
// "dragenter" is fired for an element and all its children
// "dragleave" may be fired when entering a child
// --> we use pointer-events: none in CSS, but we still need a counter to avoid some issues
// --> We store the number of enter/leave and the element entered and we remove the
// highlighting only when we have left everything
var counter = 0;
var dragenterList = [];
$element.on('dragstart', function (e) {
e.stopPropagation();
counter = 0;
dragenterList = [];
onDrag(e.originalEvent, path);
});
@@ -585,18 +581,15 @@ define([
$element.on('dragenter', function (e) {
e.preventDefault();
e.stopPropagation();
if (dragenterList.indexOf(e.target) !== -1) { return; }
dragenterList.push(e.target);
counter++;
$element.addClass('droppable');
});
$element.on('dragleave', function (e) {
e.preventDefault();
e.stopPropagation();
var idx = dragenterList.indexOf(e.target);
dragenterList.splice(idx, 1);
counter--;
if (counter <= 0) {
counter = 0;
$element.removeClass('droppable');
}
});
@@ -1283,7 +1276,6 @@ define([
var realtime = module.realtime = info.realtime;
var editHash = Cryptpad.getEditHashFromKeys(info.channel, secret.keys);
window.location.hash = editHash;
//Cryptpad.setAttribute("FS_hash", editHash, cb, store);
localStorage.FS_hash = editHash;
@@ -1303,16 +1295,17 @@ define([
});
});*/
}).on('ready', function () {
module.files = rt.proxy;
if (JSON.stringify(rt.proxy) === '{}') {
var store = Cryptpad.getStore();
var store = Cryptpad.getStore(true);
store.get(Cryptpad.storageKey, function (err, s) {
rt.proxy.filesData = s;
initLSOpened();
rt.proxy[FILES_DATA] = s;
initLocalStorage();
init(rt.proxy);
});
return;
}
initLSOpened();
initLocalStorage();
init(rt.proxy);
})
.on('disconnect', function () {