mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-31 17:38:48 +00:00
#46 upload component
This commit is contained in:
40
ng2-components/ng2-alfresco-upload/src/models/file.model.d.ts
vendored
Normal file
40
ng2-components/ng2-alfresco-upload/src/models/file.model.d.ts
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
/**
|
||||
* @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 declare class FileModel {
|
||||
id: string;
|
||||
status: number;
|
||||
statusText: string;
|
||||
progress: Object;
|
||||
name: string;
|
||||
size: string;
|
||||
response: string;
|
||||
done: boolean;
|
||||
error: boolean;
|
||||
abort: boolean;
|
||||
uploading: boolean;
|
||||
file: any;
|
||||
_xmlHttpRequest: XMLHttpRequest;
|
||||
constructor(file: any);
|
||||
setProgres(progress: any): void;
|
||||
setError(): void;
|
||||
setUploading(): void;
|
||||
setXMLHttpRequest(xmlHttpRequest: XMLHttpRequest): void;
|
||||
setAbort(): void;
|
||||
onFinished(status: number, statusText: string, response: string): void;
|
||||
private _getFileSize(sizeinbytes);
|
||||
private _generateId();
|
||||
}
|
88
ng2-components/ng2-alfresco-upload/src/models/file.model.js
Normal file
88
ng2-components/ng2-alfresco-upload/src/models/file.model.js
Normal file
@@ -0,0 +1,88 @@
|
||||
/**
|
||||
* @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.
|
||||
*/
|
||||
System.register([], function(exports_1, context_1) {
|
||||
"use strict";
|
||||
var __moduleName = context_1 && context_1.id;
|
||||
var FileModel;
|
||||
return {
|
||||
setters:[],
|
||||
execute: function() {
|
||||
FileModel = (function () {
|
||||
function FileModel(file) {
|
||||
this.done = false;
|
||||
this.error = false;
|
||||
this.abort = false;
|
||||
this.uploading = false;
|
||||
this.file = file;
|
||||
this.id = this._generateId();
|
||||
this.name = file.name;
|
||||
this.size = this._getFileSize(file.size);
|
||||
this.progress = {
|
||||
loaded: 0,
|
||||
total: 0,
|
||||
percent: 0
|
||||
};
|
||||
}
|
||||
FileModel.prototype.setProgres = function (progress) {
|
||||
this.progress = progress;
|
||||
};
|
||||
FileModel.prototype.setError = function () {
|
||||
this.error = true;
|
||||
};
|
||||
FileModel.prototype.setUploading = function () {
|
||||
this.uploading = true;
|
||||
};
|
||||
FileModel.prototype.setXMLHttpRequest = function (xmlHttpRequest) {
|
||||
this._xmlHttpRequest = xmlHttpRequest;
|
||||
};
|
||||
FileModel.prototype.setAbort = function () {
|
||||
if (!this.done && !this.error) {
|
||||
this.abort = true;
|
||||
this.uploading = false;
|
||||
this._xmlHttpRequest.abort();
|
||||
}
|
||||
};
|
||||
FileModel.prototype.onFinished = function (status, statusText, response) {
|
||||
this.status = status;
|
||||
this.statusText = statusText;
|
||||
this.response = response;
|
||||
this.done = true;
|
||||
this.uploading = false;
|
||||
};
|
||||
FileModel.prototype._getFileSize = function (sizeinbytes) {
|
||||
var fSExt = new Array('Bytes', 'KB', 'MB', 'GB');
|
||||
var size = sizeinbytes;
|
||||
var i = 0;
|
||||
while (size > 900) {
|
||||
size /= 1000;
|
||||
i++;
|
||||
}
|
||||
return Math.round((Math.round(size * 100) / 100)) + ' ' + fSExt[i];
|
||||
};
|
||||
FileModel.prototype._generateId = function () {
|
||||
return 'uploading-' + 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
|
||||
var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
|
||||
return v.toString(16);
|
||||
});
|
||||
};
|
||||
return FileModel;
|
||||
}());
|
||||
exports_1("FileModel", FileModel);
|
||||
}
|
||||
}
|
||||
});
|
||||
//# sourceMappingURL=file.model.js.map
|
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"file.model.js","sourceRoot":"","sources":["file.model.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;;;;;;;;YAGH;gBAeI,mBAAY,IAAQ;oBAPpB,SAAI,GAAW,KAAK,CAAC;oBACrB,UAAK,GAAW,KAAK,CAAC;oBACtB,UAAK,GAAW,KAAK,CAAC;oBACtB,cAAS,GAAW,KAAK,CAAC;oBAKtB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;oBACjB,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;oBAC7B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC;oBACtB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;oBACzC,IAAI,CAAC,QAAQ,GAAG;wBACZ,MAAM,EAAE,CAAC;wBACT,KAAK,EAAE,CAAC;wBACR,OAAO,EAAE,CAAC;qBACb,CAAC;gBACN,CAAC;gBAED,8BAAU,GAAV,UAAW,QAAY;oBACnB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;gBAC7B,CAAC;gBAED,4BAAQ,GAAR;oBACI,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;gBACtB,CAAC;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E,CAAC;gBAEO,+BAAW,GAAnB;oBACI,MAAM,CAAC,YAAY,GAAG,sCAAsC,CAAC,OAAO,CAAC,OAAO,EAAE,UAAU,CAAC;wBACjF,IAAI,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,IAAI,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,GAAG,GAAG,GAAG,CAAC,CAAC;wBACnE,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;oBAC1B,CAAC,CAAC,CAAC;gBACX,CAAC;gBACL,gBAAC;YAAD,CAAC,AA5ED,IA4EC;YA5ED,iCA4EC,CAAA"}
|
95
ng2-components/ng2-alfresco-upload/src/models/file.model.ts
Normal file
95
ng2-components/ng2-alfresco-upload/src/models/file.model.ts
Normal file
@@ -0,0 +1,95 @@
|
||||
/**
|
||||
* @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 class FileModel {
|
||||
id:string;
|
||||
status:number;
|
||||
statusText:string;
|
||||
progress:Object;
|
||||
name:string;
|
||||
size:string;
|
||||
response:string;
|
||||
done:boolean = false;
|
||||
error:boolean = false;
|
||||
abort:boolean = false;
|
||||
uploading:boolean = false;
|
||||
file:any;
|
||||
_xmlHttpRequest:XMLHttpRequest;
|
||||
|
||||
constructor(file:any) {
|
||||
this.file = file;
|
||||
this.id = this._generateId();
|
||||
this.name = file.name;
|
||||
this.size = this._getFileSize(file.size);
|
||||
this.progress = {
|
||||
loaded: 0,
|
||||
total: 0,
|
||||
percent: 0
|
||||
};
|
||||
}
|
||||
|
||||
setProgres(progress:any):void {
|
||||
this.progress = progress;
|
||||
}
|
||||
|
||||
setError():void {
|
||||
this.error = true;
|
||||
}
|
||||
|
||||
setUploading(){
|
||||
this.uploading = true;
|
||||
}
|
||||
|
||||
setXMLHttpRequest(xmlHttpRequest:XMLHttpRequest){
|
||||
this._xmlHttpRequest = xmlHttpRequest;
|
||||
}
|
||||
|
||||
setAbort():void {
|
||||
if(!this.done && !this.error){
|
||||
this.abort = true;
|
||||
this.uploading = false;
|
||||
this._xmlHttpRequest.abort();
|
||||
}
|
||||
}
|
||||
|
||||
onFinished(status:number, statusText:string, response:string):void {
|
||||
this.status = status;
|
||||
this.statusText = statusText;
|
||||
this.response = response;
|
||||
this.done = true;
|
||||
this.uploading = false;
|
||||
}
|
||||
|
||||
private _getFileSize(sizeinbytes):string {
|
||||
let fSExt = new Array('Bytes', 'KB', 'MB', 'GB');
|
||||
let size = sizeinbytes;
|
||||
let i = 0;
|
||||
while (size > 900) {
|
||||
size /= 1000;
|
||||
i++;
|
||||
}
|
||||
return Math.round((Math.round(size * 100) / 100)) + ' ' + fSExt[i];
|
||||
}
|
||||
|
||||
private _generateId():string {
|
||||
return 'uploading-' + '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);
|
||||
});
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user