@duoduo-oba/ng-devui
Version:
DevUI components based on Angular
1,319 lines (1,310 loc) • 61.9 kB
JavaScript
import { EventEmitter, Component, Input, Output, ViewChild, Injectable, Directive, ElementRef, HostListener, NgModule } from '@angular/core';
import { toArray, mergeMap, map, last, debounceTime } from 'rxjs/operators';
import { from, merge, Observable } from 'rxjs';
import { I18nService } from '@duoduo-oba/ng-devui/i18n';
import { CommonModule } from '@angular/common';
import endsWith from 'lodash-es/endsWith';
import { ModalAlertComponent, ModalService, ModalModule } from '@duoduo-oba/ng-devui/modal';
import { ButtonModule } from '@duoduo-oba/ng-devui/button';
/**
* @fileoverview added by tsickle
* Generated from: file-uploader.types.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
class IUploadOptions {
}
if (false) {
/** @type {?} */
IUploadOptions.prototype.uri;
/** @type {?} */
IUploadOptions.prototype.method;
/** @type {?} */
IUploadOptions.prototype.maximumSize;
/** @type {?} */
IUploadOptions.prototype.headers;
/** @type {?} */
IUploadOptions.prototype.authToken;
/** @type {?} */
IUploadOptions.prototype.authTokenHeader;
/** @type {?} */
IUploadOptions.prototype.additionalParameter;
/** @type {?} */
IUploadOptions.prototype.fileFieldName;
/** @type {?} */
IUploadOptions.prototype.checkSameName;
/** @type {?} */
IUploadOptions.prototype.withCredentials;
}
class IFileOptions {
}
if (false) {
/** @type {?} */
IFileOptions.prototype.accept;
/** @type {?} */
IFileOptions.prototype.multiple;
}
/** @enum {number} */
const UploadStatus = {
preLoad: 0,
uploading: 1,
uploaded: 2,
failed: 3,
};
UploadStatus[UploadStatus.preLoad] = 'preLoad';
UploadStatus[UploadStatus.uploading] = 'uploading';
UploadStatus[UploadStatus.uploaded] = 'uploaded';
UploadStatus[UploadStatus.failed] = 'failed';
/**
* @fileoverview added by tsickle
* Generated from: file-uploader.class.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
class FileUploader {
/**
* @param {?} file
* @param {?} uploadOptions
*/
constructor(file, uploadOptions) {
this.file = file;
this.uploadOptions = uploadOptions;
this.percentage = 0;
this.file = file;
this.uploadOptions = uploadOptions;
this.status = UploadStatus.preLoad;
}
/**
* @return {?}
*/
send() {
return new Promise((/**
* @param {?} resolve
* @param {?} reject
* @return {?}
*/
(resolve, reject) => {
const { uri, method, headers, authToken, authTokenHeader, additionalParameter, fileFieldName, withCredentials } = this.uploadOptions;
/** @type {?} */
const authTokenHeader_ = authTokenHeader || 'Authorization';
/** @type {?} */
const fileFieldName_ = fileFieldName || 'file';
this.xhr = new XMLHttpRequest();
this.xhr.open(method || 'POST', uri);
if (withCredentials) {
this.xhr.withCredentials = withCredentials;
}
if (authToken) {
this.xhr.setRequestHeader(authTokenHeader_, authToken);
}
if (headers) {
Object.keys(headers).forEach((/**
* @param {?} key
* @return {?}
*/
(key) => {
this.xhr.setRequestHeader(key, headers[key]);
}));
}
this.xhr.upload.onprogress = (/**
* @param {?} e
* @return {?}
*/
e => {
this.percentage = Math.round(e.loaded * 100 / e.total);
});
/** @type {?} */
const formData = new FormData();
formData.append(fileFieldName_, this.file);
if (additionalParameter) {
Object.keys(additionalParameter).forEach((/**
* @param {?} key
* @return {?}
*/
(key) => {
formData.append(key, additionalParameter[key]);
}));
}
this.xhr.send(formData);
this.status = UploadStatus.uploading;
this.xhr.onabort = (/**
* @return {?}
*/
() => {
this.status = UploadStatus.preLoad;
this.xhr = null;
});
this.xhr.onerror = (/**
* @return {?}
*/
() => {
this.response = this.xhr.response;
this.status = UploadStatus.failed;
reject(new Error('Upload failed in some reason.'));
});
this.xhr.onload = (/**
* @return {?}
*/
() => {
if (this.xhr.readyState === 4 && this.xhr.status >= 200 && this.xhr.status < 300) {
this.response = this.xhr.response;
this.status = UploadStatus.uploaded;
resolve({ file: this.file, response: this.xhr.response });
}
else {
this.response = this.xhr.response;
this.status = UploadStatus.failed;
reject({ file: this.file, response: this.xhr.response });
}
});
}));
}
/**
* @return {?}
*/
cancel() {
if (this.xhr) {
this.xhr.abort();
}
}
}
if (false) {
/**
* @type {?}
* @private
*/
FileUploader.prototype.xhr;
/** @type {?} */
FileUploader.prototype.status;
/** @type {?} */
FileUploader.prototype.response;
/** @type {?} */
FileUploader.prototype.percentage;
/** @type {?} */
FileUploader.prototype.file;
/**
* @type {?}
* @private
*/
FileUploader.prototype.uploadOptions;
}
/**
* @fileoverview added by tsickle
* Generated from: upload.class.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
class UploadComponent {
constructor() {
this.fileUploaders = [];
this.filesWithSameName = [];
}
/**
* @param {?} file
* @param {?} options
* @return {?}
*/
addFile(file, options) {
if (options.checkSameName) {
if (this.checkFileSame(file.name)) {
this.fileUploaders.push(new FileUploader(file, options));
}
}
else {
this.fileUploaders.push(new FileUploader(file, options));
}
}
/**
* @param {?} fileName
* @return {?}
*/
checkFileSame(fileName) {
/** @type {?} */
let checkRel = true;
for (let i = 0; i < this.fileUploaders.length; i++) {
if (fileName === this.fileUploaders[i].file.name) {
checkRel = false;
if (this.filesWithSameName.indexOf(fileName) === -1) {
this.filesWithSameName.push(fileName);
}
break;
}
}
return checkRel;
}
/**
* @return {?}
*/
getFiles() {
return this.fileUploaders.map((/**
* @param {?} fileUploader
* @return {?}
*/
fileUploader => {
return fileUploader.file;
}));
}
/**
* @return {?}
*/
upload() {
/** @type {?} */
const uploads = this.fileUploaders
.filter((/**
* @param {?} fileUploader
* @return {?}
*/
(fileUploader) => fileUploader.status !== UploadStatus.uploaded))
.map((/**
* @param {?} fileUploader
* @return {?}
*/
(fileUploader) => {
return from(fileUploader.send());
}));
if (uploads.length > 0) {
return merge(...uploads).pipe(toArray());
}
return from(Promise.reject('no files'));
}
/**
* @param {?} file
* @return {?}
*/
deleteFile(file) {
this.fileUploaders = this.fileUploaders.filter((/**
* @param {?} fileUploader
* @return {?}
*/
(fileUploader) => {
return file !== fileUploader.file;
}));
}
/**
* @return {?}
*/
removeFiles() {
this.fileUploaders = [];
this.filesWithSameName = [];
}
/**
* @return {?}
*/
getSameNameFiles() {
return this.filesWithSameName.join();
}
/**
* @return {?}
*/
resetSameNameFiles() {
this.filesWithSameName = [];
}
}
if (false) {
/** @type {?} */
UploadComponent.prototype.fileUploaders;
/** @type {?} */
UploadComponent.prototype.filesWithSameName;
}
/**
* @fileoverview added by tsickle
* Generated from: uploaded-files.component.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
class UploadedFilesComponent {
/**
* @param {?} i18n
*/
constructor(i18n) {
this.i18n = i18n;
this.uploadedFiles = [];
this.deleteUploadedFileEvent = new EventEmitter();
// 解决templateContext 传递method.bind(this)引发模板中内嵌组件initialize问题
this.deleteFileProxy = (/**
* @param {?} filePath
* @return {?}
*/
filePath => {
this.deleteFile(filePath);
});
this.i18nText = this.i18n.getI18nText().upload;
this.i18nSubscription = this.i18n.langChange().subscribe((/**
* @param {?} data
* @return {?}
*/
(data) => {
this.i18nText = data.upload;
}));
}
/**
* @return {?}
*/
cleanUploadedFiles() {
this.uploadedFiles = [];
}
/**
* @param {?} file
* @return {?}
*/
addAndOverwriteFile(file) {
this.cleanUploadedFiles();
this.uploadedFiles.push(file);
}
/**
* @param {?} file
* @return {?}
*/
addFile(file) {
this.uploadedFiles.push(file);
}
/**
* @param {?} filePath
* @return {?}
*/
deleteFile(filePath) {
this.uploadedFiles = this.uploadedFiles.filter((/**
* @param {?} file
* @return {?}
*/
(file) => {
return filePath !== ((/** @type {?} */ (file)))[this.filePath];
}));
this.deleteUploadedFileEvent.emit(filePath);
}
/**
* @return {?}
*/
ngOnDestroy() {
if (this.i18nSubscription) {
this.i18nSubscription.unsubscribe();
}
}
}
UploadedFilesComponent.decorators = [
{ type: Component, args: [{
selector: 'd-uploaded-files',
exportAs: 'dUploadFiles',
template: "<ng-template\r\n [ngTemplateOutlet]=\"uploadedFilesRef ? uploadedFilesRef : default\"\r\n [ngTemplateOutletContext]=\"{ $implicit: this, uploadedFiles: uploadedFiles, filePath: filePath, deleteFile: deleteFileProxy}\"\r\n>\r\n</ng-template>\r\n\r\n<ng-template #default>\r\n <table class=\"devui-table\" *ngIf=\"uploadedFiles.length > 0\" [style.margin-bottom.px]=\"0\">\r\n <tbody>\r\n <tr *ngFor=\"let uploadedFile of uploadedFiles; let index = index\">\r\n <td width=\"50%\">\r\n <span>{{ uploadedFile.name }}</span>\r\n </td>\r\n <td width=\"25%\">\r\n <span>{{ i18nText?.upload }}</span>\r\n </td>\r\n <td>\r\n <d-button icon=\"trash\" bsStyle=\"danger\" bsSize=\"xs\" (btnClick)=\"deleteFile(uploadedFile[filePath])\">\r\n {{ i18nText?.delete }}\r\n </d-button>\r\n </td>\r\n </tr>\r\n </tbody>\r\n </table>\r\n</ng-template>\r\n",
styles: ["table.devui-table{width:100%;max-width:100%;margin-bottom:20px}table.devui-table>tbody>tr>td{padding:8px;line-height:1.42857143;vertical-align:top;border-top:1px solid #ddd}.devui-upload-input{padding:5px 25px 5px 10px!important;cursor:pointer;text-overflow:ellipsis}"]
}] }
];
/** @nocollapse */
UploadedFilesComponent.ctorParameters = () => [
{ type: I18nService }
];
UploadedFilesComponent.propDecorators = {
uploadedFiles: [{ type: Input }],
uploadedFilesRef: [{ type: Input }],
filePath: [{ type: Input }],
deleteUploadedFileEvent: [{ type: Output }]
};
if (false) {
/** @type {?} */
UploadedFilesComponent.prototype.uploadedFiles;
/** @type {?} */
UploadedFilesComponent.prototype.uploadedFilesRef;
/** @type {?} */
UploadedFilesComponent.prototype.filePath;
/** @type {?} */
UploadedFilesComponent.prototype.deleteUploadedFileEvent;
/** @type {?} */
UploadedFilesComponent.prototype.i18nText;
/** @type {?} */
UploadedFilesComponent.prototype.i18nSubscription;
/** @type {?} */
UploadedFilesComponent.prototype.deleteFileProxy;
/**
* @type {?}
* @private
*/
UploadedFilesComponent.prototype.i18n;
}
/**
* @fileoverview added by tsickle
* Generated from: multiple-upload-view.component.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
class MultipleUploadViewComponent extends UploadComponent {
/**
* @param {?} i18n
*/
constructor(i18n) {
super();
this.i18n = i18n;
this.uploadedFiles = [];
this.deleteUploadedFileEvent = new EventEmitter();
this.UploadStatus = UploadStatus;
this.fileUploaders = [];
// 解决templateContext 传递method.bind(this)引发模板中内嵌组件initialize问题
this.deleteFileProxy = (/**
* @param {?} file
* @return {?}
*/
file => {
this.deleteFile(file);
});
this.i18nText = this.i18n.getI18nText().upload;
this.i18nSubscription = this.i18n.langChange().subscribe((/**
* @param {?} data
* @return {?}
*/
(data) => {
this.i18nText = data.upload;
}));
}
/**
* @param {?} file
* @return {?}
*/
addFile(file) {
super.addFile(file, this.uploadOptions);
}
/**
* @param {?} file
* @return {?}
*/
deleteFile(file) {
super.deleteFile(file);
this.deleteUploadedFileEvent.emit(file);
}
/**
* @return {?}
*/
removeFiles() {
super.removeFiles();
}
/**
* @param {?} filePath
* @return {?}
*/
_onDeleteUploadedFile(filePath) {
this.deleteUploadedFileEvent.emit(filePath);
}
/**
* @return {?}
*/
ngOnDestroy() {
if (this.i18nSubscription) {
this.i18nSubscription.unsubscribe();
}
}
}
MultipleUploadViewComponent.decorators = [
{ type: Component, args: [{
selector: 'd-multiple-upload-view',
template: "<d-uploaded-files\r\n #dUploadedFiles\r\n [uploadedFiles]=\"uploadedFiles\"\r\n [filePath]=\"filePath\"\r\n [uploadedFilesRef]=\"uploadedFilesRef\"\r\n (deleteUploadedFileEvent)=\"_onDeleteUploadedFile($event)\"\r\n>\r\n</d-uploaded-files>\r\n<ng-template\r\n [ngTemplateOutlet]=\"preloadFilesRef ? preloadFilesRef : default\"\r\n [ngTemplateOutletContext]=\"{ $implicit: this, fileUploaders: fileUploaders, UploadStatus: UploadStatus, deleteFile: deleteFileProxy}\"\r\n>\r\n</ng-template>\r\n<ng-template #default>\r\n <table class=\"devui-table\" *ngIf=\"fileUploaders.length > 0\">\r\n <tr *ngFor=\"let fileUploader of fileUploaders; let index = index\">\r\n <td width=\"50%\">\r\n <span>{{ fileUploader.file.name }}</span>\r\n </td>\r\n <td width=\"25%\">\r\n <span *ngIf=\"fileUploader.status === UploadStatus.preLoad\">{{ i18nText?.preload }}</span>\r\n <span *ngIf=\"fileUploader.status === UploadStatus.uploading\">{{ i18nText?.uploading }}</span>\r\n <span *ngIf=\"fileUploader.status === UploadStatus.uploaded\">{{ i18nText?.uploaded }}</span>\r\n <span *ngIf=\"fileUploader.status === UploadStatus.failed\">{{ i18nText?.uploadFailed }}</span>\r\n </td>\r\n <td>\r\n <d-button\r\n bordered=\"true\"\r\n icon=\"trash\"\r\n bsStyle=\"danger\"\r\n bsSize=\"xs\"\r\n *ngIf=\"fileUploader.status !== UploadStatus.uploaded\"\r\n [disabled]=\"fileUploader.status === UploadStatus.uploading\"\r\n (btnClick)=\"deleteFile(fileUploader.file)\"\r\n >\r\n {{ i18nText?.delete }}\r\n </d-button>\r\n </td>\r\n </tr>\r\n </table>\r\n</ng-template>\r\n",
styles: [".devui-table>tbody>tr:first-child td{border-top:none}table.devui-table{width:100%;max-width:100%;margin-bottom:20px}table.devui-table>tbody>tr>td{padding:8px;line-height:1.42857143;vertical-align:top;border-top:1px solid #ddd}"]
}] }
];
/** @nocollapse */
MultipleUploadViewComponent.ctorParameters = () => [
{ type: I18nService }
];
MultipleUploadViewComponent.propDecorators = {
uploadedFilesComponent: [{ type: ViewChild, args: ['dUploadedFiles', { static: true },] }],
uploadOptions: [{ type: Input }],
preloadFilesRef: [{ type: Input }],
uploadedFiles: [{ type: Input }],
uploadedFilesRef: [{ type: Input }],
filePath: [{ type: Input }],
deleteUploadedFileEvent: [{ type: Output }]
};
if (false) {
/** @type {?} */
MultipleUploadViewComponent.prototype.uploadedFilesComponent;
/** @type {?} */
MultipleUploadViewComponent.prototype.uploadOptions;
/** @type {?} */
MultipleUploadViewComponent.prototype.preloadFilesRef;
/** @type {?} */
MultipleUploadViewComponent.prototype.uploadedFiles;
/** @type {?} */
MultipleUploadViewComponent.prototype.uploadedFilesRef;
/** @type {?} */
MultipleUploadViewComponent.prototype.filePath;
/** @type {?} */
MultipleUploadViewComponent.prototype.deleteUploadedFileEvent;
/** @type {?} */
MultipleUploadViewComponent.prototype.UploadStatus;
/** @type {?} */
MultipleUploadViewComponent.prototype.fileUploaders;
/** @type {?} */
MultipleUploadViewComponent.prototype.i18nText;
/** @type {?} */
MultipleUploadViewComponent.prototype.i18nSubscription;
/** @type {?} */
MultipleUploadViewComponent.prototype.deleteFileProxy;
/**
* @type {?}
* @private
*/
MultipleUploadViewComponent.prototype.i18n;
}
/**
* @fileoverview added by tsickle
* Generated from: single-upload-view.component.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
class SingleUploadViewComponent extends UploadComponent {
constructor() {
super(...arguments);
this.uploadedFiles = [];
this.deleteUploadedFileEvent = new EventEmitter();
this.UploadStatus = UploadStatus;
this.fileUploaders = [];
// 解决templateContext 传递method.bind(this)引发模板中内嵌组件initialize问题
this.deleteFileProxy = (/**
* @param {?} file
* @return {?}
*/
file => {
this.deleteFile(file);
});
}
/**
* @param {?} file
* @return {?}
*/
addFile(file) {
this.fileUploaders = [];
super.addFile(file, this.uploadOptions);
}
/**
* @param {?} file
* @return {?}
*/
deleteFile(file) {
super.deleteFile(file);
this.deleteUploadedFileEvent.emit(file);
}
/**
* @param {?} filePath
* @return {?}
*/
_onDeleteUploadedFile(filePath) {
this.deleteUploadedFileEvent.emit(filePath);
}
}
SingleUploadViewComponent.decorators = [
{ type: Component, args: [{
selector: 'd-single-upload-view',
exportAs: 'dSingleUploadView',
template: "<d-uploaded-files\r\n #dUploadedFiles\r\n [uploadedFiles]=\"uploadedFiles\"\r\n [filePath]=\"filePath\"\r\n [uploadedFilesRef]=\"uploadedFilesRef || default\"\r\n (deleteUploadedFileEvent)=\"_onDeleteUploadedFile($event)\"\r\n>\r\n</d-uploaded-files>\r\n<ng-template\r\n [ngTemplateOutlet]=\"preloadFilesRef ? preloadFilesRef : default\"\r\n [ngTemplateOutletContext]=\"{ $implicit: this, fileUploaders: fileUploaders, UploadStatus: UploadStatus, deleteFile: deleteFileProxy}\"\r\n>\r\n</ng-template>\r\n<ng-template #default> </ng-template>\r\n",
styles: [".devui-table>tbody>tr:first-child td{border-top:none}"]
}] }
];
SingleUploadViewComponent.propDecorators = {
uploadOptions: [{ type: Input }],
preloadFilesRef: [{ type: Input }],
uploadedFiles: [{ type: Input }],
uploadedFilesRef: [{ type: Input }],
filePath: [{ type: Input }],
deleteUploadedFileEvent: [{ type: Output }],
uploadedFilesComponent: [{ type: ViewChild, args: ['dUploadedFiles', { static: true },] }]
};
if (false) {
/** @type {?} */
SingleUploadViewComponent.prototype.uploadOptions;
/** @type {?} */
SingleUploadViewComponent.prototype.preloadFilesRef;
/** @type {?} */
SingleUploadViewComponent.prototype.uploadedFiles;
/** @type {?} */
SingleUploadViewComponent.prototype.uploadedFilesRef;
/** @type {?} */
SingleUploadViewComponent.prototype.filePath;
/** @type {?} */
SingleUploadViewComponent.prototype.deleteUploadedFileEvent;
/** @type {?} */
SingleUploadViewComponent.prototype.uploadedFilesComponent;
/** @type {?} */
SingleUploadViewComponent.prototype.UploadStatus;
/** @type {?} */
SingleUploadViewComponent.prototype.fileUploaders;
/** @type {?} */
SingleUploadViewComponent.prototype.deleteFileProxy;
}
/**
* @fileoverview added by tsickle
* Generated from: select-files.utils.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
class SelectFiles {
/**
* @param {?} i18n
*/
constructor(i18n) {
this.i18n = i18n;
this.selectFiles = (/**
* @param {?} __0
* @return {?}
*/
({ multiple, accept }) => {
return new Promise((/**
* @param {?} resolve
* @return {?}
*/
(resolve) => {
/** @type {?} */
const tempNode = document.getElementById('d-upload-temp');
if (tempNode) {
document.body.removeChild(tempNode);
}
/** @type {?} */
const input = document.createElement('input');
input.style.position = 'fixed';
input.style.left = '-2000px';
input.style.top = '-2000px';
input.setAttribute('id', 'd-upload-temp');
input.setAttribute('type', 'file');
if (multiple) {
input.setAttribute('multiple', '');
}
if (accept) {
input.setAttribute('accept', accept);
}
input.addEventListener('change', (/**
* @param {?} event
* @return {?}
*/
event => {
resolve(Array.prototype.slice.call(((/** @type {?} */ (event.target))).files));
}));
document.body.appendChild(input); // Fix campatability issue with Internet Explorer 11
this.simulateClickEvent(input);
}));
});
this.isAllowedFileType = (/**
* @param {?} accept
* @param {?} file
* @return {?}
*/
(accept, file) => {
if (accept) {
/** @type {?} */
const acceptArr = accept.split(',');
return acceptArr.reduce((/**
* @param {?} result
* @param {?} item
* @return {?}
*/
(result, item) => {
return result || file.type.indexOf(item.replace(/[\.*]/g, '')) > -1 || endsWith(file.name, item);
}), false);
}
return true;
});
this.beyondMaximalSize = (/**
* @param {?} fileSize
* @param {?} maximumSize
* @return {?}
*/
(fileSize, maximumSize) => {
if (maximumSize) {
return fileSize > 1000000 * maximumSize;
}
return false;
});
this.triggerSelectFiles = (/**
* @param {?} fileOptions
* @param {?} uploadOptions
* @return {?}
*/
(fileOptions, uploadOptions) => {
const { multiple, accept } = fileOptions;
return this._validateFiles(from(this.selectFiles({ multiple, accept })), accept, uploadOptions);
});
this.triggerDropFiles = (/**
* @param {?} fileOptions
* @param {?} uploadOptions
* @param {?} files
* @return {?}
*/
(fileOptions, uploadOptions, files) => {
const { multiple, accept } = fileOptions;
return this._validateFiles(new Observable((/**
* @param {?} observer
* @return {?}
*/
observer => observer.next(files))), accept, uploadOptions);
});
this.i18nText = this.i18n.getI18nText().upload;
this.i18nSubscription = this.i18n.langChange().subscribe((/**
* @param {?} data
* @return {?}
*/
(data) => {
this.i18nText = data.upload;
}));
}
/**
* @param {?} observable
* @param {?} accept
* @param {?} uploadOptions
* @return {?}
*/
_validateFiles(observable, accept, uploadOptions) {
return observable.pipe(mergeMap((/**
* @param {?} file
* @return {?}
*/
file => (/** @type {?} */ (file)))), map((/**
* @param {?} file
* @return {?}
*/
(file) => {
if (!this.isAllowedFileType(accept, (/** @type {?} */ (file)))) {
this.NOT_ALLOWED_FILE_TYPE_MSG = this.i18nText.getNotAllowedFileTypeMsg(((/** @type {?} */ (file))).name, accept);
throw new Error(this.NOT_ALLOWED_FILE_TYPE_MSG);
}
if (this.beyondMaximalSize(((/** @type {?} */ (file))).size, uploadOptions.maximumSize)) {
this.BEYOND_MAXIMAL_FILE_SIZE_MSG = this.i18nText.getBeyondMaximalFileSizeMsg(((/** @type {?} */ (file))).size, uploadOptions.maximumSize);
throw new Error(this.BEYOND_MAXIMAL_FILE_SIZE_MSG);
}
return file;
})));
}
/**
* @param {?} input
* @return {?}
*/
simulateClickEvent(input) {
/** @type {?} */
const evt = document.createEvent('MouseEvents');
evt.initMouseEvent('click', true, true, window, 1, 0, 0, 0, 0, false, false, false, false, 0, null);
input.dispatchEvent(evt);
}
}
SelectFiles.decorators = [
{ type: Injectable }
];
/** @nocollapse */
SelectFiles.ctorParameters = () => [
{ type: I18nService }
];
if (false) {
/** @type {?} */
SelectFiles.prototype.NOT_ALLOWED_FILE_TYPE_MSG;
/** @type {?} */
SelectFiles.prototype.BEYOND_MAXIMAL_FILE_SIZE_MSG;
/** @type {?} */
SelectFiles.prototype.i18nText;
/** @type {?} */
SelectFiles.prototype.i18nSubscription;
/** @type {?} */
SelectFiles.prototype.selectFiles;
/** @type {?} */
SelectFiles.prototype.isAllowedFileType;
/** @type {?} */
SelectFiles.prototype.beyondMaximalSize;
/** @type {?} */
SelectFiles.prototype.triggerSelectFiles;
/** @type {?} */
SelectFiles.prototype.triggerDropFiles;
/**
* @type {?}
* @private
*/
SelectFiles.prototype.i18n;
}
/**
* @fileoverview added by tsickle
* Generated from: single-upload.component.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
class SingleUploadComponent {
/**
* @param {?} modalService
* @param {?} i18n
* @param {?} selectFiles
*/
constructor(modalService, i18n, selectFiles) {
this.modalService = modalService;
this.i18n = i18n;
this.selectFiles = selectFiles;
this.autoUpload = false;
this.withoutBtn = false;
this.uploadedFiles = [];
this.enableDrop = false;
this.successEvent = new EventEmitter();
this.errorEvent = new EventEmitter();
this.deleteUploadedFileEvent = new EventEmitter();
this.fileDrop = new EventEmitter();
this.fileOver = new EventEmitter();
this.UploadStatus = UploadStatus;
this.isDropOVer = false;
this.i18nText = this.i18n.getI18nText().upload;
this.i18nCommonText = this.i18n.getI18nText().common;
this.i18nSubscription = this.i18n.langChange().subscribe((/**
* @param {?} data
* @return {?}
*/
(data) => {
this.i18nText = data.upload;
this.i18nCommonText = data.common;
}));
}
/**
* @param {?} observale
* @return {?}
*/
_dealFiles(observale) {
observale.pipe(map((/**
* @param {?} file
* @return {?}
*/
file => {
this.singleUploadViewComponent.addFile((/** @type {?} */ (file)));
return file;
}))).subscribe((/**
* @return {?}
*/
() => {
this.singleUploadViewComponent.uploadedFilesComponent.cleanUploadedFiles();
if (this.autoUpload) {
this.upload();
}
}), (/**
* @param {?} error
* @return {?}
*/
(error) => {
this.alertMsg(error.message);
}));
}
/**
* @param {?} $event
* @return {?}
*/
onClick($event) {
this._dealFiles(this.selectFiles.triggerSelectFiles(this.fileOptions, this.uploadOptions));
}
/**
* @return {?}
*/
get filename() {
return (this.singleUploadViewComponent.getFiles()[0] || (/** @type {?} */ ({}))).name || '';
}
/**
* @param {?} files
* @return {?}
*/
onFileDrop(files) {
this.isDropOVer = false;
this._dealFiles(this.selectFiles.triggerDropFiles(this.fileOptions, this.uploadOptions, files));
this.fileDrop.emit(files[0]);
}
/**
* @param {?} event
* @return {?}
*/
onFileOver(event) {
this.isDropOVer = event;
this.fileOver.emit(event);
}
/**
* @return {?}
*/
upload() {
this.canUpload().then((/**
* @param {?} canUpload
* @return {?}
*/
(canUpload) => {
if (!canUpload) {
return;
}
this.singleUploadViewComponent
.upload()
.pipe(last()).subscribe((/**
* @param {?} results
* @return {?}
*/
(results) => {
this.successEvent.emit(results);
results.forEach((/**
* @param {?} result
* @return {?}
*/
(result) => {
this.singleUploadViewComponent.deleteFile(result.file);
this.singleUploadViewComponent.uploadedFilesComponent.addAndOverwriteFile(result.file);
}));
}), (/**
* @param {?} error
* @return {?}
*/
(error) => {
this.singleUploadViewComponent.uploadedFilesComponent.cleanUploadedFiles();
this.errorEvent.emit(error);
}));
}));
}
/**
* @return {?}
*/
canUpload() {
/** @type {?} */
let uploadResult = Promise.resolve(true);
if (this.beforeUpload) {
/** @type {?} */
const result = this.beforeUpload(this.singleUploadViewComponent.getFiles()[0] || (/** @type {?} */ ({})));
if (typeof result !== 'undefined') {
if (result.then) {
uploadResult = result;
}
else if (result.subscribe) {
uploadResult = ((/** @type {?} */ (result))).toPromise();
}
else {
uploadResult = Promise.resolve(result);
}
}
}
return uploadResult;
}
/**
* @param {?} filePath
* @return {?}
*/
_onDeleteUploadedFile(filePath) {
this.deleteUploadedFileEvent.emit(filePath);
}
/**
* @param {?} $event
* @return {?}
*/
deleteFile($event) {
$event.stopPropagation();
/** @type {?} */
const files = this.singleUploadViewComponent.getFiles();
this.singleUploadViewComponent.deleteFile(files[0]);
}
/**
* @param {?} errorMsg
* @return {?}
*/
alertMsg(errorMsg) {
/** @type {?} */
const results = this.modalService.open({
width: '300px',
backdropCloseable: false,
showAnimate: true,
component: ModalAlertComponent,
data: {
content: errorMsg,
cancelBtnText: this.confirmText ? this.confirmText : this.i18nCommonText.btnConfirm,
onClose: (/**
* @param {?} event
* @return {?}
*/
(event) => {
results.modalInstance.hide();
}),
},
});
}
/**
* @return {?}
*/
ngOnDestroy() {
if (this.i18nSubscription) {
this.i18nSubscription.unsubscribe();
}
}
}
SingleUploadComponent.decorators = [
{ type: Component, args: [{
selector: 'd-single-upload',
template: "<div\r\n [style.display]=\"withoutBtn ? '' : '-webkit-inline-box'\"\r\n d-file-drop\r\n [enableDrop]=\"enableDrop\"\r\n [isSingle]=\"true\"\r\n (fileDrop)=\"onFileDrop($event)\"\r\n (fileOver)=\"onFileOver($event)\"\r\n [ngStyle]=\"{ border: isDropOVer ? '1px solid #15bf15' : '0' }\"\r\n>\r\n <div (click)=\"onClick($event)\" class=\"devui-input-group\">\r\n <input\r\n style=\"cursor: pointer\"\r\n class=\"devui-form-control devui-upload-input\"\r\n [placeholder]=\"placeholderText ? placeholderText : i18nText?.chooseFile\"\r\n [value]=\"filename\"\r\n [title]=\"filename\"\r\n readonly\r\n />\r\n <span\r\n *ngIf=\"!!filename\"\r\n class=\"icon-close devui-upload-delete-file-button devui-icon-close-position\"\r\n (click)=\"deleteFile($event)\"\r\n ></span>\r\n <span class=\"devui-input-group-addon\" style=\"cursor: pointer\">\r\n <svg class=\"svg-icon-dot\" height=\"1em\" width=\"1em\" viewBox=\"0 0 1024 1024\" xmlns=\"http://www.w3.org/2000/svg\">\r\n <path\r\n d=\"m400.31892 176.970574c0-61.574381 50.113351-111.680569 111.679545-111.680569 61.576427 0 111.680569 50.106188 111.680569 111.680569 0 61.568241-50.104141 111.679545-111.680569 111.679545-61.566194 0-111.679545-50.111304-111.679545-111.679545zm0 335.028403c0-61.568241 50.113351-111.678522 111.679545-111.678522 61.576427 0 111.680569 50.110281 111.680569 111.678522 0 61.574381-50.105165 111.682615-111.680569 111.682615-61.566194 0-111.679545-50.108235-111.679545-111.682615zm0 335.037612c0-61.572334 50.113351-111.679545 111.679545-111.679545 61.575404 0 111.680569 50.107211 111.680569 111.679545 0 61.567217-50.105165 111.672382-111.680569 111.672382-61.566194 0-111.679545-50.105164-111.679545-111.672382zm0 0\"\r\n />\r\n </svg>\r\n </span>\r\n </div>\r\n <d-button\r\n *ngIf=\"!autoUpload && !withoutBtn\"\r\n (btnClick)=\"upload()\"\r\n bsStyle=\"common\"\r\n [style.margin-left.px]=\"10\"\r\n [disabled]=\"\r\n dSingleUploadView.uploadedFilesComponent.uploadedFiles.length > 0 ||\r\n dSingleUploadView.fileUploaders[0]?.status === UploadStatus.uploading\r\n \"\r\n >\r\n <span *ngIf=\"!dSingleUploadView.fileUploaders[0] || dSingleUploadView.fileUploaders[0]?.status === UploadStatus.preLoad\">{{\r\n uploadText || i18nText?.upload\r\n }}</span>\r\n <span *ngIf=\"dSingleUploadView.fileUploaders[0]?.status === UploadStatus.uploading\">{{ i18nText?.uploading }}</span>\r\n <span *ngIf=\"dSingleUploadView.fileUploaders[0]?.status === UploadStatus.uploaded\">{{ i18nText?.uploaded }}</span>\r\n <span *ngIf=\"dSingleUploadView.fileUploaders[0]?.status === UploadStatus.failed\">{{ i18nText?.uploadFailed }}</span>\r\n </d-button>\r\n</div>\r\n<d-single-upload-view\r\n #dSingleUploadView=\"dSingleUploadView\"\r\n [uploadOptions]=\"uploadOptions\"\r\n [filePath]=\"filePath\"\r\n [uploadedFiles]=\"uploadedFiles\"\r\n [uploadedFilesRef]=\"uploadedFilesRef\"\r\n [preloadFilesRef]=\"preloadFilesRef\"\r\n (deleteUploadedFileEvent)=\"_onDeleteUploadedFile($event)\"\r\n>\r\n</d-single-upload-view>\r\n",
exportAs: 'dSingleUpload',
styles: [".devui-input-group{position:relative;display:table;border-collapse:separate}.devui-input-group:hover .devui-input-group-addon{border-color:#344899;background-color:#dfe1e6;font-weight:700}.devui-input-group:hover .devui-form-control{border-color:#344899 #adb0b8 #344899 #344899}.devui-input-group .devui-input-group-addon:active{border-color:#344899 #adb0b8 #344899 #344899;background-color:#dfe1e6}.devui-input-group .devui-input-group-addon{width:1%;white-space:nowrap;vertical-align:middle;padding:5px 10px;font-size:14px;font-weight:400;line-height:1;color:#252b3a;text-align:center;background-color:#f8f8f8;border-top:1px solid #adb0b8;border-bottom:1px solid #adb0b8;border-right:1px solid #adb0b8;border-top-right-radius:1px;border-bottom-right-radius:1px;display:table-cell;-webkit-transition:border-color .15s ease-in-out;transition:border-color .15s ease-in-out;cursor:pointer}.devui-input-group .devui-form-control{cursor:pointer;display:block;width:100%;height:32px;padding:5px 10px;font-size:14px;line-height:1.42857143;color:#252b3a;background-image:none;border:1px solid #adb0b8;border-top-left-radius:1px;border-bottom-left-radius:1px;-webkit-transition:border-color .15s ease-in-out,box-shadow .15s ease-in-out;transition:border-color .15s ease-in-out,box-shadow .15s ease-in-out}svg.svg-icon-dot>path{fill:#252b3a}.devui-form-control{outline:0}.devui-icon-close-position{position:absolute;top:calc(50% - 7px);right:50px}"]
}] }
];
/** @nocollapse */
SingleUploadComponent.ctorParameters = () => [
{ type: ModalService },
{ type: I18nService },
{ type: SelectFiles }
];
SingleUploadComponent.propDecorators = {
uploadOptions: [{ type: Input }],
fileOptions: [{ type: Input }],
autoUpload: [{ type: Input }],
withoutBtn: [{ type: Input }],
uploadedFiles: [{ type: Input }],
uploadedFilesRef: [{ type: Input }],
preloadFilesRef: [{ type: Input }],
filePath: [{ type: Input }],
placeholderText: [{ type: Input }],
uploadText: [{ type: Input }],
confirmText: [{ type: Input }],
beforeUpload: [{ type: Input }],
enableDrop: [{ type: Input }],
successEvent: [{ type: Output }],
errorEvent: [{ type: Output }],
deleteUploadedFileEvent: [{ type: Output }],
fileDrop: [{ type: Output }],
fileOver: [{ type: Output }],
singleUploadViewComponent: [{ type: ViewChild, args: ['dSingleUploadView', { static: true },] }]
};
if (false) {
/** @type {?} */
SingleUploadComponent.prototype.dSingleUploadView;
/** @type {?} */
SingleUploadComponent.prototype.uploadOptions;
/** @type {?} */
SingleUploadComponent.prototype.fileOptions;
/** @type {?} */
SingleUploadComponent.prototype.autoUpload;
/** @type {?} */
SingleUploadComponent.prototype.withoutBtn;
/** @type {?} */
SingleUploadComponent.prototype.uploadedFiles;
/** @type {?} */
SingleUploadComponent.prototype.uploadedFilesRef;
/** @type {?} */
SingleUploadComponent.prototype.preloadFilesRef;
/** @type {?} */
SingleUploadComponent.prototype.filePath;
/** @type {?} */
SingleUploadComponent.prototype.placeholderText;
/** @type {?} */
SingleUploadComponent.prototype.uploadText;
/** @type {?} */
SingleUploadComponent.prototype.confirmText;
/** @type {?} */
SingleUploadComponent.prototype.beforeUpload;
/** @type {?} */
SingleUploadComponent.prototype.enableDrop;
/** @type {?} */
SingleUploadComponent.prototype.successEvent;
/** @type {?} */
SingleUploadComponent.prototype.errorEvent;
/** @type {?} */
SingleUploadComponent.prototype.deleteUploadedFileEvent;
/** @type {?} */
SingleUploadComponent.prototype.fileDrop;
/** @type {?} */
SingleUploadComponent.prototype.fileOver;
/** @type {?} */
SingleUploadComponent.prototype.singleUploadViewComponent;
/** @type {?} */
SingleUploadComponent.prototype.UploadStatus;
/** @type {?} */
SingleUploadComponent.prototype.isDropOVer;
/** @type {?} */
SingleUploadComponent.prototype.i18nText;
/** @type {?} */
SingleUploadComponent.prototype.i18nCommonText;
/** @type {?} */
SingleUploadComponent.prototype.i18nSubscription;
/**
* @type {?}
* @private
*/
SingleUploadComponent.prototype.modalService;
/**
* @type {?}
* @private
*/
SingleUploadComponent.prototype.i18n;
/**
* @type {?}
* @private
*/
SingleUploadComponent.prototype.selectFiles;
}
/**
* @fileoverview added by tsickle
* Generated from: multiple-upload.component.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
class MultipleUploadComponent {
/**
* @param {?} modalService
* @param {?} selectFiles
* @param {?} i18n
*/
constructor(modalService, selectFiles, i18n) {
this.modalService = modalService;
this.selectFiles = selectFiles;
this.i18n = i18n;
this.autoUpload = false;
this.withoutBtn = false;
this.uploadedFiles = [];
this.enableDrop = false;
this.successEvent = new EventEmitter();
this.errorEvent = new EventEmitter();
this.deleteUploadedFileEvent = new EventEmitter();
this.fileDrop = new EventEmitter();
this.fileOver = new EventEmitter();
this.isDropOVer = false;
this.i18nText = this.i18n.getI18nText().upload;
this.i18nCommonText = this.i18n.getI18nText().common;
this.i18nSubscription = this.i18n.langChange().subscribe((/**
* @param {?} data
* @return {?}
*/
(data) => {
this.i18nText = data.upload;
this.i18nCommonText = data.common;
}));
}
/**
* @param {?} observale
* @return {?}
*/
_dealFiles(observale) {
this.multipleUploadViewComponent.resetSameNameFiles();
observale.pipe(map((/**
* @param {?} file
* @return {?}
*/
file => this.multipleUploadViewComponent.addFile(file))), debounceTime(100))
.subscribe((/**
* @return {?}
*/
() => {
/** @type {?} */
const sameNameFiles = this.multipleUploadViewComponent.getSameNameFiles();
if (this.autoUpload) {
this.upload();
}
if (this.uploadOptions.checkSameName && sameNameFiles.length) {
this.alertMsg(this.i18nText.getExistSameNameFilesMsg(sameNameFiles));
}
}), (/**
* @param {?} error
* @return {?}
*/
(error) => {
this.alertMsg(error.message);
}));
}
/**
* @param {?} event
* @return {?}
*/
onClick(event) {
this._dealFiles(this.selectFiles.triggerSelectFiles(this.fileOptions, this.uploadOptions));
}
/**
* @param {?} files
* @return {?}
*/
onFileDrop(files) {
this.isDropOVer = false;
this._dealFiles(this.selectFiles.triggerDropFiles(this.fileOptions, this.uploadOptions, files));
this.fileDrop.emit(files);
}
/**
* @param {?} event
* @return {?}
*/
onFileOver(event) {
this.isDropOVer = event;
this.fileOver.emit(event);
}
/**
* @return {?}
*/
upload() {
this.canUpload().then((/**
* @param {?} canUpload
* @return {?}
*/
(canUpload) => {
if (!canUpload) {
this.multipleUploadViewComponent.removeFiles();
return;
}
this.multipleUploadViewComponent.upload()
.pipe(last())
.subscribe((/**
* @param {?} results
* @return {?}
*/
(results) => {
this.successEvent.emit(results);
results.forEach((/**
* @param {?} result
* @return {?}
*/
(result) => {
this.multipleUploadViewComponent.deleteFile(result.file);
this.multipleUploadViewComponent.uploadedFilesComponent.addFile(result.file);
}));
}), (/**
* @param {?} error
* @return {?}
*/
(error) => {
this.errorEvent.emit(error);
}));
}));
}
/**
* @return {?}
*/
canUpload() {
/** @type {?} */
let uploadResult = Promise.resolve(true);
if (this.beforeUpload) {
/** @type {?} */
const result = this.beforeUpload(this.multipleUploadViewComponent.getFiles());
if (typeof result !== 'undefined') {
if (result.then) {
uploadResult = result;
}
else if (result.subscribe) {
uploadResult = ((/** @type {?} */ (result))).toPromise();
}
else {
uploadResult = Promise.resolve(result);
}
}
}
return uploadResult;
}
/**
* @param {?} filePath
* @return {?}
*/
_onDeleteUploadedFile(filePath) {
this.deleteUploadedFileEvent.emit(filePath);
}
/**
* @param {?} errorMsg
* @return {?}
*/
alertMsg(errorMsg) {
/** @type {?} */
const results = this.modalService.open({
width: '300px',
backdropCloseable: false,
showAnimate: true,
component: ModalAlertComponent,
data: {
content: errorMsg,
cancelBtnText: this.confirmText ? this.confirmText : this.i18nCommonText.btnConfirm,
onClose: (/**
* @param {?} event
* @return {?}
*/
(event) => {
results.modalInstance.hide();
}),
},
});
}
/**
* @return {?}
*/
ngOnDestroy() {
if (this.i18nSubscription) {
this.i18nSubscription.unsubscribe();
}
}
}
MultipleUploadComponent.decorators = [
{ type: Component, args: [{
selector: 'd-multiple-upload',
template: "<div\r\n [style.display]=\"withoutBtn ? '' : '-webkit-inline-box'\"\r\n d-file-drop\r\n [enableDrop]=\"enableDrop\"\r\n (fileDrop)=\"onFileDrop($event)\"\r\n (fileOver)=\"onFileOver($event)\"\r\n [ngStyle]=\"{ border: isDropOVer ? '1px solid #15bf15' : '0' }\"\r\n>\r\n <div class=\"devui-input-group\" (click)=\"onClick($event)\">\r\n <input\r\n type=\"text\"\r\n style=\"cursor: pointer\"\r\n class=\"devui-form-control\"\r\n [placeholder]=\"placeholderText ? placeholderText : i18nText?.chooseFiles\"\r\n readonly\r\n />\r\n <span class=\"devui-input-group-addon\" style=\"cursor: pointer\">\r\n <svg cl