Remove the unsorted files category

pull/1/head
yflory 8 years ago
parent f50aa5c29b
commit 520dabe094

@ -495,6 +495,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 setPadTitle = common.setPadTitle = function (name, cb) {
var href = window.location.href; var href = window.location.href;
var parsed = parsePadUrl(href); var parsed = parsePadUrl(href);
@ -540,6 +552,7 @@ define([
pad.atime = +new Date(); pad.atime = +new Date();
// set the name // set the name
var old = pad.title;
pad.title = name; pad.title = name;
// If we now have a stronger version of a stored href, replace the weaker one by the strong one // If we now have a stronger version of a stored href, replace the weaker one by the strong one
@ -550,6 +563,7 @@ define([
}); });
} }
pad.href = href; pad.href = href;
updateFileName(href, old, name);
} }
return pad; return pad;
}); });
@ -557,7 +571,7 @@ define([
if (!contains) { if (!contains) {
var data = makePad(href, name); var data = makePad(href, name);
getStore().pushData(data); getStore().pushData(data);
getStore().addPad(href, common.initialPath, common.initialName || name); getStore().addPad(data, common.initialPath);
} }
if (updateWeaker.length > 0) { if (updateWeaker.length > 0) {
updateWeaker.forEach(function (obj) { updateWeaker.forEach(function (obj) {

@ -88,8 +88,8 @@ define([
ret.removeData = filesOp.removeData; ret.removeData = filesOp.removeData;
ret.pushData = filesOp.pushData; ret.pushData = filesOp.pushData;
ret.addPad = function (href, path, name) { ret.addPad = function (data, path) {
filesOp.add(href, path, name); filesOp.add(data, path);
}; };
ret.forgetPad = function (href, cb) { ret.forgetPad = function (href, cb) {

@ -41,14 +41,13 @@ define([
var getStructure = exp.getStructure = function () { var getStructure = exp.getStructure = function () {
var a = {}; var a = {};
a[ROOT] = {}; a[ROOT] = {};
a[UNSORTED] = [];
a[TRASH] = {}; a[TRASH] = {};
a[FILES_DATA] = []; a[FILES_DATA] = [];
a[TEMPLATE] = []; a[TEMPLATE] = [];
return a; return a;
}; };
var getHrefArray = function () { var getHrefArray = function () {
return [UNSORTED, TEMPLATE]; return [TEMPLATE];
}; };
@ -297,6 +296,9 @@ define([
return paths; return paths;
}; };
var findFileInRoot = exp.findFileInRoot = function (href) {
return _findFileInRoot([ROOT], href);
};
var _findFileInHrefArray = function (rootName, href) { var _findFileInHrefArray = function (rootName, href) {
var unsorted = files[rootName].slice(); var unsorted = files[rootName].slice();
var ret = []; var ret = [];
@ -345,10 +347,9 @@ define([
}; };
var findFile = exp.findFile = function (href) { var findFile = exp.findFile = function (href) {
var rootpaths = _findFileInRoot([ROOT], href); var rootpaths = _findFileInRoot([ROOT], href);
var unsortedpaths = _findFileInHrefArray(UNSORTED, href);
var templatepaths = _findFileInHrefArray(TEMPLATE, href); var templatepaths = _findFileInHrefArray(TEMPLATE, href);
var trashpaths = _findFileInTrash([TRASH], href); var trashpaths = _findFileInTrash([TRASH], href);
return rootpaths.concat(unsortedpaths, templatepaths, trashpaths); return rootpaths.concat(templatepaths, trashpaths);
}; };
var search = exp.search = function (value) { var search = exp.search = function (value) {
if (typeof(value) !== "string") { return []; } if (typeof(value) !== "string") { return []; }
@ -534,8 +535,10 @@ define([
// ADD // ADD
var add = exp.add = function (href, path, name, cb) { var add = exp.add = function (data, path) {
if (!href) { return; } if (!data || typeof(data) !== "object") { return; }
var href = data.href;
var name = data.title;
var newPath = path, parentEl; var newPath = path, parentEl;
if (path && !Array.isArray(path)) { if (path && !Array.isArray(path)) {
newPath = decodeURIComponent(path).split(','); newPath = decodeURIComponent(path).split(',');
@ -546,20 +549,16 @@ define([
parentEl.push(href); parentEl.push(href);
return; return;
} }
// Add to root // Add to root if path is ROOT or if no path
if (path && isPathIn(newPath, [ROOT]) && name) { var filesList = getFiles([ROOT, TRASH, 'hrefArray']);
parentEl = find(newPath); if ((path && isPathIn(newPath, [ROOT]) || filesList.indexOf(href) === -1) && name) {
parentEl = find(newPath || [ROOT]);
if (parentEl) { if (parentEl) {
var newName = getAvailableName(parentEl, name); var newName = getAvailableName(parentEl, name);
parentEl[newName] = href; parentEl[newName] = href;
return; 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 addFile = exp.addFile = function (filePath, name, type, cb) {
var parentEl = findElement(files, filePath); 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. // * 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 // - 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' // - 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..."); debug("Cleaning file system...");
var before = JSON.stringify(files); var before = JSON.stringify(files);
@ -821,26 +820,37 @@ define([
} }
} }
}; };
// Make sure unsorted doesn't exist anymore
var fixUnsorted = function () { var fixUnsorted = function () {
if (!Array.isArray(files[UNSORTED])) { debug("UNSORTED was not an array"); files[UNSORTED] = []; } if (!files[UNSORTED]) { return; }
files[UNSORTED] = Cryptpad.deduplicateString(files[UNSORTED].slice()); debug("UNSORTED still exists in the object, removing it...");
var us = files[UNSORTED]; var us = files[UNSORTED];
if (us.length === 0) {
delete files[UNSORTED];
return;
}
var rootFiles = getFiles([ROOT, TEMPLATE]).slice(); var rootFiles = getFiles([ROOT, TEMPLATE]).slice();
var toClean = []; var toClean = [];
var root = find([ROOT]);
us.forEach(function (el, idx) { us.forEach(function (el, idx) {
if (!isFile(el) || rootFiles.indexOf(el) !== -1) { 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); us.splice(idx, 1);
}); });*/
}; };
var fixTemplate = function () { var fixTemplate = function () {
if (!Array.isArray(files[TEMPLATE])) { debug("TEMPLATE was not an array"); files[TEMPLATE] = []; } if (!Array.isArray(files[TEMPLATE])) { debug("TEMPLATE was not an array"); files[TEMPLATE] = []; }
files[TEMPLATE] = Cryptpad.deduplicateString(files[TEMPLATE].slice()); files[TEMPLATE] = Cryptpad.deduplicateString(files[TEMPLATE].slice());
var us = files[TEMPLATE]; var us = files[TEMPLATE];
var rootFiles = getFiles([ROOT, UNSORTED]).slice(); var rootFiles = getFiles([ROOT]).slice();
var toClean = []; var toClean = [];
us.forEach(function (el, idx) { us.forEach(function (el, idx) {
if (!isFile(el) || rootFiles.indexOf(el) !== -1) { 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] = []; } if (!$.isArray(files[FILES_DATA])) { debug("FILES_DATA was not an array"); files[FILES_DATA] = []; }
var fd = files[FILES_DATA]; var fd = files[FILES_DATA];
var rootFiles = getFiles([ROOT, TRASH, 'hrefArray']); var rootFiles = getFiles([ROOT, TRASH, 'hrefArray']);
var root = find([ROOT]);
var toClean = []; var toClean = [];
fd.forEach(function (el, idx) { fd.forEach(function (el, idx) {
if (!el || typeof(el) !== "object") { if (!el || typeof(el) !== "object") {
@ -863,8 +874,10 @@ define([
return; return;
} }
if (rootFiles.indexOf(el.href) === -1) { if (rootFiles.indexOf(el.href) === -1) {
debug("An element in filesData was not in ROOT, UNSORTED or TRASH.", el); debug("An element in filesData was not in ROOT, TEMPLATE or TRASH.", el);
files[UNSORTED].push(el.href); var name = el.title || NEW_FILE_NAME;
var newName = getAvailableName(root, name);
root[newName] = el.href;
return; return;
} }
}); });

@ -41,8 +41,6 @@ define([
var SEARCH_NAME = Messages.fm_searchName; var SEARCH_NAME = Messages.fm_searchName;
var ROOT = "root"; var ROOT = "root";
var ROOT_NAME = Messages.fm_rootName; var ROOT_NAME = Messages.fm_rootName;
var UNSORTED = "unsorted";
var UNSORTED_NAME = Messages.fm_unsortedName;
var FILES_DATA = Cryptpad.storageKey; var FILES_DATA = Cryptpad.storageKey;
var FILES_DATA_NAME = Messages.fm_filesDataName; var FILES_DATA_NAME = Messages.fm_filesDataName;
var TEMPLATE = "template"; var TEMPLATE = "template";
@ -68,9 +66,9 @@ define([
var getLastOpenedFolder = function () { var getLastOpenedFolder = function () {
var path; var path;
try { try {
path = localStorage[LOCALSTORAGE_LAST] ? JSON.parse(localStorage[LOCALSTORAGE_LAST]) : [UNSORTED]; path = localStorage[LOCALSTORAGE_LAST] ? JSON.parse(localStorage[LOCALSTORAGE_LAST]) : [ROOT];
} catch (e) { } catch (e) {
path = [UNSORTED]; path = [ROOT];
} }
return path; return path;
}; };
@ -218,7 +216,7 @@ define([
// Categories dislayed in the menu // Categories dislayed in the menu
// _WORKGROUP_ : do not display unsorted // _WORKGROUP_ : do not display unsorted
var displayedCategories = [ROOT, UNSORTED, TRASH, SEARCH]; var displayedCategories = [ROOT, TRASH, SEARCH];
if (AppConfig.enableTemplates) { displayedCategories.push(TEMPLATE); } if (AppConfig.enableTemplates) { displayedCategories.push(TEMPLATE); }
if (isWorkgroup()) { displayedCategories = [ROOT, TRASH, SEARCH]; } if (isWorkgroup()) { displayedCategories = [ROOT, TRASH, SEARCH]; }
@ -680,7 +678,7 @@ define([
var msg = Messages._getKey('fm_removeSeveralDialog', [paths.length]); var msg = Messages._getKey('fm_removeSeveralDialog', [paths.length]);
if (paths.length === 1) { if (paths.length === 1) {
var path = paths[0]; 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]); msg = Messages._getKey('fm_removeDialog', [name]);
} }
Cryptpad.confirm(msg, function (res) { Cryptpad.confirm(msg, function (res) {
@ -948,7 +946,6 @@ define([
switch (name) { switch (name) {
case ROOT: pName = ROOT_NAME; break; case ROOT: pName = ROOT_NAME; break;
case TRASH: pName = TRASH_NAME; break; case TRASH: pName = TRASH_NAME; break;
case UNSORTED: pName = UNSORTED_NAME; break;
case TEMPLATE: pName = TEMPLATE_NAME; break; case TEMPLATE: pName = TEMPLATE_NAME; break;
case FILES_DATA: pName = FILES_DATA_NAME; break; case FILES_DATA: pName = FILES_DATA_NAME; break;
case SEARCH: pName = SEARCH_NAME; break; case SEARCH: pName = SEARCH_NAME; break;
@ -997,9 +994,6 @@ define([
case ROOT: case ROOT:
msg = Messages.fm_info_root; msg = Messages.fm_info_root;
break; break;
case UNSORTED:
msg = Messages.fm_info_unsorted;
break;
case TEMPLATE: case TEMPLATE:
msg = Messages.fm_info_template; msg = Messages.fm_info_template;
break; break;
@ -1243,10 +1237,6 @@ define([
//return $fileHeader; //return $fileHeader;
}; };
var allFilesSorted = function () {
return filesOp.getFiles([UNSORTED]).length === 0;
};
var sortElements = function (folder, path, oldkeys, prop, asc, useHref, useData) { var sortElements = function (folder, path, oldkeys, prop, asc, useHref, useData) {
var root = filesOp.find(path); var root = filesOp.find(path);
var test = folder ? filesOp.isFolder : filesOp.isFile; var test = folder ? filesOp.isFolder : filesOp.isFile;
@ -1343,7 +1333,6 @@ define([
// and they don't hav a hierarchical structure (folder/subfolders) // and they don't hav a hierarchical structure (folder/subfolders)
var displayHrefArray = function ($container, rootName, draggable) { var displayHrefArray = function ($container, rootName, draggable) {
var unsorted = files[rootName]; var unsorted = files[rootName];
if (rootName === UNSORTED && allFilesSorted()) { return; }
var $fileHeader = getFileListHeader(false); var $fileHeader = getFileListHeader(false);
$container.append($fileHeader); $container.append($fileHeader);
var keys = unsorted; var keys = unsorted;
@ -1517,7 +1506,6 @@ define([
} }
var isInRoot = filesOp.isPathIn(path, [ROOT]); var isInRoot = filesOp.isPathIn(path, [ROOT]);
var isTrashRoot = filesOp.comparePath(path, [TRASH]); var isTrashRoot = filesOp.comparePath(path, [TRASH]);
var isUnsorted = filesOp.comparePath(path, [UNSORTED]);
var isTemplate = filesOp.comparePath(path, [TEMPLATE]); var isTemplate = filesOp.comparePath(path, [TEMPLATE]);
var isAllFiles = filesOp.comparePath(path, [FILES_DATA]); var isAllFiles = filesOp.comparePath(path, [FILES_DATA]);
var isSearch = path[0] === SEARCH; var isSearch = path[0] === SEARCH;
@ -1596,7 +1584,7 @@ define([
var $folderHeader = getFolderListHeader(); var $folderHeader = getFolderListHeader();
var $fileHeader = getFileListHeader(true); var $fileHeader = getFileListHeader(true);
if (isUnsorted || isTemplate) { if (isTemplate) {
displayHrefArray($list, path[0], true); displayHrefArray($list, path[0], true);
} else if (isAllFiles) { } else if (isAllFiles) {
displayAllFiles($list); 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 = $('<ul>', { id: 'unsortedTree', 'class': 'category2' }).append($unsortedElement);
$container.append($unsortedList);
};
var createTemplate = function ($container, path) { var createTemplate = function ($container, path) {
var $icon = $templateIcon.clone(); var $icon = $templateIcon.clone();
var isOpened = filesOp.comparePath(path, currentPath); var isOpened = filesOp.comparePath(path, currentPath);
@ -1808,7 +1787,6 @@ define([
$tree.html(''); $tree.html('');
if (displayedCategories.indexOf(SEARCH) !== -1) { createSearch($tree); } if (displayedCategories.indexOf(SEARCH) !== -1) { createSearch($tree); }
if (displayedCategories.indexOf(ROOT) !== -1) { createTree($tree, [ROOT]); } if (displayedCategories.indexOf(ROOT) !== -1) { createTree($tree, [ROOT]); }
if (displayedCategories.indexOf(UNSORTED) !== -1) { createUnsorted($tree, [UNSORTED]); }
if (displayedCategories.indexOf(TEMPLATE) !== -1) { createTemplate($tree, [TEMPLATE]); } if (displayedCategories.indexOf(TEMPLATE) !== -1) { createTemplate($tree, [TEMPLATE]); }
if (displayedCategories.indexOf(FILES_DATA) !== -1) { createAllFiles($tree, [FILES_DATA]); } if (displayedCategories.indexOf(FILES_DATA) !== -1) { createAllFiles($tree, [FILES_DATA]); }
if (displayedCategories.indexOf(TRASH) !== -1) { createTrash($tree, [TRASH]); } if (displayedCategories.indexOf(TRASH) !== -1) { createTrash($tree, [TRASH]); }
@ -1830,9 +1808,6 @@ define([
case ROOT: case ROOT:
prettyName = ROOT_NAME; prettyName = ROOT_NAME;
break; break;
case UNSORTED:
prettyName = UNSORTED_NAME;
break;
case FILES_DATA: case FILES_DATA:
prettyName = FILES_DATA_NAME; prettyName = FILES_DATA_NAME;
break; break;
@ -2210,13 +2185,14 @@ define([
Get.put(hash, Messages.driveReadme, function (e) { Get.put(hash, Messages.driveReadme, function (e) {
if (e) { logError(e); } if (e) { logError(e); }
var href = '/pad/#' + hash; var href = '/pad/#' + hash;
proxy.drive[UNSORTED].push(href); var data = {
proxy.drive[FILES_DATA].push({
href: href, href: href,
title: Messages.driveReadmeTitle, title: Messages.driveReadmeTitle,
atime: new Date().toISOString(), atime: new Date().toISOString(),
ctime: new Date().toISOString() ctime: new Date().toISOString()
}); };
filesOp.pushData(data);
filesOp.add(data);
if (typeof(cb) === "function") { cb(); } if (typeof(cb) === "function") { cb(); }
}); });
delete sessionStorage.createReadme; delete sessionStorage.createReadme;

Loading…
Cancel
Save