mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-09-17 14:21:29 +00:00
* rework folder uploading - flatterns hierarchy on folder upload - performs a single traversal for the entire folder heirarchy and ends with a comple file list - allows now dropping folders on existing folders - overall code improvements * fix unit tests * readme updates * clean old and unused code * code cleanup * limit concurrent uploads * update code as per review * fix upload button for Safari * fixes for Safari - Safari compatibility - code updates based on review * fix code * fix unit tests
75 lines
1.8 KiB
TypeScript
75 lines
1.8 KiB
TypeScript
/*!
|
|
* @license
|
|
* Copyright 2016 Alfresco Software, Ltd.
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
|
|
export interface FileUploadProgress {
|
|
loaded: number;
|
|
total: number;
|
|
percent: number;
|
|
}
|
|
|
|
export interface FileUploadOptions {
|
|
newVersion?: boolean;
|
|
parentId?: string;
|
|
path?: string;
|
|
}
|
|
|
|
export enum FileUploadStatus {
|
|
Pending = 0,
|
|
Complete = 1,
|
|
Starting = 2,
|
|
Progress = 3,
|
|
Cancelled = 4,
|
|
Aborted = 5,
|
|
Error = 6
|
|
}
|
|
|
|
export class FileModel {
|
|
readonly id: string;
|
|
readonly name: string;
|
|
readonly size: number;
|
|
readonly file: File;
|
|
|
|
status: FileUploadStatus = FileUploadStatus.Pending;
|
|
progress: FileUploadProgress;
|
|
options: FileUploadOptions;
|
|
|
|
constructor(file: File, options?: FileUploadOptions) {
|
|
this.file = file;
|
|
|
|
this.id = this.generateId();
|
|
this.name = file.name;
|
|
this.size = file.size;
|
|
|
|
this.progress = {
|
|
loaded: 0,
|
|
total: 0,
|
|
percent: 0
|
|
};
|
|
|
|
this.options = Object.assign({}, {
|
|
newVersion: false
|
|
}, options);
|
|
}
|
|
|
|
private generateId(): string {
|
|
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
|
|
let r = Math.random() * 16 | 0, v = c === 'x' ? r : (r & 0x3 | 0x8);
|
|
return v.toString(16);
|
|
});
|
|
}
|
|
}
|