summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorTomasz Grobelny <tomasz@grobelny.net>2018-11-14 22:39:12 +0100
committerTomasz Grobelny <tomasz@grobelny.net>2018-11-24 23:55:33 +0100
commit1f6f276fa02533a696fc4157f061a4482be02917 (patch)
treeb80ff821c43e1293cdee4655bd5e6a0b883e4a2a /apps
parent7bafa54ae168a25b47d579fdca4cec19f2e1534f (diff)
downloadnextcloud-server-1f6f276fa02533a696fc4157f061a4482be02917.tar.gz
nextcloud-server-1f6f276fa02533a696fc4157f061a4482be02917.zip
Add progress reporting to move and copy operations
Signed-off-by: Tomasz Grobelny <tomasz@grobelny.net>
Diffstat (limited to 'apps')
-rw-r--r--apps/files/js/filelist.js43
-rw-r--r--apps/files/js/merged-index.json1
-rw-r--r--apps/files/js/operationprogressbar.js12
-rw-r--r--apps/files/js/semaphore.js37
4 files changed, 60 insertions, 33 deletions
diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js
index 3ee5286a3db..1891cbff5dc 100644
--- a/apps/files/js/filelist.js
+++ b/apps/files/js/filelist.js
@@ -2207,29 +2207,6 @@
fileNames = [fileNames];
}
- function Semaphore(max) {
- var counter = 0;
- var waiting = [];
-
- this.acquire = function() {
- if(counter < max) {
- counter++;
- return new Promise(function(resolve) { resolve(); });
- } else {
- return new Promise(function(resolve) { waiting.push(resolve); });
- }
- };
-
- this.release = function() {
- counter--;
- if (waiting.length > 0 && counter < max) {
- counter++;
- var promise = waiting.shift();
- promise();
- }
- };
- }
-
var moveFileFunction = function(fileName) {
var $tr = self.findFileEl(fileName);
self.showFileBusyState($tr, true);
@@ -2270,14 +2247,20 @@
self.showFileBusyState($tr, false);
});
};
+ return this.reportOperationProgress(fileNames, moveFileFunction, callback);
+ },
- var mcSemaphore = new Semaphore(10);
+ reportOperationProgress: function (fileNames, operationFunction, callback){
+ var self = this;
+ self._operationProgressBar.showProgressBar(false);
+ var mcSemaphore = new OCA.Files.Semaphore(5);
var counter = 0;
var promises = _.map(fileNames, function(arg) {
return mcSemaphore.acquire().then(function(){
- moveFileFunction(arg).then(function(){
+ return operationFunction(arg).then(function(){
mcSemaphore.release();
counter++;
+ self._operationProgressBar.setProgressBarValue(100.0*counter/fileNames.length);
});
});
});
@@ -2286,6 +2269,7 @@
if (callback) {
callback();
}
+ self._operationProgressBar.hideProgressBar();
});
},
@@ -2310,7 +2294,7 @@
if (!_.isArray(fileNames)) {
fileNames = [fileNames];
}
- _.each(fileNames, function(fileName) {
+ var copyFileFunction = function(fileName) {
var $tr = self.findFileEl(fileName);
self.showFileBusyState($tr, true);
if (targetPath.charAt(targetPath.length - 1) !== '/') {
@@ -2438,11 +2422,8 @@
}
}
});
- });
-
- if (callback) {
- callback();
- }
+ };
+ return this.reportOperationProgress(fileNames, copyFileFunction, callback);
},
/**
diff --git a/apps/files/js/merged-index.json b/apps/files/js/merged-index.json
index bc505e76034..8d25daa6b3c 100644
--- a/apps/files/js/merged-index.json
+++ b/apps/files/js/merged-index.json
@@ -21,6 +21,7 @@
"sidebarpreviewmanager.js",
"sidebarpreviewtext.js",
"detailtabview.js",
+ "semaphore.js",
"mainfileinfodetailview.js",
"operationprogressbar.js",
"detailsview.js",
diff --git a/apps/files/js/operationprogressbar.js b/apps/files/js/operationprogressbar.js
index 0ce532af494..efeea4ad78f 100644
--- a/apps/files/js/operationprogressbar.js
+++ b/apps/files/js/operationprogressbar.js
@@ -37,8 +37,16 @@
});
},
- showProgressBar: function() {
- $('#uploadprogresswrapper .stop').show();
+ showProgressBar: function(showCancelButton) {
+ if (showCancelButton) {
+ showCancelButton = true;
+ }
+ $('#uploadprogressbar').progressbar({value: 0});
+ if(showCancelButton) {
+ $('#uploadprogresswrapper .stop').show();
+ } else {
+ $('#uploadprogresswrapper .stop').hide();
+ }
$('#uploadprogresswrapper .label').show();
$('#uploadprogressbar').fadeIn();
this.$el.trigger(new $.Event('resized'));
diff --git a/apps/files/js/semaphore.js b/apps/files/js/semaphore.js
new file mode 100644
index 00000000000..044f0af23f3
--- /dev/null
+++ b/apps/files/js/semaphore.js
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2018
+ *
+ * This file is licensed under the Affero General Public License version 3
+ * or later.
+ *
+ * See the COPYING-README file.
+ *
+ */
+
+(function(){
+ var Semaphore = function(max) {
+ var counter = 0;
+ var waiting = [];
+
+ this.acquire = function() {
+ if(counter < max) {
+ counter++;
+ return new Promise(function(resolve) { resolve(); });
+ } else {
+ return new Promise(function(resolve) { waiting.push(resolve); });
+ }
+ };
+
+ this.release = function() {
+ counter--;
+ if (waiting.length > 0 && counter < max) {
+ counter++;
+ var promise = waiting.shift();
+ promise();
+ }
+ };
+ };
+
+ OCA.Files.Semaphore = Semaphore;
+
+})();