UNPKG

angular-material-datatransfer-lib

Version:

A HTML5 datatransfer UI for handling upload and download of multiple simultaneous files.

1,425 lines (1,416 loc) 192 kB
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 { __values, __extends } from 'tslib'; 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} */ var 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 {?} */ var CUSTOM_EVENT_TYPE_NS = 'github:niklr/angular-material-datatransfer.'; /** @type {?} */ var CUSTOM_EVENT_TYPE_UNKNOWN = CUSTOM_EVENT_TYPE_NS + 'unknown'; /** @type {?} */ var CUSTOM_EVENT_TYPE_CREATE = CUSTOM_EVENT_TYPE_NS + 'create'; /** @type {?} */ var CUSTOM_EVENT_TYPE_DOWNLOAD_ITEM = CUSTOM_EVENT_TYPE_NS + 'download-item'; /** @type {?} */ var CUSTOM_EVENT_TYPE_UPDATE_CONFIG = CUSTOM_EVENT_TYPE_NS + 'update-config'; /** @type {?} */ var CUSTOM_EVENT_TYPE_INIT = CUSTOM_EVENT_TYPE_NS + 'init'; /** @type {?} */ var CUSTOM_EVENT_TYPE_UPLOAD_COMPLETED = CUSTOM_EVENT_TYPE_NS + 'upload-completed'; /** @type {?} */ var CUSTOM_EVENT_TYPE_DOWNLOAD_COMPLETED = CUSTOM_EVENT_TYPE_NS + 'download-completed'; /** @type {?} */ var CUSTOM_EVENT_TYPE_ITEM_ADDED = CUSTOM_EVENT_TYPE_NS + 'item-added'; /** @type {?} */ var CUSTOM_EVENT_TYPE_ITEM_REMOVED = CUSTOM_EVENT_TYPE_NS + 'item-removed'; /** @type {?} */ var CUSTOM_EVENT_TYPE_ITEM_COMPLETED = CUSTOM_EVENT_TYPE_NS + 'item-completed'; /** @type {?} */ var 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 */ var HostDirective = /** @class */ (function () { function HostDirective(viewContainerRef) { this.viewContainerRef = viewContainerRef; } HostDirective.decorators = [ { type: Directive, args: [{ // tslint:disable-next-line: directive-selector selector: '[amd-host]', },] } ]; /** @nocollapse */ HostDirective.ctorParameters = function () { return [ { type: ViewContainerRef } ]; }; return HostDirective; }()); 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 */ var CoreAppConfig = /** @class */ (function () { function CoreAppConfig() { 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 {?} */ var target; if (request === 'preprocessHash' && this.preprocessHashChecked) { target = this.preprocessHashTarget; } if (typeof target === 'function') { return target(params); } if (target) { /** @type {?} */ var separator = target.indexOf('?') < 0 ? '?' : '&'; /** @type {?} */ var joinedParams = params.join('&'); return target + separator + joinedParams; } else { return; } }); } return CoreAppConfig; }()); 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; } var ResumableJsAppConfig = /** @class */ (function () { function ResumableJsAppConfig() { 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 + '.'); }); } return ResumableJsAppConfig; }()); 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; } var AppConfig = /** @class */ (function () { function AppConfig() { this.production = true; this.core = new CoreAppConfig(); this.resumablejs = new ResumableJsAppConfig(); } return AppConfig; }()); 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 */ var ConfigService = /** @class */ (function () { function ConfigService() { } /** * @param {?} config * @return {?} */ ConfigService.prototype.load = /** * @param {?} config * @return {?} */ function (config) { if (!!config) { ConfigService.settings.production = config.production; if (!!config.core) { Object.keys(config.core).forEach((/** * @param {?} propertyName * @return {?} */ function (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 {?} */ function (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 = function () { return []; }; return ConfigService; }()); 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} */ var 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} */ var 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 */ var BrowseDialogComponent = /** @class */ (function () { function BrowseDialogComponent(dialogRef, data) { this.dialogRef = dialogRef; this.data = data; this.datatransferFacade = (/** @type {?} */ (this.data.datatransferFacade)); } /** * @return {?} */ BrowseDialogComponent.prototype.ngAfterViewInit = /** * @return {?} */ function () { this.datatransferFacade.assignUploadBrowse(document.getElementById('amd-browse-files')); this.datatransferFacade.assignUploadBrowse(document.getElementById('amd-browse-folder'), true); }; /** * @return {?} */ BrowseDialogComponent.prototype.close = /** * @return {?} */ function () { this.dialogRef.close(); }; /** * @return {?} */ BrowseDialogComponent.prototype.onNoClick = /** * @return {?} */ function () { 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 = function () { return [ { type: MatDialogRef }, { type: undefined, decorators: [{ type: Inject, args: [MAT_DIALOG_DATA,] }] } ]; }; return BrowseDialogComponent; }()); 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 */ var EditDialogComponent = /** @class */ (function () { function EditDialogComponent(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 {?} */ EditDialogComponent.prototype.ngAfterViewInit = /** * @return {?} */ function () { }; /** * @return {?} */ EditDialogComponent.prototype.close = /** * @return {?} */ function () { this.dialogRef.close(); }; /** * @return {?} */ EditDialogComponent.prototype.onNoClick = /** * @return {?} */ function () { this.close(); }; /** * @return {?} */ EditDialogComponent.prototype.editPath = /** * @return {?} */ function () { try { this.datatransferFacade.editPath(this.item, this.item.path, this.itemPath); this.close(); } catch (error) { this.errorMessage = error; } }; /** * @return {?} */ EditDialogComponent.prototype.editFilename = /** * @return {?} */ function () { 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 = function () { return [ { type: MatDialogRef }, { type: undefined, decorators: [{ type: Inject, args: [MAT_DIALOG_DATA,] }] } ]; }; return EditDialogComponent; }()); 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 */ var DatatransferFacade = /** @class */ (function () { function DatatransferFacade(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 {?} */ DatatransferFacade.prototype.init = /** * @private * @param {?} datatransfer * @param {?} progressContainer * @return {?} */ function (datatransfer, progressContainer) { datatransfer.on('itemAdded', (/** * @param {?} item * @return {?} */ function (item) { /** @type {?} */ var that = (/** @type {?} */ (this)); that.zone.run((/** * @return {?} */ function () { that.addItem(item); })); }).bind(this)); datatransfer.on('zoneUpdated', (/** * @param {?} item * @param {?} status * @param {?=} message * @return {?} */ function (item, status, message) { /** @type {?} */ var that = (/** @type {?} */ (this)); that.zone.run((/** * @return {?} */ function () { // console.log(that.uploader.isWorking()); })); }).bind(this)); datatransfer.on('itemStatusChanged', (/** * @param {?} item * @param {?} status * @param {?=} message * @return {?} */ function (item, status, message) { /** @type {?} */ var that = (/** @type {?} */ (this)); that.zone.run((/** * @return {?} */ function () { that.changeItemStatus(item, status, message); })); }).bind(this)); datatransfer.on('itemProgressUpdated', (/** * @param {?} item * @param {?} progress * @return {?} */ function (item, progress) { /** @type {?} */ var that = (/** @type {?} */ (this)); that.zone.run((/** * @return {?} */ function () { that.updateItemProgress(item, progress); })); }).bind(this)); datatransfer.on('overallProgressUpdated', (/** * @param {?} transferType * @param {?} progress * @return {?} */ function (transferType, progress) { /** @type {?} */ var that = (/** @type {?} */ (this)); that.zone.run((/** * @return {?} */ function () { that.updateOverallProgress(progressContainer, transferType, progress); })); }).bind(this)); datatransfer.on('overallSizeUpdated', (/** * @param {?} size * @return {?} */ function (size) { /** @type {?} */ var that = (/** @type {?} */ (this)); that.zone.run((/** * @return {?} */ function () { that.updateOverallSize(progressContainer, size); })); }).bind(this)); }; /** * @param {?} element * @param {?=} isDirectory * @return {?} */ DatatransferFacade.prototype.assignUploadBrowse = /** * @param {?} element * @param {?=} isDirectory * @return {?} */ function (element, isDirectory) { if (isDirectory === void 0) { isDirectory = false; } this.uploader.assignBrowse(element, isDirectory); }; /** * @param {?} element * @return {?} */ DatatransferFacade.prototype.assignUploadDrop = /** * @param {?} element * @return {?} */ function (element) { this.uploader.assignDrop(element); }; /** * @return {?} */ DatatransferFacade.prototype.openBrowseDialog = /** * @return {?} */ function () { /** @type {?} */ var dialogRef = this.dialog.open(BrowseDialogComponent, { data: { datatransferFacade: this } }); }; /** * @param {?} item * @return {?} */ DatatransferFacade.prototype.openEditPathDialog = /** * @param {?} item * @return {?} */ function (item) { /** @type {?} */ var dialogRef = this.dialog.open(EditDialogComponent, { data: { datatransferFacade: this, mode: 'edit-path', item: item } }); }; /** * @param {?} item * @return {?} */ DatatransferFacade.prototype.openEditFilenameDialog = /** * @param {?} item * @return {?} */ function (item) { /** @type {?} */ var dialogRef = this.dialog.open(EditDialogComponent, { data: { datatransferFacade: this, mode: 'edit-filename', item: item } }); }; /** * @param {?} checked * @return {?} */ DatatransferFacade.prototype.toggleVisible = /** * @param {?} checked * @return {?} */ function (checked) { this.paginationService.paginatedItems.forEach((/** * @param {?} item * @param {?} index * @return {?} */ function (item, index) { item.isSelected = checked; })); }; /** * @return {?} */ DatatransferFacade.prototype.startAll = /** * @return {?} */ function () { var _this = this; this.store.getItems().forEach((/** * @param {?} item * @param {?} index * @return {?} */ function (item, index) { /** @type {?} */ var that = (/** @type {?} */ (_this)); if (item.transferType === TransferType.Upload && item.status === TransferStatus.Ready) { that.changeItemStatus(item, TransferStatus.Queued); } })); this.uploader.startAll(); }; /** * @return {?} */ DatatransferFacade.prototype.pauseAll = /** * @return {?} */ function () { this.store.getItems().forEach((/** * @param {?} item * @param {?} index * @return {?} */ function (item, index) { item.preprocessContainer.pause(true); })); this.uploader.pauseAll(); this.downloader.pauseAll(); }; /** * @return {?} */ DatatransferFacade.prototype.removeAll = /** * @return {?} */ function () { this.store.getItems().forEach((/** * @param {?} item * @param {?} index * @return {?} */ function (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 {?} */ DatatransferFacade.prototype.retryAll = /** * @return {?} */ function () { var _this = this; this.store.getByStatus(TransferStatus.Failed).forEach((/** * @param {?} item * @param {?} index * @return {?} */ function (item, index) { /** @type {?} */ var that = (/** @type {?} */ (_this)); that.retryItem(item); })); }; /** * @return {?} */ DatatransferFacade.prototype.removeSelected = /** * @return {?} */ function () { var _this = this; /** @type {?} */ var temp = this.store.getSelected().slice(); temp.forEach((/** * @param {?} item * @param {?} index * @return {?} */ function (item, index) { /** @type {?} */ var that = (/** @type {?} */ (_this)); that.removeItem(item); })); }; /** * @param {?} item * @return {?} */ DatatransferFacade.prototype.addItem = /** * @param {?} item * @return {?} */ function (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 {?} */ DatatransferFacade.prototype.removeItem = /** * @param {?} item * @return {?} */ function (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 {?} */ DatatransferFacade.prototype.retryItem = /** * @param {?} item * @return {?} */ function (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 {?} */ DatatransferFacade.prototype.changeItemStatus = /** * @param {?} item * @param {?} status * @param {?=} message * @return {?} */ function (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 {?} */ DatatransferFacade.prototype.updateItemProgress = /** * @param {?} item * @param {?} progress * @return {?} */ function (item, progress) { if (!!item) { /** @type {?} */ var now = this.dateUtil.now(); /** @type {?} */ var 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 {?} */ DatatransferFacade.prototype.updateOverallProgress = /** * @param {?} progressContainer * @param {?} transferType * @param {?} progress * @return {?} */ function (progressContainer, transferType, progress) { /** @type {?} */ var now = this.dateUtil.now(); /** @type {?} */ var 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 {?} */ DatatransferFacade.prototype.updateOverallSize = /** * @param {?} progressContainer * @param {?} size * @return {?} */ function (progressContainer, size) { progressContainer.reset(size); }; /** * @param {?} filename * @param {?} url * @param {?} sizeInBytes * @return {?} */ DatatransferFacade.prototype.download = /** * @param {?} filename * @param {?} url * @param {?} sizeInBytes * @return {?} */ function (filename, url, sizeInBytes) { this.downloader.download(filename, url, sizeInBytes); }; /** * @param {?} exportType * @return {?} */ DatatransferFacade.prototype.export = /** * @param {?} exportType * @return {?} */ function (exportType) { this.exportService.export(exportType); }; /** * @param {?} status * @return {?} */ DatatransferFacade.prototype.getStatusClass = /** * @param {?} status * @return {?} */ function (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 {?} */ DatatransferFacade.prototype.showStartButton = /** * @return {?} */ function () { return this.store.count > 0 && !this.uploader.isWorking() && !this.downloader.isWorking(); }; /** * @return {?} */ DatatransferFacade.prototype.showPauseButton = /** * @return {?} */ function () { return this.uploader.isWorking(); }; /** * @return {?} */ DatatransferFacade.prototype.showRemoveButton = /** * @return {?} */ function () { return this.store.count > 0; }; /** * @return {?} */ DatatransferFacade.prototype.showRetryButton = /** * @return {?} */ function () { return this.store.failedCount > 0 && !this.uploader.isWorking() && !this.downloader.isWorking(); }; /** * @param {?} item * @return {?} */ DatatransferFacade.prototype.showRetryButtonByItem = /** * @param {?} item * @return {?} */ function (item) { return item.status === TransferStatus.Failed; }; /** * @return {?} */ DatatransferFacade.prototype.showExportButton = /** * @return {?} */ function () { return this.store.count > 0; }; /** * @return {?} */ DatatransferFacade.prototype.showPreprocessingCheckbox = /** * @return {?} */ function () { return this.store.count > 0 && ConfigService.settings.core.preprocessHashEnabled; }; /** * @return {?} */ DatatransferFacade.prototype.showPreprocessingTooltip = /** * @return {?} */ function () { return this.showPreprocessingCheckbox() && !!ConfigService.settings.core.preprocessHashTooltipContent; }; /** * @param {?} item * @return {?} */ DatatransferFacade.prototype.showSpinner = /** * @param {?} item * @return {?} */ function (item) { return item.preprocessContainer.percent > 0 && item.status === TransferStatus.Preprocessing; }; /** * @param {?} item * @return {?} */ DatatransferFacade.prototype.showProgressbar = /** * @param {?} item * @return {?} */ function (item) { return item.progressContainer.percent > 0 && (item.status === TransferStatus.Uploading || item.status === TransferStatus.Downloading); }; /** * @param {?} items * @param {?} index * @return {?} */ DatatransferFacade.prototype.showPath = /** * @param {?} items * @param {?} index * @return {?} */ function (items, index) { if (index > 0 && items.length > index) { /** @type {?} */ var 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 {?} */ DatatransferFacade.prototype.showEditDialog = /** * @param {?} item * @return {?} */ function (item) { /** @type {?} */ var 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 {?} */ DatatransferFacade.prototype.editPath = /** * @param {?} item * @param {?} oldPath * @param {?} newPath * @return {?} */ function (item, oldPath, newPath) { switch (item.transferType) { case TransferType.Upload: // replace all \ with / /** @type {?} */ var cleanedPath = newPath.replace(/\\/g, '/'); // replace repeated / with one cleanedPath = cleanedPath.replace(/\/+/g, '/'); if (cleanedPath.startsWith('/')) { cleanedPath = cleanedPath.slice(1); } if (cleanedPath && !cleanedPath.endsWith('/')) { cleanedPath += '