diff --git a/customize.dist/store.js b/customize.dist/store.js index 5c4138fdf..5b82921ed 100644 --- a/customize.dist/store.js +++ b/customize.dist/store.js @@ -71,12 +71,6 @@ define(function () { } }; - Store.addPad = function () {}; - - Store.forgetPad = function (href, cb) { - - }; - var changeHandlers = Store.changeHandlers = []; Store.change = function (f) { diff --git a/www/common/cryptpad-common.js b/www/common/cryptpad-common.js index 3fc6b6b05..7241a01af 100644 --- a/www/common/cryptpad-common.js +++ b/www/common/cryptpad-common.js @@ -20,6 +20,12 @@ define([ */ var $ = window.jQuery; + // When set to true, USE_FS_STORE becomes the default store, but the localStorage store is + // still loaded for migration purpose. When false, the localStorage is used. + var USE_FS_STORE = true; + + var storeToUse = USE_FS_STORE ? FS : Store; + var common = { User: User, }; @@ -36,8 +42,8 @@ define([ var getStore = common.getStore = function (legacy) { if (!legacy && userStore) { return userStore; } - if (legacy) { return store; } - if (!legacy && fsStore) { return fsStore; } + if ((!USE_FS_STORE || legacy) && store) { return store; } + if (USE_FS_STORE && !legacy && fsStore) { return fsStore; } throw new Error("Store is not ready!"); }; @@ -379,6 +385,9 @@ define([ }; // STORAGE + var forgetFSPad = function (href, cb) { + getStore().forgetPad(href, cb); + }; var forgetPad = common.forgetPad = function (href, cb, legacy) { var parsed = parsePadUrl(href); @@ -389,6 +398,10 @@ define([ } getStore(legacy).keys(function (err, keys) { + if (err) { + cb(err); + return; + } var toRemove = keys.filter(function (k) { return k.indexOf(parsed.hash) === 0; }); @@ -403,6 +416,26 @@ define([ }); }; + if (USE_FS_STORE && !legacy) { + // TODO implement forgetPad in store.js + forgetFSPad(href, callback); + return; + } + + getRecentPads(function (err, recentPads) { + setRecentPads(recentPads.filter(function (pad) { + var p = parsePadUrl(pad.href); + // find duplicates + if (parsed.hash === p.hash && parsed.type === p.type) { + console.log("Found a duplicate"); + return; + } + return true; + }), callback, legacy); + }, legacy); + + + if (typeof(getStore(legacy).forgetPad) === "function") { // TODO implement forgetPad in store.js getStore(legacy).forgetPad(href, callback); @@ -457,8 +490,7 @@ define([ if (!contains) { var data = makePad(href, name); renamed.push(data); - if (typeof(getStore(legacy).addPad) === "function") { - //TODO implement addPad in store.js + if (USE_FS_STORE && typeof(getStore().addPad) === "function") { getStore().addPad(href); } } @@ -533,8 +565,11 @@ define([ f(void 0, env); }; - FS.ready(function (err, store) { - fsStore = common.store = env.store = store; + storeToUse.ready(function (err, store) { + common.store = env.store = store; + if (USE_FS_STORE) { + fsStore = store; + } $(function() { // Race condition : if document.body is undefined when alertify.js is loaded, Alertify diff --git a/www/file/file.css b/www/file/file.css index 03744a7f9..f75fa7772 100644 --- a/www/file/file.css +++ b/www/file/file.css @@ -86,11 +86,7 @@ li { text-decoration: underline; } -#tree #trashTree { - margin-top: 2em; -} - -#tree #unsortedTree { +#tree #trashTree, #tree #unsortedTree, #tree #allfilesTree { margin-top: 2em; } diff --git a/www/file/main.js b/www/file/main.js index 90df70b9d..e02883c72 100644 --- a/www/file/main.js +++ b/www/file/main.js @@ -322,6 +322,7 @@ define([ appStatus._onReady.forEach(function (h) { h(); }); + _onReady = []; } } }; @@ -857,6 +858,28 @@ define([ }); }; + var displayAllFiles = function ($container) { + var allfiles = files[FILES_DATA]; + if (allfiles.length === 0) { return; } + var $fileHeader = getFileListHeader(false); + $container.append($fileHeader); + allfiles.forEach(function (file, idx) { + var $icon = $fileIcon.clone(); + var $name = $('', { 'class': 'file-element element' }); + addFileData(file.href, file.title, $name, false); + var $element = $('
  • ', { + draggable: false + }).append($icon).append($name).dblclick(function () { + openFile(file.href); + }); + $element.click(function(e) { + e.stopPropagation(); + onElementClick($element); + }); + $container.append($element); + }); + }; + var displayTrashRoot = function ($list, $folderHeader, $fileHeader) { // Elements in the trash are JS arrays (several elements can have the same name) [true,false].forEach(function (folder) { @@ -890,7 +913,8 @@ define([ // Display the selected directory into the content part (rightside) // NOTE: Elements in the trash are not using the same storage structure as the others - var displayDirectory = module.displayDirectory = function (path) { + var displayDirectory = module.displayDirectory = function (path, force) { + if (!appStatus.isReady && !force) { return; } appStatus.ready(false); currentPath = path; $content.html(""); @@ -899,6 +923,7 @@ define([ } var isTrashRoot = filesOp.comparePath(path, [TRASH]); var isUnsorted = filesOp.comparePath(path, [UNSORTED]); + var isAllFiles = filesOp.comparePath(path, [FILES_DATA]); var root = filesOp.findElement(files, path); if (typeof(root) === "undefined") { @@ -906,7 +931,7 @@ define([ debug("Unable to locate the selected directory: ", path); var parentPath = path.slice(); parentPath.pop(); - displayDirectory(parentPath); + displayDirectory(parentPath, true); return; } @@ -938,6 +963,8 @@ define([ if (isUnsorted) { displayUnsorted($list); + } else if (isAllFiles) { + displayAllFiles($list); } else if (isTrashRoot) { displayTrashRoot($list, $folderHeader, $fileHeader); } else { @@ -1075,6 +1102,15 @@ define([ $container.append($unsortedList); }; + var createAllFiles = function ($container, path) { + var $icon = $unsortedIcon.clone(); + var isOpened = filesOp.comparePath(path, currentPath); + var $allfilesElement = createTreeElement(FILES_DATA_NAME, $icon, [FILES_DATA], false, false, isOpened); + $allfilesElement.addClass('root'); + var $allfilesList = $('