angular-material-datatransfer-lib
Version:
A HTML5 datatransfer UI for handling upload and download of multiple simultaneous files.
1,483 lines (1,471 loc) • 169 kB
JavaScript
import { Directive, ViewContainerRef, Injectable, Component, Inject, ReflectiveInjector, Input, NgZone, ComponentFactoryResolver, ViewChild, NgModule, ApplicationRef } from '@angular/core';
import { MatDialogRef, MAT_DIALOG_DATA, MatDialog, MatButtonModule, MatCheckboxModule, MatDialogModule, MatFormFieldModule, MatIconModule, MatInputModule, MatMenuModule, MatOptionModule, MatProgressBarModule, MatProgressSpinnerModule, MatSelectModule, MatTooltipModule } from '@angular/material';
import { FormControl, FormsModule, ReactiveFormsModule } from '@angular/forms';
import * as Resumable from 'resumablejs';
import { createHash } from 'crypto-browserify';
import { saveAs } from 'file-saver';
import { BrowserModule } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { FlexLayoutModule } from '@angular/flex-layout';
/**
* @fileoverview added by tsickle
* Generated from: lib/enums/custom-event-type.enum.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/** @enum {number} */
const CustomEventType = {
UNKNOWN: 0,
// This event can be used to bootstrap the app module. An IAppConfig can be passed as detail payload.
CREATE: 1,
// This event can be used to trigger an item download. The filename, url and size can be passed as detail payload.
DOWNLOAD_ITEM: 2,
// This event can be used to update the app configuration. An IAppConfig can be passed as detail payload.
UPDATE_CONFIG: 3,
// Indicates that the app has been initialized.
INIT: 4,
// Indicates that the overall upload has been completed.
UPLOAD_COMPLETED: 5,
// Indicates that the overall download has been completed.
DOWNLOAD_COMPLETED: 6,
// Indicates that an item has been added. It will be passed a IDatatransferItem as detail payload.
ITEM_ADDED: 7,
// Indicates that an item has been removed. It will be passed a IDatatransferItem as detail payload.
ITEM_REMOVED: 8,
// Indicates that an item has been completed.
ITEM_COMPLETED: 9,
// Indicates that all items have been cleared.
ITEMS_CLEARED: 10,
};
CustomEventType[CustomEventType.UNKNOWN] = 'UNKNOWN';
CustomEventType[CustomEventType.CREATE] = 'CREATE';
CustomEventType[CustomEventType.DOWNLOAD_ITEM] = 'DOWNLOAD_ITEM';
CustomEventType[CustomEventType.UPDATE_CONFIG] = 'UPDATE_CONFIG';
CustomEventType[CustomEventType.INIT] = 'INIT';
CustomEventType[CustomEventType.UPLOAD_COMPLETED] = 'UPLOAD_COMPLETED';
CustomEventType[CustomEventType.DOWNLOAD_COMPLETED] = 'DOWNLOAD_COMPLETED';
CustomEventType[CustomEventType.ITEM_ADDED] = 'ITEM_ADDED';
CustomEventType[CustomEventType.ITEM_REMOVED] = 'ITEM_REMOVED';
CustomEventType[CustomEventType.ITEM_COMPLETED] = 'ITEM_COMPLETED';
CustomEventType[CustomEventType.ITEMS_CLEARED] = 'ITEMS_CLEARED';
// tslint:disable-next-line: no-namespace
var CustomEventTypeExtensions;
(function (CustomEventTypeExtensions) {
/** @type {?} */
const CUSTOM_EVENT_TYPE_NS = 'github:niklr/angular-material-datatransfer.';
/** @type {?} */
const CUSTOM_EVENT_TYPE_UNKNOWN = CUSTOM_EVENT_TYPE_NS + 'unknown';
/** @type {?} */
const CUSTOM_EVENT_TYPE_CREATE = CUSTOM_EVENT_TYPE_NS + 'create';
/** @type {?} */
const CUSTOM_EVENT_TYPE_DOWNLOAD_ITEM = CUSTOM_EVENT_TYPE_NS + 'download-item';
/** @type {?} */
const CUSTOM_EVENT_TYPE_UPDATE_CONFIG = CUSTOM_EVENT_TYPE_NS + 'update-config';
/** @type {?} */
const CUSTOM_EVENT_TYPE_INIT = CUSTOM_EVENT_TYPE_NS + 'init';
/** @type {?} */
const CUSTOM_EVENT_TYPE_UPLOAD_COMPLETED = CUSTOM_EVENT_TYPE_NS + 'upload-completed';
/** @type {?} */
const CUSTOM_EVENT_TYPE_DOWNLOAD_COMPLETED = CUSTOM_EVENT_TYPE_NS + 'download-completed';
/** @type {?} */
const CUSTOM_EVENT_TYPE_ITEM_ADDED = CUSTOM_EVENT_TYPE_NS + 'item-added';
/** @type {?} */
const CUSTOM_EVENT_TYPE_ITEM_REMOVED = CUSTOM_EVENT_TYPE_NS + 'item-removed';
/** @type {?} */
const CUSTOM_EVENT_TYPE_ITEM_COMPLETED = CUSTOM_EVENT_TYPE_NS + 'item-completed';
/** @type {?} */
const CUSTOM_EVENT_TYPE_ITEMS_CLEARED = CUSTOM_EVENT_TYPE_NS + 'items-cleared';
/**
* @param {?} type
* @return {?}
*/
function toString(type) {
switch (type) {
case CustomEventType.CREATE:
return CUSTOM_EVENT_TYPE_CREATE;
case CustomEventType.DOWNLOAD_ITEM:
return CUSTOM_EVENT_TYPE_DOWNLOAD_ITEM;
case CustomEventType.UPDATE_CONFIG:
return CUSTOM_EVENT_TYPE_UPDATE_CONFIG;
case CustomEventType.INIT:
return CUSTOM_EVENT_TYPE_INIT;
case CustomEventType.UPLOAD_COMPLETED:
return CUSTOM_EVENT_TYPE_UPLOAD_COMPLETED;
case CustomEventType.DOWNLOAD_COMPLETED:
return CUSTOM_EVENT_TYPE_DOWNLOAD_COMPLETED;
case CustomEventType.ITEM_ADDED:
return CUSTOM_EVENT_TYPE_ITEM_ADDED;
case CustomEventType.ITEM_REMOVED:
return CUSTOM_EVENT_TYPE_ITEM_REMOVED;
case CustomEventType.ITEM_COMPLETED:
return CUSTOM_EVENT_TYPE_ITEM_COMPLETED;
case CustomEventType.ITEMS_CLEARED:
return CUSTOM_EVENT_TYPE_ITEMS_CLEARED;
default:
return CUSTOM_EVENT_TYPE_UNKNOWN;
}
}
CustomEventTypeExtensions.toString = toString;
/**
* @param {?} type
* @return {?}
*/
function toEnum(type) {
switch (type) {
case CUSTOM_EVENT_TYPE_CREATE:
return CustomEventType.CREATE;
case CUSTOM_EVENT_TYPE_DOWNLOAD_ITEM:
return CustomEventType.DOWNLOAD_ITEM;
case CUSTOM_EVENT_TYPE_UPDATE_CONFIG:
return CustomEventType.UPDATE_CONFIG;
case CUSTOM_EVENT_TYPE_INIT:
return CustomEventType.INIT;
case CUSTOM_EVENT_TYPE_UPLOAD_COMPLETED:
return CustomEventType.UPLOAD_COMPLETED;
case CUSTOM_EVENT_TYPE_DOWNLOAD_COMPLETED:
return CustomEventType.DOWNLOAD_COMPLETED;
case CUSTOM_EVENT_TYPE_ITEM_ADDED:
return CustomEventType.ITEM_ADDED;
case CUSTOM_EVENT_TYPE_ITEM_REMOVED:
return CustomEventType.ITEM_REMOVED;
case CUSTOM_EVENT_TYPE_ITEM_COMPLETED:
return CustomEventType.ITEM_COMPLETED;
case CUSTOM_EVENT_TYPE_ITEMS_CLEARED:
return CustomEventType.ITEMS_CLEARED;
default:
return CustomEventType.UNKNOWN;
}
}
CustomEventTypeExtensions.toEnum = toEnum;
})(CustomEventTypeExtensions || (CustomEventTypeExtensions = {}));
/**
* @fileoverview added by tsickle
* Generated from: lib/directives/host.directive.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
class HostDirective {
/**
* @param {?} viewContainerRef
*/
constructor(viewContainerRef) {
this.viewContainerRef = viewContainerRef;
}
}
HostDirective.decorators = [
{ type: Directive, args: [{
// tslint:disable-next-line: directive-selector
selector: '[amd-host]',
},] }
];
/** @nocollapse */
HostDirective.ctorParameters = () => [
{ type: ViewContainerRef }
];
if (false) {
/** @type {?} */
HostDirective.prototype.viewContainerRef;
}
/**
* @fileoverview added by tsickle
* Generated from: lib/models/app-config.model.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
class CoreAppConfig {
constructor() {
this.showUploadDropzone = true;
this.uploadBrowseElementId = undefined;
this.uploadDropElementId = undefined;
this.paginationRppOptions = [5, 10, 25];
this.simultaneousDownloads = 2;
this.downloadMethod = 'GET';
this.downloadHeaders = {};
this.downloadWithCredentials = false;
this.downloadXhrTimeout = 0;
this.preprocessHashEnabled = false;
this.preprocessHashChecked = true;
this.preprocessHashTarget = 'https://httpbin.org';
this.preprocessHashMethod = 'GET';
this.preprocessHashParameterName = 'hash';
this.preprocessHashFileNameParameterName = 'filename';
this.preprocessHashFunctionName = 'sha1';
this.preprocessHashEncodingName = 'hex';
this.preprocessHashInputEncodingName = 'latin1';
this.preprocessHashTooltipContent = 'The preprocess option checks if the file is already on the system before uploading.';
this.parseMessageCallback = (/**
* @param {?} message
* @return {?}
*/
function (message) {
return message;
});
this.getTarget = (/**
* @param {?} request
* @param {?} params
* @return {?}
*/
function (request, params) {
/** @type {?} */
let target;
if (request === 'preprocessHash' && this.preprocessHashChecked) {
target = this.preprocessHashTarget;
}
if (typeof target === 'function') {
return target(params);
}
if (target) {
/** @type {?} */
const separator = target.indexOf('?') < 0 ? '?' : '&';
/** @type {?} */
const joinedParams = params.join('&');
return target + separator + joinedParams;
}
else {
return;
}
});
}
}
if (false) {
/** @type {?} */
CoreAppConfig.prototype.showUploadDropzone;
/** @type {?} */
CoreAppConfig.prototype.uploadBrowseElementId;
/** @type {?} */
CoreAppConfig.prototype.uploadDropElementId;
/** @type {?} */
CoreAppConfig.prototype.paginationRppOptions;
/** @type {?} */
CoreAppConfig.prototype.simultaneousDownloads;
/** @type {?} */
CoreAppConfig.prototype.downloadMethod;
/** @type {?} */
CoreAppConfig.prototype.downloadHeaders;
/** @type {?} */
CoreAppConfig.prototype.downloadWithCredentials;
/** @type {?} */
CoreAppConfig.prototype.downloadXhrTimeout;
/** @type {?} */
CoreAppConfig.prototype.preprocessHashEnabled;
/** @type {?} */
CoreAppConfig.prototype.preprocessHashChecked;
/** @type {?} */
CoreAppConfig.prototype.preprocessHashTarget;
/** @type {?} */
CoreAppConfig.prototype.preprocessHashMethod;
/** @type {?} */
CoreAppConfig.prototype.preprocessHashParameterName;
/** @type {?} */
CoreAppConfig.prototype.preprocessHashFileNameParameterName;
/** @type {?} */
CoreAppConfig.prototype.preprocessHashFunctionName;
/** @type {?} */
CoreAppConfig.prototype.preprocessHashEncodingName;
/** @type {?} */
CoreAppConfig.prototype.preprocessHashInputEncodingName;
/** @type {?} */
CoreAppConfig.prototype.preprocessHashTooltipContent;
/** @type {?} */
CoreAppConfig.prototype.parseMessageCallback;
/** @type {?} */
CoreAppConfig.prototype.getTarget;
}
class ResumableJsAppConfig {
constructor() {
this.chunkSize = 1 * 1024 * 1024;
this.forceChunkSize = false;
this.simultaneousUploads = 3;
this.fileParameterName = 'file';
this.chunkNumberParameterName = 'resumableChunkNumber';
this.chunkSizeParameterName = 'resumableChunkSize';
this.currentChunkSizeParameterName = 'resumableCurrentChunkSize';
this.totalSizeParameterName = 'resumableTotalSize';
this.typeParameterName = 'resumableType';
this.identifierParameterName = 'resumableIdentifier';
this.fileNameParameterName = 'resumableFilename';
this.relativePathParameterName = 'resumableRelativePath';
this.totalChunksParameterName = 'resumableTotalChunks';
this.throttleProgressCallbacks = 0.5;
this.query = {};
this.headers = {};
this.preprocess = null;
this.preprocessFile = null;
this.method = 'multipart';
this.uploadMethod = 'POST';
this.testMethod = 'GET';
this.target = 'https://httpbin.org';
this.testTarget = null;
this.parameterNamespace = '';
this.testChunks = true;
this.generateUniqueIdentifier = null;
this.getTarget = null;
this.maxChunkRetries = 100;
this.chunkRetryInterval = undefined;
this.permanentErrors = [400, 404, 405, 415, 501];
this.maxFiles = undefined;
this.withCredentials = false;
this.xhrTimeout = 0;
this.clearInput = true;
this.chunkFormat = 'blob';
this.minFileSize = 1;
this.maxFileSize = undefined;
this.fileType = [];
this.maxFilesErrorCallback = (/**
* @param {?} files
* @param {?} errorCount
* @return {?}
*/
function (files, errorCount) {
alert('Please upload no more than ' + this.maxFiles + ' file' + (this.maxFiles === 1 ? '' : 's') + ' at a time.');
});
this.minFileSizeErrorCallback = (/**
* @param {?} file
* @param {?} errorCount
* @return {?}
*/
function (file, errorCount) {
alert(file.fileName || file.name + ' is too small; please upload files larger than ' + this.minFileSize + '.');
});
this.maxFileSizeErrorCallback = (/**
* @param {?} file
* @param {?} errorCount
* @return {?}
*/
function (file, errorCount) {
alert(file.fileName || file.name + ' is too large; please upload files less than ' + this.maxFileSize + '.');
});
this.fileTypeErrorCallback = (/**
* @param {?} file
* @param {?} errorCount
* @return {?}
*/
function (file, errorCount) {
alert(file.fileName || file.name + ' has type not allowed; please upload files of type ' + this.fileType + '.');
});
}
}
if (false) {
/** @type {?} */
ResumableJsAppConfig.prototype.chunkSize;
/** @type {?} */
ResumableJsAppConfig.prototype.forceChunkSize;
/** @type {?} */
ResumableJsAppConfig.prototype.simultaneousUploads;
/** @type {?} */
ResumableJsAppConfig.prototype.fileParameterName;
/** @type {?} */
ResumableJsAppConfig.prototype.chunkNumberParameterName;
/** @type {?} */
ResumableJsAppConfig.prototype.chunkSizeParameterName;
/** @type {?} */
ResumableJsAppConfig.prototype.currentChunkSizeParameterName;
/** @type {?} */
ResumableJsAppConfig.prototype.totalSizeParameterName;
/** @type {?} */
ResumableJsAppConfig.prototype.typeParameterName;
/** @type {?} */
ResumableJsAppConfig.prototype.identifierParameterName;
/** @type {?} */
ResumableJsAppConfig.prototype.fileNameParameterName;
/** @type {?} */
ResumableJsAppConfig.prototype.relativePathParameterName;
/** @type {?} */
ResumableJsAppConfig.prototype.totalChunksParameterName;
/** @type {?} */
ResumableJsAppConfig.prototype.throttleProgressCallbacks;
/** @type {?} */
ResumableJsAppConfig.prototype.query;
/** @type {?} */
ResumableJsAppConfig.prototype.headers;
/** @type {?} */
ResumableJsAppConfig.prototype.preprocess;
/** @type {?} */
ResumableJsAppConfig.prototype.preprocessFile;
/** @type {?} */
ResumableJsAppConfig.prototype.method;
/** @type {?} */
ResumableJsAppConfig.prototype.uploadMethod;
/** @type {?} */
ResumableJsAppConfig.prototype.testMethod;
/** @type {?} */
ResumableJsAppConfig.prototype.prioritizeFirstAndLastChunk;
/** @type {?} */
ResumableJsAppConfig.prototype.target;
/** @type {?} */
ResumableJsAppConfig.prototype.testTarget;
/** @type {?} */
ResumableJsAppConfig.prototype.parameterNamespace;
/** @type {?} */
ResumableJsAppConfig.prototype.testChunks;
/** @type {?} */
ResumableJsAppConfig.prototype.generateUniqueIdentifier;
/** @type {?} */
ResumableJsAppConfig.prototype.getTarget;
/** @type {?} */
ResumableJsAppConfig.prototype.maxChunkRetries;
/** @type {?} */
ResumableJsAppConfig.prototype.chunkRetryInterval;
/** @type {?} */
ResumableJsAppConfig.prototype.permanentErrors;
/** @type {?} */
ResumableJsAppConfig.prototype.maxFiles;
/** @type {?} */
ResumableJsAppConfig.prototype.withCredentials;
/** @type {?} */
ResumableJsAppConfig.prototype.xhrTimeout;
/** @type {?} */
ResumableJsAppConfig.prototype.clearInput;
/** @type {?} */
ResumableJsAppConfig.prototype.chunkFormat;
/** @type {?} */
ResumableJsAppConfig.prototype.minFileSize;
/** @type {?} */
ResumableJsAppConfig.prototype.maxFileSize;
/** @type {?} */
ResumableJsAppConfig.prototype.fileType;
/** @type {?} */
ResumableJsAppConfig.prototype.maxFilesErrorCallback;
/** @type {?} */
ResumableJsAppConfig.prototype.minFileSizeErrorCallback;
/** @type {?} */
ResumableJsAppConfig.prototype.maxFileSizeErrorCallback;
/** @type {?} */
ResumableJsAppConfig.prototype.fileTypeErrorCallback;
}
/**
* @record
*/
function IAppConfig() { }
if (false) {
/** @type {?} */
IAppConfig.prototype.production;
/** @type {?} */
IAppConfig.prototype.core;
/** @type {?} */
IAppConfig.prototype.resumablejs;
}
class AppConfig {
constructor() {
this.production = true;
this.core = new CoreAppConfig();
this.resumablejs = new ResumableJsAppConfig();
}
}
if (false) {
/** @type {?} */
AppConfig.prototype.production;
/** @type {?} */
AppConfig.prototype.core;
/** @type {?} */
AppConfig.prototype.resumablejs;
}
/**
* @fileoverview added by tsickle
* Generated from: lib/services/config.service.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
class ConfigService {
constructor() {
}
/**
* @param {?} config
* @return {?}
*/
load(config) {
if (!!config) {
ConfigService.settings.production = config.production;
if (!!config.core) {
Object.keys(config.core).forEach((/**
* @param {?} propertyName
* @return {?}
*/
propertyName => {
if (typeof config.core[propertyName] !== 'undefined') {
ConfigService.settings.core[propertyName] = config.core[propertyName];
}
}));
}
if (!!config.resumablejs) {
Object.keys(config.resumablejs).forEach((/**
* @param {?} propertyName
* @return {?}
*/
propertyName => {
if (typeof config.resumablejs[propertyName] !== 'undefined') {
ConfigService.settings.resumablejs[propertyName] = config.resumablejs[propertyName];
}
}));
}
}
}
}
ConfigService.settings = new AppConfig();
ConfigService.decorators = [
{ type: Injectable }
];
/** @nocollapse */
ConfigService.ctorParameters = () => [];
if (false) {
/** @type {?} */
ConfigService.settings;
}
/**
* @fileoverview added by tsickle
* Generated from: lib/enums/transfer-status.enum.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/** @enum {number} */
const TransferStatus = {
Ready: 0,
Queued: 1,
Preprocessing: 2,
Uploading: 3,
Downloading: 4,
Finished: 5,
Failed: 6,
};
TransferStatus[TransferStatus.Ready] = 'Ready';
TransferStatus[TransferStatus.Queued] = 'Queued';
TransferStatus[TransferStatus.Preprocessing] = 'Preprocessing';
TransferStatus[TransferStatus.Uploading] = 'Uploading';
TransferStatus[TransferStatus.Downloading] = 'Downloading';
TransferStatus[TransferStatus.Finished] = 'Finished';
TransferStatus[TransferStatus.Failed] = 'Failed';
/**
* @fileoverview added by tsickle
* Generated from: lib/enums/transfer-type.enum.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/** @enum {number} */
const TransferType = {
Upload: 0,
Download: 1,
};
TransferType[TransferType.Upload] = 'Upload';
TransferType[TransferType.Download] = 'Download';
/**
* @fileoverview added by tsickle
* Generated from: lib/components/browse-dialog.component.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
class BrowseDialogComponent {
/**
* @param {?} dialogRef
* @param {?} data
*/
constructor(dialogRef, data) {
this.dialogRef = dialogRef;
this.data = data;
this.datatransferFacade = (/** @type {?} */ (this.data.datatransferFacade));
}
/**
* @return {?}
*/
ngAfterViewInit() {
this.datatransferFacade.assignUploadBrowse(document.getElementById('amd-browse-files'));
this.datatransferFacade.assignUploadBrowse(document.getElementById('amd-browse-folder'), true);
}
/**
* @return {?}
*/
close() {
this.dialogRef.close();
}
/**
* @return {?}
*/
onNoClick() {
this.close();
}
}
BrowseDialogComponent.decorators = [
{ type: Component, args: [{
// tslint:disable-next-line:component-selector
selector: 'amd-browse-dialog',
template: "<mat-dialog-content>Select specific files or a folder</mat-dialog-content>\r\n<mat-dialog-actions>\r\n <button mat-raised-button id=\"amd-browse-files\" (click)=\"close()\" tabindex=\"1\">\r\n <mat-icon>insert_drive_file</mat-icon> Files</button>\r\n <button mat-raised-button id=\"amd-browse-folder\" (click)=\"close()\" tabindex=\"2\">\r\n <mat-icon>folder_open</mat-icon> Folder</button>\r\n</mat-dialog-actions>"
}] }
];
/** @nocollapse */
BrowseDialogComponent.ctorParameters = () => [
{ type: MatDialogRef },
{ type: undefined, decorators: [{ type: Inject, args: [MAT_DIALOG_DATA,] }] }
];
if (false) {
/** @type {?} */
BrowseDialogComponent.prototype.datatransferFacade;
/** @type {?} */
BrowseDialogComponent.prototype.dialogRef;
/** @type {?} */
BrowseDialogComponent.prototype.data;
}
/**
* @fileoverview added by tsickle
* Generated from: lib/components/edit-dialog.component.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
class EditDialogComponent {
/**
* @param {?} dialogRef
* @param {?} data
*/
constructor(dialogRef, data) {
this.dialogRef = dialogRef;
this.data = data;
this.datatransferFacade = (/** @type {?} */ (this.data.datatransferFacade));
this.mode = this.data.mode;
this.item = (/** @type {?} */ (this.data.item));
this.itemPath = this.item.path;
this.itemName = this.item.name;
this.editFormControl = new FormControl('', []);
}
/**
* @return {?}
*/
ngAfterViewInit() {
}
/**
* @return {?}
*/
close() {
this.dialogRef.close();
}
/**
* @return {?}
*/
onNoClick() {
this.close();
}
/**
* @return {?}
*/
editPath() {
try {
this.datatransferFacade.editPath(this.item, this.item.path, this.itemPath);
this.close();
}
catch (error) {
this.errorMessage = error;
}
}
/**
* @return {?}
*/
editFilename() {
try {
this.datatransferFacade.editFilename(this.item, this.itemName);
this.close();
}
catch (error) {
this.errorMessage = error;
}
}
}
EditDialogComponent.decorators = [
{ type: Component, args: [{
// tslint:disable-next-line:component-selector
selector: 'amd-edit-dialog',
template: "<div *ngIf=\"mode === 'edit-path'\">\r\n <mat-dialog-content>\r\n <p>Enter a new path:</p>\r\n <form>\r\n <mat-form-field>\r\n <input matInput autocomplete=\"off\" tabindex=\"1\" [value]=\"itemPath\"\r\n (input)=\"itemPath = $event.target.value; errorMessage = undefined;\" [formControl]=\"editFormControl\">\r\n </mat-form-field>\r\n <mat-error *ngIf=\"errorMessage\">\r\n {{errorMessage}}\r\n </mat-error>\r\n </form>\r\n </mat-dialog-content>\r\n <mat-dialog-actions>\r\n <button mat-raised-button (click)=\"editPath()\" tabindex=\"2\">Ok</button>\r\n <button mat-raised-button (click)=\"close()\" tabindex=\"-1\">Cancel</button>\r\n </mat-dialog-actions>\r\n</div>\r\n<div *ngIf=\"mode === 'edit-filename'\">\r\n <mat-dialog-content>\r\n <p>Enter a new filename:</p>\r\n <form>\r\n <mat-form-field>\r\n <input matInput autocomplete=\"off\" tabindex=\"1\" [value]=\"itemName\"\r\n (input)=\"itemName = $event.target.value; errorMessage = undefined;\" [formControl]=\"editFormControl\">\r\n </mat-form-field>\r\n <mat-error *ngIf=\"errorMessage\">\r\n {{errorMessage}}\r\n </mat-error>\r\n </form>\r\n </mat-dialog-content>\r\n <mat-dialog-actions>\r\n <button mat-raised-button (click)=\"editFilename()\" tabindex=\"2\">Ok</button>\r\n <button mat-raised-button (click)=\"close()\" tabindex=\"-1\">Cancel</button>\r\n </mat-dialog-actions>\r\n</div>"
}] }
];
/** @nocollapse */
EditDialogComponent.ctorParameters = () => [
{ type: MatDialogRef },
{ type: undefined, decorators: [{ type: Inject, args: [MAT_DIALOG_DATA,] }] }
];
if (false) {
/** @type {?} */
EditDialogComponent.prototype.datatransferFacade;
/** @type {?} */
EditDialogComponent.prototype.mode;
/** @type {?} */
EditDialogComponent.prototype.item;
/** @type {?} */
EditDialogComponent.prototype.itemPath;
/** @type {?} */
EditDialogComponent.prototype.itemName;
/** @type {?} */
EditDialogComponent.prototype.errorMessage;
/** @type {?} */
EditDialogComponent.prototype.editFormControl;
/** @type {?} */
EditDialogComponent.prototype.dialogRef;
/** @type {?} */
EditDialogComponent.prototype.data;
}
/**
* @fileoverview added by tsickle
* Generated from: lib/facades/datatransfer.facade.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
class DatatransferFacade {
/**
* @param {?} logger
* @param {?} zone
* @param {?} store
* @param {?} dateUtil
* @param {?} paginationService
* @param {?} exportService
* @param {?} uploader
* @param {?} downloader
* @param {?} dialog
*/
constructor(logger, zone, store, dateUtil, paginationService, exportService, uploader, downloader, dialog) {
this.logger = logger;
this.zone = zone;
this.store = store;
this.dateUtil = dateUtil;
this.paginationService = paginationService;
this.exportService = exportService;
this.uploader = uploader;
this.downloader = downloader;
this.dialog = dialog;
// Interval in milliseconds to calculate progress:
this.progressInterval = 200;
// Interval in milliseconds to calculate bitrate:
this.bitrateInterval = 1000;
this.uploadProgress = this.store.uploadProgress;
this.downloadProgress = this.store.downloadProgress;
this.init(this.uploader, this.uploadProgress);
this.init(this.downloader, this.downloadProgress);
}
/**
* @private
* @param {?} datatransfer
* @param {?} progressContainer
* @return {?}
*/
init(datatransfer, progressContainer) {
datatransfer.on('itemAdded', (/**
* @param {?} item
* @return {?}
*/
function (item) {
/** @type {?} */
const that = (/** @type {?} */ (this));
that.zone.run((/**
* @return {?}
*/
() => {
that.addItem(item);
}));
}).bind(this));
datatransfer.on('zoneUpdated', (/**
* @param {?} item
* @param {?} status
* @param {?=} message
* @return {?}
*/
function (item, status, message) {
/** @type {?} */
const that = (/** @type {?} */ (this));
that.zone.run((/**
* @return {?}
*/
() => {
// console.log(that.uploader.isWorking());
}));
}).bind(this));
datatransfer.on('itemStatusChanged', (/**
* @param {?} item
* @param {?} status
* @param {?=} message
* @return {?}
*/
function (item, status, message) {
/** @type {?} */
const that = (/** @type {?} */ (this));
that.zone.run((/**
* @return {?}
*/
() => {
that.changeItemStatus(item, status, message);
}));
}).bind(this));
datatransfer.on('itemProgressUpdated', (/**
* @param {?} item
* @param {?} progress
* @return {?}
*/
function (item, progress) {
/** @type {?} */
const that = (/** @type {?} */ (this));
that.zone.run((/**
* @return {?}
*/
() => {
that.updateItemProgress(item, progress);
}));
}).bind(this));
datatransfer.on('overallProgressUpdated', (/**
* @param {?} transferType
* @param {?} progress
* @return {?}
*/
function (transferType, progress) {
/** @type {?} */
const that = (/** @type {?} */ (this));
that.zone.run((/**
* @return {?}
*/
() => {
that.updateOverallProgress(progressContainer, transferType, progress);
}));
}).bind(this));
datatransfer.on('overallSizeUpdated', (/**
* @param {?} size
* @return {?}
*/
function (size) {
/** @type {?} */
const that = (/** @type {?} */ (this));
that.zone.run((/**
* @return {?}
*/
() => {
that.updateOverallSize(progressContainer, size);
}));
}).bind(this));
}
/**
* @param {?} element
* @param {?=} isDirectory
* @return {?}
*/
assignUploadBrowse(element, isDirectory = false) {
this.uploader.assignBrowse(element, isDirectory);
}
/**
* @param {?} element
* @return {?}
*/
assignUploadDrop(element) {
this.uploader.assignDrop(element);
}
/**
* @return {?}
*/
openBrowseDialog() {
/** @type {?} */
const dialogRef = this.dialog.open(BrowseDialogComponent, {
data: {
datatransferFacade: this
}
});
}
/**
* @param {?} item
* @return {?}
*/
openEditPathDialog(item) {
/** @type {?} */
const dialogRef = this.dialog.open(EditDialogComponent, {
data: {
datatransferFacade: this,
mode: 'edit-path',
item
}
});
}
/**
* @param {?} item
* @return {?}
*/
openEditFilenameDialog(item) {
/** @type {?} */
const dialogRef = this.dialog.open(EditDialogComponent, {
data: {
datatransferFacade: this,
mode: 'edit-filename',
item
}
});
}
/**
* @param {?} checked
* @return {?}
*/
toggleVisible(checked) {
this.paginationService.paginatedItems.forEach((/**
* @param {?} item
* @param {?} index
* @return {?}
*/
(item, index) => {
item.isSelected = checked;
}));
}
/**
* @return {?}
*/
startAll() {
this.store.getItems().forEach((/**
* @param {?} item
* @param {?} index
* @return {?}
*/
(item, index) => {
/** @type {?} */
const that = (/** @type {?} */ (this));
if (item.transferType === TransferType.Upload && item.status === TransferStatus.Ready) {
that.changeItemStatus(item, TransferStatus.Queued);
}
}));
this.uploader.startAll();
}
/**
* @return {?}
*/
pauseAll() {
this.store.getItems().forEach((/**
* @param {?} item
* @param {?} index
* @return {?}
*/
(item, index) => {
item.preprocessContainer.pause(true);
}));
this.uploader.pauseAll();
this.downloader.pauseAll();
}
/**
* @return {?}
*/
removeAll() {
this.store.getItems().forEach((/**
* @param {?} item
* @param {?} index
* @return {?}
*/
(item, index) => {
item.preprocessContainer.cancel(true);
}));
this.uploader.removeAll();
this.downloader.removeAll();
this.store.clear();
this.uploadProgress.reset(0);
this.paginationService.update(0);
document.dispatchEvent(new CustomEvent(CustomEventTypeExtensions.toString(CustomEventType.ITEMS_CLEARED)));
}
/**
* @return {?}
*/
retryAll() {
this.store.getByStatus(TransferStatus.Failed).forEach((/**
* @param {?} item
* @param {?} index
* @return {?}
*/
(item, index) => {
/** @type {?} */
const that = (/** @type {?} */ (this));
that.retryItem(item);
}));
}
/**
* @return {?}
*/
removeSelected() {
/** @type {?} */
const temp = this.store.getSelected().slice();
temp.forEach((/**
* @param {?} item
* @param {?} index
* @return {?}
*/
(item, index) => {
/** @type {?} */
const that = (/** @type {?} */ (this));
that.removeItem(item);
}));
}
/**
* @param {?} item
* @return {?}
*/
addItem(item) {
if (!!item) {
this.store.addItem(item);
this.paginationService.update(this.store.count);
document.dispatchEvent(new CustomEvent(CustomEventTypeExtensions.toString(CustomEventType.ITEM_ADDED), { detail: item }));
}
}
/**
* @param {?} item
* @return {?}
*/
removeItem(item) {
if (!!item) {
item.preprocessContainer.cancel(true);
switch (item.transferType) {
case TransferType.Upload:
this.uploader.removeItem(item);
break;
case TransferType.Download:
this.downloader.removeItem(item);
break;
default:
break;
}
this.store.removeById(item.id);
this.paginationService.update(this.store.count);
document.dispatchEvent(new CustomEvent(CustomEventTypeExtensions.toString(CustomEventType.ITEM_REMOVED), { detail: item }));
}
}
/**
* @param {?} item
* @return {?}
*/
retryItem(item) {
if (!!item) {
item.preprocessContainer.cancel(true);
switch (item.transferType) {
case TransferType.Upload:
this.uploader.retryItem(item);
break;
case TransferType.Download:
this.downloader.retryItem(item);
break;
default:
break;
}
}
}
/**
* @param {?} item
* @param {?} status
* @param {?=} message
* @return {?}
*/
changeItemStatus(item, status, message) {
if (!!item && !!status) {
if (item.status !== status) {
this.paginationService.setPageByItemId(item.id);
item.status = status;
if (!!message) {
item.message = message;
}
this.store.updateFailedCount();
if (status === TransferStatus.Finished) {
document.dispatchEvent(new CustomEvent(CustomEventTypeExtensions.toString(CustomEventType.ITEM_COMPLETED), { detail: item }));
}
}
}
}
/**
* @param {?} item
* @param {?} progress
* @return {?}
*/
updateItemProgress(item, progress) {
if (!!item) {
/** @type {?} */
const now = this.dateUtil.now();
/** @type {?} */
const loaded = item.progressContainer.total * progress;
item.progressContainer.updateBitrate(now, loaded, this.bitrateInterval);
item.progressContainer.updateProgress(now, loaded, this.progressInterval);
}
}
/**
* @param {?} progressContainer
* @param {?} transferType
* @param {?} progress
* @return {?}
*/
updateOverallProgress(progressContainer, transferType, progress) {
/** @type {?} */
const now = this.dateUtil.now();
/** @type {?} */
const loaded = progressContainer.total * progress;
// this.logger.log('total: ' + progressContainer.total + ' progress: ' + progress + ' loaded: ' + loaded);
progressContainer.updateBitrate(now, loaded, this.bitrateInterval);
progressContainer.updateProgress(now, loaded, this.progressInterval);
if (progressContainer.total > 0 && loaded >= progressContainer.total) {
switch (transferType) {
case TransferType.Upload:
document.dispatchEvent(new CustomEvent(CustomEventTypeExtensions.toString(CustomEventType.UPLOAD_COMPLETED)));
break;
case TransferType.Download:
document.dispatchEvent(new CustomEvent(CustomEventTypeExtensions.toString(CustomEventType.DOWNLOAD_COMPLETED)));
break;
default:
break;
}
}
}
/**
* @param {?} progressContainer
* @param {?} size
* @return {?}
*/
updateOverallSize(progressContainer, size) {
progressContainer.reset(size);
}
/**
* @param {?} filename
* @param {?} url
* @param {?} sizeInBytes
* @return {?}
*/
download(filename, url, sizeInBytes) {
this.downloader.download(filename, url, sizeInBytes);
}
/**
* @param {?} exportType
* @return {?}
*/
export(exportType) {
this.exportService.export(exportType);
}
/**
* @param {?} status
* @return {?}
*/
getStatusClass(status) {
switch (status) {
case TransferStatus.Ready:
return 'add_circle_outline';
case TransferStatus.Uploading:
return 'arrow_upward';
case TransferStatus.Downloading:
return 'arrow_downward';
case TransferStatus.Failed:
return 'error_outline';
case TransferStatus.Queued:
case TransferStatus.Preprocessing:
return 'schedule';
case TransferStatus.Finished:
return 'done_all';
default:
return '';
}
}
/**
* @return {?}
*/
showStartButton() {
return this.store.count > 0 && !this.uploader.isWorking() && !this.downloader.isWorking();
}
/**
* @return {?}
*/
showPauseButton() {
return this.uploader.isWorking();
}
/**
* @return {?}
*/
showRemoveButton() {
return this.store.count > 0;
}
/**
* @return {?}
*/
showRetryButton() {
return this.store.failedCount > 0 && !this.uploader.isWorking() && !this.downloader.isWorking();
}
/**
* @param {?} item
* @return {?}
*/
showRetryButtonByItem(item) {
return item.status === TransferStatus.Failed;
}
/**
* @return {?}
*/
showExportButton() {
return this.store.count > 0;
}
/**
* @return {?}
*/
showPreprocessingCheckbox() {
return this.store.count > 0 && ConfigService.settings.core.preprocessHashEnabled;
}
/**
* @return {?}
*/
showPreprocessingTooltip() {
return this.showPreprocessingCheckbox() && !!ConfigService.settings.core.preprocessHashTooltipContent;
}
/**
* @param {?} item
* @return {?}
*/
showSpinner(item) {
return item.preprocessContainer.percent > 0 && item.status === TransferStatus.Preprocessing;
}
/**
* @param {?} item
* @return {?}
*/
showProgressbar(item) {
return item.progressContainer.percent > 0 &&
(item.status === TransferStatus.Uploading || item.status === TransferStatus.Downloading);
}
/**
* @param {?} items
* @param {?} index
* @return {?}
*/
showPath(items, index) {
if (index > 0 && items.length > index) {
/** @type {?} */
const currentPath = items[index].path;
// don't show if previous path is same as current
return items[index - 1].path !== currentPath;
}
return true;
}
/**
* @param {?} item
* @return {?}
*/
showEditDialog(item) {
/** @type {?} */
let result = false;
if (item) {
switch (item.transferType) {
case TransferType.Upload:
if (item.status === TransferStatus.Ready) {
result = true;
}
break;
default:
break;
}
}
return result;
}
/**
* @param {?} item
* @param {?} oldPath
* @param {?} newPath
* @return {?}
*/
editPath(item, oldPath, newPath) {
switch (item.transferType) {
case TransferType.Upload:
// replace all \ with /
/** @type {?} */
let cleanedPath = newPath.replace(/\\/g, '/');
// replace repeated / with one
cleanedPath = cleanedPath.replace(/\/+/g, '/');
if (cleanedPath.startsWith('/')) {
cleanedPath = cleanedPath.slice(1);
}
if (cleanedPath && !cleanedPath.endsWith('/')) {
cleanedPath += '/';
}
this.uploader.editPath(oldPath, cleanedPath);
break;
default:
break;
}
}
/**
* @param {?} item
* @param {?} name
* @return {?}
*/
editFilename(item, name) {
switch (item.transferType) {
case TransferType.Upload:
this.uploader.editFilename(item, name);
break;
default:
break;
}
}
/**
* @param {?} item
* @return {?}
*/
parseMessage(item) {
if (ConfigService.settings.core.parseMessageCallback instanceof Function) {
return ConfigService.settings.core.parseMessageCallback(item.message);
}
else {
return undefined;
}
}
}
if (false) {
/**
* @type {?}
* @private
*/
DatatransferFacade.prototype.uploadProgress;
/**
* @type {?}
* @private
*/
DatatransferFacade.prototype.downloadProgress;
/**
* @type {?}
* @private
*/
DatatransferFacade.prototype.progressInterval;
/**
* @type {?}
* @private
*/
DatatransferFacade.prototype.bitrateInterval;
/**
* @type {?}
* @private
*/
DatatransferFacade.prototype.logger;
/**
* @type {?}
* @private
*/
DatatransferFacade.prototype.zone;
/**
* @type {?}
* @private
*/
DatatransferFacade.prototype.store;
/**
* @type {?}
* @private
*/
DatatransferFacade.prototype.dateUtil;
/**
* @type {?}
* @private
*/
DatatransferFacade.prototype.paginationService;
/**
* @type {?}
* @private
*/
DatatransferFacade.prototype.exportService;
/**
* @type {?}
* @private
*/
DatatransferFacade.prototype.uploader;
/**
* @type {?}
* @private
*/
DatatransferFacade.prototype.downloader;
/**
* @type {?}
* @private
*/
DatatransferFacade.prototype.dialog;
}
/**
* @fileoverview added by tsickle
* Generated from: lib/models/pagination-container.model.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/**
* @record
*/
function IPaginationContainer() { }
if (false) {
/** @type {?} */
IPaginationContainer.prototype.pages;
/** @type {?} */
IPaginationContainer.prototype.page;
/** @type {?} */
IPaginationContainer.prototype.rpp;
/** @type {?} */
IPaginationContainer.prototype.total;
/** @type {?} */
IPaginationContainer.prototype.rppOptions;
}
class PaginationContainer {
constructor() {
this.pages = [];
this.page = 1;
this.rpp = 5;
this.total = 0;
}
}
if (false) {
/** @type {?} */
PaginationContainer.prototype.pages;
/** @type {?} */
PaginationContainer.prototype.page;
/** @type {?} */
PaginationContainer.prototype.rpp;
/** @type {?} */
PaginationContainer.prototype.total;
/** @type {?} */
PaginationContainer.prototype.rppOptions;
}
/**
* @fileoverview added by tsickle
* Generated from: lib/utils/date.util.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
class DateUtil {
/**
* @return {?}
*/
now() {
return ((Date.now) ? Date.now() : (new Date()).getTime());
}
/**
* @param {?} seconds
* @return {?}
*/
format(seconds) {
/** @type {?} */
let date = new Date(seconds * 1000);
if (isNaN(date.getTime())) {
return undefined;
}
else {
return ('0' + date.getUTCHours()).slice(-2) + ':' +
('0' + date.getUTCMinutes()).slice(-2) + ':' +
('0' + date.getUTCSeconds()).slice(-2);
}
}
}
DateUtil.decorators = [
{ type: Injectable }
];
/**
* @fileoverview added by tsickle
* Generated from: lib/enums/decimal-byte-unit.enum.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/** @enum {number} */
const DecimalByteUnit = {
/**
* Byte (B)
* 1 Byte
*/
Byte: 0,
/**
* Kilobyte (kB)
* 10^3 Byte = 1.000 Byte
*/
KB: 1,
/**
* Megabyte (MB)
* 10^6 Byte = 1.000.000 Byte
*/
MB: 2,
/**
* Gigabyte (GB)
* 10^9 Byte = 1.000.000.000 Byte
*/
GB: 3,
/**
* Terabyte (TB)
* 10^12 Byte = 1.000.000.000.000 Byte
*/
TB: 4,
/**
* Petabyte (PB)
* 10^15 Byte = 1.000.000.000.000.000 Byte
*/
PB: 5,
};
DecimalByteUnit[DecimalByteUnit.Byte] = 'Byte';
DecimalB