From 6ec338f4165dc275a96e1dd7c3dccc0ebbbfe90e Mon Sep 17 00:00:00 2001 From: Harry Hedger Date: Sat, 12 Mar 2016 12:47:04 -0500 Subject: [PATCH] Fix file array issue. Add array flatten util. Wrote multipart test. Add GoogleDrive to Modal. --- src/core/Core.js | 10 ++++------ src/core/Utils.js | 8 ++++++++ src/plugins/Formtag.js | 12 +++++------- src/plugins/GoogleDrive.js | 1 - src/plugins/Multipart.js | 4 ++-- src/plugins/index.js | 2 ++ test/multipart.spec.js | 18 ++++++++++++++++++ test/tus10.spec.js | 16 ---------------- website/src/examples/modal/app.es6 | 3 ++- 9 files changed, 41 insertions(+), 33 deletions(-) create mode 100644 test/multipart.spec.js delete mode 100644 test/tus10.spec.js diff --git a/src/core/Core.js b/src/core/Core.js index b617201de..d81b69726 100644 --- a/src/core/Core.js +++ b/src/core/Core.js @@ -137,7 +137,7 @@ export default class Core { */ runType (type, method, files) { const methods = this.plugins[type].map( - plugin => plugin[method](files) + plugin => plugin[method](Utils.flatten(files)) ) return Promise.all(methods) @@ -165,13 +165,11 @@ export default class Core { ['install', 'run'].forEach(method => { // First we select only plugins of current type, // then create an array of runType methods of this plugins - const typeMethods = this.types.filter(type => { - return this.plugins[type] - }).map(type => this.runType.bind(this, type, method)) - + const typeMethods = this.types.filter(type => this.plugins[type]) + .map(type => this.runType.bind(this, type, method)) // Run waterfall of typeMethods return Utils.promiseWaterfall(typeMethods) - .then(result => { return result }) + .then(result => result) .catch(error => console.error(error)) }) } diff --git a/src/core/Utils.js b/src/core/Utils.js index d58f3bb64..10bf8e3a8 100644 --- a/src/core/Utils.js +++ b/src/core/Utils.js @@ -98,6 +98,13 @@ function addListenerMulti (el, events, cb) { } } +/** + * Shallow flatten nested arrays. + */ +function flatten (arr) { + return [].concat.apply([], arr) +} + function qsa (selector, context) { return Array.prototype.slice.call((context || document).querySelectorAll(selector) || []) } @@ -108,5 +115,6 @@ export default { addClass, removeClass, addListenerMulti, + flatten, qsa } diff --git a/src/plugins/Formtag.js b/src/plugins/Formtag.js index b3e1fdd77..ccac581b3 100644 --- a/src/plugins/Formtag.js +++ b/src/plugins/Formtag.js @@ -13,7 +13,7 @@ export default class Formtag extends Plugin { results: results }) - this.setProgress(0) + // this.setProgress(0) // form FormData // const formData = new FormData(this.dropzone) @@ -32,11 +32,9 @@ export default class Formtag extends Plugin { var selected = []; [].forEach.call(fields, (field, i) => { - [].forEach.call(field.files, (file, j) => { - selected.push({ - from: 'Formtag', - file: file - }) + selected.push({ + from: 'Formtag', + files: field.files }) }) @@ -57,7 +55,7 @@ export default class Formtag extends Plugin { // } // } // } - self.setProgress(100) + // self.setProgress(100) console.log({ selected: selected, fields: fields diff --git a/src/plugins/GoogleDrive.js b/src/plugins/GoogleDrive.js index 4c2429a6b..8639b4681 100644 --- a/src/plugins/GoogleDrive.js +++ b/src/plugins/GoogleDrive.js @@ -148,7 +148,6 @@ export default class Google extends Plugin { this.getFolder(folder) .then(data => { this.target.innerHTML = this.renderBrowser(data) - console.log(data) const folders = Utils.qsa('.GoogleDriveFolder') const files = Utils.qsa('.GoogleDriveFile') diff --git a/src/plugins/Multipart.js b/src/plugins/Multipart.js index a310ee54e..d00a8822f 100644 --- a/src/plugins/Multipart.js +++ b/src/plugins/Multipart.js @@ -21,7 +21,7 @@ export default class Multipart extends Plugin { const files = this.extractFiles(results) - this.setProgress(0) + // this.setProgress(0) var uploaders = [] if (this.opts.bundle) { @@ -52,7 +52,7 @@ export default class Multipart extends Plugin { xhr.addEventListener('progress', (e) => { var percentage = (e.loaded / e.total * 100).toFixed(2) - this.setProgress(percentage, current, total) + // this.setProgress(percentage, current, total) }) xhr.addEventListener('load', () => { diff --git a/src/plugins/index.js b/src/plugins/index.js index 045ff7aaf..25f8a2da2 100644 --- a/src/plugins/index.js +++ b/src/plugins/index.js @@ -9,6 +9,7 @@ import Dummy from './Dummy' import DragDrop from './DragDrop' import Dropbox from './Dropbox' import Formtag from './Formtag' +import GoogleDrive from './GoogleDrive' // Progressindicators import ProgressBar from './ProgressBar' @@ -32,6 +33,7 @@ export default { Present, DragDrop, Dropbox, + GoogleDrive, Formtag, Tus10, Multipart, diff --git a/test/multipart.spec.js b/test/multipart.spec.js new file mode 100644 index 000000000..d1416481f --- /dev/null +++ b/test/multipart.spec.js @@ -0,0 +1,18 @@ +var test = require('tape') +var webdriver = require('selenium-webdriver') + +test('upload two files', function (t) { + var driver = new webdriver.Builder() + .withCapabilities(webdriver.Capabilities.chrome()) + .build() + + driver.get('http://www.uppy.io/examples/multipart/') + driver.findElement(webdriver.By.id('file1')).sendKeys('./dummyFile') + driver.findElement(webdriver.By.id('file2')).sendKeys('./dummyFile2') + driver.findElement(webdriver.By.id('myupload')).click() + // driver.wait + // check for success + driver.quit() + + t.end() +}) diff --git a/test/tus10.spec.js b/test/tus10.spec.js deleted file mode 100644 index aac5ffbf6..000000000 --- a/test/tus10.spec.js +++ /dev/null @@ -1,16 +0,0 @@ -var test = require('tape') -var Core = require('../src/core/index.js') -var DragDrop = require('../src/plugins/DragDrop.js') -var Tus10 = require('../src/plugins/Tus10.js') - -test('uploadSomePizza', function (t) { - const core = new Core() - core - .use(DragDrop, {target: '??'}) - .use(Tus10, {endpoint: 'http://master.tus.io:8080/files/'}) - .run() - - // trigger an upload with a fake blob - // somehow test the resume? or just see if it's successful? - // test the expected/actual results to pass/fail -}) diff --git a/website/src/examples/modal/app.es6 b/website/src/examples/modal/app.es6 index 65c09e618..985d61ec4 100644 --- a/website/src/examples/modal/app.es6 +++ b/website/src/examples/modal/app.es6 @@ -1,5 +1,5 @@ import Uppy from 'uppy/core' -import { Dummy, DragDrop, Modal, ProgressBar, Present, Tus10 } from 'uppy/plugins' +import { Dummy, DragDrop, GoogleDrive, Modal, ProgressBar, Present, Tus10 } from 'uppy/plugins' // GoogleDrive, const uppy = new Uppy({debug: true}) @@ -9,6 +9,7 @@ uppy // .use(GoogleDrive, {target: Modal}) .use(ProgressBar, {target: Modal}) .use(DragDrop, {target: Modal}) + .use(GoogleDrive, {target: Modal}) .use(Present, {target: Modal}) .use(Tus10, {endpoint: 'http://master.tus.io:8080/files/'}) .run()