Updating Angular Version to 6
This commit is contained in:
@@ -1,53 +0,0 @@
|
|||||||
{
|
|
||||||
"project": {
|
|
||||||
"name": "ng2-chunk-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,11 +0,0 @@
|
|||||||
# http://editorconfig.org
|
|
||||||
|
|
||||||
root = true
|
|
||||||
|
|
||||||
[*]
|
|
||||||
charset = utf-8
|
|
||||||
indent_style = space
|
|
||||||
indent_size = 2
|
|
||||||
end_of_line = lf
|
|
||||||
insert_final_newline = true
|
|
||||||
trim_trailing_whitespace = true
|
|
||||||
114
angular.json
Normal file
114
angular.json
Normal file
@@ -0,0 +1,114 @@
|
|||||||
|
{
|
||||||
|
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
|
||||||
|
"version": 1,
|
||||||
|
"newProjectRoot": "projects",
|
||||||
|
"projects": {
|
||||||
|
"ng2-chunk-file-upload": {
|
||||||
|
"root": "",
|
||||||
|
"sourceRoot": "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-chunk-file-upload:build"
|
||||||
|
},
|
||||||
|
"configurations": {
|
||||||
|
"production": {
|
||||||
|
"browserTarget": "ng2-chunk-file-upload:build:production"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"extract-i18n": {
|
||||||
|
"builder": "@angular-devkit/build-angular:extract-i18n",
|
||||||
|
"options": {
|
||||||
|
"browserTarget": "ng2-chunk-file-upload:build"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"test": {
|
||||||
|
"builder": "@angular-devkit/build-angular:karma",
|
||||||
|
"options": {
|
||||||
|
"main": "demo/src/../../scripts/test.ts",
|
||||||
|
"karmaConfig": "karma.conf.js",
|
||||||
|
"scripts": [],
|
||||||
|
"styles": [],
|
||||||
|
"assets": [
|
||||||
|
"demo/src/assets"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"lint": {
|
||||||
|
"builder": "@angular-devkit/build-angular:tslint",
|
||||||
|
"options": {
|
||||||
|
"tsConfig": [],
|
||||||
|
"exclude": []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"ng2-chunk-file-upload-e2e": {
|
||||||
|
"root": "",
|
||||||
|
"sourceRoot": "",
|
||||||
|
"projectType": "application",
|
||||||
|
"architect": {
|
||||||
|
"e2e": {
|
||||||
|
"builder": "@angular-devkit/build-angular:protractor",
|
||||||
|
"options": {
|
||||||
|
"protractorConfig": "protractor.conf.js",
|
||||||
|
"devServerTarget": "ng2-chunk-file-upload:serve"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"lint": {
|
||||||
|
"builder": "@angular-devkit/build-angular:tslint",
|
||||||
|
"options": {
|
||||||
|
"tsConfig": [],
|
||||||
|
"exclude": []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"defaultProject": "ng2-chunk-file-upload",
|
||||||
|
"schematics": {
|
||||||
|
"@schematics/angular:component": {
|
||||||
|
"prefix": "",
|
||||||
|
"styleext": "css"
|
||||||
|
},
|
||||||
|
"@schematics/angular:directive": {
|
||||||
|
"prefix": ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -36,16 +36,16 @@ let gettingStarted = require('html-loader!markdown-loader!../getting-started.md'
|
|||||||
is maintained by <a href="https://github.com/valor-software">valor-software</a>.</p>
|
is maintained by <a href="https://github.com/valor-software">valor-software</a>.</p>
|
||||||
</div>
|
</div>
|
||||||
</footer>
|
</footer>
|
||||||
`
|
`,
|
||||||
})
|
})
|
||||||
export class AppComponent {
|
export class AppComponent {
|
||||||
public gettingStarted: string = gettingStarted;
|
public gettingStarted: string = gettingStarted;
|
||||||
public ngAfterContentInit(): any {
|
public ngAfterContentInit(): any {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
if (typeof PR !== 'undefined') {
|
if (typeof PR !== 'undefined') {
|
||||||
// google code-prettify
|
// google code-prettify
|
||||||
PR.prettyPrint();
|
PR.prettyPrint();
|
||||||
}
|
}
|
||||||
}, 150);
|
}, 150);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,14 +4,17 @@ import { FormsModule } from '@angular/forms';
|
|||||||
import { BrowserModule } from '@angular/platform-browser';
|
import { BrowserModule } from '@angular/platform-browser';
|
||||||
|
|
||||||
import { TabsModule } from 'ngx-bootstrap/tabs';
|
import { TabsModule } from 'ngx-bootstrap/tabs';
|
||||||
import { FileUploadModule } from 'ng2-chunk-file-upload';
|
import { FileUploadModule } from '../../../src/file-upload/file-upload.module';
|
||||||
|
|
||||||
import { AppComponent } from './app.component';
|
import { AppComponent } from './app.component';
|
||||||
|
|
||||||
import { FileUploadSectionComponent } from './components/file-upload-section';
|
import { FileUploadSectionComponent } from './components/file-upload-section';
|
||||||
import { SimpleDemoComponent } from './components/file-upload/simple-demo';
|
import { SimpleDemoComponent } from './components/file-upload/simple-demo';
|
||||||
|
import { HttpModule } from '@angular/http';
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
imports: [
|
imports: [
|
||||||
|
HttpModule,
|
||||||
BrowserModule,
|
BrowserModule,
|
||||||
CommonModule,
|
CommonModule,
|
||||||
FileUploadModule,
|
FileUploadModule,
|
||||||
|
|||||||
@@ -1,29 +1,29 @@
|
|||||||
import { Component } from "@angular/core";
|
import { Component } from '@angular/core';
|
||||||
|
|
||||||
let doc = require("html-loader!markdown-loader!../../doc.md");
|
let doc = require('html-loader!markdown-loader!../../doc.md');
|
||||||
|
|
||||||
let tabDesc: Array<any> = [
|
let tabDesc: Array<any> = [
|
||||||
{
|
{
|
||||||
heading: 'Simple',
|
heading: 'Simple',
|
||||||
ts: require("!!raw-loader?lang=typescript!./file-upload/simple-demo.ts"),
|
ts: require('!!raw-loader?lang=typescript!./file-upload/simple-demo.ts'),
|
||||||
html: require("!!raw-loader?lang=markup!./file-upload/simple-demo.html"),
|
html: require('!!raw-loader?lang=markup!./file-upload/simple-demo.html'),
|
||||||
js: require("!!raw-loader?lang=javascript!./file-upload/file-catcher.js")
|
js: require('!!raw-loader?lang=javascript!./file-upload/file-catcher.js')
|
||||||
},
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: "file-upload-section",
|
selector: 'file-upload-section',
|
||||||
templateUrl: "./file-upload-section.html",
|
templateUrl: './file-upload-section.html'
|
||||||
})
|
})
|
||||||
export class FileUploadSectionComponent {
|
export class FileUploadSectionComponent {
|
||||||
public name: string = 'File Upload';
|
public name: string = 'File Upload';
|
||||||
public currentHeading: string = 'Simple';
|
public currentHeading: string = 'Simple';
|
||||||
public doc: string = doc;
|
public doc: string = doc;
|
||||||
public tabs: any = tabDesc;
|
public tabs: any = tabDesc;
|
||||||
|
|
||||||
public select(e: any): void {
|
public select(e: any): void {
|
||||||
if (e.heading) {
|
if (e.heading) {
|
||||||
this.currentHeading = e.heading;
|
this.currentHeading = e.heading;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,22 +1,17 @@
|
|||||||
{
|
{
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"declaration": false,
|
"declaration": false,
|
||||||
"emitDecoratorMetadata": true,
|
"emitDecoratorMetadata": true,
|
||||||
"experimentalDecorators": true,
|
"experimentalDecorators": true,
|
||||||
"noEmitHelpers": false,
|
"noEmitHelpers": false,
|
||||||
"lib": ["es6", "dom"],
|
"lib": ["es6", "dom"],
|
||||||
"types": [
|
"types": ["jasmine", "webpack"],
|
||||||
"jasmine",
|
"mapRoot": "./",
|
||||||
"webpack"
|
"module": "es6",
|
||||||
],
|
"moduleResolution": "node",
|
||||||
"mapRoot": "./",
|
"outDir": "../temp/out-tsc",
|
||||||
"module": "es6",
|
"sourceMap": true,
|
||||||
"moduleResolution": "node",
|
"target": "es5",
|
||||||
"outDir": "../temp/out-tsc",
|
"typeRoots": ["../node_modules/@types"]
|
||||||
"sourceMap": true,
|
}
|
||||||
"target": "es5",
|
|
||||||
"typeRoots": [
|
|
||||||
"../node_modules/@types"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,21 +6,21 @@ const customLaunchers = require('./scripts/sauce-browsers').customLaunchers;
|
|||||||
module.exports = function (config) {
|
module.exports = function (config) {
|
||||||
const configuration = {
|
const configuration = {
|
||||||
basePath: '',
|
basePath: '',
|
||||||
frameworks: ['jasmine', '@angular/cli'],
|
frameworks: ['jasmine', '@angular-devkit/build-angular'],
|
||||||
plugins: [
|
plugins: [
|
||||||
require('karma-jasmine'),
|
require('karma-jasmine'),
|
||||||
require('karma-chrome-launcher'),
|
require('karma-chrome-launcher'),
|
||||||
require('karma-coverage-istanbul-reporter'),
|
require('karma-coverage-istanbul-reporter'),
|
||||||
require('@angular/cli/plugins/karma')
|
require('@angular-devkit/build-angular/plugins/karma')
|
||||||
],
|
],
|
||||||
files: [
|
files: [
|
||||||
{pattern: './scripts/test.ts', watched: false}
|
{pattern: './scripts/test.ts', watched: false}
|
||||||
],
|
],
|
||||||
preprocessors: {
|
preprocessors: {
|
||||||
'./scripts/test.ts': ['@angular/cli']
|
'./scripts/test.ts': ['@angular-devkit/build-angular']
|
||||||
},
|
},
|
||||||
coverageIstanbulReporter: {
|
coverageIstanbulReporter: {
|
||||||
reports: [ 'html', 'lcovonly' ],
|
dir: require('path').join(__dirname, 'coverage'), reports: [ 'html', 'lcovonly' ],
|
||||||
fixWebpackSourcePaths: false
|
fixWebpackSourcePaths: false
|
||||||
},
|
},
|
||||||
angularCli: {
|
angularCli: {
|
||||||
|
|||||||
10202
package-lock.json
generated
10202
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
123
package.json
123
package.json
@@ -31,9 +31,9 @@
|
|||||||
"angularjs",
|
"angularjs",
|
||||||
"twitter-bootstrap",
|
"twitter-bootstrap",
|
||||||
"file-upload",
|
"file-upload",
|
||||||
"angular-file-upload",
|
"angular-file-upload",
|
||||||
"chunk-file-upload",
|
"chunk-file-upload",
|
||||||
"azure-blob-storage"
|
"azure-blob-storage"
|
||||||
],
|
],
|
||||||
"author": "Paulo Peres Jr <paulo@myog.io>",
|
"author": "Paulo Peres Jr <paulo@myog.io>",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
@@ -47,75 +47,82 @@
|
|||||||
"homepage": "https://github.com/PauloPeres/ng2-chunk-file-upload#readme",
|
"homepage": "https://github.com/PauloPeres/ng2-chunk-file-upload#readme",
|
||||||
"dependencies": {},
|
"dependencies": {},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"@angular/common": "^2.3.1 || >=4.0.0",
|
"@angular/common": "^4.3.0 || >=4.3.0",
|
||||||
"@angular/core": "^2.3.1 || >=4.0.0"
|
"@angular/core": "^4.3.0 || >=4.3.0",
|
||||||
|
"@angular/http": "^4.3.0 || >=4.3.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@angular/cli": "1.0.0",
|
"@angular-devkit/build-angular": "~0.6.3",
|
||||||
"@angular/common": "2.4.3",
|
"@angular/cdk": "^6.1.0",
|
||||||
"@angular/compiler": "2.4.3",
|
"@angular/cli": "^6.0.3",
|
||||||
"@angular/compiler-cli": "2.4.3",
|
"@angular/common": "^6.0.1",
|
||||||
"@angular/core": "2.4.3",
|
"@angular/compiler": "^6.0.1",
|
||||||
"@angular/forms": "2.4.3",
|
"@angular/compiler-cli": "^6.0.1",
|
||||||
"@angular/http": "2.4.3",
|
"@angular/core": "^6.0.1",
|
||||||
"@angular/language-service": "2.4.3",
|
"@angular/forms": "^6.0.1",
|
||||||
"@angular/platform-browser": "2.4.3",
|
"@angular/http": "^6.0.1",
|
||||||
"@angular/platform-browser-dynamic": "2.4.3",
|
"@angular/language-service": "^6.0.1",
|
||||||
"@angular/router": "3.4.3",
|
"@angular/material": "^6.1.0",
|
||||||
"@angular/tsc-wrapped": "0.5.1",
|
"@angular/platform-browser": "^6.0.1",
|
||||||
"@types/jasmine": "2.5.40",
|
"@angular/platform-browser-dynamic": "^6.0.1",
|
||||||
"@types/marked": "0.0.28",
|
"@angular/router": "^6.0.1",
|
||||||
"@types/node": "7.0.0",
|
"@angular/tsc-wrapped": "4.4.6",
|
||||||
"@types/webpack": "^2.2.1",
|
"@types/jasmine": "2.8.7",
|
||||||
"bootstrap": "3.3.7",
|
"@types/marked": "0.3.0",
|
||||||
|
"@types/node": "10.1.2",
|
||||||
|
"@types/webpack": "^4.4.0",
|
||||||
|
"ajv": "^6.0.0",
|
||||||
|
"bootstrap": "4.1.1",
|
||||||
"chokidar-cli": "1.2.0",
|
"chokidar-cli": "1.2.0",
|
||||||
"classlist-polyfill": "1.0.3",
|
"classlist-polyfill": "1.2.0",
|
||||||
"codecov": "1.0.1",
|
"codecov": "3.0.2",
|
||||||
"codelyzer": "~2.0.0-beta.4",
|
"codelyzer": "~4.3.0",
|
||||||
"conventional-changelog-cli": "1.2.0",
|
"conventional-changelog-cli": "1.3.22",
|
||||||
"conventional-github-releaser": "1.1.3",
|
"conventional-github-releaser": "2.0.2",
|
||||||
"core-js": "^2.4.1",
|
"core-js": "^2.4.1",
|
||||||
"cpy": "5.0.0",
|
"cpy": "7.0.0",
|
||||||
"cpy-cli": "1.0.1",
|
"cpy-cli": "1.0.1",
|
||||||
"del-cli": "0.2.1",
|
"del-cli": "1.1.0",
|
||||||
"gh-pages": "0.12.0",
|
"gh-pages": "1.1.0",
|
||||||
"gitignore-to-glob": "0.3.0",
|
"gitignore-to-glob": "0.3.0",
|
||||||
"google-code-prettify": "1.0.5",
|
"google-code-prettify": "1.0.5",
|
||||||
"html-loader": "0.4.4",
|
"html-loader": "0.5.5",
|
||||||
"jasmine": "2.5.3",
|
"jasmine": "3.1.0",
|
||||||
"jasmine-core": "2.5.2",
|
"jasmine-core": "3.1.0",
|
||||||
"jasmine-data-provider": "2.2.0",
|
"jasmine-data-provider": "2.2.0",
|
||||||
"jasmine-spec-reporter": "3.2.0",
|
"jasmine-spec-reporter": "4.2.1",
|
||||||
"karma": "1.4.0",
|
"jquery": "^1.9.1",
|
||||||
|
"karma": "2.0.2",
|
||||||
"karma-chrome-launcher": "^2.0.0",
|
"karma-chrome-launcher": "^2.0.0",
|
||||||
"karma-cli": "^1.0.1",
|
"karma-cli": "^1.0.1",
|
||||||
"karma-coverage-istanbul-reporter": "^1.3.0",
|
"karma-coverage-istanbul-reporter": "^2.0.1",
|
||||||
"karma-jasmine": "^1.0.2",
|
"karma-jasmine": "^1.0.2",
|
||||||
"karma-remap-istanbul": "0.4.0",
|
"karma-remap-istanbul": "0.6.0",
|
||||||
"karma-sauce-launcher": "1.1.0",
|
"karma-sauce-launcher": "1.2.0",
|
||||||
"lite-server": "2.2.2",
|
"lite-server": "2.3.0",
|
||||||
"lodash": "4.17.4",
|
"lodash": "4.17.10",
|
||||||
"markdown-loader": "^0.1.7",
|
"markdown-loader": "^2.0.2",
|
||||||
"marked": "0.3.6",
|
"marked": "0.4.0",
|
||||||
"ng2-page-scroll": "4.0.0-beta.2",
|
"ngm-cli": "1.0.4",
|
||||||
"ngm-cli": "0.4.0",
|
"ngx-bootstrap": "3.0.0",
|
||||||
"ngx-bootstrap": "1.6.6",
|
|
||||||
"npm-run-all": "^4.0.1",
|
"npm-run-all": "^4.0.1",
|
||||||
|
"popper.js": "^1.14.3",
|
||||||
"pre-commit": "1.2.2",
|
"pre-commit": "1.2.2",
|
||||||
"protractor": "5.0.0",
|
"protractor": "5.3.2",
|
||||||
"reflect-metadata": "0.1.9",
|
"reflect-metadata": "0.1.12",
|
||||||
"require-dir": "0.3.1",
|
"require-dir": "1.0.0",
|
||||||
"rxjs": "5.0.3",
|
"rxjs": "^6.2.0",
|
||||||
"systemjs-builder": "0.15.34",
|
"rxjs-compat": "^6.1.0",
|
||||||
|
"rxjs-tslint": "^0.1.4",
|
||||||
|
"systemjs-builder": "0.16.13",
|
||||||
"ts-helpers": "^1.1.1",
|
"ts-helpers": "^1.1.1",
|
||||||
"ts-node": "2.0.0",
|
"ts-node": "6.0.3",
|
||||||
"tslint": "4.3.1",
|
"tslint": "5.10.0",
|
||||||
"tslint-config-valorsoft": "1.2.0",
|
"typedoc": "0.11.1",
|
||||||
"typedoc": "0.5.5",
|
"typescript": "^2.7.2",
|
||||||
"typescript": "2.1.5",
|
"wallaby-webpack": "3.9.8",
|
||||||
"wallaby-webpack": "0.0.30",
|
"webdriver-manager": "12.0.6",
|
||||||
"webdriver-manager": "11.1.1",
|
"zone.js": "0.8.26"
|
||||||
"zone.js": "0.7.5"
|
|
||||||
},
|
},
|
||||||
"contributors": [
|
"contributors": [
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,134 +1,141 @@
|
|||||||
import { map } from 'rxjs/operators/map';
|
import { HttpErrorResponse } from '@angular/common/http/src/response';
|
||||||
import { Observable } from 'rxjs';
|
|
||||||
import { FileUploaderOptions, FileUploader } from './file-uploader.class';
|
import { FileUploaderOptions, FileUploader } from './file-uploader.class';
|
||||||
import { FileItem } from './file-item.class';
|
import { FileItem } from './file-item.class';
|
||||||
import { HttpClient, HttpRequest, HttpEventType, HttpEvent, HttpErrorResponse, HttpHeaders, HttpParams } from '@angular/common/http';
|
|
||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { tap, last, catchError } from 'rxjs/operators';
|
import { HttpClient, HttpHeaders, HttpRequest, HttpEventType } from '@angular/common/http';
|
||||||
import { of } from 'rxjs/observable/of';
|
import { Observable, of} from 'rxjs';
|
||||||
|
import { map } from 'rxjs/operators';
|
||||||
|
|
||||||
export interface UploaderLinksOptions {
|
export interface UploaderLinksOptions {
|
||||||
downloadEntry: string,
|
downloadEntry: string;
|
||||||
updateEntry: string,
|
updateEntry: string;
|
||||||
createEntry: string,
|
createEntry: string;
|
||||||
deleteEntry: string,
|
deleteEntry: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface UploaderServiceOptions {
|
export interface UploaderServiceOptions {
|
||||||
createMethod: string;
|
createMethod: string;
|
||||||
updateMethod: string;
|
updateMethod: string;
|
||||||
authorizationHeaderName?: string;
|
authorizationHeaderName?: string;
|
||||||
tokenPattern?: string;
|
tokenPattern?: string;
|
||||||
token?: string;
|
token?: string;
|
||||||
chunkSize?: number;
|
chunkSize?: number;
|
||||||
totalChunkParamName?: string;
|
totalChunkParamName?: string;
|
||||||
currentChunkParamName?: string;
|
currentChunkParamName?: string;
|
||||||
fileParamName?: string;
|
fileParamName?: string;
|
||||||
idAttribute?: string;
|
idAttribute?: string;
|
||||||
}
|
}
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class FileUploaderService {
|
export class FileUploaderService {
|
||||||
public defaultLinks: UploaderLinksOptions = {
|
public defaultLinks: UploaderLinksOptions = {
|
||||||
downloadEntry: '',
|
downloadEntry: '',
|
||||||
updateEntry: '',
|
updateEntry: '',
|
||||||
createEntry: '',
|
createEntry: '',
|
||||||
deleteEntry: '',
|
deleteEntry: ''
|
||||||
}
|
};
|
||||||
public defaultOptions: UploaderServiceOptions = {
|
public defaultOptions: UploaderServiceOptions = {
|
||||||
createMethod: 'POST',
|
createMethod: 'POST',
|
||||||
updateMethod: 'POST',
|
updateMethod: 'POST',
|
||||||
authorizationHeaderName: "Authorization",
|
authorizationHeaderName: 'Authorization',
|
||||||
tokenPattern: null,
|
tokenPattern: null,
|
||||||
token: null,
|
token: null,
|
||||||
chunkSize: 0,
|
chunkSize: 0,
|
||||||
totalChunkParamName: 'total_chunks',
|
totalChunkParamName: 'total_chunks',
|
||||||
currentChunkParamName: 'current_chunk',
|
currentChunkParamName: 'current_chunk',
|
||||||
fileParamName: 'file',
|
fileParamName: 'file',
|
||||||
idAttribute: 'id',
|
idAttribute: 'id'
|
||||||
}
|
};
|
||||||
public additionalHeaders = {};
|
public additionalHeaders:any = {};
|
||||||
protected cancelError = "UPLOAD CANCELED";
|
protected cancelError = 'UPLOAD CANCELED';
|
||||||
protected uploadSubscription: any = null;
|
protected uploadSubscription: any = null;
|
||||||
public links:UploaderLinksOptions;
|
public links: UploaderLinksOptions;
|
||||||
public options:UploaderServiceOptions;
|
public options: UploaderServiceOptions;
|
||||||
private _uploader:FileUploader = null;
|
private _uploader: FileUploader = null;
|
||||||
constructor(
|
constructor(protected http: HttpClient) {
|
||||||
protected http: HttpClient
|
this.links = Object.assign({}, this.defaultLinks, this.links);
|
||||||
){
|
this.options = Object.assign({}, this.defaultOptions, this.options);
|
||||||
this.links = Object.assign({}, this.defaultLinks, this.links);
|
}
|
||||||
this.options = Object.assign({}, this.defaultOptions, this.options);
|
get uploader(): FileUploader {
|
||||||
}
|
return this._uploader;
|
||||||
get uploader():FileUploader {
|
}
|
||||||
return this._uploader;
|
set uploader(theUploader: FileUploader) {
|
||||||
}
|
this._uploader = theUploader;
|
||||||
set uploader(theUploader:FileUploader) {
|
}
|
||||||
this._uploader = theUploader;
|
public onBeforeUpload(
|
||||||
}
|
item: FileItem,
|
||||||
public onBeforeUpload(item:FileItem, options:FileUploaderOptions):Promise<any>{
|
options: FileUploaderOptions
|
||||||
const promise = new Promise((resolve, reject) => {
|
): Promise<any> {
|
||||||
resolve(true);
|
const promise = new Promise((resolve, reject) => {
|
||||||
});
|
resolve(true);
|
||||||
return promise;
|
});
|
||||||
}
|
return promise;
|
||||||
public uploadFile(item:FileItem, options:FileUploaderOptions):void{
|
}
|
||||||
this.onBeforeUpload(item,options).then(
|
public uploadFile(item: FileItem, options: FileUploaderOptions): void {
|
||||||
() => {
|
this.onBeforeUpload(item, options).then(() => {
|
||||||
this._uploadFile(item, options);
|
this._uploadFile(item, options);
|
||||||
}
|
});
|
||||||
)
|
}
|
||||||
}
|
public onBeforeGetDefaultHeaders(): Promise<any> {
|
||||||
public onBeforeGetDefaultHeaders(): Promise<any> {
|
const promise = new Promise((resolve, reject) => {
|
||||||
const promise = new Promise((resolve, reject) => {
|
resolve(true);
|
||||||
resolve(true);
|
});
|
||||||
});
|
return promise;
|
||||||
return promise;
|
}
|
||||||
}
|
protected _getDefaultHeaders(): Promise<any> {
|
||||||
protected _getDefaultHeaders(): Promise<any>{
|
return new Promise((resolve, reject) => {
|
||||||
return new Promise((resolve,reject) => {
|
this.onBeforeGetDefaultHeaders().then(
|
||||||
this.onBeforeGetDefaultHeaders().then(
|
result => {
|
||||||
(result) => {
|
const h: any = {};
|
||||||
const h:any = {}
|
if (this.options.tokenPattern && this.options.token) {
|
||||||
if (this.options.tokenPattern && this.options.token) {
|
h[
|
||||||
h[this.options.authorizationHeaderName] = this.options.tokenPattern.replace("#token#", this.options.token);
|
this.options.authorizationHeaderName
|
||||||
}
|
] = this.options.tokenPattern.replace(
|
||||||
for (const key in this.additionalHeaders) {
|
'#token#',
|
||||||
if (this.additionalHeaders.hasOwnProperty(key)) {
|
this.options.token
|
||||||
h[key] = this.additionalHeaders[key];
|
);
|
||||||
}
|
}
|
||||||
}
|
for (const key in this.additionalHeaders) {
|
||||||
resolve(h);
|
if (this.additionalHeaders.hasOwnProperty(key)) {
|
||||||
},
|
h[key] = this.additionalHeaders[key];
|
||||||
(error) => {
|
}
|
||||||
reject(error);
|
}
|
||||||
}
|
resolve(h);
|
||||||
)
|
},
|
||||||
})
|
error => {
|
||||||
}
|
reject(error);
|
||||||
protected _getRequestHeaders(item: FileItem, options: FileUploaderOptions): Promise<any> {
|
}
|
||||||
return new Promise((resolve,reject) => {
|
);
|
||||||
this._getDefaultHeaders().then(
|
});
|
||||||
(h) => {
|
}
|
||||||
if (options.headers) {
|
protected _getRequestHeaders(
|
||||||
for (let header of options.headers) {
|
item: FileItem,
|
||||||
h[header.name] = header.value;
|
options: FileUploaderOptions
|
||||||
}
|
): Promise<any> {
|
||||||
}
|
return new Promise((resolve, reject) => {
|
||||||
if (item.headers.length) {
|
this._getDefaultHeaders().then(
|
||||||
for (let header of item.headers) {
|
h => {
|
||||||
h[header.name] = header.value;
|
if (options.headers) {
|
||||||
}
|
for (let header of options.headers) {
|
||||||
}
|
h[header.name] = header.value;
|
||||||
resolve(h);
|
}
|
||||||
},
|
}
|
||||||
(error) => {
|
if (item.headers.length) {
|
||||||
reject(error)
|
for (let header of item.headers) {
|
||||||
}
|
h[header.name] = header.value;
|
||||||
)
|
}
|
||||||
})
|
}
|
||||||
}
|
resolve(h);
|
||||||
|
},
|
||||||
|
error => {
|
||||||
|
reject(error);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public buildPackageToSend(item:FileItem, options:FileUploaderOptions){
|
public buildPackageToSend(item: FileItem, options: FileUploaderOptions) {
|
||||||
let sendable: FormData = new FormData();
|
let sendable: FormData = new FormData();
|
||||||
this.uploader._onBuildItemForm(item, sendable);
|
this.uploader._onBuildItemForm(item, sendable);
|
||||||
let file: any = null;
|
let file: any = null;
|
||||||
if (this.options.chunkSize > 0) {
|
if (this.options.chunkSize > 0) {
|
||||||
@@ -136,7 +143,8 @@ export class FileUploaderService {
|
|||||||
} else {
|
} else {
|
||||||
file = item._file;
|
file = item._file;
|
||||||
}
|
}
|
||||||
const appendFile = () => sendable.append(this.options.fileParamName, file, item.file.name);
|
const appendFile = () =>
|
||||||
|
sendable.append(this.options.fileParamName, file, item.file.name);
|
||||||
if (!options.parametersBeforeFiles) {
|
if (!options.parametersBeforeFiles) {
|
||||||
appendFile();
|
appendFile();
|
||||||
}
|
}
|
||||||
@@ -146,191 +154,205 @@ export class FileUploaderService {
|
|||||||
Object.keys(options.additionalParameter).forEach((key: string) => {
|
Object.keys(options.additionalParameter).forEach((key: string) => {
|
||||||
let paramVal = options.additionalParameter[key];
|
let paramVal = options.additionalParameter[key];
|
||||||
// Allow an additional parameter to include the filename
|
// Allow an additional parameter to include the filename
|
||||||
if (typeof paramVal === 'string' && paramVal.indexOf('{{file_name}}') >= 0) {
|
if (
|
||||||
|
typeof paramVal === 'string' &&
|
||||||
|
paramVal.indexOf('{{file_name}}') >= 0
|
||||||
|
) {
|
||||||
paramVal = paramVal.replace('{{file_name}}', item.file.name);
|
paramVal = paramVal.replace('{{file_name}}', item.file.name);
|
||||||
}
|
}
|
||||||
sendable.append(key, paramVal);
|
sendable.append(key, paramVal);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.options.chunkSize > 0 && this.options.totalChunkParamName) {
|
if (this.options.chunkSize > 0 && this.options.totalChunkParamName) {
|
||||||
sendable.append(this.options.totalChunkParamName, item.getTotalChunks().toString());
|
sendable.append(
|
||||||
}
|
this.options.totalChunkParamName,
|
||||||
|
item.getTotalChunks().toString()
|
||||||
|
);
|
||||||
|
}
|
||||||
if (this.options.chunkSize > 0 && this.options.currentChunkParamName) {
|
if (this.options.chunkSize > 0 && this.options.currentChunkParamName) {
|
||||||
sendable.append(this.options.currentChunkParamName, (item.getCurrentChunk() + 1).toString() );
|
sendable.append(
|
||||||
}
|
this.options.currentChunkParamName,
|
||||||
|
(item.getCurrentChunk() + 1).toString()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if (options.parametersBeforeFiles) {
|
if (options.parametersBeforeFiles) {
|
||||||
appendFile();
|
appendFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
return sendable;
|
return sendable;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected _uploadFile(item:FileItem, options:FileUploaderOptions):void{
|
protected _uploadFile(item: FileItem, options: FileUploaderOptions): void {
|
||||||
this._getRequestHeaders(item, options).then(
|
this._getRequestHeaders(item, options).then(
|
||||||
(headers) => {
|
headers => {
|
||||||
let request_method = this.options.createMethod;
|
let request_method = this.options.createMethod;
|
||||||
let link = this.links.createEntry;
|
let link = this.links.createEntry;
|
||||||
item.setIsUploading(true);
|
item.setIsUploading(true);
|
||||||
if(this.options.chunkSize > 0){
|
if (this.options.chunkSize > 0) {
|
||||||
try{
|
try {
|
||||||
item.getCurrentChunk()
|
item.getCurrentChunk();
|
||||||
}catch(err){
|
} catch (err) {
|
||||||
item.createFileChunk(this.options.chunkSize);
|
item.createFileChunk(this.options.chunkSize);
|
||||||
}
|
}
|
||||||
request_method = item.getCurrentChunk() > 0 ? this.options.updateMethod : this.options.createMethod;
|
request_method =
|
||||||
link = item.getCurrentChunk() > 0 ? this.links.updateEntry : this.links.createEntry;
|
item.getCurrentChunk() > 0
|
||||||
}
|
? this.options.updateMethod
|
||||||
if (item.getId()){
|
: this.options.createMethod;
|
||||||
link = link.replace("#id#", item.getId());
|
link =
|
||||||
}
|
item.getCurrentChunk() > 0
|
||||||
const data = this.buildPackageToSend(item, options);
|
? this.links.updateEntry
|
||||||
let request = new HttpRequest(request_method, link, data, {
|
: this.links.createEntry;
|
||||||
headers: new HttpHeaders(headers),
|
}
|
||||||
reportProgress: true,
|
if (item.getId()) {
|
||||||
withCredentials: item.withCredentials,
|
link = link.replace('#id#', item.getId());
|
||||||
});
|
}
|
||||||
this.uploadSubscription = this.http.request(request).subscribe(
|
const data = this.buildPackageToSend(item, options);
|
||||||
(event) => {
|
const request = new HttpRequest(request_method, link, data, {
|
||||||
this.getEventMessage(event, item);
|
headers: new HttpHeaders(headers),
|
||||||
},
|
reportProgress: true,
|
||||||
(error) => {
|
withCredentials: item.withCredentials,
|
||||||
if(this.cancelError === error){
|
});
|
||||||
this.uploader.onAbort(error, item);
|
this.uploadSubscription = this.http.request(request).subscribe(
|
||||||
}else{
|
(event: any) => {
|
||||||
this.uploader.onError(error, item);
|
this.getEventMessage(event, item);
|
||||||
}
|
},
|
||||||
|
(error: any) => {
|
||||||
},
|
if (this.cancelError === error) {
|
||||||
)
|
this.uploader.onAbort(error, item);
|
||||||
},
|
} else {
|
||||||
(error) =>{
|
this.uploader.onError(error, item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
},
|
||||||
|
error => {}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
public stopUpload() {
|
||||||
|
if (this.uploadSubscription && this.uploadSubscription.unsubscribe) {
|
||||||
|
this.uploadSubscription.error(this.cancelError);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private getEventMessage(event: any, item: FileItem) {
|
||||||
|
switch (event.type) {
|
||||||
|
case HttpEventType.ResponseHeader:
|
||||||
|
break;
|
||||||
|
case HttpEventType.Sent:
|
||||||
|
this.uploader.onStart(event, item);
|
||||||
|
break;
|
||||||
|
case HttpEventType.UploadProgress:
|
||||||
|
this.uploader.onProgress(event, item);
|
||||||
|
break;
|
||||||
|
case HttpEventType.Response:
|
||||||
|
if (this.options.chunkSize > 0) {
|
||||||
|
if (item.getCurrentChunk() === 0) {
|
||||||
|
const response = event.body;
|
||||||
|
if (response[this.options.idAttribute]) {
|
||||||
|
item.setId(response[this.options.idAttribute]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.uploader.onLoad(event, item);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private handleError(item: FileItem) {
|
||||||
|
const userMessage = `${item.file.name} upload failed.`;
|
||||||
|
|
||||||
}
|
return (error: HttpErrorResponse) => {
|
||||||
)
|
this.uploader.onError(error, item);
|
||||||
}
|
|
||||||
public stopUpload() {
|
|
||||||
if(this.uploadSubscription && this.uploadSubscription.unsubscribe){
|
|
||||||
this.uploadSubscription.error(this.cancelError)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
private getEventMessage(event: any, item: FileItem) {
|
|
||||||
switch (event.type) {
|
|
||||||
case HttpEventType.ResponseHeader:
|
|
||||||
break;
|
|
||||||
case HttpEventType.Sent:
|
|
||||||
this.uploader.onStart(event, item);
|
|
||||||
break;
|
|
||||||
case HttpEventType.UploadProgress:
|
|
||||||
this.uploader.onProgress(event, item);
|
|
||||||
break;
|
|
||||||
case HttpEventType.Response:
|
|
||||||
if(this.options.chunkSize > 0){
|
|
||||||
if(item.getCurrentChunk() === 0) {
|
|
||||||
const response = event.body;
|
|
||||||
if(response[this.options.idAttribute]) {
|
|
||||||
item.setId(response[this.options.idAttribute])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.uploader.onLoad(event, item);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
private handleError(item: FileItem) {
|
|
||||||
const userMessage = `${item.file.name} upload failed.`;
|
|
||||||
|
|
||||||
return (error: HttpErrorResponse) => {
|
|
||||||
this.uploader.onError(error, item);
|
|
||||||
|
|
||||||
const message = (error.error instanceof Error) ?
|
const message =
|
||||||
error.error.message :
|
error.error instanceof Error
|
||||||
`server returned code ${error.status} with body "${error.error}"`;
|
? error.error.message
|
||||||
|
: `server returned code ${error.status} with body "${error.error}"`;
|
||||||
|
|
||||||
return of(userMessage);
|
return of (userMessage);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public deleteEntry(item: FileItem, options = {}, skipConfirmation = false): Observable<any>{
|
public deleteEntry(
|
||||||
if(item.getId() && this.links['deleteEntry']){
|
item: FileItem,
|
||||||
let link = this.links['deleteEntry'].replace(/#id#/g, item.getId());
|
options = {},
|
||||||
let confirmation = false;
|
skipConfirmation = false
|
||||||
if(skipConfirmation){
|
): Observable <any> {
|
||||||
confirmation = true;
|
if (item.getId() && this.links['deleteEntry']) {
|
||||||
} else {
|
let link = this.links['deleteEntry'].replace(/#id#/g, item.getId());
|
||||||
confirmation = confirm("Are you sure you want to delete this entry?")
|
let confirmation = false;
|
||||||
}
|
if (skipConfirmation) {
|
||||||
|
confirmation = true;
|
||||||
if (confirmation) {
|
} else {
|
||||||
return this.delete(link, options).map(
|
confirmation = confirm('Are you sure you want to delete this entry?');
|
||||||
(response: Response) => {
|
}
|
||||||
return response;
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
return Observable.of(false);
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
return Observable.of(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected delete(url: string, options = {}): Observable<any> {
|
if (confirmation) {
|
||||||
return new Observable(
|
return this.delete(link, options)
|
||||||
(observe) => {
|
} else {
|
||||||
this._getDefaultHeaders().then(
|
return of(false);
|
||||||
function(headers){
|
}
|
||||||
return this.http.delete(url, {headers: new HttpHeaders(headers) }).subscribe(
|
} else {
|
||||||
(response: Response) => {
|
return of(false);
|
||||||
observe.next(response);
|
}
|
||||||
},
|
}
|
||||||
(error) => {
|
|
||||||
observe.error(error);
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}.bind(this),
|
|
||||||
(error) => {
|
|
||||||
observe.error(error);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
protected delete(url: string, options = {}): Observable<any> {
|
||||||
HTTP General methos only bellow
|
return new Observable((observe:any) => {
|
||||||
*/
|
this._getDefaultHeaders().then(
|
||||||
protected get(url: string): Observable<any>{
|
function(headers: any) {
|
||||||
return new Observable(
|
return this.http
|
||||||
(observe) => {
|
.delete(url, { headers: new HttpHeaders(headers) })
|
||||||
this._getDefaultHeaders().then(
|
.subscribe(
|
||||||
function(headers){
|
(response: Response) => {
|
||||||
return this.http.get(url, {headers: new HttpHeaders(headers) }).subscribe(
|
observe.next(response);
|
||||||
(response: Response) => {
|
},
|
||||||
observe.next(response);
|
(error: any) => {
|
||||||
},
|
observe.error(error);
|
||||||
(error) => {
|
}
|
||||||
observe.error(error);
|
);
|
||||||
}
|
}.bind(this),
|
||||||
);
|
error => {
|
||||||
}.bind(this),
|
observe.error(error);
|
||||||
(error) => {
|
}
|
||||||
observe.error(error);
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
public addHeader(name=null, value=null){
|
/*
|
||||||
this.additionalHeaders[name] = value
|
HTTP General methos only bellow
|
||||||
}
|
*/
|
||||||
|
protected get(url: string): Observable<any> {
|
||||||
|
return new Observable(observe => {
|
||||||
|
this._getDefaultHeaders().then(
|
||||||
|
function(headers:any) {
|
||||||
|
return this.http
|
||||||
|
.get(url, { headers: new HttpHeaders(headers) })
|
||||||
|
.subscribe(
|
||||||
|
(response: Response) => {
|
||||||
|
observe.next(response);
|
||||||
|
},
|
||||||
|
(error: any) => {
|
||||||
|
observe.error(error);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}.bind(this),
|
||||||
|
error => {
|
||||||
|
observe.error(error);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public removeHeader(name=null){
|
public addHeader(name:string = null, value:any = null) {
|
||||||
if(this.additionalHeaders.hasOwnProperty(name)){
|
this.additionalHeaders[name] = value;
|
||||||
delete(this.additionalHeaders[name])
|
}
|
||||||
}
|
|
||||||
}
|
public removeHeader(name:string = null) {
|
||||||
}
|
if (this.additionalHeaders.hasOwnProperty(name)) {
|
||||||
|
delete this.additionalHeaders[name];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -20,8 +20,7 @@
|
|||||||
"eofline": true,
|
"eofline": true,
|
||||||
"forin": true,
|
"forin": true,
|
||||||
"import-blacklist": [
|
"import-blacklist": [
|
||||||
true,
|
true
|
||||||
"rxjs"
|
|
||||||
],
|
],
|
||||||
"import-spacing": true,
|
"import-spacing": true,
|
||||||
"indent": [
|
"indent": [
|
||||||
|
|||||||
Reference in New Issue
Block a user