chore(bump): updated versions #1177

Merged
SvetlanaMuravlova merged 29 commits from update-angular into development 2021-09-03 10:44:45 +00:00
14 changed files with 226 additions and 394 deletions
Showing only changes of commit c4566873f4 - Show all commits

View File

@@ -2,7 +2,7 @@ import { Component } from '@angular/core';
// eslint-disable-next-line @typescript-eslint/no-var-requires
const doc = require('html-loader!markdown-loader!../../doc.md');
const tabDesc:Array<any> = [
const tabDesc: Array<any> = [
{
heading: 'Simple',
// eslint-disable-next-line @typescript-eslint/no-var-requires
@@ -19,12 +19,12 @@ const tabDesc:Array<any> = [
templateUrl: './file-upload-section.html'
})
export class FileUploadSectionComponent {
public name = 'File Upload';
public currentHeading = 'Simple';
public doc = doc;
public tabs:any = tabDesc;
name = 'File Upload';
currentHeading = 'Simple';
doc = doc;
tabs: any = tabDesc;
public select(e:any):void {
select(e: any): void {
if (e.heading) {
this.currentHeading = e.heading;
}

View File

@@ -10,18 +10,18 @@ const URL = 'https://evening-anchorage-3159.herokuapp.com/api/';
})
export class SimpleDemoComponent {
uploader:FileUploader;
hasBaseDropZoneOver:boolean;
hasAnotherDropZoneOver:boolean;
response:string;
uploader: FileUploader;
hasBaseDropZoneOver: boolean;
hasAnotherDropZoneOver: boolean;
response: string;
constructor (){
constructor() {
this.uploader = new FileUploader({
url: URL,
disableMultipart: true, // 'DisableMultipart' must be 'true' for formatDataFunction to be called.
formatDataFunctionIsAsync: true,
formatDataFunction: async (item) => {
return new Promise( (resolve, reject) => {
formatDataFunction: async item => {
return new Promise((resolve, reject) => {
resolve({
name: item._file.name,
length: item._file.size,
@@ -37,14 +37,14 @@ export class SimpleDemoComponent {
this.response = '';
this.uploader.response.subscribe( res => this.response = res );
this.uploader.response.subscribe(res => this.response = res );
}
public fileOverBase(e:any):void {
fileOverBase(e: any): void {
this.hasBaseDropZoneOver = e;
}
public fileOverAnother(e:any):void {
fileOverAnother(e: any): void {
this.hasAnotherDropZoneOver = e;
}
}

View File

@@ -4,27 +4,27 @@ import { FileUploader, FileUploaderOptions } from './file-uploader.class';
@Directive({ selector: '[ng2FileDrop]' })
export class FileDropDirective {
@Input() public uploader?: FileUploader;
@Output() public fileOver: EventEmitter<any> = new EventEmitter();
@Input() uploader?: FileUploader;
@Output() fileOver: EventEmitter<any> = new EventEmitter();
// eslint-disable-next-line @angular-eslint/no-output-on-prefix
@Output() public onFileDrop: EventEmitter<File[]> = new EventEmitter<File[]>();
@Output() onFileDrop: EventEmitter<File[]> = new EventEmitter<File[]>();
protected element: ElementRef;
public constructor(element: ElementRef) {
constructor(element: ElementRef) {
this.element = element;
}
public getOptions(): FileUploaderOptions | void {
getOptions(): FileUploaderOptions | void {
return this.uploader?.options;
}
public getFilters(): any {
return {};
getFilters(): string {
return '';
}
@HostListener('drop', [ '$event' ])
public onDrop(event: any): void {
onDrop(event: MouseEvent): void {
const transfer = this._getTransfer(event);
if (!transfer) {
return;
@@ -41,7 +41,7 @@ export class FileDropDirective {
}
@HostListener('dragover', [ '$event' ])
public onDragOver(event: any): void {
onDragOver(event: MouseEvent): void {
const transfer = this._getTransfer(event);
if (!this._haveFiles(transfer.types)) {
return;
@@ -53,7 +53,7 @@ export class FileDropDirective {
}
@HostListener('dragleave', [ '$event' ])
public onDragLeave(event: any): any {
onDragLeave(event: MouseEvent): void {
if ((this as any).element) {
if (event.currentTarget === (this as any).element[ 0 ]) {
return;
@@ -68,12 +68,12 @@ export class FileDropDirective {
return event.dataTransfer ? event.dataTransfer : event.originalEvent.dataTransfer; // jQuery fix;
}
protected _preventAndStop(event: any): any {
protected _preventAndStop(event: MouseEvent): void {
event.preventDefault();
event.stopPropagation();
}
protected _haveFiles(types: any): any {
protected _haveFiles(types: any): boolean {
if (!types) {
return false;
}

View File

@@ -2,30 +2,30 @@ import { FileLikeObject } from './file-like-object.class';
import { FileUploader, ParsedResponseHeaders, FileUploaderOptions } from './file-uploader.class';
export class FileItem {
public file: FileLikeObject;
public _file: File;
public alias?: string;
public url? = '/';
public method?: string;
public headers: any = [];
public withCredentials = true;
public formData: any = [];
public isReady = false;
public isUploading = false;
public isUploaded = false;
public isSuccess = false;
public isCancel = false;
public isError = false;
public progress = 0;
public index?: number;
public _xhr?: XMLHttpRequest;
public _form: any;
file: FileLikeObject;
_file: File;
alias?: string;
url = '/';
method?: string;
headers: any = [];
withCredentials = true;
formData: any = [];
isReady = false;
isUploading = false;
isUploaded = false;
isSuccess = false;
isCancel = false;
isError = false;
progress = 0;
index?: number;
_xhr?: XMLHttpRequest;
_form: any;
protected uploader: FileUploader;
protected some: File;
protected options: FileUploaderOptions;
public constructor(uploader: FileUploader, some: File, options: FileUploaderOptions) {
constructor(uploader: FileUploader, some: File, options: FileUploaderOptions) {
this.uploader = uploader;
this.some = some;
this.options = options;
@@ -38,7 +38,7 @@ export class FileItem {
this.url = uploader.options.url;
}
public upload(): void {
upload(): void {
try {
this.uploader.uploadItem(this);
} catch (e) {
@@ -47,43 +47,43 @@ export class FileItem {
}
}
public cancel(): void {
cancel(): void {
this.uploader.cancelItem(this);
}
public remove(): void {
remove(): void {
this.uploader.removeFromQueue(this);
}
public onBeforeUpload(): void {
onBeforeUpload(): void {
return void 0;
}
public onBuildForm(form: any): any {
onBuildForm(form: any): any {
return { form };
}
public onProgress(progress: number): any {
onProgress(progress: number): any {
return { progress };
}
public onSuccess(response: string, status: number, headers: ParsedResponseHeaders): any {
onSuccess(response: string, status: number, headers: ParsedResponseHeaders): any {
return { response, status, headers };
}
public onError(response: string, status: number, headers: ParsedResponseHeaders): any {
onError(response: string, status: number, headers: ParsedResponseHeaders): any {
return { response, status, headers };
}
public onCancel(response: string, status: number, headers: ParsedResponseHeaders): any {
onCancel(response: string, status: number, headers: ParsedResponseHeaders): any {
return { response, status, headers };
}
public onComplete(response: string, status: number, headers: ParsedResponseHeaders): any {
onComplete(response: string, status: number, headers: ParsedResponseHeaders): any {
return { response, status, headers };
}
public _onBeforeUpload(): void {
_onBeforeUpload(): void {
this.isReady = true;
this.isUploading = true;
this.isUploaded = false;
@@ -94,16 +94,16 @@ export class FileItem {
this.onBeforeUpload();
}
public _onBuildForm(form: any): void {
_onBuildForm(form: any): void {
this.onBuildForm(form);
}
public _onProgress(progress: number): void {
_onProgress(progress: number): void {
this.progress = progress;
this.onProgress(progress);
}
public _onSuccess(response: string, status: number, headers: ParsedResponseHeaders): void {
_onSuccess(response: string, status: number, headers: ParsedResponseHeaders): void {
this.isReady = false;
this.isUploading = false;
this.isUploaded = true;
@@ -115,7 +115,7 @@ export class FileItem {
this.onSuccess(response, status, headers);
}
public _onError(response: string, status: number, headers: ParsedResponseHeaders): void {
_onError(response: string, status: number, headers: ParsedResponseHeaders): void {
this.isReady = false;
this.isUploading = false;
this.isUploaded = true;
@@ -127,7 +127,7 @@ export class FileItem {
this.onError(response, status, headers);
}
public _onCancel(response: string, status: number, headers: ParsedResponseHeaders): void {
_onCancel(response: string, status: number, headers: ParsedResponseHeaders): void {
this.isReady = false;
this.isUploading = false;
this.isUploaded = false;
@@ -139,7 +139,7 @@ export class FileItem {
this.onCancel(response, status, headers);
}
public _onComplete(response: string, status: number, headers: ParsedResponseHeaders): void {
_onComplete(response: string, status: number, headers: ParsedResponseHeaders): void {
this.onComplete(response, status, headers);
if (this.uploader.options.removeAfterUpload) {
@@ -147,7 +147,7 @@ export class FileItem {
}
}
public _prepareToUploading(): void {
_prepareToUploading(): void {
this.index = this.index || ++this.uploader._nextIndex;
this.isReady = true;
}

View File

@@ -1,31 +1,26 @@
function isElement(node: any): boolean {
return !!(node && (node.nodeName || node.prop && node.attr && node.find));
}
export class FileLikeObject {
public lastModifiedDate: any;
public size: any;
public type?: string;
public name?: string;
public rawFile: string;
lastModifiedDate: any;
size: any;
type?: string;
name?: string;
rawFile: HTMLInputElement | File;
public constructor(fileOrInput: any) {
constructor(fileOrInput: HTMLInputElement | File) {
this.rawFile = fileOrInput;
const isInput = isElement(fileOrInput);
const fakePathOrObject = isInput ? fileOrInput.value : fileOrInput;
const fakePathOrObject = fileOrInput instanceof HTMLInputElement ? fileOrInput.value : fileOrInput;
const postfix = typeof fakePathOrObject === 'string' ? 'FakePath' : 'Object';
const method = '_createFrom' + postfix;
const method = `_createFrom${postfix}`;
(this as any)[ method ](fakePathOrObject);
}
public _createFromFakePath(path: string): void {
_createFromFakePath(path: string): void {
this.lastModifiedDate = void 0;
this.size = void 0;
this.type = 'like/' + path.slice(path.lastIndexOf('.') + 1).toLowerCase();
this.type = `like/${path.slice(path.lastIndexOf('.') + 1).toLowerCase()}`;
this.name = path.slice(path.lastIndexOf('/') + path.lastIndexOf('\\') + 2);
}
public _createFromObject(object: { size: number, type: string, name: string }): void {
_createFromObject(object: { size: number, type: string, name: string }): void {
this.size = object.size;
this.type = object.type;
this.name = object.name;

View File

@@ -1,39 +1,37 @@
import { Directive, EventEmitter, ElementRef, Input, HostListener, Output } from '@angular/core';
import {FileUploader, FileUploaderOptions} from './file-uploader.class';
import { FileUploader, FileUploaderOptions } from './file-uploader.class';
@Directive({ selector: '[ng2FileSelect]' })
export class FileSelectDirective {
@Input() public uploader?: FileUploader;
@Input() uploader?: FileUploader;
// eslint-disable-next-line @angular-eslint/no-output-on-prefix
@Output() public onFileSelected: EventEmitter<File[]> = new EventEmitter<File[]>();
@Output() onFileSelected: EventEmitter<File[]> = new EventEmitter<File[]>();
protected element: ElementRef;
public constructor(element: ElementRef) {
constructor(element: ElementRef) {
this.element = element;
}
public getOptions(): FileUploaderOptions | void {
getOptions(): FileUploaderOptions | undefined {
return this.uploader?.options;
}
public getFilters(): any {
return {};
getFilters(): string {
return '';
}
public isEmptyAfterSelection(): boolean {
isEmptyAfterSelection(): boolean {
return !!this.element.nativeElement.attributes.multiple;
}
@HostListener('change')
public onChange(): any {
onChange(): void {
const files = this.element.nativeElement.files;
const options = this.getOptions();
const filters = this.getFilters();
if (options) {
this.uploader?.addToQueue(files, options, filters);
}
this.uploader?.addToQueue(files, options, filters);
this.onFileSelected.emit(files);
if (this.isEmptyAfterSelection()) {

View File

@@ -1,8 +1,9 @@
import { FileLikeObject } from "../index";
import { FileLikeObject } from '../index';
export class FileType {
/* MS office */
public static mime_doc: string[] = [
// tslint:disable-next-line:variable-name
static mime_doc: string[] = [
'application/msword',
'application/msword',
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
@@ -10,7 +11,8 @@ export class FileType {
'application/vnd.ms-word.document.macroEnabled.12',
'application/vnd.ms-word.template.macroEnabled.12'
];
public static mime_xsl: string[] = [
// tslint:disable-next-line:variable-name
static mime_xsl: string[] = [
'application/vnd.ms-excel',
'application/vnd.ms-excel',
'application/vnd.ms-excel',
@@ -21,7 +23,8 @@ export class FileType {
'application/vnd.ms-excel.addin.macroEnabled.12',
'application/vnd.ms-excel.sheet.binary.macroEnabled.12'
];
public static mime_ppt: string[] = [
// tslint:disable-next-line:variable-name
static mime_ppt: string[] = [
'application/vnd.ms-powerpoint',
'application/vnd.ms-powerpoint',
'application/vnd.ms-powerpoint',
@@ -36,7 +39,8 @@ export class FileType {
];
/* PSD */
public static mime_psd: string[] = [
// tslint:disable-next-line:variable-name
static mime_psd: string[] = [
'image/photoshop',
'image/x-photoshop',
'image/psd',
@@ -46,7 +50,8 @@ export class FileType {
];
/* Compressed files */
public static mime_compress: string[] = [
// tslint:disable-next-line:variable-name
static mime_compress: string[] = [
'application/x-gtar',
'application/x-gcompress',
'application/compress',
@@ -60,7 +65,7 @@ export class FileType {
'application/x-bzip2'
];
public static getMimeClass(file: FileLikeObject): string {
static getMimeClass(file: FileLikeObject): string {
let mimeClass = 'application';
if (file?.type && this.mime_psd.indexOf(file.type) !== -1) {
mimeClass = 'image';
@@ -88,66 +93,66 @@ export class FileType {
return mimeClass;
}
public static fileTypeDetection(inputFilename: string): string {
static fileTypeDetection(inputFilename: string): string {
const types: { [ key: string ]: string } = {
'jpg': 'image',
'jpeg': 'image',
'tif': 'image',
'psd': 'image',
'bmp': 'image',
'png': 'image',
'nef': 'image',
'tiff': 'image',
'cr2': 'image',
'dwg': 'image',
'cdr': 'image',
'ai': 'image',
'indd': 'image',
'pin': 'image',
'cdp': 'image',
'skp': 'image',
'stp': 'image',
jpg: 'image',
jpeg: 'image',
tif: 'image',
psd: 'image',
bmp: 'image',
png: 'image',
nef: 'image',
tiff: 'image',
cr2: 'image',
dwg: 'image',
cdr: 'image',
ai: 'image',
indd: 'image',
pin: 'image',
cdp: 'image',
skp: 'image',
stp: 'image',
'3dm': 'image',
'mp3': 'audio',
'wav': 'audio',
'wma': 'audio',
'mod': 'audio',
'm4a': 'audio',
'compress': 'compress',
'zip': 'compress',
'rar': 'compress',
mp3: 'audio',
wav: 'audio',
wma: 'audio',
mod: 'audio',
m4a: 'audio',
compress: 'compress',
zip: 'compress',
rar: 'compress',
'7z': 'compress',
'lz': 'compress',
'z01': 'compress',
'bz2': 'compress',
'gz': 'compress',
'pdf': 'pdf',
'xls': 'xls',
'xlsx': 'xls',
'ods': 'xls',
'mp4': 'video',
'avi': 'video',
'wmv': 'video',
'mpg': 'video',
'mts': 'video',
'flv': 'video',
lz: 'compress',
z01: 'compress',
bz2: 'compress',
gz: 'compress',
pdf: 'pdf',
xls: 'xls',
xlsx: 'xls',
ods: 'xls',
mp4: 'video',
avi: 'video',
wmv: 'video',
mpg: 'video',
mts: 'video',
flv: 'video',
'3gp': 'video',
'vob': 'video',
'm4v': 'video',
'mpeg': 'video',
'm2ts': 'video',
'mov': 'video',
'doc': 'doc',
'docx': 'doc',
'eps': 'doc',
'txt': 'doc',
'odt': 'doc',
'rtf': 'doc',
'ppt': 'ppt',
'pptx': 'ppt',
'pps': 'ppt',
'ppsx': 'ppt',
'odp': 'ppt'
vob: 'video',
m4v: 'video',
mpeg: 'video',
m2ts: 'video',
mov: 'video',
doc: 'doc',
docx: 'doc',
eps: 'doc',
txt: 'doc',
odt: 'doc',
rtf: 'doc',
ppt: 'ppt',
pptx: 'ppt',
pps: 'ppt',
ppsx: 'ppt',
odp: 'ppt'
};
const chunks = inputFilename.split('.');

View File

@@ -12,12 +12,12 @@ export interface Headers {
value: string;
}
export type ParsedResponseHeaders = { [ headerFieldName: string ]: string };
export interface ParsedResponseHeaders { [ headerFieldName: string ]: string }
export type FilterFunction = {
name: string,
fn: (item: FileLikeObject, options?: FileUploaderOptions) => boolean
};
export interface FilterFunction {
name: string;
fn(item: FileLikeObject, options?: FileUploaderOptions): boolean;
}
export interface FileUploaderOptions {
allowedMimeType?: string[];
@@ -31,7 +31,7 @@ export interface FileUploaderOptions {
maxFileSize?: number;
queueLimit?: number;
removeAfterUpload?: boolean;
url?: string;
url: string;
disableMultipart?: boolean;
itemAlias?: string;
authTokenHeader?: string;
@@ -44,33 +44,34 @@ export interface FileUploaderOptions {
export class FileUploader {
public authToken?: string;
public isUploading = false;
public queue: FileItem[] = [];
public progress = 0;
public _nextIndex = 0;
public autoUpload: any;
public authTokenHeader?: string;
public response: EventEmitter<any>;
authToken?: string;
isUploading = false;
queue: FileItem[] = [];
progress = 0;
_nextIndex = 0;
autoUpload: any;
authTokenHeader?: string;
response: EventEmitter<any>;
public options: FileUploaderOptions = {
options: FileUploaderOptions = {
autoUpload: false,
isHTML5: true,
filters: [],
removeAfterUpload: false,
disableMultipart: false,
formatDataFunction: (item: FileItem) => item._file,
formatDataFunctionIsAsync: false
formatDataFunctionIsAsync: false,
url: ''
};
protected _failFilterIndex?: number;
public constructor(options: FileUploaderOptions) {
constructor(options: FileUploaderOptions) {
this.setOptions(options);
this.response = new EventEmitter<any>();
this.response = new EventEmitter<string>();
}
public setOptions(options: FileUploaderOptions): void {
setOptions(options: FileUploaderOptions): void {
this.options = Object.assign(this.options, options);
this.authToken = this.options.authToken;
@@ -78,8 +79,8 @@ export class FileUploader {
this.autoUpload = this.options.autoUpload;
this.options.filters?.unshift({ name: 'queueLimit', fn: this._queueLimitFilter });
if (this.options.maxFileSize && this.options.filters) {
this.options.filters.unshift({ name: 'fileSize', fn: this._fileSizeFilter });
if (this.options.maxFileSize) {
this.options.filters?.unshift({ name: 'fileSize', fn: this._fileSizeFilter });
}
if (this.options.allowedFileType) {
@@ -95,7 +96,8 @@ export class FileUploader {
}
}
public addToQueue(files: File[], options?: FileUploaderOptions, filters?: FilterFunction[] | string): void {
addToQueue(files: File[], _options?: FileUploaderOptions, filters?: [] | string): void {
let options = _options;
const list: File[] = [];
for (const file of files) {
list.push(file);
@@ -131,7 +133,7 @@ export class FileUploader {
}
}
public removeFromQueue(value: FileItem): void {
removeFromQueue(value: FileItem): void {
const index = this.getIndexOfItem(value);
const item = this.queue[ index ];
if (item.isUploading) {
@@ -141,14 +143,14 @@ export class FileUploader {
this.progress = this._getTotalProgress();
}
public clearQueue(): void {
clearQueue(): void {
while (this.queue.length) {
this.queue[ 0 ].remove();
}
this.progress = 0;
}
public uploadItem(value: FileItem): void {
uploadItem(value: FileItem): void {
const index = this.getIndexOfItem(value);
const item = this.queue[ index ];
const transport = this.options.isHTML5 ? '_xhrTransport' : '_iframeTransport';
@@ -160,7 +162,7 @@ export class FileUploader {
(this as any)[ transport ](item);
}
public cancelItem(value: FileItem): void {
cancelItem(value: FileItem): void {
const index = this.getIndexOfItem(value);
const item = this.queue[ index ];
const prop = this.options.isHTML5 ? item._xhr : item._form;
@@ -169,7 +171,7 @@ export class FileUploader {
}
}
public uploadAll(): void {
uploadAll(): void {
const items = this.getNotUploadedItems().filter((item: FileItem) => !item.isUploading);
if (!items.length) {
return;
@@ -178,110 +180,111 @@ export class FileUploader {
items[ 0 ].upload();
}
public cancelAll(): void {
cancelAll(): void {
const items = this.getNotUploadedItems();
items.map((item: FileItem) => item.cancel());
}
public isFile(value: any): boolean {
isFile(value: any): boolean {
return isFile(value);
}
public isFileLikeObject(value: any): boolean {
isFileLikeObject(value: any): boolean {
return value instanceof FileLikeObject;
}
public getIndexOfItem(value: any): number {
getIndexOfItem(value: any): number {
return typeof value === 'number' ? value : this.queue.indexOf(value);
}
public getNotUploadedItems(): any[] {
getNotUploadedItems(): any[] {
return this.queue.filter((item: FileItem) => !item.isUploaded);
}
public getReadyItems(): any[] {
getReadyItems(): any[] {
return this.queue
.filter((item: FileItem) => (item.isReady && !item.isUploading))
.sort((item1: any, item2: any) => item1.index - item2.index);
}
public destroy(): void {
return void 0;
destroy(): void {
return undefined;
}
public onAfterAddingAll(fileItems: any): any {
onAfterAddingAll(fileItems: any): any {
return { fileItems };
}
public onBuildItemForm(fileItem: FileItem, form: any): any {
onBuildItemForm(fileItem: FileItem, form: any): any {
return { fileItem, form };
}
public onAfterAddingFile(fileItem: FileItem): any {
onAfterAddingFile(fileItem: FileItem): any {
return { fileItem };
}
public onWhenAddingFileFailed(item: FileLikeObject, filter: any, options: any): any {
onWhenAddingFileFailed(item: FileLikeObject, filter: any, options: any): any {
return { item, filter, options };
}
public onBeforeUploadItem(fileItem: FileItem): any {
onBeforeUploadItem(fileItem: FileItem): any {
return { fileItem };
}
public onProgressItem(fileItem: FileItem, progress: any): any {
onProgressItem(fileItem: FileItem, progress: any): any {
return { fileItem, progress };
}
public onProgressAll(progress: any): any {
onProgressAll(progress: any): any {
return { progress };
}
public onSuccessItem(item: FileItem, response: string, status: number, headers: ParsedResponseHeaders): any {
onSuccessItem(item: FileItem, response: string, status: number, headers: ParsedResponseHeaders): any {
return { item, response, status, headers };
}
public onErrorItem(item: FileItem, response: string, status: number, headers: ParsedResponseHeaders): any {
onErrorItem(item: FileItem, response: string, status: number, headers: ParsedResponseHeaders): any {
return { item, response, status, headers };
}
public onCancelItem(item: FileItem, response: string, status: number, headers: ParsedResponseHeaders): any {
onCancelItem(item: FileItem, response: string, status: number, headers: ParsedResponseHeaders): any {
return { item, response, status, headers };
}
public onCompleteItem(item: FileItem, response: string, status: number, headers: ParsedResponseHeaders): any {
onCompleteItem(item: FileItem, response: string, status: number, headers: ParsedResponseHeaders): any {
return { item, response, status, headers };
}
public onCompleteAll(): any {
onCompleteAll(): any {
return void 0;
}
public _mimeTypeFilter(item: FileLikeObject): boolean {
_mimeTypeFilter(item: FileLikeObject): boolean {
return !(item?.type && this.options.allowedMimeType && this.options.allowedMimeType?.indexOf(item.type) === -1);
}
public _fileSizeFilter(item: FileLikeObject): boolean {
_fileSizeFilter(item: FileLikeObject): boolean {
return !(this.options.maxFileSize && item.size > this.options.maxFileSize);
}
public _fileTypeFilter(item: FileLikeObject): boolean {
_fileTypeFilter(item: FileLikeObject): boolean {
return !(this.options.allowedFileType &&
this.options.allowedFileType.indexOf(FileType.getMimeClass(item)) === -1);
}
public _onErrorItem(item: FileItem, response: string, status: number, headers: ParsedResponseHeaders): void {
_onErrorItem(item: FileItem, response: string, status: number, headers: ParsedResponseHeaders): void {
item._onError(response, status, headers);
this.onErrorItem(item, response, status, headers);
}
public _onCompleteItem(item: FileItem, response: string, status: number, headers: ParsedResponseHeaders): void {
_onCompleteItem(item: FileItem, response: string, status: number, headers: ParsedResponseHeaders): void {
item._onComplete(response, status, headers);
this.onCompleteItem(item, response, status, headers);
const nextItem = this.getReadyItems()[ 0 ];
this.isUploading = false;
if (nextItem) {
nextItem.upload();
return;
}
this.onCompleteAll();
@@ -294,12 +297,14 @@ export class FileUploader {
if (name) {
return parsedHeaders[ name.toLowerCase() ] || void 0;
}
return parsedHeaders;
};
}
protected _xhrTransport(item: FileItem): any {
// eslint-disable-next-line @typescript-eslint/no-this-alias
// tslint:disable-next-line:no-this-assignment
const that = this;
const xhr = item._xhr = new XMLHttpRequest();
let sendable: any;
@@ -312,11 +317,9 @@ export class FileUploader {
sendable = new FormData();
this._onBuildItemForm(item, sendable);
let appendFile;
if (item.alias && item._file && item.file.name) {
appendFile = () => sendable.append(item.alias, item._file, item.file.name);
if (!this.options.parametersBeforeFiles) {
appendFile();
}
appendFile = () => sendable.append(item.alias, item._file, item.file.name);
if (!this.options.parametersBeforeFiles) {
appendFile();
}
// For AWS, Additional Parameters must come BEFORE Files
@@ -348,7 +351,7 @@ export class FileUploader {
const headers = this._parseHeaders(xhr.getAllResponseHeaders());
const response = this._transformResponse(xhr.response, headers);
const gist = this._isSuccessCode(xhr.status) ? 'Success' : 'Error';
const method = '_on' + gist + 'Item';
const method = `_on${gist}Item`;
(this as any)[ method ](item, response, xhr.status, headers);
this._onCompleteItem(item, response, xhr.status, headers);
};
@@ -416,9 +419,11 @@ export class FileUploader {
}
if (typeof filters === 'string') {
const names = filters.match(/[^\s,]+/g);
return this.options?.filters || []
.filter((filter: any) => names?.indexOf(filter.name) !== -1);
}
return this.options?.filters || [];
}
@@ -432,10 +437,12 @@ export class FileUploader {
protected _isValidFile(file: FileLikeObject, filters: FilterFunction[], options: FileUploaderOptions): boolean {
this._failFilterIndex = -1;
return !filters.length ? true : filters.every((filter: FilterFunction) => {
if (typeof this._failFilterIndex === 'number') {
if (this._failFilterIndex) {
this._failFilterIndex++;
}
return filter.fn.call(this, file, options);
});
}
@@ -464,6 +471,7 @@ export class FileUploader {
parsed[ key ] = parsed[ key ] ? parsed[ key ] + ', ' + val : val;
}
});
return parsed;
}

View File

@@ -1,4 +1,8 @@
{
"name": "ng2-file-upload",
"version": "1.3.0"
"version": "1.3.0",
"peerDependencies": {
"@angular/common": "*",
"@angular/core": "*"
}
}

View File

@@ -1,80 +0,0 @@
// Karma configuration file, see link for more information
// https://karma-runner.github.io/0.13/config/configuration-file.html
const customLaunchers = require('./sauce-browsers').customLaunchers;
module.exports = function (config) {
const configuration = {
basePath: '',
frameworks: ['jasmine', '@angular-devkit/build-angular'],
plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-coverage-istanbul-reporter'),
require('@angular-devkit/build-angular/plugins/karma')
],
coverageIstanbulReporter: {
dir: require('path').join(__dirname, '../coverage'), reports: [ 'html', 'lcovonly' ],
fixWebpackSourcePaths: false
},
reporters: ['dots', 'coverage-istanbul'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
browserNoActivityTimeout: 20000,
browserDisconnectTolerance: 2,
browserDisconnectTimeout: 5000,
singleRun: true,
customLaunchers: {
Chrome_travis_ci: {
base: 'ChromeHeadless',
flags: [
'--headless',
'--disable-gpu',
'--no-sandbox',
'--remote-debugging-port=9222'
]
}
},
mime: { 'text/x-typescript': ['ts','tsx'] },
client: { captureConsole: true }
};
if (process.env.TRAVIS) {
configuration.browsers = ['Chrome_travis_ci'];
}
if (process.env.SAUCE) {
if (!process.env.SAUCE_USERNAME || !process.env.SAUCE_ACCESS_KEY) {
console.log('Make sure the SAUCE_USERNAME and SAUCE_ACCESS_KEY environment variables are set.');
process.exit(1);
}
configuration.plugins.push(require('karma-sauce-launcher'));
configuration.reporters.push('saucelabs');
configuration.sauceLabs = {
verbose: true,
testName: 'ng2-bootstrap unit tests',
recordScreenshots: false,
username: process.env.SAUCE_USERNAME,
accessKey: process.env.SAUCE_ACCESS_KEY,
connectOptions: {
port: 5757,
logfile: 'sauce_connect.log'
},
public: 'public'
};
configuration.captureTimeout = 60000;
configuration.customLaunchers = customLaunchers();
configuration.browsers = Object.keys(configuration.customLaunchers);
configuration.concurrency = 4;
configuration.browserDisconnectTolerance = 2;
configuration.browserNoActivityTimeout = 20000;
configuration.browserDisconnectTimeout = 5000;
}
config.set(configuration);
};

View File

@@ -1,21 +0,0 @@
// tslint:disable
/**
* @copyright Angular ng-bootstrap team
*/
beforeEach(() => {
jasmine.addMatchers({
toHaveCssClass(/*util, customEqualityTests*/) {
return {compare: buildError(false), negativeCompare: buildError(true)};
function buildError(isNot) {
return function (actual, className) {
const orNot = isNot ? 'not ' : '';
return {
pass: actual.classList.contains(className) === !isNot,
message: `Expected ${actual.outerHTML} ${orNot} to contain the CSS class "${className}"`
};
};
}
}
});
});

View File

@@ -1,18 +0,0 @@
module.exports.customLaunchers = function customLaunchers() {
return {
sl_chrome: {base: 'SauceLabs', browserName: 'chrome'},
sl_chrome_1: {base: 'SauceLabs', browserName: 'chrome', version: 'latest-1'},
sl_firefox: {base: 'SauceLabs', browserName: 'firefox'},
sl_firefox_1: {base: 'SauceLabs', browserName: 'firefox', version: 'latest-1'},
sl_ie9: {base: 'SauceLabs', browserName: 'internet explorer', platform: 'Windows 2008', version: '9'},
'SL_IE10': {base: 'SauceLabs', browserName: 'internet explorer', platform: 'Windows 2012', version: '10'},
'SL_IE11': {base: 'SauceLabs', browserName: 'internet explorer', platform: 'Windows 8.1', version: '11'},
'SL_EDGE': {base: 'SauceLabs', browserName: 'MicrosoftEdge', platform: 'Windows 10', version: '13.10586'},
'SL_IOS9': {base: 'SauceLabs', browserName: 'iphone', platform: 'OS X 10.10', version: '9.3'},
'SL_IOS10': {base: 'SauceLabs', browserName: 'iphone', platform: 'OS X 10.10', version: '10.0'},
'SL_ANDROID4.4': {base: 'SauceLabs', browserName: 'android', platform: 'Linux', version: '4.4'},
'SL_ANDROID5': {base: 'SauceLabs', browserName: 'android', platform: 'Linux', version: '5.1'},
'SL_SAFARI9': {base: 'SauceLabs', browserName: 'safari', platform: 'OS X 10.11', version: '9.0'}
};
};

View File

@@ -1,37 +0,0 @@
import '../scripts/polyfills.ts';
import 'zone.js/dist/long-stack-trace-zone';
import 'zone.js/dist/proxy.js';
import 'zone.js/dist/sync-test';
import 'zone.js/dist/jasmine-patch';
import 'zone.js/dist/async-test';
import 'zone.js/dist/fake-async-test';
import { getTestBed } from '@angular/core/testing';
import {
BrowserDynamicTestingModule,
platformBrowserDynamicTesting
} from '@angular/platform-browser-dynamic/testing';
import './matchers';
// Unfortunately there's no typing for the `__karma__` variable. Just declare it as any.
declare let __karma__: any;
declare let require: any;
// Prevent Karma from running prematurely.
__karma__.loaded = Function.prototype;
// First, initialize the Angular testing environment.
getTestBed().initTestEnvironment(
BrowserDynamicTestingModule,
platformBrowserDynamicTesting()
);
// Then we find all the tests.
const context = require.context('../demo/src', true, /\.spec\.ts/);
// And load the modules.
context.keys().map(context);
const context2 = require.context('../src/spec', true, /\.spec\.ts/);
context2.keys().map(context2);
// Finally, start Karma to run the tests.
__karma__.start();

View File

@@ -1,22 +0,0 @@
{
"compilerOptions": {
"experimentalDecorators": true,
"module": "esnext",
"moduleResolution": "node",
"target": "es2015",
"outDir": "./out-tsc/spec",
"types": [
"jasmine",
"node"
]
},
"files": [
"../scripts/typings.d.ts",
"test.ts",
"../scripts/polyfills.ts",
],
"include": [
"../src/**/*.spec.ts",
"../demo/src/**/*.spec.ts"
]
}