Add progress reporting to move and copy operations
Signed-off-by: Tomasz Grobelny <tomasz@grobelny.net>
This commit is contained in:
parent
7bafa54ae1
commit
1f6f276fa0
|
@ -2207,29 +2207,6 @@
|
||||||
fileNames = [fileNames];
|
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 moveFileFunction = function(fileName) {
|
||||||
var $tr = self.findFileEl(fileName);
|
var $tr = self.findFileEl(fileName);
|
||||||
self.showFileBusyState($tr, true);
|
self.showFileBusyState($tr, true);
|
||||||
|
@ -2270,14 +2247,20 @@
|
||||||
self.showFileBusyState($tr, false);
|
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 counter = 0;
|
||||||
var promises = _.map(fileNames, function(arg) {
|
var promises = _.map(fileNames, function(arg) {
|
||||||
return mcSemaphore.acquire().then(function(){
|
return mcSemaphore.acquire().then(function(){
|
||||||
moveFileFunction(arg).then(function(){
|
return operationFunction(arg).then(function(){
|
||||||
mcSemaphore.release();
|
mcSemaphore.release();
|
||||||
counter++;
|
counter++;
|
||||||
|
self._operationProgressBar.setProgressBarValue(100.0*counter/fileNames.length);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -2286,6 +2269,7 @@
|
||||||
if (callback) {
|
if (callback) {
|
||||||
callback();
|
callback();
|
||||||
}
|
}
|
||||||
|
self._operationProgressBar.hideProgressBar();
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -2310,7 +2294,7 @@
|
||||||
if (!_.isArray(fileNames)) {
|
if (!_.isArray(fileNames)) {
|
||||||
fileNames = [fileNames];
|
fileNames = [fileNames];
|
||||||
}
|
}
|
||||||
_.each(fileNames, function(fileName) {
|
var copyFileFunction = function(fileName) {
|
||||||
var $tr = self.findFileEl(fileName);
|
var $tr = self.findFileEl(fileName);
|
||||||
self.showFileBusyState($tr, true);
|
self.showFileBusyState($tr, true);
|
||||||
if (targetPath.charAt(targetPath.length - 1) !== '/') {
|
if (targetPath.charAt(targetPath.length - 1) !== '/') {
|
||||||
|
@ -2438,11 +2422,8 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
};
|
||||||
|
return this.reportOperationProgress(fileNames, copyFileFunction, callback);
|
||||||
if (callback) {
|
|
||||||
callback();
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
"sidebarpreviewmanager.js",
|
"sidebarpreviewmanager.js",
|
||||||
"sidebarpreviewtext.js",
|
"sidebarpreviewtext.js",
|
||||||
"detailtabview.js",
|
"detailtabview.js",
|
||||||
|
"semaphore.js",
|
||||||
"mainfileinfodetailview.js",
|
"mainfileinfodetailview.js",
|
||||||
"operationprogressbar.js",
|
"operationprogressbar.js",
|
||||||
"detailsview.js",
|
"detailsview.js",
|
||||||
|
|
|
@ -37,8 +37,16 @@
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
showProgressBar: function() {
|
showProgressBar: function(showCancelButton) {
|
||||||
$('#uploadprogresswrapper .stop').show();
|
if (showCancelButton) {
|
||||||
|
showCancelButton = true;
|
||||||
|
}
|
||||||
|
$('#uploadprogressbar').progressbar({value: 0});
|
||||||
|
if(showCancelButton) {
|
||||||
|
$('#uploadprogresswrapper .stop').show();
|
||||||
|
} else {
|
||||||
|
$('#uploadprogresswrapper .stop').hide();
|
||||||
|
}
|
||||||
$('#uploadprogresswrapper .label').show();
|
$('#uploadprogresswrapper .label').show();
|
||||||
$('#uploadprogressbar').fadeIn();
|
$('#uploadprogressbar').fadeIn();
|
||||||
this.$el.trigger(new $.Event('resized'));
|
this.$el.trigger(new $.Event('resized'));
|
||||||
|
|
|
@ -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;
|
||||||
|
|
||||||
|
})();
|
Loading…
Reference in New Issue