From 0e843f0beb620372de74710157767ebcdb95e1d0 Mon Sep 17 00:00:00 2001 From: ClemDee Date: Wed, 17 Jul 2019 10:32:37 +0200 Subject: [PATCH 01/17] Add upload files in contextmenu --- www/drive/inner.js | 52 ++++++++++++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 20 deletions(-) diff --git a/www/drive/inner.js b/www/drive/inner.js index f393cac3f..c615d3a7c 100644 --- a/www/drive/inner.js +++ b/www/drive/inner.js @@ -87,6 +87,7 @@ define([ var faDelete = 'fa-eraser'; var faProperties = 'fa-database'; var faTags = 'fa-hashtag'; + var faUploadFiles = 'cptools-file-upload'; var faEmpty = 'fa-trash-o'; var faRestore = 'fa-repeat'; var faShowParent = 'fa-location-arrow'; @@ -354,6 +355,11 @@ define([ 'data-icon': faTags, }, Messages.fc_hashtag)), $separator.clone()[0], + h('li', h('a.cp-app-drive-context-uploadfiles.dropdown-item.cp-app-drive-context-editable', { + 'tabindex': '-1', + 'data-icon': faUploadFiles, + }, Messages.uploadButton)), + $separator.clone()[0], h('li', h('a.cp-app-drive-context-newdoc.dropdown-item.cp-app-drive-context-editable', { 'tabindex': '-1', 'data-icon': AppConfig.applicationsIcon.pad, @@ -977,7 +983,10 @@ define([ // Hide the new shared folder menu if we're already in a shared folder return manager.isInSharedFolder(currentPath) || APP.disableSF; } - return AppConfig.availablePadTypes.indexOf($el.attr('data-type')) === -1; + if (className === 'uploadfiles') { return; } + if (className === 'newdoc') { + return AppConfig.availablePadTypes.indexOf($el.attr('data-type')) === -1; + } }; } else { // In case of multiple selection, we must hide the option if at least one element @@ -1086,7 +1095,7 @@ define([ switch(type) { case 'content': - show = ['newfolder', 'newsharedfolder', 'newdoc']; + show = ['newfolder', 'newsharedfolder', 'uploadfiles', 'newdoc']; break; case 'tree': show = ['open', 'openro', 'expandall', 'collapseall', 'color', 'download', 'share', 'rename', 'delete', 'deleteowned', 'removesf', 'properties', 'hashtag']; @@ -2099,6 +2108,23 @@ define([ }); return arr; }; + var openUploadFilesModal = function () { + var $input = $('', { + 'type': 'file', + 'style': 'display: none;', + 'multiple': 'multiple' + }).on('change', function (e) { + var files = Util.slice(e.target.files); + files.forEach(function (file) { + var ev = { + target: $content[0], + path: findDropPath($content[0]) + }; + APP.FM.handleFile(file, ev); + }); + }); + $input.click(); + } var addNewPadHandlers = function ($block, isInRoot) { // Handlers if (isInRoot) { @@ -2125,24 +2151,7 @@ define([ }); }); } - $block.find('a.cp-app-drive-new-upload, li.cp-app-drive-new-upload') - .click(function () { - var $input = $('', { - 'type': 'file', - 'style': 'display: none;', - 'multiple': 'multiple' - }).on('change', function (e) { - var files = Util.slice(e.target.files); - files.forEach(function (file) { - var ev = { - target: $content[0], - path: findDropPath($content[0]) - }; - APP.FM.handleFile(file, ev); - }); - }); - $input.click(); - }); + $block.find('a.cp-app-drive-new-upload, li.cp-app-drive-new-upload').click(openUploadFilesModal); } $block.find('a.cp-app-drive-new-doc, li.cp-app-drive-new-doc') .click(function () { @@ -3631,6 +3640,9 @@ define([ manager.addSharedFolder(paths[0].path, obj, refresh); }); } + else if ($(this).hasClass("cp-app-drive-context-uploadfiles")) { + openUploadFilesModal(); + } else if ($(this).hasClass("cp-app-drive-context-newdoc")) { var ntype = $(this).data('type') || 'pad'; var path2 = manager.isPathIn(currentPath, [TRASH]) ? '' : currentPath; From e18433c7f9bd0022ebfe1d3e26a06242f5c1f9ba Mon Sep 17 00:00:00 2001 From: ClemDee Date: Wed, 17 Jul 2019 12:00:22 +0200 Subject: [PATCH 02/17] Add dummy folder upload --- www/common/translations/messages.fr.json | 1 + www/common/translations/messages.json | 1 + www/drive/inner.js | 53 +++++++++++++++++++----- 3 files changed, 44 insertions(+), 11 deletions(-) diff --git a/www/common/translations/messages.fr.json b/www/common/translations/messages.fr.json index 8d2edb610..3fbeed23e 100644 --- a/www/common/translations/messages.fr.json +++ b/www/common/translations/messages.fr.json @@ -109,6 +109,7 @@ "newButton": "Nouveau", "newButtonTitle": "Créer un nouveau pad", "uploadButton": "Importer des fichiers", + "uploadFolderButton": "Importer un dossier", "uploadButtonTitle": "Importer un nouveau fichier dans le dossier actuel", "saveTemplateButton": "Sauver en tant que modèle", "saveTemplatePrompt": "Choisir un titre pour ce modèle", diff --git a/www/common/translations/messages.json b/www/common/translations/messages.json index 7c5a2ee5b..a45e9a821 100644 --- a/www/common/translations/messages.json +++ b/www/common/translations/messages.json @@ -110,6 +110,7 @@ "newButton": "New", "newButtonTitle": "Create a new pad", "uploadButton": "Upload files", + "uploadFolderButton": "Upload folder", "uploadButtonTitle": "Upload a new file to the current folder", "saveTemplateButton": "Save as template", "saveTemplatePrompt": "Choose a title for the template", diff --git a/www/drive/inner.js b/www/drive/inner.js index c615d3a7c..9b43426ea 100644 --- a/www/drive/inner.js +++ b/www/drive/inner.js @@ -88,6 +88,7 @@ define([ var faProperties = 'fa-database'; var faTags = 'fa-hashtag'; var faUploadFiles = 'cptools-file-upload'; + var faUploadFolder = 'cptools-folder-upload'; var faEmpty = 'fa-trash-o'; var faRestore = 'fa-repeat'; var faShowParent = 'fa-location-arrow'; @@ -135,6 +136,8 @@ define([ var LS_SEARCHCURSOR = "app-drive-searchCursor"; var FOLDER_CONTENT_ID = "cp-app-drive-content-folder"; + var ALLOW_FOLDERUPLOAD = true; + var config = {}; var DEBUG = config.DEBUG = false; var debug = config.debug = DEBUG ? function () { @@ -359,6 +362,10 @@ define([ 'tabindex': '-1', 'data-icon': faUploadFiles, }, Messages.uploadButton)), + h('li', h('a.cp-app-drive-context-uploadfolder.dropdown-item.cp-app-drive-context-editable', { + 'tabindex': '-1', + 'data-icon': faUploadFolder, + }, Messages.uploadFolderButton)), $separator.clone()[0], h('li', h('a.cp-app-drive-context-newdoc.dropdown-item.cp-app-drive-context-editable', { 'tabindex': '-1', @@ -984,6 +991,7 @@ define([ return manager.isInSharedFolder(currentPath) || APP.disableSF; } if (className === 'uploadfiles') { return; } + if (className === 'uploadfolder') { return !ALLOW_FOLDERUPLOAD; } if (className === 'newdoc') { return AppConfig.availablePadTypes.indexOf($el.attr('data-type')) === -1; } @@ -1095,7 +1103,7 @@ define([ switch(type) { case 'content': - show = ['newfolder', 'newsharedfolder', 'uploadfiles', 'newdoc']; + show = ['newfolder', 'newsharedfolder', 'uploadfiles', 'uploadfolder', 'newdoc']; break; case 'tree': show = ['open', 'openro', 'expandall', 'collapseall', 'color', 'download', 'share', 'rename', 'delete', 'deleteowned', 'removesf', 'properties', 'hashtag']; @@ -2108,7 +2116,7 @@ define([ }); return arr; }; - var openUploadFilesModal = function () { + var showUploadFilesModal = function () { var $input = $('', { 'type': 'file', 'style': 'display: none;', @@ -2124,7 +2132,10 @@ define([ }); }); $input.click(); - } + }; + var showUploadFolderModal = function () { + console.log("%cIMPORT FOLDER", "color: red"); + }; var addNewPadHandlers = function ($block, isInRoot) { // Handlers if (isInRoot) { @@ -2151,7 +2162,8 @@ define([ }); }); } - $block.find('a.cp-app-drive-new-upload, li.cp-app-drive-new-upload').click(openUploadFilesModal); + $block.find('a.cp-app-drive-new-fileupload, li.cp-app-drive-new-fileupload').click(showUploadFilesModal); + $block.find('a.cp-app-drive-new-folderupload, li.cp-app-drive-new-folderupload').click(showUploadFolderModal); } $block.find('a.cp-app-drive-new-doc, li.cp-app-drive-new-doc') .click(function () { @@ -2186,9 +2198,16 @@ define([ options.push({tag: 'hr'}); options.push({ tag: 'a', - attributes: {'class': 'cp-app-drive-new-upload'}, + attributes: {'class': 'cp-app-drive-new-fileupload'}, content: $('
').append(getIcon('fileupload')).html() + Messages.uploadButton }); + if (ALLOW_FOLDERUPLOAD) { + options.push({ + tag: 'a', + attributes: {'class': 'cp-app-drive-new-folderupload'}, + content: $('
').append(getIcon('folderupload')).html() + Messages.uploadFolderButton + }); + } options.push({tag: 'hr'}); } getNewPadTypes().forEach(function (type) { @@ -2470,13 +2489,22 @@ define([ $element3.append($('', { 'class': 'cp-app-drive-new-name' }) .text(Messages.fm_sharedFolder)); } - // File - var $element2 = $('
  • ', { - 'class': 'cp-app-drive-new-upload cp-app-drive-element-row ' + - 'cp-app-drive-element-grid' + // Upload file + var $elementFileUpload = $('
  • ', { + 'class': 'cp-app-drive-new-fileupload cp-app-drive-element-row ' + + 'cp-app-drive-element-grid' }).prepend(getIcon('fileupload')).appendTo($container); - $element2.append($('', {'class': 'cp-app-drive-new-name'}) + $elementFileUpload.append($('', {'class': 'cp-app-drive-new-name'}) .text(Messages.uploadButton)); + // Upload folder + if (ALLOW_FOLDERUPLOAD) { + var $elementFolderUpload = $('
  • ', { + 'class': 'cp-app-drive-new-folderupload cp-app-drive-element-row ' + + 'cp-app-drive-element-grid' + }).prepend(getIcon('folderupload')).appendTo($container); + $elementFolderUpload.append($('', {'class': 'cp-app-drive-new-name'}) + .text(Messages.uploadFolderButton)); + } } // Pads getNewPadTypes().forEach(function (type) { @@ -3641,7 +3669,10 @@ define([ }); } else if ($(this).hasClass("cp-app-drive-context-uploadfiles")) { - openUploadFilesModal(); + showUploadFilesModal(); + } + else if ($(this).hasClass("cp-app-drive-context-uploadfolder")) { + showUploadFolderModal(); } else if ($(this).hasClass("cp-app-drive-context-newdoc")) { var ntype = $(this).data('type') || 'pad'; From 1bb47e28efa041cbcb9adb9fc19dbd21e0d63c63 Mon Sep 17 00:00:00 2001 From: yflory Date: Wed, 17 Jul 2019 10:58:30 +0200 Subject: [PATCH 03/17] Update icons --- .../fonts/cptools/fonts/cptools.svg | 1 + .../fonts/cptools/fonts/cptools.ttf | Bin 5956 -> 6124 bytes .../fonts/cptools/fonts/cptools.woff | Bin 6032 -> 6200 bytes customize.dist/fonts/cptools/style.css | 9 ++++++--- 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/customize.dist/fonts/cptools/fonts/cptools.svg b/customize.dist/fonts/cptools/fonts/cptools.svg index f7fe0879f..93eef8d38 100644 --- a/customize.dist/fonts/cptools/fonts/cptools.svg +++ b/customize.dist/fonts/cptools/fonts/cptools.svg @@ -25,4 +25,5 @@ + \ No newline at end of file diff --git a/customize.dist/fonts/cptools/fonts/cptools.ttf b/customize.dist/fonts/cptools/fonts/cptools.ttf index 1dac2ff871a9f8f7fd1f68931e4b34be7d153381..18338a9ee52ce2984e55859361c7740d8b91cac9 100644 GIT binary patch delta 347 zcmX@2_eQ^-fsuiMft#U$ftkU;KUm+0Ux-Z!D6$8L6OwZi3&g`N&17I;lmYTX(i4jd zfV2RR5288Jb1Ktn10A0N`4tQd!bdVv6H`P_WOXtyh}r<<%`$)j?1z|d0Qn_AzDh=J zNktF?TO5!-1IUlb$xn7n)LCYv02KHF6fnq5tSDemX9PM)Oa;hS$V<#k-I=8&4dlB3 zEom#rFD?N(6bQu6faDpNnV(HOV9zKtiP4);XtNKauP{F|gBgPn^C@OO21y1J2AjzZ zEan`H%BITZ;>x0v1z0uMmZW*s)Ob$LV^!4p7jx#?wKL!#0NUwozVc^0zs*+$ZWfRg z3^zk2bHeD!dqm6`#V3CeiC_Urnoaf*)f3`;1lB3e@SlMntbu8=p}6qo`Jzi10kh3b AfdBvi delta 277 zcmaE(e?+gIfsuiMft#U$ftkU;KUm+0Ux-ZsD6$8L6OwZi3&g`N&0t_)lmYTX(i4jd zfV2RR5288Jb1Ks=I;hnE`4tQd!U`Fwi7BG>M*kTYM1Xo2%rbxi?1z}I1Nj$#e3gvc zk_tZtHVq*E3y>d?lb`IEsIyGNj)6hc2PmMIn^;l6pvDMvk|@wn28F!D+|->}TGBxN z9H1p_1^LA#K!*Z>xC%&~ftmT~!~^z>f|D4%83i}{F!~BBgZu-;tKVh%#`D{JW#DE3 msb{#U|J?;fPfiduXB3+}Lo{OY7g0S9pfE_2*k&!ULyQ1GzC5G= diff --git a/customize.dist/fonts/cptools/fonts/cptools.woff b/customize.dist/fonts/cptools/fonts/cptools.woff index 4f01d5d158a831d3f86ed12a0b385ad642835da6..d8f56ba86d4b8da18c3e0b7ccfbf8e9b67c5d96a 100644 GIT binary patch delta 372 zcmbQBzr#SJ+~3WOfsp|SBrF)XLA3ari6YwdO3As21q=*~89=XB3+3!|2T@w0Q=juP{F|&}BxYlyB+av?#&hy6Rzt8jViR?Q>lKo76AKs^7&CwpAs{Rsc4 zVlhZ;50K9R#RBO$m1#h+BMc0}3Lt#ZL9HeuH8F*OLF5TgjTs1w)*JoL017fNh{^!@ zDj>{$i1~U(Zb=1D%mK)c0AW7{HjSM8WS}}f(HTGiJrLGereT+xSOK(H^aPNv0LE&J zjCqNUWvG@%%Pl8Ms-10t^f{^}oBo=*eqD%^AfeKM{?X>>#Em1QZ5o5@Yz!zz Date: Wed, 17 Jul 2019 12:15:14 +0200 Subject: [PATCH 04/17] Add upload-folder icon --- www/common/application_config_internal.js | 1 + www/common/common-interface.js | 1 + www/drive/inner.js | 9 ++++----- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/www/common/application_config_internal.js b/www/common/application_config_internal.js index e4d5aa4f9..6a362b133 100644 --- a/www/common/application_config_internal.js +++ b/www/common/application_config_internal.js @@ -93,6 +93,7 @@ define(function() { config.applicationsIcon = { file: 'cptools-file', fileupload: 'cptools-file-upload', + folderupload: 'cptools-folder-upload', pad: 'cptools-pad', code: 'cptools-code', slide: 'cptools-slide', diff --git a/www/common/common-interface.js b/www/common/common-interface.js index e44a4ecff..6f70d15c3 100644 --- a/www/common/common-interface.js +++ b/www/common/common-interface.js @@ -773,6 +773,7 @@ define([ var icon = AppConfig.applicationsIcon[type]; var font = icon.indexOf('cptools') === 0 ? 'cptools' : 'fa'; if (type === 'fileupload') { type = 'file'; } + if (type === 'folderupload') { type = 'file'; } var appClass = ' cp-icon cp-icon-color-'+type; $icon = $('', {'class': font + ' ' + icon + appClass}); } diff --git a/www/drive/inner.js b/www/drive/inner.js index 9b43426ea..61d3ade27 100644 --- a/www/drive/inner.js +++ b/www/drive/inner.js @@ -45,6 +45,7 @@ define([ editable: false, mobile: function () { return $('body').width() <= 600; }, // Menu and content area are not inline-block anymore for mobiles isMac: navigator.platform === "MacIntel", + allowFolderUpload: true, }; var stringify = function (obj) { @@ -136,8 +137,6 @@ define([ var LS_SEARCHCURSOR = "app-drive-searchCursor"; var FOLDER_CONTENT_ID = "cp-app-drive-content-folder"; - var ALLOW_FOLDERUPLOAD = true; - var config = {}; var DEBUG = config.DEBUG = false; var debug = config.debug = DEBUG ? function () { @@ -991,7 +990,7 @@ define([ return manager.isInSharedFolder(currentPath) || APP.disableSF; } if (className === 'uploadfiles') { return; } - if (className === 'uploadfolder') { return !ALLOW_FOLDERUPLOAD; } + if (className === 'uploadfolder') { return !APP.allowFolderUpload; } if (className === 'newdoc') { return AppConfig.availablePadTypes.indexOf($el.attr('data-type')) === -1; } @@ -2201,7 +2200,7 @@ define([ attributes: {'class': 'cp-app-drive-new-fileupload'}, content: $('
    ').append(getIcon('fileupload')).html() + Messages.uploadButton }); - if (ALLOW_FOLDERUPLOAD) { + if (APP.allowFolderUpload) { options.push({ tag: 'a', attributes: {'class': 'cp-app-drive-new-folderupload'}, @@ -2497,7 +2496,7 @@ define([ $elementFileUpload.append($('', {'class': 'cp-app-drive-new-name'}) .text(Messages.uploadButton)); // Upload folder - if (ALLOW_FOLDERUPLOAD) { + if (APP.allowFolderUpload) { var $elementFolderUpload = $('
  • ', { 'class': 'cp-app-drive-new-folderupload cp-app-drive-element-row ' + 'cp-app-drive-element-grid' From a5310e323a4d95714198e30b4ca3c6f5f268a07d Mon Sep 17 00:00:00 2001 From: ClemDee Date: Wed, 17 Jul 2019 18:02:25 +0200 Subject: [PATCH 05/17] Almost functionnal folder import --- www/drive/inner.js | 81 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) diff --git a/www/drive/inner.js b/www/drive/inner.js index 61d3ade27..c1d05d4ab 100644 --- a/www/drive/inner.js +++ b/www/drive/inner.js @@ -2132,8 +2132,89 @@ define([ }); $input.click(); }; + + // create the folder structure before to upload files from folder + var uploadFolder = function (fileList) { + var currentFolder = currentPath; + // create an array of all the files relative path + var files = Array.prototype.map.call(fileList, function (file) { + return { + file: file, + path: file.webkitRelativePath.split("/"), + }; + }); + // if folder name already exist in drive, rename it + var uploadedFolderName = files[0].path[0]; + var availableName = manager.user.userObject.getAvailableName(manager.user.userObject.find(currentFolder), uploadedFolderName); + if (uploadedFolderName !== availableName) { + files.forEach(function (file) { + file.path[0] = availableName; + }); + } + + // uploadSteps is an array of objects {folders: [], files: []}, containing all the folders and files to create safely + // at the index i + 1, the files and folders are children of the folders at the index i + var maxSteps = files.reduce(function (max, file) { return Math.max(max, file.path.length); }, 0); + console.log("maxSteps", maxSteps); + var uploadSteps = [] + for (var i = 0 ; i < maxSteps ; i++) { + uploadSteps[i] = { + folders: [], + files: [], + }; + } + files.forEach(function (file) { + // add steps for subfolders containing file + for (var depth = 0 ; depth < file.path.length - 1 ; depth++) { + var subfolderStr = file.path.slice(0, depth + 1).join("/"); + if (uploadSteps[depth].folders.indexOf(subfolderStr) === -1) { + uploadSteps[depth].folders.push(subfolderStr); + } + }; + // add step for file (one step later than the step for its direct parent folder) + uploadSteps[file.path.length - 1].files.push(file); + }); + console.log(uploadSteps); + + // add folders, then add files when theirs folders have been created + // wait for the folders to be created to go to the next step (don't wait for the files) + var stepByStep = function (uploadSteps, i) { + if (i >= uploadSteps.length) { return; } + nThen(function (waitFor) { + // add folders + uploadSteps[i].folders.forEach(function (folder) { + var folderPath = folder.split("/"); + var parentFolder = currentFolder.concat(folderPath.slice(0, -1)); + var folderName = folderPath.slice(-1); + manager.addFolder(parentFolder, folderName, waitFor(refresh)); + }); + // upload files + uploadSteps[i].files.forEach(function (file) { + var ev = { + target: $content[0], + path: file.path, + }; + console.log(file); + console.log(ev); +// APP.FM.handleFile(file.file, ev); // THIS LINE NEED TO BE FIXED + }); + }).nThen(function () { + stepByStep(uploadSteps, i + 1); + }); + } + stepByStep(uploadSteps, 0); + }; var showUploadFolderModal = function () { console.log("%cIMPORT FOLDER", "color: red"); + var $input = $('', { + 'type': 'file', + 'style': 'display: none;', + 'multiple': 'multiple', + 'webkitdirectory': true, + }).on('change', function (e) { + uploadFolder(e.target.files); + }); + $input.click(); }; var addNewPadHandlers = function ($block, isInRoot) { // Handlers From 73dcce564e2ea7116e266d91aec1186882aeee96 Mon Sep 17 00:00:00 2001 From: ClemDee Date: Thu, 18 Jul 2019 11:38:33 +0200 Subject: [PATCH 06/17] Functionnal folder upload --- www/drive/inner.js | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/www/drive/inner.js b/www/drive/inner.js index c1d05d4ab..e37cc09a0 100644 --- a/www/drive/inner.js +++ b/www/drive/inner.js @@ -2145,7 +2145,7 @@ define([ }); // if folder name already exist in drive, rename it var uploadedFolderName = files[0].path[0]; - var availableName = manager.user.userObject.getAvailableName(manager.user.userObject.find(currentFolder), uploadedFolderName); + var availableName = manager.user.userObject.getAvailableName(manager.find(currentFolder), uploadedFolderName); if (uploadedFolderName !== availableName) { files.forEach(function (file) { file.path[0] = availableName; @@ -2155,8 +2155,7 @@ define([ // uploadSteps is an array of objects {folders: [], files: []}, containing all the folders and files to create safely // at the index i + 1, the files and folders are children of the folders at the index i var maxSteps = files.reduce(function (max, file) { return Math.max(max, file.path.length); }, 0); - console.log("maxSteps", maxSteps); - var uploadSteps = [] + var uploadSteps = []; for (var i = 0 ; i < maxSteps ; i++) { uploadSteps[i] = { folders: [], @@ -2170,7 +2169,7 @@ define([ if (uploadSteps[depth].folders.indexOf(subfolderStr) === -1) { uploadSteps[depth].folders.push(subfolderStr); } - }; + } // add step for file (one step later than the step for its direct parent folder) uploadSteps[file.path.length - 1].files.push(file); }); @@ -2192,16 +2191,14 @@ define([ uploadSteps[i].files.forEach(function (file) { var ev = { target: $content[0], - path: file.path, + path: currentFolder.concat(file.path.slice(0, -1)), }; - console.log(file); - console.log(ev); -// APP.FM.handleFile(file.file, ev); // THIS LINE NEED TO BE FIXED + APP.FM.handleFile(file.file, ev); }); }).nThen(function () { stepByStep(uploadSteps, i + 1); }); - } + }; stepByStep(uploadSteps, 0); }; var showUploadFolderModal = function () { From 1361334eaf19bad918f4dfd71b253f0309214771 Mon Sep 17 00:00:00 2001 From: ClemDee Date: Thu, 18 Jul 2019 11:43:14 +0200 Subject: [PATCH 07/17] Fix file name & extension in upload options --- www/common/sframe-common-file.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/www/common/sframe-common-file.js b/www/common/sframe-common-file.js index 099176afd..8358b7054 100644 --- a/www/common/sframe-common-file.js +++ b/www/common/sframe-common-file.js @@ -235,9 +235,9 @@ define([ store: true }; var fileUploadModal = function (file, cb) { - var extIdx = file.name.lastIndexOf('.'); - var name = extIdx !== -1 ? file.name.slice(0,extIdx) : file.name; - var ext = extIdx !== -1 ? file.name.slice(extIdx) : ""; + var parsedName = /^(\.?.+?)(\.[^.]+)?$/.exec(file.name) || []; + var name = parsedName[1] || file.name; + var ext = parsedName[2] || ""; var createHelper = function (href, text) { var q = h('a.fa.fa-question-circle', { @@ -264,7 +264,7 @@ define([ h('h4', Messages.upload_modal_title), UIElements.setHTML(h('label', {for: 'cp-upload-name'}), Messages._getKey('upload_modal_filename', [ext])), - h('input#cp-upload-name', {type: 'text', placeholder: name}), + h('input#cp-upload-name', {type: 'text', placeholder: name, value: name}), h('label', {for: 'cp-upload-password'}, Messages.creation_passwordValue), UI.passwordInput({id: 'cp-upload-password'}), h('span', { From 06cbabd3735a965abac320c77f368a16fbf31798 Mon Sep 17 00:00:00 2001 From: ClemDee Date: Thu, 18 Jul 2019 12:15:20 +0200 Subject: [PATCH 08/17] Add extension in file name in upload options --- www/common/sframe-common-file.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/www/common/sframe-common-file.js b/www/common/sframe-common-file.js index 8358b7054..d72db01c6 100644 --- a/www/common/sframe-common-file.js +++ b/www/common/sframe-common-file.js @@ -264,7 +264,7 @@ define([ h('h4', Messages.upload_modal_title), UIElements.setHTML(h('label', {for: 'cp-upload-name'}), Messages._getKey('upload_modal_filename', [ext])), - h('input#cp-upload-name', {type: 'text', placeholder: name, value: name}), + h('input#cp-upload-name', {type: 'text', placeholder: file.name, value: file.name}), h('label', {for: 'cp-upload-password'}, Messages.creation_passwordValue), UI.passwordInput({id: 'cp-upload-password'}), h('span', { From 165feef7d4037ec267af3bc8d894c9bc7a945f81 Mon Sep 17 00:00:00 2001 From: ClemDee Date: Thu, 18 Jul 2019 15:22:09 +0200 Subject: [PATCH 09/17] Folder upload only shows a modal for global folder options --- www/common/sframe-common-file.js | 128 +++++++++++++++++++++++-------- www/drive/inner.js | 106 +++++++++++++------------ 2 files changed, 154 insertions(+), 80 deletions(-) diff --git a/www/common/sframe-common-file.js b/www/common/sframe-common-file.js index d72db01c6..7605ad85d 100644 --- a/www/common/sframe-common-file.js +++ b/www/common/sframe-common-file.js @@ -234,37 +234,40 @@ define([ owned: true, store: true }; - var fileUploadModal = function (file, cb) { - var parsedName = /^(\.?.+?)(\.[^.]+)?$/.exec(file.name) || []; - var name = parsedName[1] || file.name; - var ext = parsedName[2] || ""; - - var createHelper = function (href, text) { - var q = h('a.fa.fa-question-circle', { - style: 'text-decoration: none !important;', - title: text, - href: origin + href, - target: "_blank", - 'data-tippy-placement': "right" - }); - return q; - }; - + var createHelper = function (href, text) { + var q = h('a.fa.fa-question-circle', { + style: 'text-decoration: none !important;', + title: text, + href: origin + href, + target: "_blank", + 'data-tippy-placement': "right" + }); + return q; + }; + var createManualStore = function (isFolderUpload) { var privateData = common.getMetadataMgr().getPrivateData(); var autoStore = Util.find(privateData, ['settings', 'general', 'autostore']) || 0; var initialState = modalState.owned || modalState.store; var initialDisabled = modalState.owned ? { disabled: true } : {}; var manualStore = autoStore === 1 ? undefined : - UI.createCheckbox('cp-upload-store', Messages.autostore_forceSave, initialState, { - input: initialDisabled - }); + UI.createCheckbox('cp-upload-store', isFolderUpload ? (Messages.uploadFolder_modal_forceSave || "Store files in your cryptDrive") : Messages.autostore_forceSave, initialState, { + input: initialDisabled + }); + return manualStore; + } + var fileUploadModal = function (defaultFileName, cb) { + var parsedName = /^(\.?.+?)(\.[^.]+)?$/.exec(defaultFileName) || []; + var name = parsedName[1] || defaultFileName; + var ext = parsedName[2] || ""; + + var manualStore = createManualStore(); // Ask for name, password and owner var content = h('div', [ h('h4', Messages.upload_modal_title), UIElements.setHTML(h('label', {for: 'cp-upload-name'}), Messages._getKey('upload_modal_filename', [ext])), - h('input#cp-upload-name', {type: 'text', placeholder: file.name, value: file.name}), + h('input#cp-upload-name', {type: 'text', placeholder: defaultFileName, value: defaultFileName}), h('label', {for: 'cp-upload-password'}, Messages.creation_passwordValue), UI.passwordInput({id: 'cp-upload-password'}), h('span', { @@ -298,7 +301,7 @@ define([ modalState.store = forceSave; // Add extension to the name if needed - if (!newName || !newName.trim()) { newName = file.name; } + if (!newName || !newName.trim()) { newName = defaultFileName; } var newExtIdx = newName.lastIndexOf('.'); var newExt = newExtIdx !== -1 ? newName.slice(newExtIdx) : ""; if (newExt !== ext) { newName += ext; } @@ -312,12 +315,64 @@ define([ }); }; + var showFolderUploadModal = File.showFolderUploadModal = function (foldername, cb) { + var manualStore = createManualStore(); + + // Ask for name, password and owner + var content = h('div', [ + h('h4', Messages.uploadFolder_modal_title || "Folder upload options"), + UIElements.setHTML(h('label', {for: 'cp-upload-name'}), Messages.fm_folderName), + h('input#cp-upload-foldername', {type: 'text', placeholder: foldername, value: foldername}), + h('label', {for: 'cp-upload-password'}, Messages.uploadFolder_modal_filesPassword || "Files password"), + UI.passwordInput({id: 'cp-upload-password'}), + h('span', { + style: 'display:flex;align-items:center;justify-content:space-between' + }, [ + UI.createCheckbox('cp-upload-owned', Messages.uploadFolder_modal_owner || "Owned files", modalState.owned), + createHelper('/faq.html#keywords-owned', Messages.creation_owned1) + ]), + manualStore + ]); + + $(content).find('#cp-upload-owned').on('change', function () { + var val = $(content).find('#cp-upload-owned').is(':checked'); + if (val) { + $(content).find('#cp-upload-store').prop('checked', true).prop('disabled', true); + } else { + $(content).find('#cp-upload-store').prop('disabled', false); + } + }); + + UI.confirm(content, function (yes) { + if (!yes) { return void cb(); } + + // Get the values + var newName = $(content).find('#cp-upload-foldername').val(); + var password = $(content).find('#cp-upload-password').val() || undefined; + var owned = $(content).find('#cp-upload-owned').is(':checked'); + var forceSave = owned || $(content).find('#cp-upload-store').is(':checked'); + + modalState.owned = owned; + modalState.store = forceSave; + + if (!newName || !newName.trim()) { newName = foldername; } + + cb({ + folderName: newName, + password: password, + owned: owned, + forceSave: forceSave + }); + }); + } + var handleFileState = { queue: [], inProgress: false }; - var handleFile = File.handleFile = function (file, e) { - if (handleFileState.inProgress) { return void handleFileState.queue.push([file, e]); } + /* if defaultOptions is passed, the function does not show the upload options modal, and directly save the file with the specified options */ + var handleFile = File.handleFile = function (file, e, defaultOptions) { + if (handleFileState.inProgress) { return void handleFileState.queue.push([file, e, defaultOptions]); } handleFileState.inProgress = true; var thumb; @@ -345,7 +400,7 @@ define([ handleFileState.inProgress = false; if (handleFileState.queue.length) { var next = handleFileState.queue.shift(); - handleFile(next[0], next[1]); + handleFile(next[0], next[1], next[2]); } }; var getName = function () { @@ -354,14 +409,25 @@ define([ if (config.noStore) { return void finish(); } // Otherwise, ask for password, name and ownership - fileUploadModal(file, function (obj) { - if (!obj) { return void finish(true); } - name = obj.name; - password = obj.password; - owned = obj.owned; - forceSave = obj.forceSave; + // if default options were passed, upload file immediately + if (defaultOptions && typeof defaultOptions === "object") { + name = defaultOptions.name || file.name; + password = defaultOptions.password || undefined; + owned = defaultOptions.owned || true; + forceSave = defaultOptions.forceSave || true; finish(); - }); + } + // if no default options were passed, ask the user + else { + fileUploadModal(file.name, function (obj) { + if (!obj) { return void finish(true); } + name = obj.name; + password = obj.password; + owned = obj.owned; + forceSave = obj.forceSave; + finish(); + }); + } }; blobToArrayBuffer(file, function (e, buffer) { diff --git a/www/drive/inner.js b/www/drive/inner.js index e37cc09a0..2018df703 100644 --- a/www/drive/inner.js +++ b/www/drive/inner.js @@ -2146,60 +2146,68 @@ define([ // if folder name already exist in drive, rename it var uploadedFolderName = files[0].path[0]; var availableName = manager.user.userObject.getAvailableName(manager.find(currentFolder), uploadedFolderName); - if (uploadedFolderName !== availableName) { + + // ask for folder name and files options, then upload all the files! + APP.FM.showFolderUploadModal(availableName, function (folderUploadOptions) { + if (!folderUploadOptions) { return; } + + // verfify folder name is possible, and update files path + availableName = manager.user.userObject.getAvailableName(manager.find(currentFolder), folderUploadOptions.folderName); + if (uploadedFolderName !== availableName) { + files.forEach(function (file) { + file.path[0] = availableName; + }); + } + + // uploadSteps is an array of objects {folders: [], files: []}, containing all the folders and files to create safely + // at the index i + 1, the files and folders are children of the folders at the index i + var maxSteps = files.reduce(function (max, file) { return Math.max(max, file.path.length); }, 0); + var uploadSteps = []; + for (var i = 0 ; i < maxSteps ; i++) { + uploadSteps[i] = { + folders: [], + files: [], + }; + } files.forEach(function (file) { - file.path[0] = availableName; + // add steps to create subfolders containing file + for (var depth = 0 ; depth < file.path.length - 1 ; depth++) { + var subfolderStr = file.path.slice(0, depth + 1).join("/"); + if (uploadSteps[depth].folders.indexOf(subfolderStr) === -1) { + uploadSteps[depth].folders.push(subfolderStr); + } + } + // add step to upload file (one step later than the step of its direct parent folder) + uploadSteps[file.path.length - 1].files.push(file); }); - } - // uploadSteps is an array of objects {folders: [], files: []}, containing all the folders and files to create safely - // at the index i + 1, the files and folders are children of the folders at the index i - var maxSteps = files.reduce(function (max, file) { return Math.max(max, file.path.length); }, 0); - var uploadSteps = []; - for (var i = 0 ; i < maxSteps ; i++) { - uploadSteps[i] = { - folders: [], - files: [], + // add folders, then add files when theirs folders have been created + // wait for the folders to be created to go to the next step (don't wait for the files) + var stepByStep = function (uploadSteps, i) { + if (i >= uploadSteps.length) { return; } + nThen(function (waitFor) { + // add folders + uploadSteps[i].folders.forEach(function (folder) { + var folderPath = folder.split("/"); + var parentFolder = currentFolder.concat(folderPath.slice(0, -1)); + var folderName = folderPath.slice(-1); + manager.addFolder(parentFolder, folderName, waitFor(refresh)); + }); + // upload files + uploadSteps[i].files.forEach(function (file) { + var ev = { + target: $content[0], + path: currentFolder.concat(file.path.slice(0, -1)), + }; + APP.FM.handleFile(file.file, ev, folderUploadOptions); + }); + }).nThen(function () { + stepByStep(uploadSteps, i + 1); + }); }; - } - files.forEach(function (file) { - // add steps for subfolders containing file - for (var depth = 0 ; depth < file.path.length - 1 ; depth++) { - var subfolderStr = file.path.slice(0, depth + 1).join("/"); - if (uploadSteps[depth].folders.indexOf(subfolderStr) === -1) { - uploadSteps[depth].folders.push(subfolderStr); - } - } - // add step for file (one step later than the step for its direct parent folder) - uploadSteps[file.path.length - 1].files.push(file); + + stepByStep(uploadSteps, 0); }); - console.log(uploadSteps); - - // add folders, then add files when theirs folders have been created - // wait for the folders to be created to go to the next step (don't wait for the files) - var stepByStep = function (uploadSteps, i) { - if (i >= uploadSteps.length) { return; } - nThen(function (waitFor) { - // add folders - uploadSteps[i].folders.forEach(function (folder) { - var folderPath = folder.split("/"); - var parentFolder = currentFolder.concat(folderPath.slice(0, -1)); - var folderName = folderPath.slice(-1); - manager.addFolder(parentFolder, folderName, waitFor(refresh)); - }); - // upload files - uploadSteps[i].files.forEach(function (file) { - var ev = { - target: $content[0], - path: currentFolder.concat(file.path.slice(0, -1)), - }; - APP.FM.handleFile(file.file, ev); - }); - }).nThen(function () { - stepByStep(uploadSteps, i + 1); - }); - }; - stepByStep(uploadSteps, 0); }; var showUploadFolderModal = function () { console.log("%cIMPORT FOLDER", "color: red"); From 5c5a6b963d22b8c2c8346b928af3e0540a4e1be1 Mon Sep 17 00:00:00 2001 From: ClemDee Date: Thu, 18 Jul 2019 16:07:14 +0200 Subject: [PATCH 10/17] Fix defaults options for folder upload --- www/common/sframe-common-file.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/www/common/sframe-common-file.js b/www/common/sframe-common-file.js index 7605ad85d..9af9ab18a 100644 --- a/www/common/sframe-common-file.js +++ b/www/common/sframe-common-file.js @@ -413,8 +413,8 @@ define([ if (defaultOptions && typeof defaultOptions === "object") { name = defaultOptions.name || file.name; password = defaultOptions.password || undefined; - owned = defaultOptions.owned || true; - forceSave = defaultOptions.forceSave || true; + owned = !!defaultOptions.owned; + forceSave = !!defaultOptions.forceSave; finish(); } // if no default options were passed, ask the user From 438ff211e1cb4c7defd97a106197d79d7eda6085 Mon Sep 17 00:00:00 2001 From: ClemDee Date: Thu, 18 Jul 2019 16:11:19 +0200 Subject: [PATCH 11/17] Add condition to allow folder upload --- www/drive/inner.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/www/drive/inner.js b/www/drive/inner.js index 2018df703..bf01942f4 100644 --- a/www/drive/inner.js +++ b/www/drive/inner.js @@ -45,7 +45,7 @@ define([ editable: false, mobile: function () { return $('body').width() <= 600; }, // Menu and content area are not inline-block anymore for mobiles isMac: navigator.platform === "MacIntel", - allowFolderUpload: true, + allowFolderUpload: File.prototype.hasOwnProperty("webkitRelativePath"), }; var stringify = function (obj) { From b49c39b895890d8277f0cc70106dc9db9c3b111a Mon Sep 17 00:00:00 2001 From: ClemDee Date: Fri, 19 Jul 2019 11:34:30 +0200 Subject: [PATCH 12/17] Fix file progress value going over 100% --- www/common/outer/upload.js | 1 + 1 file changed, 1 insertion(+) diff --git a/www/common/outer/upload.js b/www/common/outer/upload.js index cd0f9b134..9cb19f18b 100644 --- a/www/common/outer/upload.js +++ b/www/common/outer/upload.js @@ -65,6 +65,7 @@ define([ if (box) { actual += box.length; var progressValue = (actual / estimate * 100); + progressValue = Math.min(progressValue, 100); updateProgress(progressValue); return void sendChunk(box, function (e) { From b74f7b5ec2d68320ebf2c24ba2daa0d6141aa5c5 Mon Sep 17 00:00:00 2001 From: ClemDee Date: Fri, 19 Jul 2019 11:36:43 +0200 Subject: [PATCH 13/17] Set file upload progressbar responsive --- www/common/sframe-common-file.js | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/www/common/sframe-common-file.js b/www/common/sframe-common-file.js index 9af9ab18a..f400511a1 100644 --- a/www/common/sframe-common-file.js +++ b/www/common/sframe-common-file.js @@ -106,10 +106,14 @@ define([ var $pc = $row.find('.cp-fileupload-table-progress'); var $link = $row.find('.cp-fileupload-table-link'); + /** + * Update progress in the download panel, for uploading a file + * @param {number} progressValue Progression of download, between 0 and 100 + */ updateProgress = function (progressValue) { - $pv.text(Math.round(progressValue*100)/100 + '%'); + $pv.text(Math.round(progressValue * 100) / 100 + '%'); $pb.css({ - width: (progressValue/100)*$pc.width()+'px' + width: progressValue + '%' }); }; @@ -537,20 +541,28 @@ define([ queue.next(); }; + /** + * Update progress in the download panel, for downloading a file + * @param {number} progressValue Progression of download, between 0 and 1 + */ var updateDLProgress = function (progressValue) { - var text = Math.round(progressValue*100) + '%'; - text += ' ('+ Messages.download_step1 +'...)'; + var text = Math.round(progressValue * 100) + '%'; + text += ' ('+ Messages.download_step1 + '...)'; $pv.text(text); $pb.css({ - width: progressValue * $pc.width()+'px' + width: (progressValue * 100) + '%' }); }; + /** + * Update progress in the download panel, for decrypting a file (after downloading it) + * @param {number} progressValue Progression of download, between 0 and 1 + */ var updateProgress = function (progressValue) { - var text = Math.round(progressValue*100) + '%'; - text += progressValue === 1 ? '' : ' ('+ Messages.download_step2 +'...)'; + var text = Math.round(progressValue * 100) + '%'; + text += progressValue === 1 ? '' : ' (' + Messages.download_step2 + '...)'; $pv.text(text); $pb.css({ - width: progressValue * $pc.width()+'px' + width: (progressValue * 100) + '%' }); }; From e542be75a3ac8186b42c41bdffa7a3144422e887 Mon Sep 17 00:00:00 2001 From: ClemDee Date: Fri, 19 Jul 2019 11:37:50 +0200 Subject: [PATCH 14/17] Don't hide download panel if mouse over --- www/common/sframe-common-file.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/www/common/sframe-common-file.js b/www/common/sframe-common-file.js index f400511a1..ef537811b 100644 --- a/www/common/sframe-common-file.js +++ b/www/common/sframe-common-file.js @@ -183,8 +183,14 @@ define([ clearTimeout(queue.to); queue.to = window.setTimeout(function () { if (config.keepTable) { return; } - File.$container.fadeOut(); - }, 3000); + // don't hide panel if mouse over + if (File.$container.is(":hover")) { + File.$container.one("mouseleave", function () { File.$container.fadeOut(); }); + } + else { + File.$container.fadeOut(); + } + }, 20000); return; } if (queue.inProgress) { return; } From ef95da707ed8988c04425fd31f5a2335a19cf21c Mon Sep 17 00:00:00 2001 From: ClemDee Date: Mon, 29 Jul 2019 11:22:52 +0200 Subject: [PATCH 15/17] Modify upload panel style --- .../src/less2/include/fileupload.less | 78 ++++++++++++++----- www/common/sframe-common-file.js | 69 +++++++++------- 2 files changed, 102 insertions(+), 45 deletions(-) diff --git a/customize.dist/src/less2/include/fileupload.less b/customize.dist/src/less2/include/fileupload.less index e993d3030..8871eb6af 100644 --- a/customize.dist/src/less2/include/fileupload.less +++ b/customize.dist/src/less2/include/fileupload.less @@ -1,3 +1,4 @@ +@import (reference) "./browser.less"; @import (reference) './colortheme-all.less'; @import (reference) './modal.less'; @@ -10,24 +11,35 @@ #cp-fileupload { .modal_base(); position: absolute; - left: 10vw; right: 10vw; + right: 10vw; bottom: 10vh; - opacity: 0.9; box-sizing: border-box; z-index: 1000000; //Z file upload table container display: none; - #cp-fileupload-table { - width: 80vw; - tr:nth-child(1) { - background-color: darken(@colortheme_modal-bg, 20%); - td { - font-weight: bold; - padding: 0.25em; - &:nth-child(4), &:nth-child(5) { - text-align: center; - } + color: darken(@colortheme_drive-bg, 10%); + + @media screen and (max-width: @browser_media-medium-screen) { + left: 5vw; right: 5vw; bottom: 5vw; + } + + .cp-fileupload-header { + display: flex; + background-color: darken(@colortheme_modal-bg, 10%); + font-weight: bold; + .cp-fileupload-header-title { + padding: 0.25em 0.5em; + flex-grow: 1; + } + .cp-fileupload-header-close { + padding: 0.25em 0.5em; + cursor: pointer; + &:hover { + background-color: rgba(0,0,0,0.1); } } + } + #cp-fileupload-table { + width: 100%; @upload_pad_h: 0.25em; @upload_pad_v: 0.5em; @@ -35,27 +47,55 @@ padding: @upload_pad_h @upload_pad_v; } .cp-fileupload-table-link { + display: flex; + align-items: center; + white-space: nowrap; + max-width: 30vw; + margin: 0px @upload_pad_v; .fa { + margin-top: 4px; margin-right: 5px; } + .cp-fileupload-table-name { + overflow: hidden; + text-overflow: ellipsis; + } + &[href]:hover { + text-decoration: none; + .cp-fileupload-table-name { + text-decoration: underline; + } + } } .cp-fileupload-table-progress { - width: 25%; + min-width: 8em; + max-width: 16em; position: relative; text-align: center; box-sizing: border-box; } .cp-fileupload-table-progress-container { + position: relative; + } + .cp-fileupload-table-progressbar { position: absolute; width: 0px; - left: @upload_pad_v; - top: @upload_pad_h; bottom: @upload_pad_h; - background-color: rgba(0,0,255,0.3); + height: 100%; + background-color: #dddddd; z-index: -1; //Z file upload progress container } - .cp-fileupload-table-cancel { text-align: center; } - .fa.cancel { - color: rgb(255, 0, 115); + .cp-fileupload-table-cancel { + text-align: center; + padding: 0px; + &:not(.success):not(.cancelled):hover { + background-color: rgba(0,0,0,0.1); + } + .fa { + padding: @upload_pad_h @upload_pad_v; + &.fa-times { + cursor: pointer; + } + } } } } diff --git a/www/common/sframe-common-file.js b/www/common/sframe-common-file.js index ef537811b..8f71d281b 100644 --- a/www/common/sframe-common-file.js +++ b/www/common/sframe-common-file.js @@ -42,16 +42,19 @@ define([ return 'cp-fileupload-element-' + String(Math.random()).substring(2); }; + var tableHeader = h('div.cp-fileupload-header', [ + h('div.cp-fileupload-header-title', h('span', Messages.fileuploadHeader || 'Uploaded files')), + h('div.cp-fileupload-header-close', h('span.fa.fa-times')), + ]); + + var $table = File.$table = $('', { id: 'cp-fileupload-table' }); - var $thead = $('').appendTo($table); - $('', {id: id}).appendTo($table); var $lines = $table.find('tr[id]'); @@ -221,19 +224,28 @@ define([ var $cancel = $('', {'class': 'cp-fileupload-table-cancel-button fa fa-times'}).click(function () { queue.queue = queue.queue.filter(function (el) { return el.id !== id; }); $cancel.remove(); - $tr.find('.cp-fileupload-table-cancel').text('-'); + $tr.find('.cp-fileupload-table-cancel').addClass('cancelled').html('').append(h('span.fa.fa-minus')); $tr.find('.cp-fileupload-table-progress-value').text(Messages.upload_cancelled); }); var $link = $('', { 'class': 'cp-fileupload-table-link', 'rel': 'noopener noreferrer' - }).text(obj.dl ? obj.name : obj.metadata.name); + }).append(h('span.cp-fileupload-table-name', obj.dl ? obj.name : obj.metadata.name)); - $('
    ').text(Messages.upload_type).appendTo($thead); - $('').text(Messages.upload_name).appendTo($thead); - $('').text(Messages.upload_size).appendTo($thead); - $('').text(Messages.upload_progress).appendTo($thead); - $('').text(Messages.cancel).appendTo($thead); var createTableContainer = function ($body) { - File.$container = $('
    ', { id: 'cp-fileupload' }).append($table).appendTo($body); + File.$container = $('
    ', { id: 'cp-fileupload' }).append(tableHeader).append($table).appendTo($body); + $('.cp-fileupload-header-close').click(function () { + File.$container.fadeOut(); + }); return File.$container; }; @@ -100,10 +103,9 @@ define([ var $row = $table.find('tr[id="'+id+'"]'); - $row.find('.cp-fileupload-table-cancel').html('-'); + $row.find('.cp-fileupload-table-cancel').addClass('success').html('').append(h('span.fa.fa-check')); var $pv = $row.find('.cp-fileupload-table-progress-value'); - var $pb = $row.find('.cp-fileupload-table-progress-container'); - var $pc = $row.find('.cp-fileupload-table-progress'); + var $pb = $row.find('.cp-fileupload-table-progressbar'); var $link = $row.find('.cp-fileupload-table-link'); /** @@ -190,7 +192,7 @@ define([ else { File.$container.fadeOut(); } - }, 20000); + }, 60000); return; } if (queue.inProgress) { return; } @@ -209,8 +211,9 @@ define([ window.setTimeout(function () { $table.show(); }); var estimate = obj.dl ? obj.size : FileCrypto.computeEncryptedSize(obj.blob.byteLength, obj.metadata); - var $progressBar = $('
    ', {'class':'cp-fileupload-table-progress-container'}); - var $progressValue = $('', {'class':'cp-fileupload-table-progress-value'}).text(Messages.upload_pending); + var $progressContainer = $('
    ', {'class':'cp-fileupload-table-progress-container'}); + $('
    ', {'class':'cp-fileupload-table-progressbar'}).appendTo($progressContainer); + $('', {'class':'cp-fileupload-table-progress-value'}).text(Messages.upload_pending).appendTo($progressContainer); var $tr = $('
    ').text(obj.dl ? Messages.download_dl : Messages.upload_up).appendTo($tr); + var typeIcon; + if (obj.dl) { typeIcon = h('span.fa.fa-arrow-down', { title: Messages.download_dl }); } + else { typeIcon = h('span.fa.fa-arrow-up', { title: Messages.upload_up }); } + + // type (download / upload) + $('', {'class': 'cp-fileupload-table-type'}).append(typeIcon).appendTo($tr); + // name $('').append($link).appendTo($tr); + // size $('').text(prettySize(estimate)).appendTo($tr); - $('', {'class': 'cp-fileupload-table-progress'}).append($progressBar).append($progressValue).appendTo($tr); + // progress + $('', {'class': 'cp-fileupload-table-progress'}).append($progressContainer).appendTo($tr); + // cancel $('', {'class': 'cp-fileupload-table-cancel'}).append($cancel).appendTo($tr); queue.next(); @@ -264,10 +276,9 @@ define([ input: initialDisabled }); return manualStore; - } + }; var fileUploadModal = function (defaultFileName, cb) { var parsedName = /^(\.?.+?)(\.[^.]+)?$/.exec(defaultFileName) || []; - var name = parsedName[1] || defaultFileName; var ext = parsedName[2] || ""; var manualStore = createManualStore(); @@ -325,7 +336,7 @@ define([ }); }; - var showFolderUploadModal = File.showFolderUploadModal = function (foldername, cb) { + File.showFolderUploadModal = function (foldername, cb) { var manualStore = createManualStore(); // Ask for name, password and owner @@ -374,7 +385,7 @@ define([ forceSave: forceSave }); }); - } + }; var handleFileState = { queue: [], @@ -537,12 +548,16 @@ define([ var $row = $table.find('tr[id="'+id+'"]'); var $pv = $row.find('.cp-fileupload-table-progress-value'); - var $pb = $row.find('.cp-fileupload-table-progress-container'); - var $pc = $row.find('.cp-fileupload-table-progress'); + var $pb = $row.find('.cp-fileupload-table-progressbar'); var $link = $row.find('.cp-fileupload-table-link'); var done = function () { - $row.find('.cp-fileupload-table-cancel').text('-'); + $row.find('.cp-fileupload-table-cancel').addClass('success').html('').append(h('span.fa.fa-check')); + queue.inProgress = false; + queue.next(); + }; + var cancelled = function () { + $row.find('.cp-fileupload-table-cancel').addClass('cancelled').html('').append(h('span.fa.fa-minus')); queue.inProgress = false; queue.next(); }; @@ -594,9 +609,11 @@ define([ dl.cancel(); $cancel.remove(); $row.find('.cp-fileupload-table-progress-value').text(Messages.upload_cancelled); - done(); + cancelled(); }); - $row.find('.cp-fileupload-table-cancel').html('').append($cancel); + $row.find('.cp-fileupload-table-cancel') + .html('') + .append($cancel); }; queue.push({ dl: todo, From 23dc301eb19dc27ed249edd4a21da91dde56fef8 Mon Sep 17 00:00:00 2001 From: ClemDee Date: Mon, 12 Aug 2019 18:44:25 +0200 Subject: [PATCH 16/17] Small fixes in sframe-common-file --- www/common/sframe-common-file.js | 16 ++++++++-------- www/drive/inner.js | 1 - 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/www/common/sframe-common-file.js b/www/common/sframe-common-file.js index 8f71d281b..b07bc8854 100644 --- a/www/common/sframe-common-file.js +++ b/www/common/sframe-common-file.js @@ -103,7 +103,7 @@ define([ var $row = $table.find('tr[id="'+id+'"]'); - $row.find('.cp-fileupload-table-cancel').addClass('success').html('').append(h('span.fa.fa-check')); + $row.find('.cp-fileupload-table-cancel').addClass('success').html('').append(h('span.fa.fa-minus')); var $pv = $row.find('.cp-fileupload-table-progress-value'); var $pb = $row.find('.cp-fileupload-table-progressbar'); var $link = $row.find('.cp-fileupload-table-link'); @@ -301,7 +301,7 @@ define([ ]); $(content).find('#cp-upload-owned').on('change', function () { - var val = $(content).find('#cp-upload-owned').is(':checked'); + var val = Util.isCheked($(content).find('#cp-upload-owned')); if (val) { $(content).find('#cp-upload-store').prop('checked', true).prop('disabled', true); } else { @@ -315,8 +315,8 @@ define([ // Get the values var newName = $(content).find('#cp-upload-name').val(); var password = $(content).find('#cp-upload-password').val() || undefined; - var owned = $(content).find('#cp-upload-owned').is(':checked'); - var forceSave = owned || $(content).find('#cp-upload-store').is(':checked'); + var owned = Util.isChecked($(content).find('#cp-upload-owned')); + var forceSave = owned || Util.isChecked($(content).find('#cp-upload-store')); modalState.owned = owned; modalState.store = forceSave; @@ -356,7 +356,7 @@ define([ ]); $(content).find('#cp-upload-owned').on('change', function () { - var val = $(content).find('#cp-upload-owned').is(':checked'); + var val = Util.isChecked($(content).find('#cp-upload-owned')); if (val) { $(content).find('#cp-upload-store').prop('checked', true).prop('disabled', true); } else { @@ -370,8 +370,8 @@ define([ // Get the values var newName = $(content).find('#cp-upload-foldername').val(); var password = $(content).find('#cp-upload-password').val() || undefined; - var owned = $(content).find('#cp-upload-owned').is(':checked'); - var forceSave = owned || $(content).find('#cp-upload-store').is(':checked'); + var owned = Util.isChecked($(content).find('#cp-upload-owned')); + var forceSave = owned || Util.isChecked($(content).find('#cp-upload-store')); modalState.owned = owned; modalState.store = forceSave; @@ -436,7 +436,7 @@ define([ password = defaultOptions.password || undefined; owned = !!defaultOptions.owned; forceSave = !!defaultOptions.forceSave; - finish(); + return void finish(); } // if no default options were passed, ask the user else { diff --git a/www/drive/inner.js b/www/drive/inner.js index bf01942f4..155ed7ac0 100644 --- a/www/drive/inner.js +++ b/www/drive/inner.js @@ -2210,7 +2210,6 @@ define([ }); }; var showUploadFolderModal = function () { - console.log("%cIMPORT FOLDER", "color: red"); var $input = $('', { 'type': 'file', 'style': 'display: none;', From 2a2f45ec2553e3515174f4517a0d99b428b3cc14 Mon Sep 17 00:00:00 2001 From: ClemDee Date: Wed, 14 Aug 2019 10:36:53 +0200 Subject: [PATCH 17/17] Remove translation fallbacks --- www/common/sframe-common-file.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/www/common/sframe-common-file.js b/www/common/sframe-common-file.js index b07bc8854..489a8b0ec 100644 --- a/www/common/sframe-common-file.js +++ b/www/common/sframe-common-file.js @@ -272,7 +272,7 @@ define([ var initialState = modalState.owned || modalState.store; var initialDisabled = modalState.owned ? { disabled: true } : {}; var manualStore = autoStore === 1 ? undefined : - UI.createCheckbox('cp-upload-store', isFolderUpload ? (Messages.uploadFolder_modal_forceSave || "Store files in your cryptDrive") : Messages.autostore_forceSave, initialState, { + UI.createCheckbox('cp-upload-store', isFolderUpload ? (Messages.uploadFolder_modal_forceSave) : Messages.autostore_forceSave, initialState, { input: initialDisabled }); return manualStore; @@ -341,15 +341,14 @@ define([ // Ask for name, password and owner var content = h('div', [ - h('h4', Messages.uploadFolder_modal_title || "Folder upload options"), + h('h4', Messages.uploadFolder_modal_title), UIElements.setHTML(h('label', {for: 'cp-upload-name'}), Messages.fm_folderName), h('input#cp-upload-foldername', {type: 'text', placeholder: foldername, value: foldername}), - h('label', {for: 'cp-upload-password'}, Messages.uploadFolder_modal_filesPassword || "Files password"), + h('label', {for: 'cp-upload-password'}, Messages.uploadFolder_modal_filesPassword), UI.passwordInput({id: 'cp-upload-password'}), h('span', { style: 'display:flex;align-items:center;justify-content:space-between' }, [ - UI.createCheckbox('cp-upload-owned', Messages.uploadFolder_modal_owner || "Owned files", modalState.owned), createHelper('/faq.html#keywords-owned', Messages.creation_owned1) ]), manualStore