]> source.dussan.org Git - nextcloud-server.git/commitdiff
Fix appending of rows after upload
authorVincent Petry <pvince81@owncloud.com>
Thu, 19 Jun 2014 15:19:28 +0000 (17:19 +0200)
committerVincent Petry <pvince81@owncloud.com>
Thu, 19 Jun 2014 16:21:42 +0000 (18:21 +0200)
When uploading files or folders, they only need to be appended or
updated when their path or a section of their path is inside the current
directory (which happens for folder upload)

Fixes issue where file was appended when dragging on a parent directory
onto the breadcrumb.

Fixes appending issue when uploading folders.

apps/files/js/filelist.js
apps/files/tests/js/filelistSpec.js

index cb6c3dcb2c06fda9135e432dba4e3b7a00f64540..241997be2bcd2d54c0c0a421bf3c58082758db7c 100644 (file)
                                                data.context.find('td.filesize').text(humanFileSize(size));
                                        } else {
                                                // only append new file if uploaded into the current folder
-                                               if (file.directory !== '/' && file.directory !== self.getCurrentDirectory()) {
+                                               if (file.directory !== self.getCurrentDirectory()) {
+                                                       // Uploading folders actually uploads a list of files
+                                                       // for which the target directory (file.directory) might lie deeper
+                                                       // than the current directory
+
+                                                       var fileDirectory = file.directory.replace('/','').replace(/\/$/, "");
+                                                       var currentDirectory = self.getCurrentDirectory().replace('/','').replace(/\/$/, "") + '/';
+
+                                                       if (currentDirectory !== '/') {
+                                                               // abort if fileDirectory does not start with current one
+                                                               if (fileDirectory.indexOf(currentDirectory) !== 0) {
+                                                                       return;
+                                                               }
+
+                                                               // remove the current directory part
+                                                               fileDirectory = fileDirectory.substr(currentDirectory.length);
+                                                       }
 
-                                                       var fileDirectory = file.directory.replace('/','').replace(/\/$/, "").split('/');
+                                                       // only take the first section of the path
+                                                       fileDirectory = fileDirectory.split('/');
 
-                                                       if (fileDirectory.length === 1) {
+                                                       var fd;
+                                                       // if the first section exists / is a subdir
+                                                       if (fileDirectory.length) {
                                                                fileDirectory = fileDirectory[0];
 
-                                                               // Get the directory
-                                                               var fd = self.findFileEl(fileDirectory);
+                                                               // See whether it is already in the list
+                                                               fd = self.findFileEl(fileDirectory);
                                                                if (fd.length === 0) {
                                                                        var dir = {
                                                                                name: fileDirectory,
                                                                                size: 0,
                                                                                id: file.parentId
                                                                        };
-                                                                       self.add(dir, {insert: true});
+                                                                       fd = self.add(dir, {insert: true});
                                                                }
-                                                       } else {
-                                                               fileDirectory = fileDirectory[0];
-                                                       }
 
-                                                       fileDirectory = self.findFileEl(fileDirectory);
-
-                                                       // update folder size
-                                                       size = parseInt(fileDirectory.attr('data-size'), 10);
-                                                       size += parseInt(file.size, 10);
-                                                       fileDirectory.attr('data-size', size);
-                                                       fileDirectory.find('td.filesize').text(humanFileSize(size));
+                                                               // update folder size
+                                                               size = parseInt(fd.attr('data-size'), 10);
+                                                               size += parseInt(file.size, 10);
+                                                               fd.attr('data-size', size);
+                                                               fd.find('td.filesize').text(OC.Util.humanFileSize(size));
+                                                       }
 
                                                        return;
                                                }
index 7d3bc946dd3a6793375a0988b4ea001b4c86361b..011e73d4b30994d6a3dbc2e557f6f7b0f5a68a80 100644 (file)
@@ -1730,20 +1730,6 @@ describe('OCA.Files.FileList tests', function() {
                                return ev;
                        }
 
-                       /**
-                        * Convert form data to a flat list
-                        * 
-                        * @param formData form data array as used by jquery.upload
-                        * @return map based on the array's key values
-                        */
-                       function decodeFormData(data) {
-                               var map = {};
-                               _.each(data.formData(), function(entry) {
-                                       map[entry.name] = entry.value;
-                               });
-                               return map;
-                       }
-
                        beforeEach(function() {
                                // simulate data structure from jquery.upload
                                uploadData = {
@@ -1803,11 +1789,7 @@ describe('OCA.Files.FileList tests', function() {
                                ev = dropOn(fileList.findFileEl('somedir').find('td:eq(2)'), uploadData);
 
                                expect(ev.result).not.toEqual(false);
-                               expect(uploadData.formData).toBeDefined();
-                               formData = decodeFormData(uploadData);
-                               expect(formData.dir).toEqual('/subdir/somedir');
-                               expect(formData.file_directory).toEqual('fileToUpload.txt');
-                               expect(formData.requesttoken).toBeDefined();
+                               expect(uploadData.targetDir).toEqual('/subdir/somedir');
                        });
                        it('drop on a breadcrumb inside the table triggers upload to target folder', function() {
                                var ev, formData;
@@ -1815,11 +1797,7 @@ describe('OCA.Files.FileList tests', function() {
                                ev = dropOn(fileList.$el.find('.crumb:eq(2)'), uploadData);
 
                                expect(ev.result).not.toEqual(false);
-                               expect(uploadData.formData).toBeDefined();
-                               formData = decodeFormData(uploadData);
-                               expect(formData.dir).toEqual('/a/b');
-                               expect(formData.file_directory).toEqual('fileToUpload.txt');
-                               expect(formData.requesttoken).toBeDefined();
+                               expect(uploadData.targetDir).toEqual('/a/b');
                        });
                });
        });