Skip to content

Commit aa14483

Browse files
author
Adrian Fâciu
authored
Merge pull request #903 from adrianfaciu/chore/docs
Updating docs and formatting files
2 parents bcf40f4 + e1e36bb commit aa14483

8 files changed

Lines changed: 228 additions & 248 deletions

File tree

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ Easy to use Angular2 directives for files upload ([demo](http://valor-software.g
2525

2626
- `uploader` - (`FileUploader`) - uploader object. See using in [demo](https://github.com/valor-software/ng2-file-upload/blob/master/demo/components/file-upload/simple-demo.ts)
2727

28+
### Events
29+
- `onFileSelected` - fires when files are selected and added to the uploader queue
30+
2831
## API for `ng2FileDrop`
2932

3033
### Properties
@@ -39,6 +42,7 @@ Easy to use Angular2 directives for files upload ([demo](http://valor-software.g
3942
4. `itemAlias` - item alias (form name redefenition)
4043
5. `formatDataFunction` - Function to modify the request body. 'DisableMultipart' must be 'true' for this function to be called.
4144
6. `formatDataFunctionIsAsync` - Informs if the function sent in 'formatDataFunction' is asynchronous. Defaults to false.
45+
7. `parametersBeforeFiles` - States if additional parameters should be appended before or after the file. Defaults to false.
4246

4347
### Events
4448

demo/src/doc.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ import { FileSelectDirective, FileDropDirective, FileUploader } from 'ng2-file-u
2828
4. `itemAlias` - item alias (form name redefenition)
2929
5. `formatDataFunction` - Function to modify the request body. 'DisableMultipart' must be 'true' for this function to be called.
3030
6. `formatDataFunctionIsAsync` - Informs if the function sent in 'formatDataFunction' is asynchronous. Defaults to false.
31+
7. `parametersBeforeFiles` - States if additional parameters should be appended before or after the file. Defaults to false.
32+
33+
### Events
34+
- `onFileSelected` - fires when files are selected and added to the uploader queue
3135

3236
## FileDrop API
3337

@@ -40,4 +44,4 @@ import { FileSelectDirective, FileDropDirective, FileUploader } from 'ng2-file-u
4044
- `fileOver` - it fires during 'over' and 'out' events for Drop Area; returns `boolean`: `true` if file is over Drop Area, `false` in case of out.
4145
See using in [ts demo](https://github.com/valor-software/ng2-file-upload/blob/master/demo/components/file-upload/simple-demo.ts) and
4246
[html demo](https://github.com/valor-software/ng2-file-upload/blob/master/demo/components/file-upload/simple-demo.html)
43-
- `onFileDrop` - it fires after a file has been dropped on a Drop Area; you can pass in `$event` to get the list of files that were dropped. i.e. `(onFileDrop)="dropped($event)"`
47+
- `onFileDrop` - it fires after a file has been dropped on a Drop Area; you can pass in `$event` to get the list of files that were dropped. i.e. `(onFileDrop)="dropped($event)"`

src/file-upload/file-item.class.ts

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,30 @@ import { FileLikeObject } from './file-like-object.class';
22
import { FileUploader, ParsedResponseHeaders, FileUploaderOptions } from './file-uploader.class';
33

44
export class FileItem {
5-
public file:FileLikeObject;
6-
public _file:File;
7-
public alias:string;
8-
public url:string = '/';
9-
public method:string;
10-
public headers:any = [];
11-
public withCredentials:boolean = true;
12-
public formData:any = [];
13-
public isReady:boolean = false;
14-
public isUploading:boolean = false;
15-
public isUploaded:boolean = false;
16-
public isSuccess:boolean = false;
17-
public isCancel:boolean = false;
18-
public isError:boolean = false;
19-
public progress:number = 0;
20-
public index:number = void 0;
21-
public _xhr:XMLHttpRequest;
22-
public _form:any;
23-
24-
protected uploader:FileUploader;
25-
protected some:File;
26-
protected options:FileUploaderOptions;
27-
28-
public constructor(uploader:FileUploader, some:File, options:FileUploaderOptions) {
5+
public file: FileLikeObject;
6+
public _file: File;
7+
public alias: string;
8+
public url: string = '/';
9+
public method: string;
10+
public headers: any = [];
11+
public withCredentials: boolean = true;
12+
public formData: any = [];
13+
public isReady: boolean = false;
14+
public isUploading: boolean = false;
15+
public isUploaded: boolean = false;
16+
public isSuccess: boolean = false;
17+
public isCancel: boolean = false;
18+
public isError: boolean = false;
19+
public progress: number = 0;
20+
public index: number = void 0;
21+
public _xhr: XMLHttpRequest;
22+
public _form: any;
23+
24+
protected uploader: FileUploader;
25+
protected some: File;
26+
protected options: FileUploaderOptions;
27+
28+
public constructor(uploader: FileUploader, some: File, options: FileUploaderOptions) {
2929
this.uploader = uploader;
3030
this.some = some;
3131
this.options = options;
@@ -38,7 +38,7 @@ export class FileItem {
3838
this.url = uploader.options.url;
3939
}
4040

41-
public upload():void {
41+
public upload(): void {
4242
try {
4343
this.uploader.uploadItem(this);
4444
} catch (e) {
@@ -47,43 +47,43 @@ export class FileItem {
4747
}
4848
}
4949

50-
public cancel():void {
50+
public cancel(): void {
5151
this.uploader.cancelItem(this);
5252
}
5353

54-
public remove():void {
54+
public remove(): void {
5555
this.uploader.removeFromQueue(this);
5656
}
5757

58-
public onBeforeUpload():void {
58+
public onBeforeUpload(): void {
5959
return void 0;
6060
}
6161

62-
public onBuildForm(form:any):any {
63-
return {form};
62+
public onBuildForm(form: any): any {
63+
return { form };
6464
}
6565

66-
public onProgress(progress:number):any {
67-
return {progress};
66+
public onProgress(progress: number): any {
67+
return { progress };
6868
}
6969

70-
public onSuccess(response:string, status:number, headers:ParsedResponseHeaders):any {
71-
return {response, status, headers};
70+
public onSuccess(response: string, status: number, headers: ParsedResponseHeaders): any {
71+
return { response, status, headers };
7272
}
7373

74-
public onError(response:string, status:number, headers:ParsedResponseHeaders):any {
75-
return {response, status, headers};
74+
public onError(response: string, status: number, headers: ParsedResponseHeaders): any {
75+
return { response, status, headers };
7676
}
7777

78-
public onCancel(response:string, status:number, headers:ParsedResponseHeaders):any {
79-
return {response, status, headers};
78+
public onCancel(response: string, status: number, headers: ParsedResponseHeaders): any {
79+
return { response, status, headers };
8080
}
8181

82-
public onComplete(response:string, status:number, headers:ParsedResponseHeaders):any {
83-
return {response, status, headers};
82+
public onComplete(response: string, status: number, headers: ParsedResponseHeaders): any {
83+
return { response, status, headers };
8484
}
8585

86-
public _onBeforeUpload():void {
86+
public _onBeforeUpload(): void {
8787
this.isReady = true;
8888
this.isUploading = true;
8989
this.isUploaded = false;
@@ -94,16 +94,16 @@ export class FileItem {
9494
this.onBeforeUpload();
9595
}
9696

97-
public _onBuildForm(form:any):void {
97+
public _onBuildForm(form: any): void {
9898
this.onBuildForm(form);
9999
}
100100

101-
public _onProgress(progress:number):void {
101+
public _onProgress(progress: number): void {
102102
this.progress = progress;
103103
this.onProgress(progress);
104104
}
105105

106-
public _onSuccess(response:string, status:number, headers:ParsedResponseHeaders):void {
106+
public _onSuccess(response: string, status: number, headers: ParsedResponseHeaders): void {
107107
this.isReady = false;
108108
this.isUploading = false;
109109
this.isUploaded = true;
@@ -115,7 +115,7 @@ export class FileItem {
115115
this.onSuccess(response, status, headers);
116116
}
117117

118-
public _onError(response:string, status:number, headers:ParsedResponseHeaders):void {
118+
public _onError(response: string, status: number, headers: ParsedResponseHeaders): void {
119119
this.isReady = false;
120120
this.isUploading = false;
121121
this.isUploaded = true;
@@ -127,7 +127,7 @@ export class FileItem {
127127
this.onError(response, status, headers);
128128
}
129129

130-
public _onCancel(response:string, status:number, headers:ParsedResponseHeaders):void {
130+
public _onCancel(response: string, status: number, headers: ParsedResponseHeaders): void {
131131
this.isReady = false;
132132
this.isUploading = false;
133133
this.isUploaded = false;
@@ -139,15 +139,15 @@ export class FileItem {
139139
this.onCancel(response, status, headers);
140140
}
141141

142-
public _onComplete(response:string, status:number, headers:ParsedResponseHeaders):void {
142+
public _onComplete(response: string, status: number, headers: ParsedResponseHeaders): void {
143143
this.onComplete(response, status, headers);
144144

145145
if (this.uploader.options.removeAfterUpload) {
146146
this.remove();
147147
}
148148
}
149149

150-
public _prepareToUploading():void {
150+
public _prepareToUploading(): void {
151151
this.index = this.index || ++this.uploader._nextIndex;
152152
this.isReady = true;
153153
}

src/file-upload/file-like-object.class.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,31 @@
1-
function isElement(node:any):boolean {
1+
function isElement(node: any): boolean {
22
return !!(node && (node.nodeName || node.prop && node.attr && node.find));
33
}
44

55
export class FileLikeObject {
6-
public lastModifiedDate:any;
7-
public size:any;
8-
public type:string;
9-
public name:string;
10-
public rawFile:string;
6+
public lastModifiedDate: any;
7+
public size: any;
8+
public type: string;
9+
public name: string;
10+
public rawFile: string;
1111

12-
public constructor(fileOrInput:any) {
12+
public constructor(fileOrInput: any) {
1313
this.rawFile = fileOrInput;
1414
let isInput = isElement(fileOrInput);
1515
let fakePathOrObject = isInput ? fileOrInput.value : fileOrInput;
1616
let postfix = typeof fakePathOrObject === 'string' ? 'FakePath' : 'Object';
1717
let method = '_createFrom' + postfix;
18-
(this as any)[method](fakePathOrObject);
18+
(this as any)[ method ](fakePathOrObject);
1919
}
2020

21-
public _createFromFakePath(path:string):void {
21+
public _createFromFakePath(path: string): void {
2222
this.lastModifiedDate = void 0;
2323
this.size = void 0;
2424
this.type = 'like/' + path.slice(path.lastIndexOf('.') + 1).toLowerCase();
2525
this.name = path.slice(path.lastIndexOf('/') + path.lastIndexOf('\\') + 2);
2626
}
2727

28-
public _createFromObject(object:{size:number, type:string, name:string}):void {
29-
// this.lastModifiedDate = copy(object.lastModifiedDate);
28+
public _createFromObject(object: { size: number, type: string, name: string }): void {
3029
this.size = object.size;
3130
this.type = object.type;
3231
this.name = object.name;

src/file-upload/file-select.directive.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@ import { Directive, EventEmitter, ElementRef, Input, HostListener, Output } from
22

33
import { FileUploader } from './file-uploader.class';
44

5-
// todo: filters
6-
75
@Directive({ selector: '[ng2FileSelect]' })
86
export class FileSelectDirective {
97
@Input() public uploader: FileUploader;
10-
@Output() public onFileSelected:EventEmitter<File[]> = new EventEmitter<File[]>();
8+
@Output() public onFileSelected: EventEmitter<File[]> = new EventEmitter<File[]>();
119

1210
protected element: ElementRef;
1311

@@ -27,23 +25,17 @@ export class FileSelectDirective {
2725
return !!this.element.nativeElement.attributes.multiple;
2826
}
2927

30-
@HostListener('change', ['$event'])
28+
@HostListener('change')
3129
public onChange(): any {
32-
// let files = this.uploader.isHTML5 ? this.element.nativeElement[0].files : this.element.nativeElement[0];
3330
let files = this.element.nativeElement.files;
3431
let options = this.getOptions();
3532
let filters = this.getFilters();
3633

37-
// if(!this.uploader.isHTML5) this.destroy();
38-
3934
this.uploader.addToQueue(files, options, filters);
4035
this.onFileSelected.emit(files);
4136

4237
if (this.isEmptyAfterSelection()) {
43-
// todo
4438
this.element.nativeElement.value = '';
45-
/*this.element.nativeElement
46-
.replaceWith(this.element = this.element.nativeElement.clone(true)); // IE fix*/
4739
}
4840
}
4941
}

src/file-upload/file-type.class.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
export class FileType {
22
/* MS office */
3-
public static mime_doc:string[] = [
3+
public static mime_doc: string[] = [
44
'application/msword',
55
'application/msword',
66
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
77
'application/vnd.openxmlformats-officedocument.wordprocessingml.template',
88
'application/vnd.ms-word.document.macroEnabled.12',
99
'application/vnd.ms-word.template.macroEnabled.12'
1010
];
11-
public static mime_xsl:string[] = [
11+
public static mime_xsl: string[] = [
1212
'application/vnd.ms-excel',
1313
'application/vnd.ms-excel',
1414
'application/vnd.ms-excel',
@@ -19,7 +19,7 @@ export class FileType {
1919
'application/vnd.ms-excel.addin.macroEnabled.12',
2020
'application/vnd.ms-excel.sheet.binary.macroEnabled.12'
2121
];
22-
public static mime_ppt:string[] = [
22+
public static mime_ppt: string[] = [
2323
'application/vnd.ms-powerpoint',
2424
'application/vnd.ms-powerpoint',
2525
'application/vnd.ms-powerpoint',
@@ -34,7 +34,7 @@ export class FileType {
3434
];
3535

3636
/* PSD */
37-
public static mime_psd:string[] = [
37+
public static mime_psd: string[] = [
3838
'image/photoshop',
3939
'image/x-photoshop',
4040
'image/psd',
@@ -44,7 +44,7 @@ export class FileType {
4444
];
4545

4646
/* Compressed files */
47-
public static mime_compress:string[] = [
47+
public static mime_compress: string[] = [
4848
'application/x-gtar',
4949
'application/x-gcompress',
5050
'application/compress',
@@ -53,7 +53,7 @@ export class FileType {
5353
'application/octet-stream'
5454
];
5555

56-
public static getMimeClass(file:any):string {
56+
public static getMimeClass(file: any): string {
5757
let mimeClass = 'application';
5858
if (this.mime_psd.indexOf(file.type) !== -1) {
5959
mimeClass = 'image';
@@ -81,8 +81,8 @@ export class FileType {
8181
return mimeClass;
8282
}
8383

84-
public static fileTypeDetection(inputFilename:string):string {
85-
let types:{[key:string]:string} = {
84+
public static fileTypeDetection(inputFilename: string): string {
85+
let types: { [ key: string ]: string } = {
8686
'jpg': 'image',
8787
'jpeg': 'image',
8888
'tif': 'image',
@@ -144,11 +144,11 @@ export class FileType {
144144
if (chunks.length < 2) {
145145
return 'application';
146146
}
147-
let extension = chunks[chunks.length - 1].toLowerCase();
148-
if (types[extension] === undefined) {
147+
let extension = chunks[ chunks.length - 1 ].toLowerCase();
148+
if (types[ extension ] === undefined) {
149149
return 'application';
150150
} else {
151-
return types[extension];
151+
return types[ extension ];
152152
}
153153
}
154154
}

src/file-upload/file-upload.module.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import { FileDropDirective } from './file-drop.directive';
55
import { FileSelectDirective } from './file-select.directive';
66

77
@NgModule({
8-
imports: [CommonModule],
9-
declarations: [FileDropDirective, FileSelectDirective],
10-
exports: [FileDropDirective, FileSelectDirective]
8+
imports: [ CommonModule ],
9+
declarations: [ FileDropDirective, FileSelectDirective ],
10+
exports: [ FileDropDirective, FileSelectDirective ]
1111
})
1212
export class FileUploadModule {
1313
}

0 commit comments

Comments
 (0)