#46 upload jsdoc and clean code

This commit is contained in:
Mario Romano
2016-05-06 12:48:53 +01:00
parent 54b1707b30
commit 1a7248b1e9
40 changed files with 803 additions and 317 deletions

View File

@@ -14,6 +14,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
*
* This object represent the status of an uploading file.
*
*
* @returns {FileModel} .
*/
export declare class FileModel {
id: string;
status: number;
@@ -33,8 +40,24 @@ export declare class FileModel {
setError(): void;
setUploading(): void;
setXMLHttpRequest(xmlHttpRequest: XMLHttpRequest): void;
/**
* Stop the uploading of the file.
*/
setAbort(): void;
/**
* Update status of the file when upload finish or is ended.
*/
onFinished(status: number, statusText: string, response: string): void;
/**
* Calculate the size of the file in kb,mb and gb.
*
* @param {number} sizeinbytes - size in bytes of the file.
*/
private _getFileSize(sizeinbytes);
/**
* Calculate the size of the file in kb,mb and gb.
*
* @return {string} - return a unique file uploading id.
*/
private _generateId();
}

View File

@@ -21,6 +21,13 @@ System.register([], function(exports_1, context_1) {
return {
setters:[],
execute: function() {
/**
*
* This object represent the status of an uploading file.
*
*
* @returns {FileModel} .
*/
FileModel = (function () {
function FileModel(file) {
this.done = false;
@@ -49,6 +56,9 @@ System.register([], function(exports_1, context_1) {
FileModel.prototype.setXMLHttpRequest = function (xmlHttpRequest) {
this._xmlHttpRequest = xmlHttpRequest;
};
/**
* Stop the uploading of the file.
*/
FileModel.prototype.setAbort = function () {
if (!this.done && !this.error) {
this.abort = true;
@@ -56,6 +66,9 @@ System.register([], function(exports_1, context_1) {
this._xmlHttpRequest.abort();
}
};
/**
* Update status of the file when upload finish or is ended.
*/
FileModel.prototype.onFinished = function (status, statusText, response) {
this.status = status;
this.statusText = statusText;
@@ -63,6 +76,11 @@ System.register([], function(exports_1, context_1) {
this.done = true;
this.uploading = false;
};
/**
* Calculate the size of the file in kb,mb and gb.
*
* @param {number} sizeinbytes - size in bytes of the file.
*/
FileModel.prototype._getFileSize = function (sizeinbytes) {
var fSExt = new Array('Bytes', 'KB', 'MB', 'GB');
var size = sizeinbytes;
@@ -73,8 +91,13 @@ System.register([], function(exports_1, context_1) {
}
return Math.round((Math.round(size * 100) / 100)) + ' ' + fSExt[i];
};
/**
* Calculate the size of the file in kb,mb and gb.
*
* @return {string} - return a unique file uploading id.
*/
FileModel.prototype._generateId = function () {
return 'uploading-' + 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
return 'uploading-file-' + '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);
});

View File

@@ -1 +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;gBAED,gCA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,CAAC,CAAC,GAAG,GAAG,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;gBACvE,CAAC;gBAED;;;;mBAIG;gBACK,+BAAW,GAAnB;oBACI,MAAM,CAAC,iBAAiB,GAAG,sCAAsC,CAAC,OAAO,CAAC,OAAO,EAAE,UAAU,CAAC;wBACtF,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,AA5FD,IA4FC;YA5FD,iCA4FC,CAAA"}

View File

@@ -15,23 +15,29 @@
* limitations under the License.
*/
/**
*
* This object represent the status of an uploading file.
*
*
* @returns {FileModel} .
*/
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;
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) {
constructor(file: any) {
this.file = file;
this.id = this._generateId();
this.name = file.name;
@@ -43,31 +49,37 @@ export class FileModel {
};
}
setProgres(progress:any):void {
setProgres(progress: any): void {
this.progress = progress;
}
setError():void {
setError(): void {
this.error = true;
}
setUploading(){
setUploading() {
this.uploading = true;
}
setXMLHttpRequest(xmlHttpRequest:XMLHttpRequest){
setXMLHttpRequest(xmlHttpRequest: XMLHttpRequest) {
this._xmlHttpRequest = xmlHttpRequest;
}
setAbort():void {
if(!this.done && !this.error){
/**
* Stop the uploading of the file.
*/
setAbort(): void {
if (!this.done && !this.error) {
this.abort = true;
this.uploading = false;
this._xmlHttpRequest.abort();
}
}
onFinished(status:number, statusText:string, response:string):void {
/**
* Update status of the file when upload finish or is ended.
*/
onFinished(status: number, statusText: string, response: string): void {
this.status = status;
this.statusText = statusText;
this.response = response;
@@ -75,7 +87,12 @@ export class FileModel {
this.uploading = false;
}
private _getFileSize(sizeinbytes):string {
/**
* Calculate the size of the file in kb,mb and gb.
*
* @param {number} sizeinbytes - size in bytes of the file.
*/
private _getFileSize(sizeinbytes): string {
let fSExt = new Array('Bytes', 'KB', 'MB', 'GB');
let size = sizeinbytes;
let i = 0;
@@ -86,8 +103,13 @@ export class FileModel {
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) {
/**
* Calculate the size of the file in kb,mb and gb.
*
* @return {string} - return a unique file uploading id.
*/
private _generateId(): string {
return 'uploading-file-' + '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);
});