Show folders in the results of drive search

pull/1/head
ClemDee 6 years ago
parent 29b7c2c295
commit 9b8fed55e9

@ -514,6 +514,40 @@ define([
data: exp.getFileData(l)
});
});
// find folders
var resFolders = [];
var findFoldersRec = function (folder, path) {
for (var key in folder) {
if (isFolder(folder[key])) {
if (isSharedFolder(folder[key])) {
// var name = getSharedFolderData(folder[key]).title || "";
// if (name.toLowerCase().indexOf(lValue) !== -1) {
// resFolders.push(path.concat([key, ROOT]));
// }
findFoldersRec(folder[key], path.concat([key, ROOT]));
}
else {
if (key.toLowerCase().indexOf(lValue) !== -1) {
resFolders.push({
id: null,
paths: [path.concat(key)],
data: {
title: key
}
});
}
findFoldersRec(folder[key], path.concat(key));
}
}
}
};
findFoldersRec(files[ROOT], [ROOT]);
resFolders = resFolders.sort(function (a, b) {
return a.data.title.toLowerCase() > b.data.title.toLowerCase();
});
ret = resFolders.concat(ret);
return ret;
};
exp.getRecentPads = function () {

@ -2610,6 +2610,7 @@ define([
var displaySearch = function ($list, value) {
var filesList = manager.search(value);
filesList.forEach(function (r) {
// if r.id === null, then it's a folder, not a file
r.paths.forEach(function (path) {
if (!r.inSharedFolder &&
APP.hideDuplicateOwned && manager.isDuplicateOwned(path)) { return; }
@ -2617,25 +2618,27 @@ define([
var parsed = Hash.parsePadUrl(href);
var $table = $('<table>');
var $icon = $('<td>', {'rowspan': '3', 'class': 'cp-app-drive-search-icon'})
.append(getFileIcon(r.id));
.append(r.id ? getFileIcon(r.id) : $folderIcon.clone());
var $title = $('<td>', {
'class': 'cp-app-drive-search-col1 cp-app-drive-search-title'
}).text(r.data.title)
.click(function () {
openFile(null, r.data.href);
});
}).text(r.data.title);
if (r.id) {
$title.click(function () {
openFile(null, r.data.href);
});
}
var $typeName = $('<td>', {'class': 'cp-app-drive-search-label2'})
.text(Messages.fm_type);
var $type = $('<td>', {'class': 'cp-app-drive-search-col2'})
.text(Messages.type[parsed.type] || parsed.type);
.text(r.id ? Messages.type[parsed.type] || parsed.type : Messages.fm_folder);
var $atimeName = $('<td>', {'class': 'cp-app-drive-search-label2'})
.text(Messages.fm_lastAccess);
.text(r.id ? Messages.fm_lastAccess : "");
var $atime = $('<td>', {'class': 'cp-app-drive-search-col2'})
.text(new Date(r.data.atime).toLocaleString());
.text(r.id ? new Date(r.data.atime).toLocaleString() : "");
var $ctimeName = $('<td>', {'class': 'cp-app-drive-search-label2'})
.text(Messages.fm_creation);
.text(r.id ? Messages.fm_creation : "");
var $ctime = $('<td>', {'class': 'cp-app-drive-search-col2'})
.text(new Date(r.data.ctime).toLocaleString());
.text(r.id ? new Date(r.data.ctime).toLocaleString() : "");
if (manager.isPathIn(path, ['hrefArray'])) {
path.pop();
path.push(r.data.title);
@ -2646,23 +2649,33 @@ define([
createTitle($path, path, true);
var parentPath = path.slice();
var $a;
if (parentPath) {
$a = $('<a>').text(Messages.fm_openParent).click(function (e) {
if (r.id) {
if (parentPath) {
$a = $('<a>').text(Messages.fm_openParent).click(function (e) {
e.preventDefault();
if (manager.isInTrashRoot(parentPath)) { parentPath = [TRASH]; }
else { parentPath.pop(); }
APP.selectedFiles = [r.id];
APP.displayDirectory(parentPath);
});
}
}
else {
$a = $('<a>').text(Messages.fm_OpenFolder || "Open folder").click(function (e) {
e.preventDefault();
if (manager.isInTrashRoot(parentPath)) { parentPath = [TRASH]; }
else { parentPath.pop(); }
APP.selectedFiles = [r.id];
APP.displayDirectory(parentPath);
APP.displayDirectory(path);
});
}
var $openDir = $('<td>', {'class': 'cp-app-drive-search-opendir'}).append($a);
$('<a>').text(Messages.fc_prop).click(function () {
APP.getProperties(r.id, function (e, $prop) {
if (e) { return void logError(e); }
UI.alert($prop[0], undefined, true);
});
}).appendTo($openDir);
if (r.id) {
$('<a>').text(Messages.fc_prop).click(function () {
APP.getProperties(r.id, function (e, $prop) {
if (e) { return void logError(e); }
UI.alert($prop[0], undefined, true);
});
}).appendTo($openDir);
}
// rows 1-3
$('<tr>').append($icon).append($title).append($typeName).append($type).appendTo($table);
@ -3208,7 +3221,7 @@ define([
placeholder: Messages.fm_searchPlaceholder
}).keyup(function (e) {
if (search.to) { window.clearTimeout(search.to); }
if ([38, 39, 40, 41].indexOf(e.which) !== -1) {
if ([37, 38, 39, 40].indexOf(e.which) !== -1) {
if (!$input.val()) {
$input.blur();
$content.focus();

Loading…
Cancel
Save