diff options
Diffstat (limited to 'apps/files/js/filelist.js')
-rw-r--r-- | apps/files/js/filelist.js | 143 |
1 files changed, 68 insertions, 75 deletions
diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js index 363f81a1a73..868623d9a8a 100644 --- a/apps/files/js/filelist.js +++ b/apps/files/js/filelist.js @@ -386,11 +386,16 @@ }); } + this._operationProgressBar = new OCA.Files.OperationProgressBar(); + this._operationProgressBar.render(); + this.$el.find('#uploadprogresswrapper').replaceWith(this._operationProgressBar.$el); + if (options.enableUpload) { // TODO: auto-create this element var $uploadEl = this.$el.find('#file_upload_start'); if ($uploadEl.exists()) { this._uploader = new OC.Uploader($uploadEl, { + progressBar: this._operationProgressBar, fileList: this, filesClient: this.filesClient, dropZone: $('#content'), @@ -2206,21 +2211,39 @@ remove: function(name, options){ options = options || {}; var fileEl = this.findFileEl(name); - var fileId = fileEl.data('id'); - var index = fileEl.index(); - if (!fileEl.length) { - return null; + var fileData = _.findWhere(this.files, {name: name}); + if (!fileData) { + return; } + var fileId = fileData.id; if (this._selectedFiles[fileId]) { // remove from selection first this._selectFileEl(fileEl, false); this.updateSelectionSummary(); } + if (this._selectedFiles[fileId]) { + delete this._selectedFiles[fileId]; + this._selectionSummary.remove(fileData); + this.updateSelectionSummary(); + } + var index = this.files.findIndex(function(el){return el.name==name;}); + this.files.splice(index, 1); + + // TODO: improve performance on batch update + this.isEmpty = !this.files.length; + if (typeof(options.updateSummary) === 'undefined' || !!options.updateSummary) { + this.updateEmptyContent(); + this.fileSummary.remove({type: fileData.type, size: fileData.size}, true); + } + + if (!fileEl.length) { + return null; + } + if (this._dragOptions && (fileEl.data('permissions') & OC.PERMISSION_DELETE)) { // file is only draggable when delete permissions are set fileEl.find('td.filename').draggable('destroy'); } - this.files.splice(index, 1); if (this._currentFileModel && this._currentFileModel.get('id') === fileId) { // Note: in the future we should call destroy() directly on the model // and the model will take care of the deletion. @@ -2230,12 +2253,6 @@ this._updateDetailsView(null); } fileEl.remove(); - // TODO: improve performance on batch update - this.isEmpty = !this.files.length; - if (typeof(options.updateSummary) === 'undefined' || !!options.updateSummary) { - this.updateEmptyContent(); - this.fileSummary.remove({type: fileEl.attr('data-type'), size: fileEl.attr('data-size')}, true); - } var lastIndex = this.$fileList.children().length; // if there are less elements visible than one page @@ -2282,29 +2299,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); @@ -2316,7 +2310,7 @@ return self.filesClient.move(dir + fileName, targetPath + fileName) .done(function() { // if still viewing the same directory - if (OC.joinPaths(self.getCurrentDirectory(), '/') === dir) { + if (OC.joinPaths(self.getCurrentDirectory(), '/') === OC.joinPaths(dir, '/')) { // recalculate folder size var oldFile = self.findFileEl(target); var newFile = self.findFileEl(fileName); @@ -2325,7 +2319,6 @@ oldFile.data('size', newSize); oldFile.find('td.filesize').text(OC.Util.humanFileSize(newSize)); - // TODO: also update entry in FileList.files self.remove(fileName); } }) @@ -2345,22 +2338,33 @@ self.showFileBusyState($tr, false); }); }; + return this.reportOperationProgress(fileNames, moveFileFunction, callback); + }, + + _reflect: function (promise){ + return promise.then(function(v){ return {};}, function(e){ return {};}); + }, - 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).always(function(){ mcSemaphore.release(); counter++; + self._operationProgressBar.setProgressBarValue(100.0*counter/fileNames.length); }); }); }); - return Promise.all(promises).then(function(){ + return Promise.all(_.map(promises, self._reflect)).then(function(){ if (callback) { callback(); } + self._operationProgressBar.hideProgressBar(); }); }, @@ -2385,7 +2389,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) !== '/') { @@ -2441,12 +2445,12 @@ } } } - self.filesClient.copy(dir + fileName, targetPathAndName) + return self.filesClient.copy(dir + fileName, targetPathAndName) .done(function () { filesToNotify.push(fileName); // if still viewing the same directory - if (OC.joinPaths(self.getCurrentDirectory(), '/') === dir) { + if (OC.joinPaths(self.getCurrentDirectory(), '/') === OC.joinPaths(dir, '/')) { // recalculate folder size var oldFile = self.findFileEl(target); var newFile = self.findFileEl(fileName); @@ -2513,11 +2517,8 @@ } } }); - }); - - if (callback) { - callback(); - } + }; + return this.reportOperationProgress(fileNames, copyFileFunction, callback); }, /** @@ -2939,9 +2940,6 @@ // delete all files in directory files = _.pluck(this.files, 'name'); } - if (files) { - this.showFileBusyState(files, true); - } // Finish any existing actions if (this.lastAction) { this.lastAction(); @@ -2949,43 +2947,38 @@ dir = dir || this.getCurrentDirectory(); - function removeFromList(file) { - var fileEl = self.remove(file, {updateSummary: false}); - // FIXME: not sure why we need this after the - // element isn't even in the DOM any more - fileEl.find('.selectCheckBox').prop('checked', false); - fileEl.removeClass('selected'); - self.fileSummary.remove({type: fileEl.attr('data-type'), size: fileEl.attr('data-size')}); - // TODO: this info should be returned by the ajax call! - self.updateEmptyContent(); - self.fileSummary.update(); - self.updateSelectionSummary(); - // FIXME: don't repeat this, do it once all files are done - self.updateStorageStatistics(); - self.updateStorageQuotas(); - } - - _.each(files, function(file) { - self.filesClient.remove(dir + '/' + file) + var removeFunction = function(fileName) { + var $tr = self.findFileEl(fileName); + self.showFileBusyState($tr, true); + return self.filesClient.remove(dir + '/' + fileName) .done(function() { - removeFromList(file); + if (OC.joinPaths(self.getCurrentDirectory(), '/') === OC.joinPaths(dir, '/')) { + self.remove(fileName); + } }) .fail(function(status) { if (status === 404) { // the file already did not exist, remove it from the list - removeFromList(file); + if (OC.joinPaths(self.getCurrentDirectory(), '/') === OC.joinPaths(dir, '/')) { + self.remove(fileName); + } } else { // only reset the spinner for that one file OC.Notification.show(t('files', 'Error deleting file "{fileName}".', - {fileName: file}), {type: 'error'} + {fileName: fileName}), {type: 'error'} ); - var deleteAction = self.findFileEl(file).find('.action.delete'); - deleteAction.removeClass('icon-loading-small').addClass('icon-delete'); - self.showFileBusyState(files, false); } + }) + .always(function() { + self.showFileBusyState($tr, false); }); - }); + }; + return this.reportOperationProgress(files, removeFunction).then(function(){ + self.updateStorageStatistics(); + self.updateStorageQuotas(); + }); }, + /** * Creates the file summary section */ |