Compare commits
13 Commits
duykhang53
...
vmachavolu
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2d240804f5 | ||
|
|
8171bc831b | ||
|
|
d63c8ce9e2 | ||
|
|
33ac156208 | ||
|
|
2888f4cb11 | ||
|
|
7a342268bb | ||
|
|
6cb3f87e57 | ||
|
|
49a3334942 | ||
|
|
9fae840b69 | ||
|
|
7b4f871200 | ||
|
|
268534b3e1 | ||
|
|
77f2466f17 | ||
|
|
01c2d173f3 |
@@ -1,57 +0,0 @@
|
||||
{
|
||||
"project": {
|
||||
"name": "ng2-file-upload"
|
||||
},
|
||||
"apps": [
|
||||
{
|
||||
"root": "demo/src",
|
||||
"outDir": "demo/dist",
|
||||
"assets": [
|
||||
"assets"
|
||||
],
|
||||
"index": "index.html",
|
||||
"main": "main.ts",
|
||||
"test": "../../scripts/test.ts",
|
||||
"tsconfig": "tsconfig.json",
|
||||
"prefix": "",
|
||||
"mobile": false,
|
||||
"styles": [
|
||||
],
|
||||
"scripts": [
|
||||
],
|
||||
"environmentSource": "environments/environment.ts",
|
||||
"environments": {
|
||||
"dev": "environments/environment.ts",
|
||||
"prod": "environments/environment.prod.ts"
|
||||
}
|
||||
}
|
||||
],
|
||||
"addons": [],
|
||||
"packages": [],
|
||||
"e2e": {
|
||||
"protractor": {
|
||||
"config": "protractor.conf.js"
|
||||
}
|
||||
},
|
||||
"test": {
|
||||
"karma": {
|
||||
"config": "karma.conf.js"
|
||||
}
|
||||
},
|
||||
"defaults": {
|
||||
"styleExt": "css",
|
||||
"prefixInterfaces": false,
|
||||
"inline": {
|
||||
"style": false,
|
||||
"template": false
|
||||
},
|
||||
"spec": {
|
||||
"class": false,
|
||||
"component": true,
|
||||
"directive": true,
|
||||
"module": false,
|
||||
"pipe": true,
|
||||
"service": true
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,13 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- "10.15.0"
|
||||
- "10"
|
||||
|
||||
sudo: required
|
||||
services:
|
||||
- xvfb
|
||||
|
||||
before_install:
|
||||
- google-chrome-stable --headless --disable-gpu --remote-debugging-port=9222 http://localhost &
|
||||
- export CHROME_BIN=chromium-browser
|
||||
- export DISPLAY=:99.0
|
||||
|
||||
script:
|
||||
- npm run pretest
|
||||
@@ -17,7 +17,6 @@ after_success:
|
||||
- ./node_modules/.bin/codecov
|
||||
|
||||
addons:
|
||||
chrome: stable
|
||||
firefox: "latest"
|
||||
apt:
|
||||
sources:
|
||||
|
||||
@@ -63,7 +63,7 @@ Easy to use Angular2 directives for files upload ([demo](http://valor-software.g
|
||||
1. `url` - URL of File Uploader's route
|
||||
2. `authToken` - Auth token that will be applied as 'Authorization' header during file send.
|
||||
3. `disableMultipart` - If 'true', disable using a multipart form for file upload and instead stream the file. Some APIs (e.g. Amazon S3) may expect the file to be streamed rather than sent via a form. Defaults to false.
|
||||
4. `itemAlias` - item alias (form name redefenition)
|
||||
4. `itemAlias` - item alias (form name redefinition)
|
||||
5. `formatDataFunction` - Function to modify the request body. 'DisableMultipart' must be 'true' for this function to be called.
|
||||
6. `formatDataFunctionIsAsync` - Informs if the function sent in 'formatDataFunction' is asynchronous. Defaults to false.
|
||||
7. `parametersBeforeFiles` - States if additional parameters should be appended before or after the file. Defaults to false.
|
||||
@@ -77,7 +77,7 @@ Easy to use Angular2 directives for files upload ([demo](http://valor-software.g
|
||||
|
||||
# Troubleshooting
|
||||
|
||||
Please follow this guidelines when reporting bugs and feature requests:
|
||||
Please follow these guidelines when reporting bugs and feature requests:
|
||||
|
||||
1. Use [GitHub Issues](https://github.com/valor-software/ng2-file-upload/issues) board to report bugs and feature requests (not our email address)
|
||||
2. Please **always** write steps to reproduce the error. That way we can focus on fixing the bug, not scratching our heads trying to reproduce it.
|
||||
|
||||
112
angular.json
Normal file
112
angular.json
Normal file
@@ -0,0 +1,112 @@
|
||||
{
|
||||
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
|
||||
"version": 1,
|
||||
"newProjectRoot": "projects",
|
||||
"projects": {
|
||||
"ng2-file-upload": {
|
||||
"root": ".",
|
||||
"sourceRoot": "src",
|
||||
"projectType": "library",
|
||||
"architect": {
|
||||
"build": {
|
||||
"builder": "@angular-devkit/build-ng-packagr:build",
|
||||
"options": {
|
||||
"tsConfig": "src/tsconfig.json",
|
||||
"project": "src/ng-package.json"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"ng2-file-upload-demo": {
|
||||
"root": "demo",
|
||||
"sourceRoot": "demo/src",
|
||||
"projectType": "application",
|
||||
"architect": {
|
||||
"build": {
|
||||
"builder": "@angular-devkit/build-angular:browser",
|
||||
"options": {
|
||||
"outputPath": "demo/dist",
|
||||
"index": "demo/src/index.html",
|
||||
"main": "demo/src/main.ts",
|
||||
"tsConfig": "demo/src/tsconfig.json",
|
||||
"assets": [
|
||||
"demo/src/assets"
|
||||
],
|
||||
"styles": [],
|
||||
"scripts": []
|
||||
},
|
||||
"configurations": {
|
||||
"production": {
|
||||
"optimization": true,
|
||||
"outputHashing": "all",
|
||||
"sourceMap": false,
|
||||
"extractCss": true,
|
||||
"namedChunks": false,
|
||||
"aot": true,
|
||||
"extractLicenses": true,
|
||||
"vendorChunk": false,
|
||||
"buildOptimizer": true,
|
||||
"fileReplacements": [
|
||||
{
|
||||
"replace": "demo/src/environments/environment.ts",
|
||||
"with": "demo/src/environments/environment.prod.ts"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"serve": {
|
||||
"builder": "@angular-devkit/build-angular:dev-server",
|
||||
"options": {
|
||||
"browserTarget": "ng2-file-upload-demo:build"
|
||||
},
|
||||
"configurations": {
|
||||
"production": {
|
||||
"browserTarget": "ng2-file-upload-demo:build:production"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"ng2-file-upload-test": {
|
||||
"root": ".",
|
||||
"sourceRoot": "test",
|
||||
"projectType": "library",
|
||||
"architect": {
|
||||
"test": {
|
||||
"builder": "@angular-devkit/build-angular:karma",
|
||||
"options": {
|
||||
"main": "test/test.ts",
|
||||
"karmaConfig": "test/karma.conf.js",
|
||||
"scripts": [],
|
||||
"styles": [],
|
||||
"tsConfig": "test/tsconfig.json"
|
||||
}
|
||||
},
|
||||
"lint": {
|
||||
"builder": "@angular-devkit/build-angular:tslint",
|
||||
"options": {
|
||||
"tsConfig": [
|
||||
"src/tsconfig.json",
|
||||
"demo/src/tsconfig.json",
|
||||
"test/tsconfig.json"
|
||||
],
|
||||
"exclude": [
|
||||
"**/node_modules/**"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"defaultProject": "ng2-file-upload-demo",
|
||||
"schematics": {
|
||||
"@schematics/angular:component": {
|
||||
"prefix": "",
|
||||
"styleext": "css"
|
||||
},
|
||||
"@schematics/angular:directive": {
|
||||
"prefix": ""
|
||||
}
|
||||
}
|
||||
}
|
||||
12
demo/browserslist
Normal file
12
demo/browserslist
Normal file
@@ -0,0 +1,12 @@
|
||||
# This file is used by the build system to adjust CSS and JS output to support the specified browsers below.
|
||||
# For additional information regarding the format and rule options, please see:
|
||||
# https://github.com/browserslist/browserslist#queries
|
||||
|
||||
# You can see what browsers were selected by your queries by running:
|
||||
# npx browserslist
|
||||
|
||||
> 0.5%
|
||||
last 2 versions
|
||||
Firefox ESR
|
||||
not dead
|
||||
not IE 9-11 # For IE 9-11 support, remove 'not'.
|
||||
@@ -5,9 +5,9 @@ let doc = require('html-loader!markdown-loader!../../doc.md');
|
||||
let tabDesc:Array<any> = [
|
||||
{
|
||||
heading: 'Simple',
|
||||
ts: require('!!raw-loader?lang=typescript!./file-upload/simple-demo.ts'),
|
||||
html: require('!!raw-loader?lang=markup!./file-upload/simple-demo.html'),
|
||||
js: require('!!raw-loader?lang=javascript!./file-upload/file-catcher.js')
|
||||
ts: require('!!raw-loader!./file-upload/simple-demo.ts').default,
|
||||
html: require('!!raw-loader!./file-upload/simple-demo.html').default,
|
||||
js: require('!!raw-loader!./file-upload/file-catcher.js').default
|
||||
}
|
||||
];
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import './polyfills.ts';
|
||||
import '../../scripts/polyfills.ts';
|
||||
|
||||
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
|
||||
import { enableProdMode } from '@angular/core';
|
||||
|
||||
@@ -1,22 +1,25 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"baseUrl": ".",
|
||||
"declaration": false,
|
||||
"downlevelIteration": true,
|
||||
"emitDecoratorMetadata": true,
|
||||
"experimentalDecorators": true,
|
||||
"noEmitHelpers": false,
|
||||
"lib": ["es6", "dom"],
|
||||
"types": [
|
||||
"jasmine",
|
||||
"webpack"
|
||||
],
|
||||
"mapRoot": "./",
|
||||
"module": "es6",
|
||||
"module": "esnext",
|
||||
"moduleResolution": "node",
|
||||
"outDir": "../temp/out-tsc",
|
||||
"sourceMap": true,
|
||||
"target": "es5",
|
||||
"typeRoots": [
|
||||
"../node_modules/@types"
|
||||
]
|
||||
}
|
||||
"target": "es2015"
|
||||
},
|
||||
"files": [
|
||||
"../../scripts/typings.d.ts",
|
||||
"main.ts",
|
||||
"../../scripts/polyfills.ts"
|
||||
],
|
||||
"exclude": [
|
||||
"**/*.spec.ts"
|
||||
]
|
||||
}
|
||||
|
||||
16
demo/src/typings.d.ts
vendored
16
demo/src/typings.d.ts
vendored
@@ -1,16 +0,0 @@
|
||||
// Typings reference file, you can add your own global typings here
|
||||
// https://www.typescriptlang.org/docs/handbook/writing-declaration-files.html
|
||||
// tslint:disable
|
||||
declare const System: any;
|
||||
declare const ENV:string;
|
||||
// google code-prettify
|
||||
declare const PR:any;
|
||||
|
||||
// declare const require:any;
|
||||
// declare const global:any;
|
||||
|
||||
declare module jasmine {
|
||||
interface Matchers {
|
||||
toHaveCssClass(expected: any): boolean;
|
||||
}
|
||||
}
|
||||
11824
package-lock.json
generated
11824
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
92
package.json
92
package.json
@@ -7,24 +7,21 @@
|
||||
"lite-server": "lite-server -c demo/bs-config.json",
|
||||
"demo.serve": "run-s build link demo.build lite-server",
|
||||
"demo.gh-pages": "run-s build demo.build demo.deploy",
|
||||
"demo.build": "ng build -prod --aot",
|
||||
"demo.build": "ng build ng2-file-upload-demo --prod",
|
||||
"demo.deploy": "gh-pages -d demo/dist",
|
||||
"link": "ngm link -p src --here",
|
||||
"link": "cd dist/ng2-file-upload/ && npm link && cd ../../ && npm link ng2-file-upload",
|
||||
"lint": "exit 0",
|
||||
"disable-lint": "tslint \"**/*.ts\" -c tslint.json --fix --type-check -t prose -e \"node_modules/**\" -e \"dist/**\" -e \"temp/**\" -e \"scripts/docs/**\"",
|
||||
"flow.changelog": "conventional-changelog -i CHANGELOG.md -s -p angular",
|
||||
"flow.github-release": "conventional-github-releaser -p angular",
|
||||
"build": "ngm build -p src --clean",
|
||||
"build.watch": "ngm build -p src --watch --skip-bundles",
|
||||
"start": "ng serve --aot",
|
||||
"build": "ng build ng2-file-upload",
|
||||
"build.watch": "ng build ng2-file-upload --watch",
|
||||
"start": "ng serve ng2-file-upload-demo --aot",
|
||||
"pretest": "run-s lint build link",
|
||||
"test": "ng test -sr",
|
||||
"test-coverage": "ng test -sr -cc",
|
||||
"test": "ng test ng2-file-upload-test",
|
||||
"test-coverage": "ng test ng2-file-upload-test --code-coverage",
|
||||
"version": "npm run flow.changelog && git add -A"
|
||||
},
|
||||
"main": "bundles/ng2-file-upload.umd.js",
|
||||
"module": "index.js",
|
||||
"typings": "index.d.ts",
|
||||
"keywords": [
|
||||
"angular2",
|
||||
"bootstrap",
|
||||
@@ -43,33 +40,29 @@
|
||||
"url": "https://github.com/valor-software/ng2-file-upload/issues"
|
||||
},
|
||||
"homepage": "https://github.com/valor-software/ng2-file-upload#readme",
|
||||
"dependencies": {},
|
||||
"peerDependencies": {
|
||||
"@angular/common": "^2.3.1 || >=4.0.0",
|
||||
"@angular/core": "^2.3.1 || >=4.0.0"
|
||||
},
|
||||
"peerDependencies": {},
|
||||
"devDependencies": {
|
||||
"@angular/cli": "1.0.0",
|
||||
"@angular/common": "2.4.3",
|
||||
"@angular/compiler": "2.4.3",
|
||||
"@angular/compiler-cli": "2.4.3",
|
||||
"@angular/core": "2.4.3",
|
||||
"@angular/forms": "2.4.3",
|
||||
"@angular/http": "2.4.3",
|
||||
"@angular/language-service": "2.4.3",
|
||||
"@angular/platform-browser": "2.4.3",
|
||||
"@angular/platform-browser-dynamic": "2.4.3",
|
||||
"@angular/router": "3.4.3",
|
||||
"@angular/tsc-wrapped": "0.5.1",
|
||||
"@angular-devkit/build-angular": "~0.803.0",
|
||||
"@angular-devkit/build-ng-packagr": "^0.803.0",
|
||||
"@angular/cli": "^8.3.0",
|
||||
"@angular/common": "^8.2.3",
|
||||
"@angular/compiler": "^8.2.3",
|
||||
"@angular/compiler-cli": "^8.2.3",
|
||||
"@angular/core": "^8.2.3",
|
||||
"@angular/forms": "^8.2.3",
|
||||
"@angular/language-service": "8.2.3",
|
||||
"@angular/platform-browser": "^8.2.3",
|
||||
"@angular/platform-browser-dynamic": "^8.2.3",
|
||||
"@angular/router": "^8.2.3",
|
||||
"@types/jasmine": "2.5.40",
|
||||
"@types/marked": "0.0.28",
|
||||
"@types/node": "7.0.0",
|
||||
"@types/webpack": "^2.2.1",
|
||||
"@types/webpack": "^3.8.18",
|
||||
"bootstrap": "3.3.7",
|
||||
"chokidar-cli": "1.2.0",
|
||||
"classlist-polyfill": "1.0.3",
|
||||
"codecov": "1.0.1",
|
||||
"codelyzer": "~2.0.0-beta.4",
|
||||
"codelyzer": "^5.0.1",
|
||||
"conventional-changelog-cli": "1.2.0",
|
||||
"conventional-github-releaser": "1.1.3",
|
||||
"core-js": "^2.4.1",
|
||||
@@ -79,41 +72,41 @@
|
||||
"gh-pages": "0.12.0",
|
||||
"gitignore-to-glob": "0.3.0",
|
||||
"google-code-prettify": "1.0.5",
|
||||
"html-loader": "0.4.4",
|
||||
"jasmine": "2.5.3",
|
||||
"jasmine-core": "2.5.2",
|
||||
"html-loader": "^0.5.5",
|
||||
"jasmine-core": "3.1.0",
|
||||
"jasmine-data-provider": "2.2.0",
|
||||
"jasmine-spec-reporter": "3.2.0",
|
||||
"karma": "^4.2.0",
|
||||
"karma-chrome-launcher": "^3.1.0",
|
||||
"jasmine-spec-reporter": "4.2.1",
|
||||
"karma": "4.1.0",
|
||||
"karma-chrome-launcher": "2.2.0",
|
||||
"karma-cli": "^1.0.1",
|
||||
"karma-coverage-istanbul-reporter": "^1.3.0",
|
||||
"karma-jasmine": "^1.0.2",
|
||||
"karma-remap-istanbul": "0.4.0",
|
||||
"karma-sauce-launcher": "1.1.0",
|
||||
"karma-coverage-istanbul-reporter": "1.4.3",
|
||||
"karma-jasmine": "1.1.2",
|
||||
"karma-remap-istanbul": "0.6.0",
|
||||
"karma-sauce-launcher": "1.2.0",
|
||||
"lite-server": "2.2.2",
|
||||
"lodash": "4.17.4",
|
||||
"markdown-loader": "^0.1.7",
|
||||
"markdown-loader": "^5.1.0",
|
||||
"marked": "0.3.6",
|
||||
"ng2-page-scroll": "4.0.0-beta.2",
|
||||
"ngm-cli": "0.4.0",
|
||||
"ng-packagr": "^5.5.0",
|
||||
"ngx-bootstrap": "1.6.6",
|
||||
"npm-run-all": "^4.0.1",
|
||||
"pre-commit": "1.2.2",
|
||||
"protractor": "5.0.0",
|
||||
"raw-loader": "^3.1.0",
|
||||
"reflect-metadata": "0.1.9",
|
||||
"require-dir": "0.3.1",
|
||||
"rxjs": "5.0.3",
|
||||
"rxjs": "^6.5.2",
|
||||
"systemjs-builder": "0.15.34",
|
||||
"ts-helpers": "^1.1.1",
|
||||
"ts-node": "2.0.0",
|
||||
"tslint": "4.3.1",
|
||||
"tslint-config-valorsoft": "1.2.0",
|
||||
"tsickle": "^0.37.0",
|
||||
"tslint": "^5.19.0",
|
||||
"tslint-config-valorsoft": "^2.2.1",
|
||||
"typedoc": "0.5.5",
|
||||
"typescript": "2.1.5",
|
||||
"typescript": "3.5.3",
|
||||
"wallaby-webpack": "0.0.30",
|
||||
"webdriver-manager": "11.1.1",
|
||||
"zone.js": "0.7.5"
|
||||
"zone.js": "~0.9.1"
|
||||
},
|
||||
"contributors": [
|
||||
{
|
||||
@@ -136,5 +129,8 @@
|
||||
"email": "otelnov@gmail.com",
|
||||
"url": "https://github.com/otelnov"
|
||||
}
|
||||
]
|
||||
],
|
||||
"dependencies": {
|
||||
"tslib": "^1.10.0"
|
||||
}
|
||||
}
|
||||
|
||||
1
scripts/.gitignore
vendored
1
scripts/.gitignore
vendored
@@ -1 +0,0 @@
|
||||
!**/*.js
|
||||
@@ -1,14 +1,12 @@
|
||||
import { Directive, ElementRef, EventEmitter, HostListener, Input, Output } from '@angular/core';
|
||||
import { Directive, EventEmitter, ElementRef, HostListener, Input, Output } from '@angular/core';
|
||||
|
||||
import { FileUploader, FileUploaderOptions, FilterFunction } from './file-uploader.class';
|
||||
import { FileUploader, FileUploaderOptions } from './file-uploader.class';
|
||||
|
||||
@Directive({ selector: '[ng2FileDrop]' })
|
||||
export class FileDropDirective {
|
||||
@Input() public uploader: FileUploader;
|
||||
// tslint:disable-next-line:no-input-rename
|
||||
@Input('ng2FileFilter') public filter: FilterFunction['fn'];
|
||||
@Output() public fileOver: EventEmitter<any> = new EventEmitter();
|
||||
@Output() public onFileDrop: EventEmitter<FileList> = new EventEmitter<FileList>();
|
||||
@Output() public onFileDrop: EventEmitter<File[]> = new EventEmitter<File[]>();
|
||||
|
||||
protected element: ElementRef;
|
||||
|
||||
@@ -24,7 +22,7 @@ export class FileDropDirective {
|
||||
return {};
|
||||
}
|
||||
|
||||
@HostListener('drop', ['$event'])
|
||||
@HostListener('drop', [ '$event' ])
|
||||
public onDrop(event: any): void {
|
||||
let transfer = this._getTransfer(event);
|
||||
if (!transfer) {
|
||||
@@ -32,17 +30,14 @@ export class FileDropDirective {
|
||||
}
|
||||
|
||||
let options = this.getOptions();
|
||||
let filters = typeof this.filter === 'function' ? [{
|
||||
name: 'ng2FileDropDirectiveFilter',
|
||||
fn: this.filter
|
||||
}, ...options.filters] : this.getFilters();
|
||||
let filters = this.getFilters();
|
||||
this._preventAndStop(event);
|
||||
this.uploader.addToQueue(transfer.files, options, filters);
|
||||
this.fileOver.emit(false);
|
||||
this.onFileDrop.emit(transfer.files);
|
||||
}
|
||||
|
||||
@HostListener('dragover', ['$event'])
|
||||
@HostListener('dragover', [ '$event' ])
|
||||
public onDragOver(event: any): void {
|
||||
let transfer = this._getTransfer(event);
|
||||
if (!this._haveFiles(transfer.types)) {
|
||||
@@ -54,10 +49,10 @@ export class FileDropDirective {
|
||||
this.fileOver.emit(true);
|
||||
}
|
||||
|
||||
@HostListener('dragleave', ['$event'])
|
||||
@HostListener('dragleave', [ '$event' ])
|
||||
public onDragLeave(event: any): any {
|
||||
if ((this as any).element) {
|
||||
if (event.currentTarget === (this as any).element[0]) {
|
||||
if (event.currentTarget === (this as any).element[ 0 ]) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -66,11 +61,11 @@ export class FileDropDirective {
|
||||
this.fileOver.emit(false);
|
||||
}
|
||||
|
||||
protected _getTransfer(event: any): DragEvent['dataTransfer'] {
|
||||
protected _getTransfer(event: any): any {
|
||||
return event.dataTransfer ? event.dataTransfer : event.originalEvent.dataTransfer; // jQuery fix;
|
||||
}
|
||||
|
||||
protected _preventAndStop(event: Event): any {
|
||||
protected _preventAndStop(event: any): any {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
}
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
import { Directive, ElementRef, EventEmitter, HostListener, Input, Output } from '@angular/core';
|
||||
import { Directive, EventEmitter, ElementRef, Input, HostListener, Output } from '@angular/core';
|
||||
|
||||
import { FileUploader, FilterFunction } from './file-uploader.class';
|
||||
import { FileUploader } from './file-uploader.class';
|
||||
|
||||
@Directive({ selector: '[ng2FileSelect]' })
|
||||
export class FileSelectDirective {
|
||||
@Input() public uploader: FileUploader;
|
||||
// tslint:disable-next-line:no-input-rename
|
||||
@Input('ng2FileFilter') public filter: FilterFunction['fn'];
|
||||
@Output() public onFileSelected: EventEmitter<File[]> = new EventEmitter<File[]>();
|
||||
|
||||
protected element: ElementRef;
|
||||
@@ -31,10 +29,7 @@ export class FileSelectDirective {
|
||||
public onChange(): any {
|
||||
let files = this.element.nativeElement.files;
|
||||
let options = this.getOptions();
|
||||
let filters = typeof this.filter === 'function' ? [{
|
||||
name: 'ng2FileSelectDirectiveFilter',
|
||||
fn: this.filter
|
||||
}, ...options.filters] : this.getFilters();
|
||||
let filters = this.getFilters();
|
||||
|
||||
this.uploader.addToQueue(files, options, filters);
|
||||
this.onFileSelected.emit(files);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { FileLikeObject } from "../ng2-file-upload";
|
||||
import { FileLikeObject } from "../index";
|
||||
|
||||
export class FileType {
|
||||
/* MS office */
|
||||
@@ -125,6 +125,7 @@ export class FileType {
|
||||
'xls': 'xls',
|
||||
'xlsx': 'xls',
|
||||
'ods': 'xls',
|
||||
'csv': 'xls',
|
||||
'mp4': 'video',
|
||||
'avi': 'video',
|
||||
'wmv': 'video',
|
||||
|
||||
@@ -12,11 +12,11 @@ export interface Headers {
|
||||
value: string;
|
||||
}
|
||||
|
||||
export type ParsedResponseHeaders = { [headerFieldName: string]: string };
|
||||
export type ParsedResponseHeaders = { [ headerFieldName: string ]: string };
|
||||
|
||||
export interface FilterFunction {
|
||||
name: string;
|
||||
fn(this: FileUploader, item?: FileLikeObject, options?: FileUploaderOptions, queueIndex?: number): boolean | Promise<boolean>;
|
||||
export type FilterFunction = {
|
||||
name: string,
|
||||
fn: (item?: FileLikeObject, options?: FileUploaderOptions) => boolean
|
||||
};
|
||||
|
||||
export interface FileUploaderOptions {
|
||||
@@ -35,7 +35,7 @@ export interface FileUploaderOptions {
|
||||
disableMultipart?: boolean;
|
||||
itemAlias?: string;
|
||||
authTokenHeader?: string;
|
||||
additionalParameter?: { [key: string]: any };
|
||||
additionalParameter?: { [ key: string ]: any };
|
||||
parametersBeforeFiles?: boolean;
|
||||
formatDataFunction?: Function;
|
||||
formatDataFunctionIsAsync?: boolean;
|
||||
@@ -89,39 +89,35 @@ export class FileUploader {
|
||||
this.options.filters.unshift({ name: 'mimeType', fn: this._mimeTypeFilter });
|
||||
}
|
||||
|
||||
for (const q of this.queue) {
|
||||
q.url = this.options.url;
|
||||
for (let i = 0; i < this.queue.length; i++) {
|
||||
this.queue[ i ].url = this.options.url;
|
||||
}
|
||||
}
|
||||
|
||||
public async addToQueue(files: FileList, options?: FileUploaderOptions, filters?: FilterFunction[] | string): Promise<void> {
|
||||
public addToQueue(files: File[], options?: FileUploaderOptions, filters?: FilterFunction[] | string): void {
|
||||
let list: File[] = [];
|
||||
// tslint:disable-next-line:prefer-for-of
|
||||
for (let i = 0; i < files.length; i++) {
|
||||
list.push(files[i]);
|
||||
for (let file of files) {
|
||||
list.push(file);
|
||||
}
|
||||
|
||||
let arrayOfFilters = this._getFilters(filters);
|
||||
let count = this.queue.length;
|
||||
let addedFileItems: FileItem[] = [];
|
||||
let idx = 0;
|
||||
|
||||
for (const some of list) {
|
||||
list.map((some: File) => {
|
||||
if (!options) {
|
||||
options = this.options;
|
||||
}
|
||||
|
||||
let temp = new FileLikeObject(some);
|
||||
if (await this._isValidFile(temp, arrayOfFilters, options, idx++)) {
|
||||
if (this._isValidFile(temp, arrayOfFilters, options)) {
|
||||
let fileItem = new FileItem(this, some, options);
|
||||
addedFileItems.push(fileItem);
|
||||
this.queue.push(fileItem);
|
||||
this._onAfterAddingFile(fileItem);
|
||||
} else {
|
||||
let filter = arrayOfFilters[this._failFilterIndex];
|
||||
let filter = arrayOfFilters[ this._failFilterIndex ];
|
||||
this._onWhenAddingFileFailed(temp, filter, options);
|
||||
}
|
||||
}
|
||||
});
|
||||
if (this.queue.length !== count) {
|
||||
this._onAfterAddingAll(addedFileItems);
|
||||
this.progress = this._getTotalProgress();
|
||||
@@ -134,7 +130,7 @@ export class FileUploader {
|
||||
|
||||
public removeFromQueue(value: FileItem): void {
|
||||
let index = this.getIndexOfItem(value);
|
||||
let item = this.queue[index];
|
||||
let item = this.queue[ index ];
|
||||
if (item.isUploading) {
|
||||
item.cancel();
|
||||
}
|
||||
@@ -144,26 +140,26 @@ export class FileUploader {
|
||||
|
||||
public clearQueue(): void {
|
||||
while (this.queue.length) {
|
||||
this.queue[0].remove();
|
||||
this.queue[ 0 ].remove();
|
||||
}
|
||||
this.progress = 0;
|
||||
}
|
||||
|
||||
public uploadItem(value: FileItem): void {
|
||||
let index = this.getIndexOfItem(value);
|
||||
let item = this.queue[index];
|
||||
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);
|
||||
(this as any)[ transport ](item);
|
||||
}
|
||||
|
||||
public cancelItem(value: FileItem): void {
|
||||
let index = this.getIndexOfItem(value);
|
||||
let item = this.queue[index];
|
||||
let item = this.queue[ index ];
|
||||
let prop = this.options.isHTML5 ? item._xhr : item._form;
|
||||
if (item && item.isUploading) {
|
||||
prop.abort();
|
||||
@@ -176,7 +172,7 @@ export class FileUploader {
|
||||
return;
|
||||
}
|
||||
items.map((item: FileItem) => item._prepareToUploading());
|
||||
items[0].upload();
|
||||
items[ 0 ].upload();
|
||||
}
|
||||
|
||||
public cancelAll(): void {
|
||||
@@ -279,7 +275,7 @@ export class FileUploader {
|
||||
public _onCompleteItem(item: FileItem, response: string, status: number, headers: ParsedResponseHeaders): void {
|
||||
item._onComplete(response, status, headers);
|
||||
this.onCompleteItem(item, response, status, headers);
|
||||
let nextItem = this.getReadyItems()[0];
|
||||
let nextItem = this.getReadyItems()[ 0 ];
|
||||
this.isUploading = false;
|
||||
if (nextItem) {
|
||||
nextItem.upload();
|
||||
@@ -293,7 +289,7 @@ export class FileUploader {
|
||||
protected _headersGetter(parsedHeaders: ParsedResponseHeaders): any {
|
||||
return (name: any): any => {
|
||||
if (name) {
|
||||
return parsedHeaders[name.toLowerCase()] || void 0;
|
||||
return parsedHeaders[ name.toLowerCase() ] || void 0;
|
||||
}
|
||||
return parsedHeaders;
|
||||
};
|
||||
@@ -320,7 +316,7 @@ export class FileUploader {
|
||||
// For AWS, Additional Parameters must come BEFORE Files
|
||||
if (this.options.additionalParameter !== undefined) {
|
||||
Object.keys(this.options.additionalParameter).forEach((key: string) => {
|
||||
let paramVal = this.options.additionalParameter[key];
|
||||
let paramVal = this.options.additionalParameter[ key ];
|
||||
// Allow an additional parameter to include the filename
|
||||
if (typeof paramVal === 'string' && paramVal.indexOf('{{file_name}}') >= 0) {
|
||||
paramVal = paramVal.replace('{{file_name}}', item.file.name);
|
||||
@@ -345,7 +341,7 @@ export class FileUploader {
|
||||
let response = this._transformResponse(xhr.response, headers);
|
||||
let gist = this._isSuccessCode(xhr.status) ? 'Success' : 'Error';
|
||||
let method = '_on' + gist + 'Item';
|
||||
(this as any)[method](item, response, xhr.status, headers);
|
||||
(this as any)[ method ](item, response, xhr.status, headers);
|
||||
this._onCompleteItem(item, response, xhr.status, headers);
|
||||
};
|
||||
xhr.onerror = () => {
|
||||
@@ -375,11 +371,11 @@ export class FileUploader {
|
||||
if (this.authToken) {
|
||||
xhr.setRequestHeader(this.authTokenHeader, this.authToken);
|
||||
}
|
||||
xhr.onreadystatechange = function (): void {
|
||||
if (xhr.readyState === XMLHttpRequest.DONE) {
|
||||
that.response.emit(xhr.responseText);
|
||||
xhr.onreadystatechange = function () {
|
||||
if (xhr.readyState == XMLHttpRequest.DONE) {
|
||||
that.response.emit(xhr.responseText)
|
||||
}
|
||||
};
|
||||
}
|
||||
if (this.options.formatDataFunctionIsAsync) {
|
||||
sendable.then(
|
||||
(result: any) => xhr.send(JSON.stringify(result))
|
||||
@@ -424,18 +420,12 @@ export class FileUploader {
|
||||
return this.options.queueLimit === undefined || this.queue.length < this.options.queueLimit;
|
||||
}
|
||||
|
||||
protected async _isValidFile(file: FileLikeObject, filters: FilterFunction[], options: FileUploaderOptions, queueIndex: number): Promise<boolean> {
|
||||
protected _isValidFile(file: FileLikeObject, filters: FilterFunction[], options: FileUploaderOptions): boolean {
|
||||
this._failFilterIndex = -1;
|
||||
|
||||
for (const filter of filters) {
|
||||
return !filters.length ? true : filters.every((filter: FilterFunction) => {
|
||||
this._failFilterIndex++;
|
||||
|
||||
if (!(await Promise.resolve(filter.fn.call(this, file, options, queueIndex)))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
return filter.fn.call(this, file, options);
|
||||
});
|
||||
}
|
||||
|
||||
protected _isSuccessCode(status: number): boolean {
|
||||
@@ -459,7 +449,7 @@ export class FileUploader {
|
||||
key = line.slice(0, i).trim().toLowerCase();
|
||||
val = line.slice(i + 1).trim();
|
||||
if (key) {
|
||||
parsed[key] = parsed[key] ? parsed[key] + ', ' + val : val;
|
||||
parsed[ key ] = parsed[ key ] ? parsed[ key ] + ', ' + val : val;
|
||||
}
|
||||
});
|
||||
return parsed;
|
||||
|
||||
7
src/ng-package.json
Normal file
7
src/ng-package.json
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"$schema": "../node_modules/ng-packagr/ng-package.schema.json",
|
||||
"dest": "../dist/ng2-file-upload",
|
||||
"lib": {
|
||||
"entryFile": "index.ts"
|
||||
}
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
export * from './index';
|
||||
@@ -1,8 +1,9 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"baseUrl": ".",
|
||||
"outDir": "../dist",
|
||||
"target": "es5",
|
||||
"module": "commonjs",
|
||||
"module": "esnext",
|
||||
"moduleResolution": "node",
|
||||
"emitDecoratorMetadata": true,
|
||||
"experimentalDecorators": true,
|
||||
@@ -14,24 +15,19 @@
|
||||
"stripInternal": true,
|
||||
"noUnusedLocals": false,
|
||||
"noUnusedParameters": false,
|
||||
"lib": ["dom", "es6"],
|
||||
"types": [
|
||||
"jasmine",
|
||||
"webpack"
|
||||
],
|
||||
"typeRoots": [
|
||||
"../node_modules/@types"
|
||||
]
|
||||
"lib": ["dom", "es6"]
|
||||
},
|
||||
"exclude": [
|
||||
"node_modules"
|
||||
],
|
||||
"files": [
|
||||
"../scripts/typings.d.ts",
|
||||
"./ng2-file-upload.ts",
|
||||
"./index.ts"
|
||||
],
|
||||
"angularCompilerOptions": {
|
||||
"genDir": "../temp/factories"
|
||||
}
|
||||
"annotateForClosureCompiler": true,
|
||||
"strictMetadataEmit": true,
|
||||
"skipTemplateCodegen": true,
|
||||
"flatModuleOutFile": "ng2-file-upload.js",
|
||||
"flatModuleId": "ng2-file-upload"
|
||||
},
|
||||
"include": [
|
||||
"../scripts/typings.d.ts"
|
||||
],
|
||||
"exclude": [
|
||||
"**/*.spec.ts"
|
||||
]
|
||||
}
|
||||
|
||||
@@ -1,45 +1,42 @@
|
||||
// Karma configuration file, see link for more information
|
||||
// https://karma-runner.github.io/0.13/config/configuration-file.html
|
||||
|
||||
const customLaunchers = require('./scripts/sauce-browsers').customLaunchers;
|
||||
const customLaunchers = require('./sauce-browsers').customLaunchers;
|
||||
|
||||
module.exports = function (config) {
|
||||
const configuration = {
|
||||
basePath: '',
|
||||
frameworks: ['jasmine', '@angular/cli'],
|
||||
frameworks: ['jasmine', '@angular-devkit/build-angular'],
|
||||
plugins: [
|
||||
require('karma-jasmine'),
|
||||
require('karma-chrome-launcher'),
|
||||
require('karma-coverage-istanbul-reporter'),
|
||||
require('@angular/cli/plugins/karma')
|
||||
require('@angular-devkit/build-angular/plugins/karma')
|
||||
],
|
||||
files: [
|
||||
{pattern: './scripts/test.ts', watched: false}
|
||||
],
|
||||
preprocessors: {
|
||||
'./scripts/test.ts': ['@angular/cli']
|
||||
},
|
||||
coverageIstanbulReporter: {
|
||||
reports: [ 'html', 'lcovonly' ],
|
||||
dir: require('path').join(__dirname, '../coverage'), reports: [ 'html', 'lcovonly' ],
|
||||
fixWebpackSourcePaths: false
|
||||
},
|
||||
angularCli: {
|
||||
config: './angular-cli.json',
|
||||
environment: 'dev'
|
||||
},
|
||||
reporters: config.angularCli && config.angularCli.codeCoverage
|
||||
? ['dots', 'coverage-istanbul']
|
||||
: ['dots'],
|
||||
|
||||
reporters: ['dots', 'coverage-istanbul'],
|
||||
port: 9876,
|
||||
colors: true,
|
||||
logLevel: config.LOG_INFO,
|
||||
autoWatch: true,
|
||||
browsers: ['Chrome'],
|
||||
singleRun: false,
|
||||
browsers: ['ChromeHeadless'],
|
||||
browserNoActivityTimeout: 20000,
|
||||
browserDisconnectTolerance: 2,
|
||||
browserDisconnectTimeout: 5000,
|
||||
singleRun: true,
|
||||
customLaunchers: {
|
||||
Chrome_travis_ci: {
|
||||
base: 'Chrome',
|
||||
flags: ['--no-sandbox']
|
||||
base: 'ChromeHeadless',
|
||||
flags: [
|
||||
'--headless',
|
||||
'--disable-gpu',
|
||||
'--no-sandbox',
|
||||
'--remote-debugging-port=9222'
|
||||
]
|
||||
}
|
||||
},
|
||||
mime: { 'text/x-typescript': ['ts','tsx'] },
|
||||
@@ -48,7 +45,6 @@ module.exports = function (config) {
|
||||
|
||||
if (process.env.TRAVIS) {
|
||||
configuration.browsers = ['Chrome_travis_ci'];
|
||||
configuration.singleRun = true;
|
||||
}
|
||||
|
||||
if (process.env.SAUCE) {
|
||||
@@ -71,10 +67,10 @@ module.exports = function (config) {
|
||||
},
|
||||
public: 'public'
|
||||
};
|
||||
configuration.captureTimeout = 0;
|
||||
configuration.captureTimeout = 60000;
|
||||
configuration.customLaunchers = customLaunchers();
|
||||
configuration.browsers = Object.keys(configuration.customLaunchers);
|
||||
configuration.concurrency = 3;
|
||||
configuration.concurrency = 4;
|
||||
configuration.browserDisconnectTolerance = 2;
|
||||
configuration.browserNoActivityTimeout = 20000;
|
||||
configuration.browserDisconnectTimeout = 5000;
|
||||
@@ -1,4 +1,4 @@
|
||||
import '../demo/src/polyfills.ts';
|
||||
import '../scripts/polyfills.ts';
|
||||
|
||||
import 'zone.js/dist/long-stack-trace-zone';
|
||||
import 'zone.js/dist/proxy.js';
|
||||
22
test/tsconfig.json
Normal file
22
test/tsconfig.json
Normal file
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"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"
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user