Fix file array issue. Add array flatten util. Wrote multipart test. Add GoogleDrive to Modal.

This commit is contained in:
Harry Hedger 2016-03-12 12:47:04 -05:00
parent 19b16a6877
commit 6ec338f416
9 changed files with 41 additions and 33 deletions

View file

@ -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))
})
}

View file

@ -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
}

View file

@ -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

View file

@ -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')

View file

@ -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', () => {

View file

@ -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,

18
test/multipart.spec.js Normal file
View file

@ -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()
})

View file

@ -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
})

View file

@ -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()