feat(core): added nx

This commit is contained in:
svetlanaMuravlova
2021-08-31 12:18:44 +03:00
parent 69cd64dc28
commit de738f7c63
69 changed files with 11483 additions and 615 deletions

60
.eslintrc.json Normal file
View File

@@ -0,0 +1,60 @@
{
"root": true,
"ignorePatterns": [
"**/*"
],
"plugins": [
"@nrwl/nx"
],
"overrides": [
{
"files": [
"*.ts",
"*.tsx",
"*.js",
"*.jsx"
],
"rules": {
"@nrwl/nx/enforce-module-boundaries": [
"error",
{
"enforceBuildableLibDependency": true,
"allow": [],
"depConstraints": [
{
"sourceTag": "*",
"onlyDependOnLibsWithTags": [
"*"
]
}
]
}
]
}
},
{
"files": [
"*.ts",
"*.tsx"
],
"extends": [
"plugin:@nrwl/nx/typescript"
],
"parserOptions": { "project": "./tsconfig.*?.json" },
"rules": {
"semi": "off",
"@typescript-eslint/semi": ["error"]
}
},
{
"files": [
"*.js",
"*.jsx"
],
"extends": [
"plugin:@nrwl/nx/javascript"
],
"rules": {}
}
]
}

View File

@@ -1,3 +1,21 @@
# [1.3.0](https://github.com/valor-software/ng2-file-upload/compare/v1.2.0...v1.3.0) (2021-08-31)
### Bug Fixes
* **ci:** fix xvfb service issue ([33ac156](https://github.com/valor-software/ng2-file-upload/commit/33ac156208bfcf57851210f037719107e1ca9eb9))
* **style:** delete extra rule ([b5917b9](https://github.com/valor-software/ng2-file-upload/commit/b5917b9fa77e63c4c1b06598abc817b8033730c3))
* **typo:** fix grammatical mistake in readme ([#1119](https://github.com/valor-software/ng2-file-upload/issues/1119)) ([8171bc8](https://github.com/valor-software/ng2-file-upload/commit/8171bc831b69692d04b650be19ff82f04ff56662))
### Features
* **bump:** added strict mode, doesn't build in dist, should be resolved ([69cd64d](https://github.com/valor-software/ng2-file-upload/commit/69cd64dc287c9bdd1c35af1062e27ce32a47e977))
* **package:** relaxed peer dependencies to allow ng v4 ([#713](https://github.com/valor-software/ng2-file-upload/issues/713)) ([7704e0e](https://github.com/valor-software/ng2-file-upload/commit/7704e0e970276ebcd8bfefe34bf153f82108a11e))
* **upgrade:** updated up to angular 11 tests are failed ([ce9dc20](https://github.com/valor-software/ng2-file-upload/commit/ce9dc20056cc6c7cd58e502af05d7d97043c8f3a))
<a name="1.3.0"></a>
# [1.3.0](https://github.com/valor-software/ng2-file-upload/compare/v1.2.0...v1.3.0) (2017-11-25)

View File

@@ -2,45 +2,87 @@
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"defaultProject": "ng2-file-upload-demo",
"projects": {
"ng2-file-upload": {
"root": ".",
"sourceRoot": "src",
"root": "libs/ng2-file-upload",
"sourceRoot": "libs/ng2-file-upload/src",
"projectType": "library",
"architect": {
"build": {
"builder": "@angular-devkit/build-ng-packagr:build",
"builder": "@nrwl/angular:package",
"outputs": [
"./dist/ng2-file-upload"
"dist/libs/ng2-file-upload"
],
"options": {
"tsConfig": "src/tsconfig.lib.json",
"project": "src/ng-package.json"
"tsConfig": "libs/ng2-file-upload/tsconfig.lib.json",
"project": "libs/ng2-file-upload/ng-package.json"
},
"configurations": {
"production": {
"tsConfig": "src/tsconfig.lib.prod.json"
"tsConfig": "libs/ng2-file-upload/tsconfig.lib.prod.json"
}
}
},
"lint": {
"builder": "@nrwl/linter:eslint",
"options": {
"lintFilePatterns": [
"libs/ng2-file-upload/**/*.ts"
]
}
},
"test": {
"builder": "@nrwl/jest:jest",
"outputs": [
"coverage/libs/ng2-file-upload"
],
"options": {
"jestConfig": "libs/ng2-file-upload/jest.config.js",
"passWithNoTests": true
}
},
"version": {
"builder": "@nrwl/workspace:run-commands",
"outputs": [
],
"options": {
"commands": [
"conventional-changelog -i CHANGELOG.md -s -p angular",
"git add -A"
],
"parallel": false
},
"configurations": {
"production": {}
}
}
}
},
"ng2-file-upload-demo": {
"root": "demo",
"sourceRoot": "demo/src",
"root": "apps/demo",
"sourceRoot": "apps/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"],
"outputPath": "dist/apps/demo",
"index": "apps/demo/src/index.html",
"main": "apps/demo/src/main.ts",
"tsConfig": "apps/demo/tsconfig.json",
"assets": [
"apps/demo/src/assets"
],
"styles": [],
"scripts": []
},
"dependsOn": [
{
"target": "build",
"projects": "dependencies"
}
],
"configurations": {
"production": {
"optimization": true,
@@ -54,8 +96,8 @@
"buildOptimizer": true,
"fileReplacements": [
{
"replace": "demo/src/environments/environment.ts",
"with": "demo/src/environments/environment.prod.ts"
"replace": "apps/demo/src/environments/environment.ts",
"with": "apps/demo/src/environments/environment.prod.ts"
}
]
}
@@ -71,33 +113,13 @@
"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",
"builder": "@nrwl/linter:eslint",
"options": {
"tsConfig": [
"src/tsconfig.json",
"demo/src/tsconfig.json",
"test/tsconfig.json"
],
"exclude": ["**/node_modules/**"]
"lintFilePatterns": [
"apps/demo/**/*.ts"
]
}
}
}

21
apps/demo/.eslintrc.json Normal file
View File

@@ -0,0 +1,21 @@
{
"extends": ["../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts"],
"extends": [
"plugin:@nrwl/nx/angular",
"plugin:@angular-eslint/template/process-inline-templates"
],
"parserOptions": { "project": ["src/accordion/tsconfig.*?.json"] },
"rules": {
}
},
{
"files": ["*.html"],
"extends": ["plugin:@nrwl/nx/angular-template"],
"rules": {}
}
]
}

4
apps/demo/bs-config.json Normal file
View File

@@ -0,0 +1,4 @@
{
"port": 4200,
"server": { "baseDir": "./dist/apps/demo" }
}

View File

@@ -1,6 +1,6 @@
import { Component } from '@angular/core';
let gettingStarted = require('html-loader!markdown-loader!../getting-started.md');
// eslint-disable-next-line @typescript-eslint/no-var-requires
const gettingStarted = require('html-loader!markdown-loader!../getting-started.md');
@Component({
selector: 'app',

View File

@@ -1,12 +1,15 @@
import { Component } from '@angular/core';
// eslint-disable-next-line @typescript-eslint/no-var-requires
const doc = require('html-loader!markdown-loader!../../doc.md');
let doc = require('html-loader!markdown-loader!../../doc.md');
let tabDesc:Array<any> = [
const tabDesc:Array<any> = [
{
heading: 'Simple',
// eslint-disable-next-line @typescript-eslint/no-var-requires
ts: require('!!raw-loader!./file-upload/simple-demo.ts').default,
// eslint-disable-next-line @typescript-eslint/no-var-requires
html: require('!!raw-loader!./file-upload/simple-demo.html').default,
// eslint-disable-next-line @typescript-eslint/no-var-requires
js: require('!!raw-loader!./file-upload/file-catcher.js').default
}
];
@@ -16,9 +19,9 @@ let tabDesc:Array<any> = [
templateUrl: './file-upload-section.html'
})
export class FileUploadSectionComponent {
public name:string = 'File Upload';
public currentHeading:string = 'Simple';
public doc:string = doc;
public name = 'File Upload';
public currentHeading = 'Simple';
public doc = doc;
public tabs:any = tabDesc;
public select(e:any):void {

View File

Before

Width:  |  Height:  |  Size: 106 KiB

After

Width:  |  Height:  |  Size: 106 KiB

View File

Before

Width:  |  Height:  |  Size: 5.3 KiB

After

Width:  |  Height:  |  Size: 5.3 KiB

View File

@@ -1,4 +1,4 @@
import '../../scripts/polyfills.ts';
import '../../../scripts/polyfills.ts';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';

View File

@@ -9,7 +9,7 @@ declare const ENV:string;
declare const PR:any;
// declare const global:any;
// eslint-disable-next-line @typescript-eslint/prefer-namespace-keyword
declare module jasmine {
interface Matchers<T> {
toHaveCssClass(expected: any): boolean;

View File

@@ -0,0 +1,8 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"types": ["node"]
},
"files": ["src/main.ts"]
}

View File

@@ -0,0 +1,7 @@
{
"extends": "./tsconfig.json",
"include": ["**/*.ts"],
"compilerOptions": {
"types": ["jest", "node"]
}
}

51
apps/demo/tsconfig.json Normal file
View File

@@ -0,0 +1,51 @@
{
"extends": "../../tsconfig.base.json",
"files": [
"./src/main.ts",
"../../scripts/polyfills.ts"
],
"include": ["./src/typings.d.ts"],
"references": [
{
"path": "./tsconfig.app.json"
},
{
"path": "./tsconfig.spec.json"
},
{
"path": "./tsconfig.editor.json"
}
],
"exclude": ["**/*.spec.ts"]
}
//{
// "compilerOptions": {
// "baseUrl": ".",
// "declaration": false,
// "downlevelIteration": true,
// "emitDecoratorMetadata": true,
// "experimentalDecorators": true,
// "noEmitHelpers": false,
// "lib": ["es6", "dom"],
// "mapRoot": "./",
// "module": "esnext",
// "moduleResolution": "node",
// "outDir": "../temp/out-tsc",
// "sourceMap": true,
// "target": "es2015"
// },
// "files": [
// "../../scripts/typings.d.ts",
// "main.ts",
// "../../scripts/polyfills.ts"
// ],
// "exclude": [
// "**/*.spec.ts"
// ],
// "paths": {
// "@ng2-file-upload": [
// "../../dist/ng2-file-upload/index.ts"
// ]
// }
//}

69
decorate-angular-cli.js Normal file
View File

@@ -0,0 +1,69 @@
/**
* This file decorates the Angular CLI with the Nx CLI to enable features such as computation caching
* and faster execution of tasks.
*
* It does this by:
*
* - Patching the Angular CLI to warn you in case you accidentally use the undecorated ng command.
* - Symlinking the ng to nx command, so all commands run through the Nx CLI
* - Updating the package.json postinstall script to give you control over this script
*
* The Nx CLI decorates the Angular CLI, so the Nx CLI is fully compatible with it.
* Every command you run should work the same when using the Nx CLI, except faster.
*
* Because of symlinking you can still type `ng build/test/lint` in the terminal. The ng command, in this case,
* will point to nx, which will perform optimizations before invoking ng. So the Angular CLI is always invoked.
* The Nx CLI simply does some optimizations before invoking the Angular CLI.
*
* To opt out of this patch:
* - Replace occurrences of nx with ng in your package.json
* - Remove the script from your postinstall script in your package.json
* - Delete and reinstall your node_modules
*/
const fs = require('fs');
const os = require('os');
const cp = require('child_process');
const isWindows = os.platform() === 'win32';
let output;
try {
output = require('@nrwl/workspace').output;
} catch (e) {
console.warn('Angular CLI could not be decorated to enable computation caching. Please ensure @nrwl/workspace is installed.');
process.exit(0);
}
/**
* Symlink of ng to nx, so you can keep using `ng build/test/lint` and still
* invoke the Nx CLI and get the benefits of computation caching.
*/
function symlinkNgCLItoNxCLI() {
try {
const ngPath = './node_modules/.bin/ng';
const nxPath = './node_modules/.bin/nx';
if (isWindows) {
/**
* This is the most reliable way to create symlink-like behavior on Windows.
* Such that it works in all shells and works with npx.
*/
['', '.cmd', '.ps1'].forEach(ext => {
if (fs.existsSync(nxPath + ext)) fs.writeFileSync(ngPath + ext, fs.readFileSync(nxPath + ext));
});
} else {
// If unix-based, symlink
cp.execSync(`ln -sf ./nx ${ngPath}`);
}
}
catch(e) {
output.error({ title: 'Unable to create a symlink from the Angular CLI to the Nx CLI:' + e.message });
throw e;
}
}
try {
symlinkNgCLItoNxCLI();
require('@nrwl/cli/lib/decorate-cli').decorateCli();
output.log({ title: 'Angular CLI has been decorated to enable computation caching.' });
} catch(e) {
output.error({ title: 'Decoration of the Angular CLI did not complete successfully' });
}

View File

@@ -1,4 +0,0 @@
{
"port": 4200,
"server": { "baseDir": "./demo/dist" }
}

View File

@@ -1,30 +0,0 @@
{
"compilerOptions": {
"baseUrl": ".",
"declaration": false,
"downlevelIteration": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"noEmitHelpers": false,
"lib": ["es6", "dom"],
"mapRoot": "./",
"module": "esnext",
"moduleResolution": "node",
"outDir": "../temp/out-tsc",
"sourceMap": true,
"target": "es2015"
},
"files": [
"../../scripts/typings.d.ts",
"main.ts",
"../../scripts/polyfills.ts"
],
"exclude": [
"**/*.spec.ts"
],
"paths": {
"@ng2-file-upload": [
"../../dist/ng2-file-upload/index.ts"
]
}
}

5
jest.config.js Normal file
View File

@@ -0,0 +1,5 @@
module.exports = {
projects: [
'<rootDir>/libs/ng2-file-upload'
]
};

7
jest.preset.js Normal file
View File

@@ -0,0 +1,7 @@
const nxPreset = require('@nrwl/jest/preset');
module.exports = {
...nxPreset,
...{
coverageReporters: ['text-summary', 'json', 'lcov']
}
}

View File

@@ -0,0 +1,21 @@
{
"extends": ["../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts"],
"extends": [
"plugin:@nrwl/nx/angular",
"plugin:@angular-eslint/template/process-inline-templates"
],
"parserOptions": { "project": ["src/accordion/tsconfig.*?.json"] },
"rules": {
}
},
{
"files": ["*.html"],
"extends": ["plugin:@nrwl/nx/angular-template"],
"rules": {}
}
]
}

View File

@@ -0,0 +1,10 @@
# libs-ng2-file-upload
This library was generated with [Nx](https://nx.dev).
## Running unit tests
Run `nx test libs-ng2-file-upload` to execute the unit tests via [Jest](https://jestjs.io).

View File

@@ -6,6 +6,7 @@ import { FileUploader, FileUploaderOptions } from './file-uploader.class';
export class FileDropDirective {
@Input() public uploader?: FileUploader;
@Output() public fileOver: EventEmitter<any> = new EventEmitter();
// eslint-disable-next-line @angular-eslint/no-output-on-prefix
@Output() public onFileDrop: EventEmitter<File[]> = new EventEmitter<File[]>();
protected element: ElementRef;
@@ -24,13 +25,13 @@ export class FileDropDirective {
@HostListener('drop', [ '$event' ])
public onDrop(event: any): void {
let transfer = this._getTransfer(event);
const transfer = this._getTransfer(event);
if (!transfer) {
return;
}
let options = this.getOptions();
let filters = this.getFilters();
const options = this.getOptions();
const filters = this.getFilters();
this._preventAndStop(event);
if (options) {
this.uploader?.addToQueue(transfer.files, options, filters);
@@ -41,7 +42,7 @@ export class FileDropDirective {
@HostListener('dragover', [ '$event' ])
public onDragOver(event: any): void {
let transfer = this._getTransfer(event);
const transfer = this._getTransfer(event);
if (!this._haveFiles(transfer.types)) {
return;
}

View File

@@ -8,15 +8,15 @@ export class FileItem {
public url? = '/';
public method?: string;
public headers: any = [];
public withCredentials: boolean = true;
public withCredentials = true;
public formData: any = [];
public isReady: boolean = false;
public isUploading: boolean = false;
public isUploaded: boolean = false;
public isSuccess: boolean = false;
public isCancel: boolean = false;
public isError: boolean = false;
public progress: number = 0;
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;

View File

@@ -11,10 +11,10 @@ export class FileLikeObject {
public constructor(fileOrInput: any) {
this.rawFile = fileOrInput;
let isInput = isElement(fileOrInput);
let fakePathOrObject = isInput ? fileOrInput.value : fileOrInput;
let postfix = typeof fakePathOrObject === 'string' ? 'FakePath' : 'Object';
let method = '_createFrom' + postfix;
const isInput = isElement(fileOrInput);
const fakePathOrObject = isInput ? fileOrInput.value : fileOrInput;
const postfix = typeof fakePathOrObject === 'string' ? 'FakePath' : 'Object';
const method = '_createFrom' + postfix;
(this as any)[ method ](fakePathOrObject);
}

View File

@@ -5,6 +5,7 @@ import {FileUploader, FileUploaderOptions} from './file-uploader.class';
@Directive({ selector: '[ng2FileSelect]' })
export class FileSelectDirective {
@Input() public uploader?: FileUploader;
// eslint-disable-next-line @angular-eslint/no-output-on-prefix
@Output() public onFileSelected: EventEmitter<File[]> = new EventEmitter<File[]>();
protected element: ElementRef;
@@ -27,9 +28,9 @@ export class FileSelectDirective {
@HostListener('change')
public onChange(): any {
let files = this.element.nativeElement.files;
let options = this.getOptions();
let filters = this.getFilters();
const files = this.element.nativeElement.files;
const options = this.getOptions();
const filters = this.getFilters();
if (options) {
this.uploader?.addToQueue(files, options, filters);
}

View File

@@ -89,7 +89,7 @@ export class FileType {
}
public static fileTypeDetection(inputFilename: string): string {
let types: { [ key: string ]: string } = {
const types: { [ key: string ]: string } = {
'jpg': 'image',
'jpeg': 'image',
'tif': 'image',
@@ -150,11 +150,11 @@ export class FileType {
'odp': 'ppt'
};
let chunks = inputFilename.split('.');
const chunks = inputFilename.split('.');
if (chunks.length < 2) {
return 'application';
}
let extension = chunks[ chunks.length - 1 ].toLowerCase();
const extension = chunks[ chunks.length - 1 ].toLowerCase();
if (types[ extension ] === undefined) {
return 'application';
} else {

View File

@@ -37,6 +37,7 @@ export interface FileUploaderOptions {
authTokenHeader?: string;
additionalParameter?: { [ key: string ]: any };
parametersBeforeFiles?: boolean;
// eslint-disable-next-line @typescript-eslint/ban-types
formatDataFunction?: Function;
formatDataFunctionIsAsync?: boolean;
}
@@ -44,10 +45,10 @@ export interface FileUploaderOptions {
export class FileUploader {
public authToken?: string;
public isUploading: boolean = false;
public isUploading = false;
public queue: FileItem[] = [];
public progress: number = 0;
public _nextIndex: number = 0;
public progress = 0;
public _nextIndex = 0;
public autoUpload: any;
public authTokenHeader?: string;
public response: EventEmitter<any>;
@@ -95,27 +96,27 @@ export class FileUploader {
}
public addToQueue(files: File[], options?: FileUploaderOptions, filters?: FilterFunction[] | string): void {
let list: File[] = [];
for (let file of files) {
const list: File[] = [];
for (const file of files) {
list.push(file);
}
let arrayOfFilters = this._getFilters(filters);
let count = this.queue.length;
let addedFileItems: FileItem[] = [];
const arrayOfFilters = this._getFilters(filters);
const count = this.queue.length;
const addedFileItems: FileItem[] = [];
list.map((some: File) => {
if (!options) {
options = this.options;
}
let temp = new FileLikeObject(some);
const temp = new FileLikeObject(some);
if (this._isValidFile(temp, arrayOfFilters, options)) {
let fileItem = new FileItem(this, some, options);
const fileItem = new FileItem(this, some, options);
addedFileItems.push(fileItem);
this.queue.push(fileItem);
this._onAfterAddingFile(fileItem);
} else {
if (this._failFilterIndex) {
let filter = arrayOfFilters[ this._failFilterIndex ];
const filter = arrayOfFilters[ this._failFilterIndex ];
this._onWhenAddingFileFailed(temp, filter, options);
}
}
@@ -131,8 +132,8 @@ export class FileUploader {
}
public removeFromQueue(value: FileItem): void {
let index = this.getIndexOfItem(value);
let item = this.queue[ index ];
const index = this.getIndexOfItem(value);
const item = this.queue[ index ];
if (item.isUploading) {
item.cancel();
}
@@ -148,9 +149,9 @@ export class FileUploader {
}
public uploadItem(value: FileItem): void {
let index = this.getIndexOfItem(value);
let item = this.queue[ index ];
let transport = this.options.isHTML5 ? '_xhrTransport' : '_iframeTransport';
const index = this.getIndexOfItem(value);
const item = this.queue[ index ];
const transport = this.options.isHTML5 ? '_xhrTransport' : '_iframeTransport';
item._prepareToUploading();
if (this.isUploading) {
return;
@@ -160,16 +161,16 @@ export class FileUploader {
}
public cancelItem(value: FileItem): void {
let index = this.getIndexOfItem(value);
let item = this.queue[ index ];
let prop = this.options.isHTML5 ? item._xhr : item._form;
const index = this.getIndexOfItem(value);
const item = this.queue[ index ];
const prop = this.options.isHTML5 ? item._xhr : item._form;
if (item && item.isUploading) {
prop.abort();
}
}
public uploadAll(): void {
let items = this.getNotUploadedItems().filter((item: FileItem) => !item.isUploading);
const items = this.getNotUploadedItems().filter((item: FileItem) => !item.isUploading);
if (!items.length) {
return;
}
@@ -178,7 +179,7 @@ export class FileUploader {
}
public cancelAll(): void {
let items = this.getNotUploadedItems();
const items = this.getNotUploadedItems();
items.map((item: FileItem) => item.cancel());
}
@@ -277,7 +278,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 ];
const nextItem = this.getReadyItems()[ 0 ];
this.isUploading = false;
if (nextItem) {
nextItem.upload();
@@ -298,8 +299,9 @@ export class FileUploader {
}
protected _xhrTransport(item: FileItem): any {
let that = this;
let xhr = item._xhr = new XMLHttpRequest();
// eslint-disable-next-line @typescript-eslint/no-this-alias
const that = this;
const xhr = item._xhr = new XMLHttpRequest();
let sendable: any;
this._onBeforeUploadItem(item);
@@ -339,26 +341,26 @@ export class FileUploader {
}
xhr.upload.onprogress = (event: any) => {
let progress = Math.round(event.lengthComputable ? event.loaded * 100 / event.total : 0);
const progress = Math.round(event.lengthComputable ? event.loaded * 100 / event.total : 0);
this._onProgressItem(item, progress);
};
xhr.onload = () => {
let headers = this._parseHeaders(xhr.getAllResponseHeaders());
let response = this._transformResponse(xhr.response, headers);
let gist = this._isSuccessCode(xhr.status) ? 'Success' : 'Error';
let method = '_on' + gist + 'Item';
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';
(this as any)[ method ](item, response, xhr.status, headers);
this._onCompleteItem(item, response, xhr.status, headers);
};
xhr.onerror = () => {
let headers = this._parseHeaders(xhr.getAllResponseHeaders());
let response = this._transformResponse(xhr.response, headers);
const headers = this._parseHeaders(xhr.getAllResponseHeaders());
const response = this._transformResponse(xhr.response, headers);
this._onErrorItem(item, response, xhr.status, headers);
this._onCompleteItem(item, response, xhr.status, headers);
};
xhr.onabort = () => {
let headers = this._parseHeaders(xhr.getAllResponseHeaders());
let response = this._transformResponse(xhr.response, headers);
const headers = this._parseHeaders(xhr.getAllResponseHeaders());
const response = this._transformResponse(xhr.response, headers);
this._onCancelItem(item, response, xhr.status, headers);
this._onCompleteItem(item, response, xhr.status, headers);
};
@@ -367,12 +369,12 @@ export class FileUploader {
}
xhr.withCredentials = item.withCredentials;
if (this.options.headers) {
for (let header of this.options.headers) {
for (const header of this.options.headers) {
xhr.setRequestHeader(header.name, header.value);
}
}
if (item.headers.length) {
for (let header of item.headers) {
for (const header of item.headers) {
xhr.setRequestHeader(header.name, header.value);
}
}
@@ -381,9 +383,9 @@ 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) {
sendable.then(
(result: any) => xhr.send(JSON.stringify(result))
@@ -394,14 +396,14 @@ export class FileUploader {
this._render();
}
protected _getTotalProgress(value: number = 0): number {
protected _getTotalProgress(value = 0): number {
if (this.options.removeAfterUpload) {
return value;
}
let notUploaded = this.getNotUploadedItems().length;
let uploaded = notUploaded ? this.queue.length - notUploaded : this.queue.length;
let ratio = 100 / this.queue.length;
let current = value * ratio / 100;
const notUploaded = this.getNotUploadedItems().length;
const uploaded = notUploaded ? this.queue.length - notUploaded : this.queue.length;
const ratio = 100 / this.queue.length;
const current = value * ratio / 100;
return Math.round(uploaded * ratio + current);
}
@@ -413,7 +415,7 @@ export class FileUploader {
return filters;
}
if (typeof filters === 'string') {
let names = filters.match(/[^\s,]+/g);
const names = filters.match(/[^\s,]+/g);
return this.options?.filters || []
.filter((filter: any) => names?.indexOf(filter.name) !== -1);
}
@@ -447,7 +449,7 @@ export class FileUploader {
}
protected _parseHeaders(headers: string): ParsedResponseHeaders {
let parsed: any = {};
const parsed: any = {};
let key: any;
let val: any;
let i: any;
@@ -488,7 +490,7 @@ export class FileUploader {
}
protected _onProgressItem(item: FileItem, progress: any): void {
let total = this._getTotalProgress(progress);
const total = this._getTotalProgress(progress);
this.progress = total;
item._onProgress(progress);
this.onProgressItem(item, progress);

View File

@@ -1,7 +1,9 @@
export * from './file-upload/file-select.directive';
export * from './file-upload/file-drop.directive';
export * from './file-upload/file-uploader.class';
export * from './file-upload/file-item.class';
export * from './file-upload/file-like-object.class';
export * from './file-upload/file-like-object.class';
export { FileUploadModule } from './file-upload/file-upload.module';
export { FileSelectDirective } from './file-upload/file-select.directive';

View File

@@ -0,0 +1,26 @@
module.exports = {
displayName: 'ng2-file-upload',
preset: '../../jest.preset.js',
setupFilesAfterEnv: ['<rootDir>/testing/test-setup.ts'],
globals: {
'ts-jest': {
tsconfig: '<rootDir>/tsconfig.spec.json',
astTransformers: {
before: [
'jest-preset-angular/build/InlineFilesTransformer',
'jest-preset-angular/build/StripStylesTransformer',
]
}
}
},
transform: {
'^.+\\.[tj]sx?$': 'ts-jest'
},
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
coverageDirectory: '../../coverage/libs/ng2-file-upload',
snapshotSerializers: [
'jest-preset-angular/build/AngularNoNgAttributesSnapshotSerializer.js',
'jest-preset-angular/build/AngularSnapshotSerializer.js',
'jest-preset-angular/build/HTMLCommentSerializer.js',
]
};

View File

@@ -0,0 +1,7 @@
{
"$schema": "../../node_modules/ng-packagr/ng-package.schema.json",
"dest": "../../dist/libs/ng2-file-upload",
"lib": {
"entryFile": "index.ts"
}
}

View File

@@ -0,0 +1,4 @@
{
"name": "ng2-file-upload",
"version": "1.3.0"
}

View File

@@ -2,9 +2,9 @@ import { Component, DebugElement } from '@angular/core';
import { By } from '@angular/platform-browser';
import { inject, ComponentFixture, TestBed } from '@angular/core/testing';
import { FileUploader } from '../file-upload/file-uploader.class';
import { FileUploadModule } from '../file-upload/file-upload.module';
import { FileDropDirective } from '../file-upload/file-drop.directive';
import { FileUploader } from '../../file-upload/file-uploader.class';
import { FileUploadModule } from '../../file-upload/file-upload.module';
import { FileDropDirective } from '../../file-upload/file-drop.directive';
@Component({
selector: 'container',
@@ -57,13 +57,15 @@ describe('Directive: FileDropDirective', () => {
const options = fileDropDirective.getOptions();
// Check url set through binding
expect(options.url).toBe(hostComponent.url);
// Check default options
expect(options.autoUpload).toBeFalsy();
expect(options.isHTML5).toBeTruthy();
expect(options.removeAfterUpload).toBeFalsy();
expect(options.disableMultipart).toBeFalsy();
expect(options).toBeTruthy();
if (options) {
expect(options.url).toBe(hostComponent.url);
expect(options.autoUpload).toBeFalsy();
expect(options.isHTML5).toBeTruthy();
expect(options.removeAfterUpload).toBeFalsy();
expect(options.disableMultipart).toBeFalsy();
}
});
it('can get filters', () => {
@@ -142,5 +144,5 @@ function getFakeEventData(): any {
},
preventDefault: () => undefined,
stopPropagation: () => undefined
}
};
}

View File

@@ -2,9 +2,9 @@ import { TestBed, ComponentFixture } from '@angular/core/testing';
import { Component, DebugElement } from '@angular/core';
import { By } from '@angular/platform-browser';
import { FileUploadModule } from '../file-upload/file-upload.module';
import { FileSelectDirective } from '../file-upload/file-select.directive';
import { FileUploader } from '../file-upload/file-uploader.class';
import { FileUploadModule } from '../../file-upload/file-upload.module';
import { FileSelectDirective } from '../../file-upload/file-select.directive';
import { FileUploader } from '../../file-upload/file-uploader.class';
@Component({
selector: 'container',
@@ -54,15 +54,18 @@ describe('Directive: FileSelectDirective', () => {
it('can get uploader options', () => {
const options = fileSelectDirective.getOptions();
expect(options).toBeTruthy();
if (options) {
// Check url set through binding
expect(options.url).toBe(hostComponent.url);
// Check url set through binding
expect(options.url).toBe(hostComponent.url);
// Check default options
expect(options.autoUpload).toBeFalsy();
expect(options.isHTML5).toBeTruthy();
expect(options.removeAfterUpload).toBeFalsy();
expect(options.disableMultipart).toBeFalsy();
}
// Check default options
expect(options.autoUpload).toBeFalsy();
expect(options.isHTML5).toBeTruthy();
expect(options.removeAfterUpload).toBeFalsy();
expect(options.disableMultipart).toBeFalsy();
});
it('can get filters', () => {

View File

@@ -0,0 +1 @@
import 'jest-preset-angular';

View File

@@ -0,0 +1,28 @@
{
"extends": "../../tsconfig.base.json",
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.lib.json"
},
{
"path": "./tsconfig.lib.prod.json"
},
{
"path": "./tsconfig.spec.json"
}
],
"compilerOptions": {
"forceConsistentCasingInFileNames": false,
"strict": false,
"noImplicitReturns": false,
"noFallthroughCasesInSwitch": false
},
"angularCompilerOptions": {
"strictInjectionParameters": false,
"strictTemplates": false,
"fullTemplateTypeCheck": false
}
}

View File

@@ -1,7 +1,7 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../dist/ng2-file-upload",
"outDir": "../../dist/out-tsc",
"target": "es2015",
"declaration": true,
"declarationMap": true,
@@ -14,7 +14,10 @@
"strictMetadataEmit": true,
"enableResourceInlining": true
},
"include": [
"**/*.ts"
],
"exclude": [
"**/*.spec.ts"],
"include": ["**/*.ts"]
"**/*.spec.ts"
]
}

View File

@@ -0,0 +1,12 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"module": "commonjs",
"types": ["jest", "node"]
},
"include": [
"**/*.spec.ts",
"**/*.d.ts"
]
}

38
nx.json Normal file
View File

@@ -0,0 +1,38 @@
{
"npmScope": "ng2-file-upload-demo",
"implicitDependencies": {
"angular.json": "*",
"package.json": "*",
"tsconfig.json": "*",
"tslint.json": "*",
".eslintrc.json": "*",
"nx.json": "*"
},
"projects": {
"ng2-file-upload": {
"tags": [
"lib"
]
},
"ng2-file-upload-demo": {
"tags": [],
"implicitDependencies": [
"ng2-file-upload"
]
}
},
"tasksRunnerOptions": {
"default": {
"runner": "@nrwl/workspace/tasks-runners/default",
"options": {
"cacheableOperations": [
"build",
"lint",
"test",
"e2e"
]
}
}
}
}

11193
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -4,29 +4,25 @@
"private": true,
"description": "Angular file upload directives",
"scripts": {
"lite-server": "lite-server -c demo/bs-config.json",
"demo.serve": "run-s build-prod link demo.build lite-server",
"demo.gh-pages": "run-s build demo.build demo.deploy",
"demo.build": "ng build ng2-file-upload-demo --prod",
"demo.deploy": "gh-pages -d demo/dist",
"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": "ng build ng2-file-upload",
"build-prod": "ng build ng2-file-upload --prod",
"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 ng2-file-upload-test",
"test-coverage": "ng test ng2-file-upload-test --code-coverage",
"version": "npm run flow.changelog && git add -A"
"ng": "nx",
"start": "ng serve",
"build": "ng build",
"lib-build": "nx run ng2-file-upload:build",
"build-prod": "nx run ng2-file-upload:build:production",
"build.watch": "nx run ng2-file-upload:build --watch",
"test": "nx run-many --all --target=test",
"version": "nx run ng2-file-upload:version",
"lint": "nx run-many --all --target=lint",
"pretest": "run-s lint lib-build",
"test-coverage": "nx run-many --all --target=test --codeCoverage",
"demo.gh-pages": "run-s lib-build build demo.deploy",
"demo.deploy": "gh-pages -d dist/apps/ng2-file-upload",
"postinstall": "node ./decorate-angular-cli.js",
"flow.github-release": "conventional-github-releaser -p angular"
},
"keywords": [
"angular2",
"angular",
"bootstrap",
"angularjs",
"twitter-bootstrap",
"file-upload",
"angular-file-upload"
@@ -43,9 +39,9 @@
"homepage": "https://github.com/valor-software/ng2-file-upload#readme",
"peerDependencies": {},
"devDependencies": {
"@angular/animations": "~11.2.14",
"@angular-devkit/build-angular": "~0.1102.13",
"@angular-devkit/build-ng-packagr": "^0.1002.0",
"@angular/animations": "~11.2.14",
"@angular/cli": "~11.2.14",
"@angular/common": "~11.2.14",
"@angular/compiler": "~11.2.14",
@@ -55,10 +51,21 @@
"@angular/platform-browser": "~11.2.14",
"@angular/platform-browser-dynamic": "~11.2.14",
"@angular/router": "~11.2.14",
"@angular-eslint/eslint-plugin": "4.3.0",
"@angular-eslint/eslint-plugin-template": "4.3.0",
"@angular-eslint/template-parser": "4.3.0",
"@nrwl/angular": "11.2.12",
"@nrwl/node": "11.2.12",
"@nrwl/eslint-plugin-nx": "11.2.12",
"@nrwl/jest": "11.2.12",
"@nrwl/linter": "11.2.12",
"@types/jasmine": "~3.7.7",
"@types/jest": "26.0.20",
"@types/marked": "2.0.3",
"@types/node": "^12.11.1",
"@types/webpack": "^5.0.0",
"@typescript-eslint/eslint-plugin": "~4.28.3",
"@typescript-eslint/parser": "~4.28.3",
"bootstrap": "3.3.7",
"chokidar-cli": "^2.1.0",
"classlist-polyfill": "1.2.0",
@@ -70,6 +77,8 @@
"cpy": "8.1.2",
"cpy-cli": "3.1.1",
"del-cli": "3.0.1",
"eslint": "7.22.0",
"eslint-config-prettier": "7.2.0",
"gh-pages": "3.2.2",
"gitignore-to-glob": "0.3.0",
"google-code-prettify": "1.0.5",
@@ -77,13 +86,16 @@
"jasmine-core": "3.6.0",
"jasmine-data-provider": "2.2.0",
"jasmine-spec-reporter": "7.0.0",
"jest": "26.6.3",
"jest-createspyobj": "2.0.0",
"jest-preset-angular": "8.3.2",
"karma": "~6.1.0",
"karma-chrome-launcher": "~3.1.0",
"karma-cli": "~2.0.0",
"karma-coverage-istanbul-reporter": "^3.0.3",
"karma-jasmine": "4.0.1",
"karma-remap-istanbul": "0.6.0",
"karma-sauce-launcher": "4.3.6",
"karma-coverage-istanbul-reporter": "^3.0.3",
"lite-server": "2.6.1",
"lodash": "4.17.21",
"markdown-loader": "^6.0.0",
@@ -99,6 +111,7 @@
"rxjs": "^6.6.0",
"systemjs-builder": "0.16.15",
"ts-helpers": "^1.1.2",
"ts-jest": "26.5.1",
"ts-node": "8.3.0",
"tsickle": "^0.40.0",
"tslint": "^6.1.0",
@@ -132,6 +145,7 @@
}
],
"dependencies": {
"@nrwl/workspace": "^12.8.0",
"tslib": "^2.0.0"
}
}

View File

@@ -1,7 +0,0 @@
{
"$schema": "../node_modules/ng-packagr/ng-package.schema.json",
"dest": "../node_modules/ng2-file-upload",
"lib": {
"entryFile": "index.ts"
}
}

View File

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

View File

@@ -1,45 +0,0 @@
{
"compilerOptions": {
"baseUrl": ".",
"outDir": "../dist/ng2-file-upload",
"target": "es2015",
"module": "esnext",
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"sourceMap": false,
"noEmitHelpers": false,
"noImplicitAny": true,
"declaration": true,
"skipLibCheck": true,
"stripInternal": true,
"noUnusedLocals": false,
"noUnusedParameters": false,
"lib": ["dom", "es2018"],
"strict": true
},
"angularCompilerOptions": {
"annotateForClosureCompiler": true,
"strictMetadataEmit": true,
"skipTemplateCodegen": true,
"strictInjectionParameters": true,
"strictTemplates": false,
"fullTemplateTypeCheck": true,
"flatModuleOutFile": "ng2-file-upload.d.ts",
"flatModuleId": "ng2-file-upload"
},
"include": [
"../scripts/typings.d.ts"
],
"exclude": [
"**/*.spec.ts"
],
"references": [
{
"path": "./tsconfig.lib.json"
},
{
"path": "./tsconfig.lib.prod.json"
}
]
}

View File

@@ -15,8 +15,8 @@ import {
import './matchers';
// Unfortunately there's no typing for the `__karma__` variable. Just declare it as any.
declare var __karma__: any;
declare var require: any;
declare let __karma__: any;
declare let require: any;
// Prevent Karma from running prematurely.
__karma__.loaded = Function.prototype;
@@ -27,11 +27,11 @@ getTestBed().initTestEnvironment(
platformBrowserDynamicTesting()
);
// Then we find all the tests.
let context = require.context('../demo/src', true, /\.spec\.ts/);
const context = require.context('../demo/src', true, /\.spec\.ts/);
// And load the modules.
context.keys().map(context);
let context2 = require.context('../src/spec', true, /\.spec\.ts/);
const context2 = require.context('../src/spec', true, /\.spec\.ts/);
context2.keys().map(context2);
// Finally, start Karma to run the tests.
__karma__.start();

27
tsconfig.base.json Normal file
View File

@@ -0,0 +1,27 @@
{
"compileOnSave": false,
"compilerOptions": {
"rootDir": ".",
"sourceMap": true,
"declaration": false,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"importHelpers": true,
"target": "es2015",
"module": "esnext",
"lib": [
"es2017",
"dom"
],
"skipLibCheck": true,
"skipDefaultLibCheck": true,
"baseUrl": ".",
"paths": {
"ng2-file-upload": [
"libs/ng2-file-upload/index.ts"
]
}
},
"exclude": []
}