From 634b051d42a8c930b8292a08b40059d30eb283bf Mon Sep 17 00:00:00 2001 From: ClemDee Date: Thu, 13 Jun 2019 11:51:38 +0200 Subject: [PATCH] Add expand/collapse all feature in drive tree --- www/common/translations/messages.fr.json | 2 ++ www/common/translations/messages.json | 2 ++ www/drive/inner.js | 44 +++++++++++++++++++++++- 3 files changed, 47 insertions(+), 1 deletion(-) diff --git a/www/common/translations/messages.fr.json b/www/common/translations/messages.fr.json index 431a04110..e623a65f9 100644 --- a/www/common/translations/messages.fr.json +++ b/www/common/translations/messages.fr.json @@ -383,6 +383,8 @@ "fc_rename": "Renommer", "fc_open": "Ouvrir", "fc_open_ro": "Ouvrir (lecture seule)", + "fc_expandAll": "Développer tout", + "fc_collapseAll": "Réduire tout", "fc_delete": "Déplacer vers la corbeille", "fc_delete_owned": "Supprimer du serveur", "fc_restore": "Restaurer", diff --git a/www/common/translations/messages.json b/www/common/translations/messages.json index 693f65053..bae665e40 100644 --- a/www/common/translations/messages.json +++ b/www/common/translations/messages.json @@ -387,6 +387,8 @@ "fc_rename": "Rename", "fc_open": "Open", "fc_open_ro": "Open (read-only)", + "fc_expandAll": "Expand All", + "fc_collapseAll": "Collapse All", "fc_delete": "Move to trash", "fc_delete_owned": "Delete from the server", "fc_restore": "Restore", diff --git a/www/drive/inner.js b/www/drive/inner.js index 214f98d47..8ea57fd95 100644 --- a/www/drive/inner.js +++ b/www/drive/inner.js @@ -293,6 +293,14 @@ define([ 'tabindex': '-1', 'data-icon': faReadOnly, }, Messages.fc_open_ro)), + h('li', h('a.cp-app-drive-context-expandall.dropdown-item', { + 'tabindex': '-1', + 'data-icon': "expandAll", + }, Messages.fc_expandAll)), + h('li', h('a.cp-app-drive-context-collapseall.dropdown-item', { + 'tabindex': '-1', + 'data-icon': "collapseAll", + }, Messages.fc_collapseAll)), h('li', h('a.cp-app-drive-context-download.dropdown-item', { 'tabindex': '-1', 'data-icon': faDownload, @@ -878,6 +886,10 @@ define([ paths.forEach(function (p) { var path = p.path; var $element = p.element; + if (!$element.closest("#cp-app-drive-tree").length) { + hide.push('expandall'); + hide.push('collapseall'); + } if (path.length === 1) { // Can't rename or delete root elements hide.push('delete'); @@ -908,6 +920,8 @@ define([ if (containsFolder) { // More than 1 folder selected: cannot create a new subfolder hide.push('newfolder'); + hide.push('expandall'); + hide.push('collapseall'); } containsFolder = true; hide.push('openro'); @@ -918,6 +932,8 @@ define([ if (containsFolder) { // More than 1 folder selected: cannot create a new subfolder hide.push('newfolder'); + hide.push('expandall'); + hide.push('collapseall'); } containsFolder = true; hide.push('openro'); @@ -970,7 +986,7 @@ define([ show = ['newfolder', 'newsharedfolder', 'newdoc']; break; case 'tree': - show = ['open', 'openro', 'download', 'share', 'rename', 'delete', 'deleteowned', 'removesf', + show = ['open', 'openro', 'expandall', 'collapseall', 'download', 'share', 'rename', 'delete', 'deleteowned', 'removesf', 'newfolder', 'properties', 'hashtag']; break; case 'default': @@ -3336,6 +3352,32 @@ define([ openFile(null, href); }); } + else if ($(this).hasClass('cp-app-drive-context-expandall') || + $(this).hasClass('cp-app-drive-context-collapseall')) { + if (paths.length !== 1) { return; } + var opened = $(this).hasClass('cp-app-drive-context-expandall'); + var openRecursive = function (path) { + setFolderOpened(path, opened); + var folderContent = manager.find(path); + var subfolders = []; + for (var k in folderContent) { + if (manager.isFolder(folderContent[k])) { + if (manager.isSharedFolder(folderContent[k])) { + subfolders.push([k].concat(manager.user.userObject.ROOT)); + } + else { + subfolders.push(k); + } + } + } + subfolders.forEach(function (p) { + var subPath = path.concat(p); + openRecursive(subPath); + }); + }; + openRecursive(paths[0].path); + refresh(); + } else if ($(this).hasClass('cp-app-drive-context-download')) { if (paths.length !== 1) { return; } el = manager.find(paths[0].path);