diff --git a/www/common/cryptpad-common.js b/www/common/cryptpad-common.js index f4834b285..75ec129b8 100644 --- a/www/common/cryptpad-common.js +++ b/www/common/cryptpad-common.js @@ -496,6 +496,18 @@ define([ } }; + var updateFileName = function (href, oldName, newName) { + var fo = getStore().getProxy().fo; + var paths = fo.findFileInRoot(href); + paths.forEach(function (path) { + if (path.length !== 2) { return; } + var name = path[1].split('_')[0]; + var parsed = parsePadUrl(href); + if (path.length === 2 && name === oldName && isDefaultName(parsed, name)) { + fo.rename(path, newName); + } + }); + }; var setPadTitle = common.setPadTitle = function (name, cb) { var href = window.location.href; var parsed = parsePadUrl(href); @@ -541,6 +553,7 @@ define([ pad.atime = +new Date(); // set the name + var old = pad.title; pad.title = name; // If we now have a stronger version of a stored href, replace the weaker one by the strong one @@ -551,6 +564,7 @@ define([ }); } pad.href = href; + updateFileName(href, old, name); } return pad; }); @@ -558,7 +572,7 @@ define([ if (!contains) { var data = makePad(href, name); getStore().pushData(data); - getStore().addPad(href, common.initialPath, common.initialName || name); + getStore().addPad(data, common.initialPath); } if (updateWeaker.length > 0) { updateWeaker.forEach(function (obj) { diff --git a/www/common/fsStore.js b/www/common/fsStore.js index 74ccd710a..c5e30558c 100644 --- a/www/common/fsStore.js +++ b/www/common/fsStore.js @@ -88,8 +88,8 @@ define([ ret.removeData = filesOp.removeData; ret.pushData = filesOp.pushData; - ret.addPad = function (href, path, name) { - filesOp.add(href, path, name); + ret.addPad = function (data, path) { + filesOp.add(data, path); }; ret.forgetPad = function (href, cb) { diff --git a/www/common/userObject.js b/www/common/userObject.js index ca2bae258..9ea1af726 100644 --- a/www/common/userObject.js +++ b/www/common/userObject.js @@ -41,14 +41,13 @@ define([ var getStructure = exp.getStructure = function () { var a = {}; a[ROOT] = {}; - a[UNSORTED] = []; a[TRASH] = {}; a[FILES_DATA] = []; a[TEMPLATE] = []; return a; }; var getHrefArray = function () { - return [UNSORTED, TEMPLATE]; + return [TEMPLATE]; }; @@ -297,6 +296,9 @@ define([ return paths; }; + var findFileInRoot = exp.findFileInRoot = function (href) { + return _findFileInRoot([ROOT], href); + }; var _findFileInHrefArray = function (rootName, href) { var unsorted = files[rootName].slice(); var ret = []; @@ -345,10 +347,9 @@ define([ }; var findFile = exp.findFile = function (href) { var rootpaths = _findFileInRoot([ROOT], href); - var unsortedpaths = _findFileInHrefArray(UNSORTED, href); var templatepaths = _findFileInHrefArray(TEMPLATE, href); var trashpaths = _findFileInTrash([TRASH], href); - return rootpaths.concat(unsortedpaths, templatepaths, trashpaths); + return rootpaths.concat(templatepaths, trashpaths); }; var search = exp.search = function (value) { if (typeof(value) !== "string") { return []; } @@ -534,8 +535,10 @@ define([ // ADD - var add = exp.add = function (href, path, name, cb) { - if (!href) { return; } + var add = exp.add = function (data, path) { + if (!data || typeof(data) !== "object") { return; } + var href = data.href; + var name = data.title; var newPath = path, parentEl; if (path && !Array.isArray(path)) { newPath = decodeURIComponent(path).split(','); @@ -546,20 +549,16 @@ define([ parentEl.push(href); return; } - // Add to root - if (path && isPathIn(newPath, [ROOT]) && name) { - parentEl = find(newPath); + // Add to root if path is ROOT or if no path + var filesList = getFiles([ROOT, TRASH, 'hrefArray']); + if ((path && isPathIn(newPath, [ROOT]) || filesList.indexOf(href) === -1) && name) { + parentEl = find(newPath || [ROOT]); if (parentEl) { var newName = getAvailableName(parentEl, name); parentEl[newName] = href; return; } } - // No path: push to unsorted - var filesList = getFiles([ROOT, TRASH, 'hrefArray']); - if (filesList.indexOf(href) === -1) { files[UNSORTED].push(href); } - - if (typeof cb === "function") { cb(); } }; var addFile = exp.addFile = function (filePath, name, type, cb) { var parentEl = findElement(files, filePath); @@ -780,7 +779,7 @@ define([ // * FILES_DATA: - Data (title, cdate, adte) are stored in filesData. filesData contains only href keys linking to object with title, cdate, adate. // - Dates (adate, cdate) can be parsed/formatted // - All files in filesData should be either in 'root', 'trash' or 'unsorted'. If that's not the case, copy the fily to 'unsorted' - // * UNSORTED: Contains only files (href), and does not contains files that are in ROOT + // * TEMPLATE: Contains only files (href), and does not contains files that are in ROOT debug("Cleaning file system..."); var before = JSON.stringify(files); @@ -821,26 +820,37 @@ define([ } } }; + // Make sure unsorted doesn't exist anymore var fixUnsorted = function () { - if (!Array.isArray(files[UNSORTED])) { debug("UNSORTED was not an array"); files[UNSORTED] = []; } - files[UNSORTED] = Cryptpad.deduplicateString(files[UNSORTED].slice()); + if (!files[UNSORTED]) { return; } + debug("UNSORTED still exists in the object, removing it..."); var us = files[UNSORTED]; + if (us.length === 0) { + delete files[UNSORTED]; + return; + } var rootFiles = getFiles([ROOT, TEMPLATE]).slice(); var toClean = []; + var root = find([ROOT]); us.forEach(function (el, idx) { if (!isFile(el) || rootFiles.indexOf(el) !== -1) { - toClean.push(idx); + return; + //toClean.push(idx); } + var name = getFileData(el).title || NEW_FILE_NAME; + var newName = getAvailableName(root, name); + root[newName] = el; }); - toClean.forEach(function (idx) { + delete files[UNSORTED]; + /*toClean.forEach(function (idx) { us.splice(idx, 1); - }); + });*/ }; var fixTemplate = function () { if (!Array.isArray(files[TEMPLATE])) { debug("TEMPLATE was not an array"); files[TEMPLATE] = []; } files[TEMPLATE] = Cryptpad.deduplicateString(files[TEMPLATE].slice()); var us = files[TEMPLATE]; - var rootFiles = getFiles([ROOT, UNSORTED]).slice(); + var rootFiles = getFiles([ROOT]).slice(); var toClean = []; us.forEach(function (el, idx) { if (!isFile(el) || rootFiles.indexOf(el) !== -1) { @@ -855,6 +865,7 @@ define([ if (!$.isArray(files[FILES_DATA])) { debug("FILES_DATA was not an array"); files[FILES_DATA] = []; } var fd = files[FILES_DATA]; var rootFiles = getFiles([ROOT, TRASH, 'hrefArray']); + var root = find([ROOT]); var toClean = []; fd.forEach(function (el, idx) { if (!el || typeof(el) !== "object") { @@ -863,8 +874,10 @@ define([ return; } if (rootFiles.indexOf(el.href) === -1) { - debug("An element in filesData was not in ROOT, UNSORTED or TRASH.", el); - files[UNSORTED].push(el.href); + debug("An element in filesData was not in ROOT, TEMPLATE or TRASH.", el); + var name = el.title || NEW_FILE_NAME; + var newName = getAvailableName(root, name); + root[newName] = el.href; return; } }); diff --git a/www/drive/main.js b/www/drive/main.js index d7d90a9d8..038f9402e 100644 --- a/www/drive/main.js +++ b/www/drive/main.js @@ -41,8 +41,6 @@ define([ var SEARCH_NAME = Messages.fm_searchName; var ROOT = "root"; var ROOT_NAME = Messages.fm_rootName; - var UNSORTED = "unsorted"; - var UNSORTED_NAME = Messages.fm_unsortedName; var FILES_DATA = Cryptpad.storageKey; var FILES_DATA_NAME = Messages.fm_filesDataName; var TEMPLATE = "template"; @@ -68,9 +66,9 @@ define([ var getLastOpenedFolder = function () { var path; try { - path = localStorage[LOCALSTORAGE_LAST] ? JSON.parse(localStorage[LOCALSTORAGE_LAST]) : [UNSORTED]; + path = localStorage[LOCALSTORAGE_LAST] ? JSON.parse(localStorage[LOCALSTORAGE_LAST]) : [ROOT]; } catch (e) { - path = [UNSORTED]; + path = [ROOT]; } return path; }; @@ -218,7 +216,7 @@ define([ // Categories dislayed in the menu // _WORKGROUP_ : do not display unsorted - var displayedCategories = [ROOT, UNSORTED, TRASH, SEARCH]; + var displayedCategories = [ROOT, TRASH, SEARCH]; if (AppConfig.enableTemplates) { displayedCategories.push(TEMPLATE); } if (isWorkgroup()) { displayedCategories = [ROOT, TRASH, SEARCH]; } @@ -680,7 +678,7 @@ define([ var msg = Messages._getKey('fm_removeSeveralDialog', [paths.length]); if (paths.length === 1) { var path = paths[0]; - var name = path[0] === UNSORTED ? filesOp.getTitle(filesOp.find(path)) : path[path.length - 1]; + var name = path[0] === TEMPLATE ? filesOp.getTitle(filesOp.find(path)) : path[path.length - 1]; msg = Messages._getKey('fm_removeDialog', [name]); } Cryptpad.confirm(msg, function (res) { @@ -948,7 +946,6 @@ define([ switch (name) { case ROOT: pName = ROOT_NAME; break; case TRASH: pName = TRASH_NAME; break; - case UNSORTED: pName = UNSORTED_NAME; break; case TEMPLATE: pName = TEMPLATE_NAME; break; case FILES_DATA: pName = FILES_DATA_NAME; break; case SEARCH: pName = SEARCH_NAME; break; @@ -997,9 +994,6 @@ define([ case ROOT: msg = Messages.fm_info_root; break; - case UNSORTED: - msg = Messages.fm_info_unsorted; - break; case TEMPLATE: msg = Messages.fm_info_template; break; @@ -1243,10 +1237,6 @@ define([ //return $fileHeader; }; - var allFilesSorted = function () { - return filesOp.getFiles([UNSORTED]).length === 0; - }; - var sortElements = function (folder, path, oldkeys, prop, asc, useHref, useData) { var root = filesOp.find(path); var test = folder ? filesOp.isFolder : filesOp.isFile; @@ -1343,7 +1333,6 @@ define([ // and they don't hav a hierarchical structure (folder/subfolders) var displayHrefArray = function ($container, rootName, draggable) { var unsorted = files[rootName]; - if (rootName === UNSORTED && allFilesSorted()) { return; } var $fileHeader = getFileListHeader(false); $container.append($fileHeader); var keys = unsorted; @@ -1517,7 +1506,6 @@ define([ } var isInRoot = filesOp.isPathIn(path, [ROOT]); var isTrashRoot = filesOp.comparePath(path, [TRASH]); - var isUnsorted = filesOp.comparePath(path, [UNSORTED]); var isTemplate = filesOp.comparePath(path, [TEMPLATE]); var isAllFiles = filesOp.comparePath(path, [FILES_DATA]); var isSearch = path[0] === SEARCH; @@ -1596,7 +1584,7 @@ define([ var $folderHeader = getFolderListHeader(); var $fileHeader = getFileListHeader(true); - if (isUnsorted || isTemplate) { + if (isTemplate) { displayHrefArray($list, path[0], true); } else if (isAllFiles) { displayAllFiles($list); @@ -1733,15 +1721,6 @@ define([ }); }; - var createUnsorted = function ($container, path) { - var $icon = $unsortedIcon.clone(); - var isOpened = filesOp.comparePath(path, currentPath); - var $unsortedElement = createTreeElement(UNSORTED_NAME, $icon, [UNSORTED], false, true, false, isOpened); - $unsortedElement.addClass('root'); - var $unsortedList = $('