Compare commits
3 Commits
infinum/fe
...
ravinderpa
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
36ebe449b0 | ||
|
|
f72aa05e4e | ||
|
|
5b26793662 |
@@ -1,7 +1,14 @@
|
||||
import { FileLikeObject } from './file-like-object.class';
|
||||
import { FileUploader, ParsedResponseHeaders, FileUploaderOptions } from './file-uploader.class';
|
||||
|
||||
import {Observable} from "rxjs/Rx";
|
||||
|
||||
export class FileItem {
|
||||
public observer:any;
|
||||
/**
|
||||
* Observable for subscribing the server result
|
||||
*/
|
||||
public resObservable:Observable;
|
||||
public file:FileLikeObject;
|
||||
public _file:File;
|
||||
public alias:string;
|
||||
@@ -36,6 +43,7 @@ export class FileItem {
|
||||
this.alias = uploader.options.itemAlias || 'file';
|
||||
}
|
||||
this.url = uploader.options.url;
|
||||
this.resObservable=new Observable.create(observer=>{this.observer=observer});
|
||||
}
|
||||
|
||||
public upload():void {
|
||||
|
||||
@@ -13,7 +13,7 @@ export interface Headers {
|
||||
|
||||
export type ParsedResponseHeaders = {[headerFieldName:string]:string};
|
||||
|
||||
export type FilterFunction = {name:string, fn:(item?:FileLikeObject, options?:FileUploaderOptions)=>boolean|Promise<boolean>};
|
||||
export type FilterFunction = {name:string, fn:(item?:FileLikeObject, options?:FileUploaderOptions)=>boolean};
|
||||
|
||||
export interface FileUploaderOptions {
|
||||
allowedMimeType?:Array<string>;
|
||||
@@ -96,17 +96,16 @@ export class FileUploader {
|
||||
if (!options) {
|
||||
options = this.options;
|
||||
}
|
||||
|
||||
let temp = new FileLikeObject(some);
|
||||
this._isValidFile(temp, arrayOfFilters, options).then(() => {
|
||||
if (this._isValidFile(temp, arrayOfFilters, options)) {
|
||||
let fileItem = new FileItem(this, some, options);
|
||||
addedFileItems.push(fileItem);
|
||||
this.queue.push(fileItem);
|
||||
this._onAfterAddingFile(fileItem);
|
||||
}).catch(() => {
|
||||
} else {
|
||||
let filter = arrayOfFilters[this._failFilterIndex];
|
||||
this._onWhenAddingFileFailed(temp, filter, options);
|
||||
});
|
||||
}
|
||||
});
|
||||
if (this.queue.length !== count) {
|
||||
this._onAfterAddingAll(addedFileItems);
|
||||
@@ -278,6 +277,7 @@ export class FileUploader {
|
||||
}
|
||||
this.onCompleteAll();
|
||||
this.progress = this._getTotalProgress();
|
||||
this.item.observer.next(response);
|
||||
this._render();
|
||||
}
|
||||
|
||||
@@ -328,7 +328,8 @@ export class FileUploader {
|
||||
let gist = this._isSuccessCode(xhr.status) ? 'Success' : 'Error';
|
||||
let method = '_on' + gist + 'Item';
|
||||
(this as any)[method](item, response, xhr.status, headers);
|
||||
this._onCompleteItem(item, response, xhr.status, headers);
|
||||
this._
|
||||
(item, response, xhr.status, headers);
|
||||
};
|
||||
xhr.onerror = () => {
|
||||
let headers = this._parseHeaders(xhr.getAllResponseHeaders());
|
||||
@@ -400,27 +401,11 @@ export class FileUploader {
|
||||
return this.options.queueLimit === undefined || this.queue.length < this.options.queueLimit;
|
||||
}
|
||||
|
||||
protected _isValidFile(file:FileLikeObject, filters:FilterFunction[], options:FileUploaderOptions): Promise<boolean> {
|
||||
if (!filters.length) {
|
||||
return Promise.resolve(true);
|
||||
}
|
||||
|
||||
protected _isValidFile(file:FileLikeObject, filters:FilterFunction[], options:FileUploaderOptions):boolean {
|
||||
this._failFilterIndex = -1;
|
||||
|
||||
return Promise.all(
|
||||
filters.map((filter: FilterFunction) => {
|
||||
const isValid: boolean = filter.fn.call(this, file, options);
|
||||
|
||||
return Promise.resolve(isValid);
|
||||
})
|
||||
).then((values) => {
|
||||
const isValid = values.every((value: boolean) => {
|
||||
this._failFilterIndex++;
|
||||
|
||||
return value;
|
||||
})
|
||||
|
||||
return isValid ? Promise.resolve(isValid) : Promise.reject(isValid);
|
||||
return !filters.length ? true : filters.every((filter:FilterFunction) => {
|
||||
this._failFilterIndex++;
|
||||
return filter.fn.call(this, file, options);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
6
src/file-upload/rxjs/operator.ts
Normal file
6
src/file-upload/rxjs/operator.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
import 'rxjs/add/operator/catch';
|
||||
import 'rxjs/add/operator/debounceTime';
|
||||
import 'rxjs/add/operator/distinctUntilChanged';
|
||||
import 'rxjs/add/operator/map';
|
||||
import 'rxjs/add/operator/switchMap';
|
||||
import 'rxjs/add/operator/toPromise';
|
||||
Reference in New Issue
Block a user