Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cc4359fa99 |
@@ -52,8 +52,8 @@
|
||||
<thead>
|
||||
<tr>
|
||||
<th width="50%">Name</th>
|
||||
<th>Size</th>
|
||||
<th>Progress</th>
|
||||
<th *ngIf="uploader.options.isHTML5">Size</th>
|
||||
<th *ngIf="uploader.options.isHTML5">Progress</th>
|
||||
<th>Status</th>
|
||||
<th>Actions</th>
|
||||
</tr>
|
||||
|
||||
@@ -39,12 +39,12 @@ export interface FileUploaderOptions {
|
||||
parametersBeforeFiles?: boolean;
|
||||
formatDataFunction?: Function;
|
||||
formatDataFunctionIsAsync?: boolean;
|
||||
parallelUploads?: number;
|
||||
}
|
||||
|
||||
export class FileUploader {
|
||||
|
||||
public authToken: string;
|
||||
public isUploading: boolean = false;
|
||||
public queue: FileItem[] = [];
|
||||
public progress: number = 0;
|
||||
public _nextIndex: number = 0;
|
||||
@@ -52,10 +52,6 @@ export class FileUploader {
|
||||
public authTokenHeader: string;
|
||||
public response: EventEmitter<any>;
|
||||
|
||||
public get isUploading(): boolean {
|
||||
return this.queue.some((item: FileItem) => item.isUploading);
|
||||
}
|
||||
|
||||
public options: FileUploaderOptions = {
|
||||
autoUpload: false,
|
||||
isHTML5: true,
|
||||
@@ -93,8 +89,8 @@ export class FileUploader {
|
||||
this.options.filters.unshift({ name: 'mimeType', fn: this._mimeTypeFilter });
|
||||
}
|
||||
|
||||
for (let item of this.queue) {
|
||||
item.url = this.options.url;
|
||||
for (let i = 0; i < this.queue.length; i++) {
|
||||
this.queue[ i ].url = this.options.url;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -154,6 +150,10 @@ export class FileUploader {
|
||||
let item = this.queue[ index ];
|
||||
let transport = this.options.isHTML5 ? '_xhrTransport' : '_iframeTransport';
|
||||
item._prepareToUploading();
|
||||
if (this.isUploading) {
|
||||
return;
|
||||
}
|
||||
this.isUploading = true;
|
||||
(this as any)[ transport ](item);
|
||||
}
|
||||
|
||||
@@ -172,10 +172,7 @@ export class FileUploader {
|
||||
return;
|
||||
}
|
||||
items.map((item: FileItem) => item._prepareToUploading());
|
||||
let numberUploadsToStart = Math.min(items.length, this.options.parallelUploads || 1);
|
||||
for (let i = 0; i < numberUploadsToStart; ++i) {
|
||||
items[ i ].upload();
|
||||
}
|
||||
items[ 0 ].upload();
|
||||
}
|
||||
|
||||
public cancelAll(): void {
|
||||
@@ -279,6 +276,7 @@ export class FileUploader {
|
||||
item._onComplete(response, status, headers);
|
||||
this.onCompleteItem(item, response, status, headers);
|
||||
let nextItem = this.getReadyItems()[ 0 ];
|
||||
this.isUploading = false;
|
||||
if (nextItem) {
|
||||
nextItem.upload();
|
||||
return;
|
||||
@@ -375,7 +373,7 @@ export class FileUploader {
|
||||
}
|
||||
xhr.onreadystatechange = function () {
|
||||
if (xhr.readyState == XMLHttpRequest.DONE) {
|
||||
that.response.emit(xhr.responseText);
|
||||
that.response.emit(xhr.responseText)
|
||||
}
|
||||
}
|
||||
if (this.options.formatDataFunctionIsAsync) {
|
||||
|
||||
Reference in New Issue
Block a user