Add a recent pads category in the drive

pull/1/head
yflory 7 years ago
parent 1752124071
commit b4864b96ac

@ -413,6 +413,15 @@ define([
}); });
return ret; return ret;
}; };
exp.getRecentPads = function () {
var allFiles = files[FILES_DATA];
var sorted = Object.keys(allFiles)
.sort(function (a,b) {
return allFiles[a].atime < allFiles[b].atime;
})
.map(function (str) { return Number(str); });
return sorted;
};
/** /**
* OPERATIONS * OPERATIONS

@ -51,6 +51,8 @@ define([
var TEMPLATE_NAME = Messages.fm_templateName; var TEMPLATE_NAME = Messages.fm_templateName;
var TRASH = "trash"; var TRASH = "trash";
var TRASH_NAME = Messages.fm_trashName; var TRASH_NAME = Messages.fm_trashName;
var RECENT = "recent";
var RECENT_NAME = "Recent pads";
var LOCALSTORAGE_LAST = "cryptpad-file-lastOpened"; var LOCALSTORAGE_LAST = "cryptpad-file-lastOpened";
var LOCALSTORAGE_OPENED = "cryptpad-file-openedFolders"; var LOCALSTORAGE_OPENED = "cryptpad-file-openedFolders";
@ -233,9 +235,10 @@ define([
// Categories dislayed in the menu // Categories dislayed in the menu
// _WORKGROUP_ : do not display unsorted // _WORKGROUP_ : do not display unsorted
var displayedCategories = [ROOT, TRASH, SEARCH]; var displayedCategories = [ROOT, TRASH, SEARCH, RECENT];
if (AppConfig.enableTemplates) { displayedCategories.push(TEMPLATE); } if (AppConfig.enableTemplates) { displayedCategories.push(TEMPLATE); }
if (isWorkgroup()) { displayedCategories = [ROOT, TRASH, SEARCH]; } if (isWorkgroup()) { displayedCategories = [ROOT, TRASH, SEARCH]; }
var virtualCategories = [SEARCH, RECENT];
if (!APP.loggedIn) { if (!APP.loggedIn) {
displayedCategories = [FILES_DATA]; displayedCategories = [FILES_DATA];
@ -1259,6 +1262,7 @@ define([
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;
case RECENT: pName = RECENT_NAME; break;
default: pName = name; default: pName = name;
} }
return pName; return pName;
@ -1318,6 +1322,9 @@ define([
case FILES_DATA: case FILES_DATA:
msg = Messages.fm_info_allFiles; msg = Messages.fm_info_allFiles;
break; break;
case RECENT:
msg = Messages.fm_info_recent || 'TODO';
break;
default: default:
msg = undefined; msg = undefined;
} }
@ -1805,6 +1812,50 @@ define([
}); });
}; };
var displayRecent = function ($list) {
var filesList = filesOp.getRecentPads();
var limit = 20;
var i = 0;
filesList.forEach(function (id) {
if (i >= 20) { return; }
// Check path (pad exists and not in trash)
var paths = filesOp.findFile(id);
if (!paths.length) { return; }
var path = paths[0];
if (filesOp.isPathIn(path, [TRASH])) { return; }
// Display the pad
var file = filesOp.getFileData(id);
if (!file) {
//debug("Unsorted or template returns an element not present in filesData: ", href);
file = { title: Messages.fm_noname };
//return;
}
var $icon = getFileIcon(id);
var ro = filesOp.isReadOnlyFile(id);
// ro undefined mens it's an old hash which doesn't support read-only
var roClass = typeof(ro) === 'undefined' ? ' noreadonly' : ro ? ' readonly' : '';
var $element = $('<li>', {
'class': 'file-element element element-row' + roClass,
});
addFileData(id, $element);
$element.prepend($icon).dblclick(function () {
openFile(id);
});
$element.data('path', path);
$element.click(function(e) {
e.stopPropagation();
onElementClick(e, $element, path);
});
$element.contextmenu(openDefaultContextMenu);
$element.data('context', $defaultContextMenu);
/*if (draggable) {
addDragAndDropHandlers($element, path, false, false);
}*/
$list.append($element);
i++;
});
};
// Display the selected directory into the content part (rightside) // Display the selected directory into the content part (rightside)
// NOTE: Elements in the trash are not using the same storage structure as the others // NOTE: Elements in the trash are not using the same storage structure as the others
// _WORKGROUP_ : do not change the lastOpenedFolder value in localStorage // _WORKGROUP_ : do not change the lastOpenedFolder value in localStorage
@ -1833,9 +1884,11 @@ define([
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;
var isRecent = path[0] === RECENT;
var isVirtual = virtualCategories.indexOf(path[0]) !== -1;
var root = isSearch ? undefined : filesOp.find(path); var root = isVirtual ? undefined : filesOp.find(path);
if (!isSearch && typeof(root) === "undefined") { if (!isVirtual && typeof(root) === "undefined") {
log(Messages.fm_unknownFolderError); log(Messages.fm_unknownFolderError);
debug("Unable to locate the selected directory: ", path); debug("Unable to locate the selected directory: ", path);
var parentPath = path.slice(); var parentPath = path.slice();
@ -1921,6 +1974,8 @@ define([
displayTrashRoot($list, $folderHeader, $fileHeader); displayTrashRoot($list, $folderHeader, $fileHeader);
} else if (isSearch) { } else if (isSearch) {
displaySearch($list, path[1]); displaySearch($list, path[1]);
} else if (isRecent) {
displayRecent($list);
} else { } else {
$dirContent.contextmenu(openContentContextMenu); $dirContent.contextmenu(openContentContextMenu);
if (filesOp.hasSubfolder(root)) { $list.append($folderHeader); } if (filesOp.hasSubfolder(root)) { $list.append($folderHeader); }
@ -2093,6 +2148,15 @@ define([
$container.append($trashList); $container.append($trashList);
}; };
var createRecent = function ($container, path) {
var $icon = $templateIcon.clone(); //TODO
var isOpened = filesOp.comparePath(path, currentPath);
var $element = createTreeElement(RECENT_NAME, $icon, [RECENT], false, false, false, isOpened);
$element.addClass('root');
var $list = $('<ul>', { id: 'recentTree', 'class': 'category' }).append($element);
$container.append($list);
};
var search = APP.Search = {}; var search = APP.Search = {};
var createSearch = function ($container) { var createSearch = function ($container) {
var isInSearch = currentPath[0] === SEARCH; var isInSearch = currentPath[0] === SEARCH;
@ -2145,6 +2209,7 @@ define([
$tree.html(''); $tree.html('');
if (displayedCategories.indexOf(SEARCH) !== -1) { createSearch($tree); } if (displayedCategories.indexOf(SEARCH) !== -1) { createSearch($tree); }
var $div = $('<div>', {'class': 'categories-container'}).appendTo($tree); var $div = $('<div>', {'class': 'categories-container'}).appendTo($tree);
if (displayedCategories.indexOf(RECENT) !== -1) { createRecent($div, [RECENT]); }
if (displayedCategories.indexOf(ROOT) !== -1) { createTree($div, [ROOT]); } if (displayedCategories.indexOf(ROOT) !== -1) { createTree($div, [ROOT]); }
if (displayedCategories.indexOf(TEMPLATE) !== -1) { createTemplate($div, [TEMPLATE]); } if (displayedCategories.indexOf(TEMPLATE) !== -1) { createTemplate($div, [TEMPLATE]); }
if (displayedCategories.indexOf(FILES_DATA) !== -1) { createAllFiles($div, [FILES_DATA]); } if (displayedCategories.indexOf(FILES_DATA) !== -1) { createAllFiles($div, [FILES_DATA]); }

Loading…
Cancel
Save