moontech-file-upload
Version:
## About Based on ng2-file-upload
1,088 lines (1,079 loc) • 32.1 kB
JavaScript
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { Subject as Subject$1 } from 'rxjs/Subject';
import { v4 } from 'uuid';
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
/**
* @param {?} node
* @return {?}
*/
function isElement(node) {
return !!(node && (node.nodeName || node.prop && node.attr && node.find));
}
var FileLikeObject = (function () {
function FileLikeObject(fileOrInput) {
this.rawFile = fileOrInput;
var /** @type {?} */ isInput = isElement(fileOrInput);
var /** @type {?} */ fakePathOrObject = isInput ? fileOrInput.value : fileOrInput;
var /** @type {?} */ postfix = typeof fakePathOrObject === 'string' ? 'FakePath' : 'Object';
var /** @type {?} */ method = '_createFrom' + postfix;
(/** @type {?} */ (this))[method](fakePathOrObject);
}
/**
* @param {?} path
* @return {?}
*/
FileLikeObject.prototype._createFromFakePath = /**
* @param {?} path
* @return {?}
*/
function (path) {
this.lastModifiedDate = void 0;
this.size = void 0;
this.type = 'like/' + path.slice(path.lastIndexOf('.') + 1).toLowerCase();
this.name = path.slice(path.lastIndexOf('/') + path.lastIndexOf('\\') + 2);
};
/**
* @param {?} object
* @return {?}
*/
FileLikeObject.prototype._createFromObject = /**
* @param {?} object
* @return {?}
*/
function (object) {
this.size = object.size;
this.type = object.type;
this.name = object.name;
};
return FileLikeObject;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
var FileType = (function () {
function FileType() {
}
/**
* @param {?} file
* @return {?}
*/
FileType.getMimeClass = /**
* @param {?} file
* @return {?}
*/
function (file) {
var /** @type {?} */ mimeClass = 'application';
if (this.mime_psd.indexOf(file.type) !== -1) {
mimeClass = 'image';
}
else if (file.type.match('image.*')) {
mimeClass = 'image';
}
else if (file.type.match('video.*')) {
mimeClass = 'video';
}
else if (file.type.match('audio.*')) {
mimeClass = 'audio';
}
else if (file.type === 'application/pdf') {
mimeClass = 'pdf';
}
else if (this.mime_compress.indexOf(file.type) !== -1) {
mimeClass = 'compress';
}
else if (this.mime_doc.indexOf(file.type) !== -1) {
mimeClass = 'doc';
}
else if (this.mime_xsl.indexOf(file.type) !== -1) {
mimeClass = 'xls';
}
else if (this.mime_ppt.indexOf(file.type) !== -1) {
mimeClass = 'ppt';
}
if (mimeClass === 'application') {
mimeClass = this.fileTypeDetection(file.name);
}
return mimeClass;
};
/**
* @param {?} inputFilename
* @return {?}
*/
FileType.fileTypeDetection = /**
* @param {?} inputFilename
* @return {?}
*/
function (inputFilename) {
var /** @type {?} */ types = {
jpg: 'image',
jpeg: 'image',
tif: 'image',
psd: 'image',
bmp: 'image',
png: 'image',
nef: 'image',
tiff: 'image',
'cr2': 'image',
dwg: 'image',
cdr: 'image',
ai: 'image',
indd: 'image',
pin: 'image',
cdp: 'image',
skp: 'image',
stp: 'image',
'3dm': 'image',
'mp3': 'audio',
wav: 'audio',
wma: 'audio',
mod: 'audio',
'm4a': 'audio',
compress: 'compress',
zip: 'compress',
rar: 'compress',
'7z': 'compress',
lz: 'compress',
'z01': 'compress',
'bz2': 'compress',
gz: 'compress',
pdf: 'pdf',
xls: 'xls',
xlsx: 'xls',
ods: 'xls',
'mp4': 'video',
avi: 'video',
wmv: 'video',
mpg: 'video',
mts: 'video',
flv: 'video',
'3gp': 'video',
vob: 'video',
'm4v': 'video',
mpeg: 'video',
'm2ts': 'video',
mov: 'video',
doc: 'doc',
docx: 'doc',
eps: 'doc',
txt: 'doc',
odt: 'doc',
rtf: 'doc',
ppt: 'ppt',
pptx: 'ppt',
pps: 'ppt',
ppsx: 'ppt',
odp: 'ppt'
};
var /** @type {?} */ chunks = inputFilename.split('.');
if (chunks.length < 2) {
return 'application';
}
var /** @type {?} */ extension = chunks[chunks.length - 1].toLowerCase();
if (types[extension] === undefined) {
return 'application';
}
else {
return types[extension];
}
};
FileType.mime_doc = [
'application/msword',
'application/msword',
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'application/vnd.openxmlformats-officedocument.wordprocessingml.template',
'application/vnd.ms-word.document.macroEnabled.12',
'application/vnd.ms-word.template.macroEnabled.12'
];
FileType.mime_xsl = [
'application/vnd.ms-excel',
'application/vnd.ms-excel',
'application/vnd.ms-excel',
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
'application/vnd.openxmlformats-officedocument.spreadsheetml.template',
'application/vnd.ms-excel.sheet.macroEnabled.12',
'application/vnd.ms-excel.template.macroEnabled.12',
'application/vnd.ms-excel.addin.macroEnabled.12',
'application/vnd.ms-excel.sheet.binary.macroEnabled.12'
];
FileType.mime_ppt = [
'application/vnd.ms-powerpoint',
'application/vnd.ms-powerpoint',
'application/vnd.ms-powerpoint',
'application/vnd.ms-powerpoint',
'application/vnd.openxmlformats-officedocument.presentationml.presentation',
'application/vnd.openxmlformats-officedocument.presentationml.template',
'application/vnd.openxmlformats-officedocument.presentationml.slideshow',
'application/vnd.ms-powerpoint.addin.macroEnabled.12',
'application/vnd.ms-powerpoint.presentation.macroEnabled.12',
'application/vnd.ms-powerpoint.presentation.macroEnabled.12',
'application/vnd.ms-powerpoint.slideshow.macroEnabled.12'
];
FileType.mime_psd = [
'image/photoshop',
'image/x-photoshop',
'image/psd',
'application/photoshop',
'application/psd',
'zz-application/zz-winassoc-psd'
];
FileType.mime_compress = [
'application/x-gtar',
'application/x-gcompress',
'application/compress',
'application/x-tar',
'application/x-rar-compressed',
'application/octet-stream',
'application/x-zip-compressed',
'application/zip-compressed',
'application/x-7z-compressed',
'application/gzip',
'application/x-bzip2'
];
return FileType;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
/**
* @record
*/
var FileItem = (function () {
function FileItem(file, options) {
this.errorSubject = new Subject$1();
this.successSubject = new Subject$1();
this.progressSubject = new Subject$1();
this.cancelSubject = new Subject$1();
this.pauseSubject = new Subject$1();
this.slicedFile = false;
this.onSlicedBytesSent = 0;
this.bytesSent = 0;
this.isReady = false;
this.isUploading = false;
this.isUploaded = false;
this.isSuccess = false;
this.isCancel = false;
this.isError = false;
this.isPause = false;
this.setOptions(options);
this._id = v4();
this._file = file;
this._notModificableFile = this._file;
this.fileLike = new FileLikeObject(this._file);
if (this.options.maxFileSize) {
this.options.filters.unshift({ name: 'fileSize', fn: this._fileSizeFilter });
}
if (this.options.allowedFileType) {
this.options.filters.unshift({ name: 'fileType', fn: this._fileTypeFilter });
}
if (this.options.allowedMimeType) {
this.options.filters.unshift({ name: 'mimeType', fn: this._mimeTypeFilter });
}
if (this.options.autoUpload) {
this.upload();
}
}
/**
* @return {?}
*/
FileItem.prototype.onError = /**
* @return {?}
*/
function () {
return this.errorSubject.asObservable();
};
/**
* @return {?}
*/
FileItem.prototype.onSuccess = /**
* @return {?}
*/
function () {
return this.successSubject.asObservable();
};
/**
* @return {?}
*/
FileItem.prototype.onProgress = /**
* @return {?}
*/
function () {
return this.progressSubject.asObservable();
};
/**
* @return {?}
*/
FileItem.prototype.onCancel = /**
* @return {?}
*/
function () {
return this.cancelSubject.asObservable();
};
/**
* @return {?}
*/
FileItem.prototype.onPause = /**
* @return {?}
*/
function () {
return this.pauseSubject.asObservable();
};
/**
* @return {?}
*/
FileItem.prototype.getId = /**
* @return {?}
*/
function () {
return this._id;
};
/**
* @return {?}
*/
FileItem.prototype.cancel = /**
* @return {?}
*/
function () {
if (this.isUploading) {
this.isCancel = true;
this._xhr.abort();
}
};
/**
* @return {?}
*/
FileItem.prototype.pause = /**
* @return {?}
*/
function () {
if (this.isUploading) {
this.isPause = true;
this._xhr.abort();
}
};
/**
* @return {?}
*/
FileItem.prototype.upload = /**
* @return {?}
*/
function () {
this.isReady = true;
this.isUploading = true;
this.isUploaded = false;
this.isSuccess = false;
this.isCancel = false;
this.isError = false;
this.isPause = false;
this._xhrTransport();
};
/**
* @return {?}
*/
FileItem.prototype.validateFile = /**
* @return {?}
*/
function () {
var _this = this;
var /** @type {?} */ filters = this.options.filters;
return !filters.length ? true : filters.every(function (filter) {
var /** @type {?} */ success = filter.fn.call(_this.fileLike, _this.options);
if (success) {
return success;
}
throw new Error(filter.name);
});
};
/**
* @param {?} options
* @return {?}
*/
FileItem.prototype.setOptions = /**
* @param {?} options
* @return {?}
*/
function (options) {
this.options = options;
if (!this.options.formatDataFunction) {
this.options.formatDataFunction = function (item) {
return item._file;
};
}
};
/**
* @param {?} item
* @return {?}
*/
FileItem.prototype._mimeTypeFilter = /**
* @param {?} item
* @return {?}
*/
function (item) {
return !(this.options.allowedMimeType && this.options.allowedMimeType.indexOf(item.type) === -1);
};
/**
* @param {?} item
* @return {?}
*/
FileItem.prototype._fileSizeFilter = /**
* @param {?} item
* @return {?}
*/
function (item) {
return !(this.options.maxFileSize && item.size > this.options.maxFileSize);
};
/**
* @param {?} item
* @return {?}
*/
FileItem.prototype._fileTypeFilter = /**
* @param {?} item
* @return {?}
*/
function (item) {
return !(this.options.allowedFileType &&
this.options.allowedFileType.indexOf(FileType.getMimeClass(item)) === -1);
};
/**
* @return {?}
*/
FileItem.prototype._xhrTransport = /**
* @return {?}
*/
function () {
var _this = this;
var /** @type {?} */ xhr = this._xhr = new XMLHttpRequest();
var /** @type {?} */ sendable;
if (this._file.size <= 0) {
throw new TypeError('The file specified is no longer valid');
}
if (!this.options.disableMultipart) {
sendable = new FormData();
var /** @type {?} */ appendFile = function () { return sendable.append(_this.options.itemAlias, _this._file, _this._file.name); };
if (!this.options.parametersBeforeFiles) {
appendFile();
}
// For AWS, Additional Parameters must come BEFORE Files
if (this.options.additionalParameter !== undefined) {
Object.keys(this.options.additionalParameter).forEach(function (key) {
var /** @type {?} */ paramVal = _this.options.additionalParameter[key];
// Allow an additional parameter to include the filename
if (typeof paramVal === 'string' && paramVal.indexOf('{{file_name}}') >= 0) {
paramVal = paramVal.replace('{{file_name}}', _this._file.name);
}
sendable.append(key, paramVal);
});
}
if (this.options.parametersBeforeFiles) {
appendFile();
}
}
else {
sendable = this.options.formatDataFunction(this);
}
xhr.upload.onprogress = function (event) {
var /** @type {?} */ loaded;
var /** @type {?} */ total;
if (_this.slicedFile) {
total = _this._notModificableFile.size;
loaded = Number(_this.onSlicedBytesSent) + Number(event.loaded);
}
else {
total = Number(event.total);
loaded = Number(event.loaded);
}
var /** @type {?} */ progress = Math.round(event.lengthComputable ? loaded * 100 / total : 0);
_this._onProgress(progress, loaded);
};
xhr.onload = function () {
var /** @type {?} */ headers = _this._parseHeaders(xhr.getAllResponseHeaders());
var /** @type {?} */ response = _this._transformResponse(xhr.response, headers);
var /** @type {?} */ gist = _this._isSuccessCode(xhr.status) ?
_this._onSuccess(response, xhr.status, headers) : _this._onError(response, xhr.status, headers);
};
xhr.onerror = function () {
var /** @type {?} */ headers = _this._parseHeaders(xhr.getAllResponseHeaders());
var /** @type {?} */ response = _this._transformResponse(xhr.response, headers);
_this._onError(response, xhr.status, headers);
};
xhr.onabort = function () {
var /** @type {?} */ headers = _this._parseHeaders(xhr.getAllResponseHeaders());
var /** @type {?} */ response = _this._transformResponse(xhr.response, headers);
if (_this.isCancel) {
_this._onCancel(response, xhr.status, headers);
}
else {
_this._onPause(response, xhr.status, headers);
}
};
xhr.open(this.options.method, this.options.url, true);
xhr.withCredentials = this.options.withCredentials;
if (this.options.headers) {
for (var _i = 0, _a = this.options.headers.keys(); _i < _a.length; _i++) {
var header = _a[_i];
xhr.setRequestHeader(header, this.options.headers.get(header));
}
}
if (this.options.formatDataFunctionIsAsync) {
sendable.then(function (result) { return xhr.send(JSON.stringify(result)); });
}
else {
xhr.send(sendable);
}
};
/**
* @param {?} progress
* @param {?} bytesSent
* @return {?}
*/
FileItem.prototype._onProgress = /**
* @param {?} progress
* @param {?} bytesSent
* @return {?}
*/
function (progress, bytesSent) {
this.progress = progress;
this.bytesSent = bytesSent;
this.progressSubject.next({ item: this, progress: progress, bytesSent: bytesSent });
};
/**
* @param {?} headers
* @return {?}
*/
FileItem.prototype._parseHeaders = /**
* @param {?} headers
* @return {?}
*/
function (headers) {
var /** @type {?} */ parsed = {};
var /** @type {?} */ key;
var /** @type {?} */ val;
var /** @type {?} */ i;
if (!headers) {
return parsed;
}
headers.split('\n').map(function (line) {
i = line.indexOf(':');
key = line.slice(0, i).trim().toLowerCase();
val = line.slice(i + 1).trim();
if (key) {
parsed[key] = parsed[key] ? parsed[key] + ', ' + val : val;
}
});
return parsed;
};
/**
* @param {?} response
* @param {?} headers
* @return {?}
*/
FileItem.prototype._transformResponse = /**
* @param {?} response
* @param {?} headers
* @return {?}
*/
function (response, headers) {
return response;
};
/**
* @param {?} status
* @return {?}
*/
FileItem.prototype._isSuccessCode = /**
* @param {?} status
* @return {?}
*/
function (status) {
return (status >= 200 && status < 300) || status === 304;
};
/**
* @return {?}
*/
FileItem.prototype._setFinalized = /**
* @return {?}
*/
function () {
this.isReady = false;
this.isUploading = false;
this.isUploaded = true;
this.isSuccess = true;
this.isCancel = false;
this.isError = false;
this.progress = 100;
this.isPause = false;
this.bytesSent = this._file.size;
};
/**
* @param {?} response
* @param {?} status
* @param {?} headers
* @return {?}
*/
FileItem.prototype._onSuccess = /**
* @param {?} response
* @param {?} status
* @param {?} headers
* @return {?}
*/
function (response, status, headers) {
this._setFinalized();
this.successSubject.next({ item: this, response: response, status: status, headers: headers });
};
/**
* @param {?} response
* @param {?} status
* @param {?} headers
* @return {?}
*/
FileItem.prototype._onError = /**
* @param {?} response
* @param {?} status
* @param {?} headers
* @return {?}
*/
function (response, status, headers) {
this.isReady = false;
this.isUploading = false;
this.isUploaded = false;
this.isSuccess = false;
this.isCancel = false;
this.isError = true;
this.progress = 0;
this.isPause = false;
this.resetToOriginalFile();
this.errorSubject.next({ item: this, response: response, status: status, headers: headers });
};
/**
* @param {?} response
* @param {?} status
* @param {?} headers
* @return {?}
*/
FileItem.prototype._onCancel = /**
* @param {?} response
* @param {?} status
* @param {?} headers
* @return {?}
*/
function (response, status, headers) {
this.isReady = false;
this.isUploading = false;
this.isUploaded = false;
this.isSuccess = false;
this.isCancel = true;
this.isError = false;
this.isPause = false;
this.resetToOriginalFile();
this.cancelSubject.next({ item: this, response: response, status: status, headers: headers });
};
/**
* @param {?} response
* @param {?} status
* @param {?} headers
* @return {?}
*/
FileItem.prototype._onPause = /**
* @param {?} response
* @param {?} status
* @param {?} headers
* @return {?}
*/
function (response, status, headers) {
this.isReady = false;
this.isUploading = false;
this.isUploaded = false;
this.isSuccess = false;
this.isCancel = false;
this.isError = false;
this.isPause = true;
this.sliceFile();
this.pauseSubject.next({ item: this, response: response, status: status, headers: headers });
};
/**
* @param {?=} offset
* @return {?}
*/
FileItem.prototype.sliceFile = /**
* @param {?=} offset
* @return {?}
*/
function (offset) {
this.bytesSent = offset ? offset : this.bytesSent;
this._file = new File([this._file.slice(this.bytesSent, this._file.size)], this._file.name, {
lastModified: this._file.lastModifiedDate,
type: this._file.type
});
this.slicedFile = true;
this.onSlicedBytesSent = this.bytesSent;
if (this.bytesSent === this._notModificableFile.size) {
this._setFinalized();
}
};
/**
* @return {?}
*/
FileItem.prototype.resetToOriginalFile = /**
* @return {?}
*/
function () {
this.bytesSent = 0;
this._file = this._notModificableFile;
this.slicedFile = false;
this.onSlicedBytesSent = 0;
};
return FileItem;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
/**
* @record
*/
var QueueController = (function () {
function QueueController(options) {
this.queueProgress = 0;
this.isUploading = false;
this.itemUploaded = new Subject$1();
this.itemError = new Subject$1();
this.itemPause = new Subject$1();
this.itemProgress = new Subject$1();
this.itemCancel = new Subject$1();
this.queueOptions = options;
this.uploadingQueue = [];
}
/**
* @return {?}
*/
QueueController.prototype.onItemUploaded = /**
* @return {?}
*/
function () {
return this.itemUploaded.asObservable();
};
/**
* @return {?}
*/
QueueController.prototype.onItemError = /**
* @return {?}
*/
function () {
return this.itemError.asObservable();
};
/**
* @return {?}
*/
QueueController.prototype.onItemPause = /**
* @return {?}
*/
function () {
return this.itemPause.asObservable();
};
/**
* @return {?}
*/
QueueController.prototype.onItemProgress = /**
* @return {?}
*/
function () {
return this.itemProgress.asObservable();
};
/**
* @return {?}
*/
QueueController.prototype.onItemCancel = /**
* @return {?}
*/
function () {
return this.itemCancel.asObservable();
};
/**
* @return {?}
*/
QueueController.prototype.getNotUploadedItems = /**
* @return {?}
*/
function () {
return this.uploadingQueue.filter(function (item) { return !item.item.isUploaded; });
};
/**
* @return {?}
*/
QueueController.prototype.getQueueLenght = /**
* @return {?}
*/
function () {
return this.uploadingQueue.length;
};
/**
* @param {?} files
* @param {?} options
* @param {?=} validate
* @return {?}
*/
QueueController.prototype.addFilesToQueue = /**
* @param {?} files
* @param {?} options
* @param {?=} validate
* @return {?}
*/
function (files, options, validate) {
var _this = this;
var /** @type {?} */ addedFiles = [];
files.forEach(function (file) {
var /** @type {?} */ fileItem = new FileItem(file, options);
if (validate) {
fileItem.validateFile();
}
addedFiles.push(fileItem);
var /** @type {?} */ uploadingItem = { item: fileItem, subscriptions: [] };
_this.subscribeToFileItemEvents(uploadingItem);
_this.uploadingQueue.push(uploadingItem);
});
return addedFiles;
};
/**
* @param {?} uploadingItem
* @return {?}
*/
QueueController.prototype.subscribeToFileItemEvents = /**
* @param {?} uploadingItem
* @return {?}
*/
function (uploadingItem) {
var _this = this;
uploadingItem.subscriptions.push(uploadingItem.item.onProgress().subscribe(function (response) {
_this.itemProgress.next(response);
_this.calculateProgress();
_this.isFilesUploading();
}));
uploadingItem.subscriptions.push(uploadingItem.item.onCancel().subscribe(function (response) {
_this.itemCancel.next(response);
_this.calculateProgress();
_this.isFilesUploading();
}));
uploadingItem.subscriptions.push(uploadingItem.item.onError().subscribe(function (response) {
_this.itemError.next(response);
_this.calculateProgress();
_this.isFilesUploading();
}));
uploadingItem.subscriptions.push(uploadingItem.item.onPause().subscribe(function (response) {
_this.itemPause.next(response);
_this.calculateProgress();
_this.isFilesUploading();
}));
uploadingItem.subscriptions.push(uploadingItem.item.onSuccess().subscribe(function (response) {
_this.itemUploaded.next(response);
_this.calculateProgress();
var /** @type {?} */ next = _this.getNextToUpload();
if (next && next.markedToUpload) {
_this.uploadItem(next);
}
if (_this.queueOptions.removeAfterUpload) {
_this.removeFromQueue(uploadingItem.item);
}
}));
};
/**
* @param {?} files
* @param {?=} validate
* @return {?}
*/
QueueController.prototype.addFileItemsToQueue = /**
* @param {?} files
* @param {?=} validate
* @return {?}
*/
function (files, validate) {
var _this = this;
files.forEach(function (file) {
if (validate) {
file.validateFile();
}
var /** @type {?} */ uploadingItem = { item: file, subscriptions: [] };
_this.subscribeToFileItemEvents(uploadingItem);
_this.uploadingQueue.push({ item: file, subscriptions: [] });
});
return files;
};
/**
* @param {?} file
* @return {?}
*/
QueueController.prototype.removeFromQueue = /**
* @param {?} file
* @return {?}
*/
function (file) {
var /** @type {?} */ itemIndex = -1;
var /** @type {?} */ uploadingItem = this.uploadingQueue.find(function (entry, i) {
if (entry.item.getId() === file.getId()) {
itemIndex = i;
return true;
}
return false;
});
if (uploadingItem) {
uploadingItem.subscriptions.forEach(function (entry) {
entry.unsubscribe();
});
if (uploadingItem.item.isUploading) {
uploadingItem.item.cancel();
}
this.uploadingQueue.splice(itemIndex, 1);
}
};
/**
* @return {?}
*/
QueueController.prototype.uploadAll = /**
* @return {?}
*/
function () {
var _this = this;
if (this.queueOptions.parallel) {
this.uploadingQueue.forEach(function (uploadingItem) {
if (!uploadingItem.item.isUploading && !uploadingItem.item.isUploaded) {
_this.uploadItem(uploadingItem);
}
});
}
else {
this.uploadingQueue.forEach(function (item) {
item.markedToUpload = true;
});
var /** @type {?} */ itemToUpload = this.getNextToUpload();
if (itemToUpload) {
this.uploadItem(itemToUpload);
}
}
};
/**
* @return {?}
*/
QueueController.prototype.getNextToUpload = /**
* @return {?}
*/
function () {
var /** @type {?} */ itemToUpload;
for (var _i = 0, _a = this.uploadingQueue; _i < _a.length; _i++) {
var uploadingItem = _a[_i];
if (!uploadingItem.item.isUploaded
&& !uploadingItem.item.isUploading
&& !uploadingItem.item.isError
&& !uploadingItem.item.isPause) {
itemToUpload = uploadingItem;
break;
}
}
return itemToUpload;
};
/**
* @return {?}
*/
QueueController.prototype.cancelAll = /**
* @return {?}
*/
function () {
this.uploadingQueue.forEach(function (uploadingItem) {
uploadingItem.item.cancel();
});
this.queueProgress = 0;
};
/**
* @return {?}
*/
QueueController.prototype.clearQueue = /**
* @return {?}
*/
function () {
this.uploadingQueue.forEach(function (uploadingItem) {
uploadingItem.subscriptions.forEach(function (entry) {
entry.unsubscribe();
});
uploadingItem.item.cancel();
});
this.uploadingQueue = [];
this.queueProgress = 0;
};
/**
* @return {?}
*/
QueueController.prototype.calculateProgress = /**
* @return {?}
*/
function () {
var /** @type {?} */ totalBytes = 0;
var /** @type {?} */ totalSent = 0;
this.uploadingQueue.forEach(function (uploadingItem) {
totalBytes += uploadingItem.item.fileLike.size;
totalSent += uploadingItem.item.bytesSent;
});
this.queueProgress = Number(((totalSent * 100) / totalBytes).toFixed(2));
};
/**
* @param {?} uploadingItem
* @return {?}
*/
QueueController.prototype.uploadItem = /**
* @param {?} uploadingItem
* @return {?}
*/
function (uploadingItem) {
uploadingItem.item.upload();
this.isFilesUploading();
};
/**
* @return {?}
*/
QueueController.prototype.isFilesUploading = /**
* @return {?}
*/
function () {
var /** @type {?} */ isUploading = false;
for (var _i = 0, _a = this.uploadingQueue; _i < _a.length; _i++) {
var uploadingItem = _a[_i];
if (uploadingItem.item.isUploading) {
isUploading = true;
break;
}
}
this.isUploading = isUploading;
};
return QueueController;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes} checked by tsc
*/
var MoontechFileUploadModule = (function () {
function MoontechFileUploadModule() {
}
/**
* @return {?}
*/
MoontechFileUploadModule.forRoot = /**
* @return {?}
*/
function () {
return {
ngModule: MoontechFileUploadModule,
};
};
MoontechFileUploadModule.decorators = [
{ type: NgModule, args: [{
imports: [
CommonModule
],
declarations: [],
exports: []
},] },
];
return MoontechFileUploadModule;
}());
export { MoontechFileUploadModule, FileItem, FileLikeObject, FileType, QueueController };