Skip to content

Commit e1c1f9a

Browse files
authored
Merge pull request #11 from pointcloudtechnology/5-add-option-to-distinguish-between-different-kind-of-files
Add option to distinguish between different kind of files
2 parents 264561f + b7b6141 commit e1c1f9a

17 files changed

+965
-114
lines changed

dist/helpers.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/helpers.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/main.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/main.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/resumable.d.ts

Lines changed: 51 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,24 @@ import { ResumableConfiguration } from './types/types';
66
*/
77
export declare class Resumable extends ResumableEventHandler {
88
private opts;
9+
/**
10+
* An object that contains one entry for every file category. The key is the category name, the value is an array of
11+
* all ResumableFiles of that category that were added to this instance.
12+
*/
913
private files;
14+
/**
15+
* Contains all file categories for which the upload was not yet completed.
16+
*/
17+
private uncompletedFileCategories;
1018
private validators;
1119
private support;
1220
clearInput: boolean;
1321
dragOverClass: string;
14-
fileTypes: string[];
22+
fileCategories: string[];
23+
defaultFileCategory: string | null;
24+
fileTypes: string[] | {
25+
[fileCategory: string]: string[];
26+
};
1527
fileTypeErrorCallback: Function;
1628
_generateUniqueIdentifier: Function;
1729
maxFileSize?: number;
@@ -38,6 +50,7 @@ export declare class Resumable extends ResumableEventHandler {
3850
*/
3951
protected setInstanceProperties(options: ResumableConfiguration): void;
4052
private sanitizeFileTypes;
53+
private throwIfUnknownFileCategory;
4154
/**
4255
* Transforms a single fileEntry or directoryEntry item into a list of File objects this method is used to convert
4356
* entries found inside dragged-and-dropped directories.
@@ -61,7 +74,6 @@ export declare class Resumable extends ResumableEventHandler {
6174
* class to the element when a file is dropped onto it. In this case, we have to remove that class again before
6275
* calling "onDrop()".
6376
* If "onDrop()" is called from "handleDropEvent()" this is not needed.
64-
*
6577
*/
6678
private removeDragOverClassAndCallOnDrop;
6779
/**
@@ -80,47 +92,70 @@ export declare class Resumable extends ResumableEventHandler {
8092
* Validate and clean a list of files. This includes the removal of duplicates, a check whether the file type is
8193
* allowed and custom validation functions defined per file type.
8294
* @param {ExtendedFile[]} files A list of File instances that were previously extended with a uniqueIdentifier
95+
* @param fileCategory The file category that has been provided for the files. Defaults to `defaultFileCategory`.
8396
*/
8497
private validateFiles;
8598
/**
86-
* Add an array of files to this instance's file list by creating new ResumableFiles. This includes a validation and
87-
* deduplication of the provided array.
99+
* Add an array of files to this instance's file list (of the file category, if given) by creating new ResumableFiles.
100+
* This includes a validation and deduplication of the provided array.
88101
* @param fileList An array containing File objects
89102
* @param event The event with which the fileList was provided
103+
* @param fileCategory The file category that has been provided for the file. Defaults to `defaultFileCategory`.
90104
*/
91105
private appendFilesFromFileList;
92106
/**
93107
* Generate a new unique identifier for a given file either with a default helper function or with a custom
94108
* generator function.
95109
* @param file The file as an HTML 5 File object
96110
* @param event The event with which the file was provided originally
111+
* @param fileCategory The file category that has been provided for the file. Defaults to `defaultFileCategory`.
97112
*/
98113
private generateUniqueIdentifier;
99114
/**
100115
* Queue a new chunk to be uploaded that is currently awaiting upload.
101116
*/
102117
private uploadNextChunk;
118+
/**
119+
* Returns all ResumableFiles of all file categories.
120+
* The files are ordered by the order of the file categories in `this.fileCategories`. Files of the first category
121+
* are added first, files of the second category are added second etc.
122+
*
123+
* @returns {ResumableFile[]} Array of all ResumableFiles that are stored for any category.
124+
*/
125+
private getFilesOfAllCategories;
103126
/**
104127
* PUBLIC METHODS FOR RESUMABLE.JS
105128
* This section only includes methods that should be callable from external packages.
106129
*/
107130
/**
108131
* Assign a browse action to one or more DOM nodes. Pass in true to allow directories to be selected (Chrome only).
132+
*
133+
* @param domNodes The dom nodes to which the browse action should be assigned (can be an array or a single dom node).
134+
* @param isDirectory If true, directories can be added via the file picker (Chrome only).
135+
* @param fileCategory The file category that will be assigned to all added files. Defaults to `defaultFileCategory`.
109136
*/
110-
assignBrowse(domNodes: HTMLElement | HTMLElement[], isDirectory?: boolean): void;
137+
assignBrowse(domNodes: HTMLElement | HTMLElement[], isDirectory?: boolean, fileCategory?: string): void;
111138
/**
112139
* Assign one or more DOM nodes as a drop target.
140+
*
141+
* @param domNodes The dom nodes to which the drop action should be assigned (can be an array or a single dom node).
142+
* @param fileCategory The file category that will be assigned to all added files. Defaults to `defaultFileCategory`.
113143
*/
114-
assignDrop(domNodes: HTMLElement | HTMLElement[]): void;
144+
assignDrop(domNodes: HTMLElement | HTMLElement[], fileCategory?: string): void;
115145
/**
116146
* Remove one or more DOM nodes as a drop target.
117147
*/
118148
unAssignDrop(domNodes: HTMLElement | HTMLElement[]): void;
119149
/**
120-
* Set the file types allowed to upload. Optionally pass a dom node on which the accepted file types should be
121-
* updated as well.
150+
* Set the file types allowed to upload.
151+
* Per default the file types are updated for the default file category.
152+
* Optionally pass a dom node on which the accepted file types should be updated as well.
153+
*
154+
* @param fileTypes String array of all allowed file types
155+
* @param domNode An optional HTMLInputElement for which the "accepted" attribute should be updated accordingly.
156+
* @param fileCategory The file category for which the file types should be updated. Defaults to `defaultFileCategory`.
122157
*/
123-
setFileTypes(fileTypes: string[], domNode?: HTMLInputElement): void;
158+
setFileTypes(fileTypes: string[], domNode?: HTMLInputElement, fileCategory?: string): void;
124159
/**
125160
* Check whether any files are currently uploading
126161
*/
@@ -144,11 +179,11 @@ export declare class Resumable extends ResumableEventHandler {
144179
/**
145180
* Add a HTML5 File object to the list of files.
146181
*/
147-
addFile(file: File, event: Event): void;
182+
addFile(file: File, event: Event, fileCategory?: string): void;
148183
/**
149184
* Add a list of HTML5 File objects to the list of files.
150185
*/
151-
addFiles(files: File[], event: Event): void;
186+
addFiles(files: File[], event: Event, fileCategory?: string): void;
152187
/**
153188
* Add a validator function for the given file type. This can e.g. be used to read the file and validate
154189
* checksums based on certain properties.
@@ -157,7 +192,7 @@ export declare class Resumable extends ResumableEventHandler {
157192
*/
158193
addFileValidator(fileType: string, validator: Function): void;
159194
/**
160-
* Cancel the upload of a specific ResumableFile object and remove it from the file list.
195+
* Remove the given resumable file from the file list (of its corresponding file category).
161196
*/
162197
removeFile(file: ResumableFile): void;
163198
/**
@@ -171,13 +206,14 @@ export declare class Resumable extends ResumableEventHandler {
171206
/**
172207
* Call the event handler for a DragEvent (when a file is dropped on a drop area).
173208
*/
174-
handleDropEvent(e: DragEvent): void;
209+
handleDropEvent(e: DragEvent, fileCategory?: string): void;
175210
/**
176211
* Call the event handler for an InputEvent (i.e. received one or multiple files).
177212
*/
178-
handleChangeEvent(e: InputEvent): void;
213+
handleChangeEvent(e: InputEvent, fileCategory?: string): void;
179214
/**
180-
* Check whether the upload is completed, i.e. if all files were uploaded successfully.
215+
* Check whether the upload is completed (if all files of a category are uploaded and if all files in general are
216+
* uploaded).
181217
*/
182218
checkUploadComplete(): void;
183219
/**

dist/resumableChunk.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export default class ResumableChunk extends ResumableEventHandler {
2626
totalSizeParameterName: string;
2727
typeParameterName: string;
2828
identifierParameterName: string;
29+
fileCategoryParameterName: string;
2930
fileNameParameterName: string;
3031
relativePathParameterName: string;
3132
totalChunksParameterName: string;

dist/resumableFile.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ export default class ResumableFile extends ResumableEventHandler {
1313
size: number;
1414
relativePath: string;
1515
uniqueIdentifier: string;
16+
fileCategory: string;
1617
private _error;
1718
chunks: ResumableChunk[];
1819
private chunkSize;
19-
constructor(file: File, uniqueIdentifier: string, options: object);
20+
constructor(file: File, uniqueIdentifier: string, fileCategory: string, options: object);
2021
/**
2122
* Set the options provided inside the configuration object on this instance
2223
*/

0 commit comments

Comments
 (0)