@duoduo-oba/ng-devui
Version:
DevUI components based on Angular
1,174 lines (1,141 loc) • 88.1 kB
JavaScript
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('rxjs/operators'), require('rxjs'), require('ng-devui/i18n'), require('@angular/common'), require('lodash-es/endsWith'), require('ng-devui/modal'), require('ng-devui/button')) :
typeof define === 'function' && define.amd ? define('ng-devui/upload', ['exports', '@angular/core', 'rxjs/operators', 'rxjs', 'ng-devui/i18n', '@angular/common', 'lodash-es/endsWith', 'ng-devui/modal', 'ng-devui/button'], factory) :
(global = global || self, factory((global['ng-devui'] = global['ng-devui'] || {}, global['ng-devui'].upload = {}), global.ng.core, global.rxjs.operators, global.rxjs, global['ng-devui'].i18n, global.ng.common, global.endsWith, global['ng-devui'].modal, global['ng-devui'].button));
}(this, (function (exports, core, operators, rxjs, i18n, common, endsWith, modal, button) { 'use strict';
endsWith = endsWith && endsWith.hasOwnProperty('default') ? endsWith['default'] : endsWith;
/*! *****************************************************************************
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at http://www.apache.org/licenses/LICENSE-2.0
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.
See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
***************************************************************************** */
/* global Reflect, Promise */
var extendStatics = function(d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
function __extends(d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
}
var __assign = function() {
__assign = Object.assign || function __assign(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
function __rest(s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
}
function __decorate(decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
}
function __param(paramIndex, decorator) {
return function (target, key) { decorator(target, key, paramIndex); }
}
function __metadata(metadataKey, metadataValue) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
}
function __awaiter(thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
}
function __generator(thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
}
function __exportStar(m, exports) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
function __values(o) {
var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0;
if (m) return m.call(o);
return {
next: function () {
if (o && i >= o.length) o = void 0;
return { value: o && o[i++], done: !o };
}
};
}
function __read(o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
}
function __spread() {
for (var ar = [], i = 0; i < arguments.length; i++)
ar = ar.concat(__read(arguments[i]));
return ar;
}
function __spreadArrays() {
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
for (var r = Array(s), k = 0, i = 0; i < il; i++)
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
r[k] = a[j];
return r;
};
function __await(v) {
return this instanceof __await ? (this.v = v, this) : new __await(v);
}
function __asyncGenerator(thisArg, _arguments, generator) {
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
var g = generator.apply(thisArg, _arguments || []), i, q = [];
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
function fulfill(value) { resume("next", value); }
function reject(value) { resume("throw", value); }
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
}
function __asyncDelegator(o) {
var i, p;
return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
}
function __asyncValues(o) {
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
var m = o[Symbol.asyncIterator], i;
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
}
function __makeTemplateObject(cooked, raw) {
if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
return cooked;
};
function __importStar(mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result.default = mod;
return result;
}
function __importDefault(mod) {
return (mod && mod.__esModule) ? mod : { default: mod };
}
/**
* @fileoverview added by tsickle
* Generated from: file-uploader.types.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var IUploadOptions = /** @class */ (function () {
function IUploadOptions() {
}
return 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;
}
var IFileOptions = /** @class */ (function () {
function IFileOptions() {
}
return IFileOptions;
}());
if (false) {
/** @type {?} */
IFileOptions.prototype.accept;
/** @type {?} */
IFileOptions.prototype.multiple;
}
/** @enum {number} */
var 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
*/
var FileUploader = /** @class */ (function () {
function FileUploader(file, uploadOptions) {
this.file = file;
this.uploadOptions = uploadOptions;
this.percentage = 0;
this.file = file;
this.uploadOptions = uploadOptions;
this.status = UploadStatus.preLoad;
}
/**
* @return {?}
*/
FileUploader.prototype.send = /**
* @return {?}
*/
function () {
var _this = this;
return new Promise((/**
* @param {?} resolve
* @param {?} reject
* @return {?}
*/
function (resolve, reject) {
var _a = _this.uploadOptions, uri = _a.uri, method = _a.method, headers = _a.headers, authToken = _a.authToken, authTokenHeader = _a.authTokenHeader, additionalParameter = _a.additionalParameter, fileFieldName = _a.fileFieldName, withCredentials = _a.withCredentials;
/** @type {?} */
var authTokenHeader_ = authTokenHeader || 'Authorization';
/** @type {?} */
var 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 {?}
*/
function (key) {
_this.xhr.setRequestHeader(key, headers[key]);
}));
}
_this.xhr.upload.onprogress = (/**
* @param {?} e
* @return {?}
*/
function (e) {
_this.percentage = Math.round(e.loaded * 100 / e.total);
});
/** @type {?} */
var formData = new FormData();
formData.append(fileFieldName_, _this.file);
if (additionalParameter) {
Object.keys(additionalParameter).forEach((/**
* @param {?} key
* @return {?}
*/
function (key) {
formData.append(key, additionalParameter[key]);
}));
}
_this.xhr.send(formData);
_this.status = UploadStatus.uploading;
_this.xhr.onabort = (/**
* @return {?}
*/
function () {
_this.status = UploadStatus.preLoad;
_this.xhr = null;
});
_this.xhr.onerror = (/**
* @return {?}
*/
function () {
_this.response = _this.xhr.response;
_this.status = UploadStatus.failed;
reject(new Error('Upload failed in some reason.'));
});
_this.xhr.onload = (/**
* @return {?}
*/
function () {
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 {?}
*/
FileUploader.prototype.cancel = /**
* @return {?}
*/
function () {
if (this.xhr) {
this.xhr.abort();
}
};
return FileUploader;
}());
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
*/
var UploadComponent = /** @class */ (function () {
function UploadComponent() {
this.fileUploaders = [];
this.filesWithSameName = [];
}
/**
* @param {?} file
* @param {?} options
* @return {?}
*/
UploadComponent.prototype.addFile = /**
* @param {?} file
* @param {?} options
* @return {?}
*/
function (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 {?}
*/
UploadComponent.prototype.checkFileSame = /**
* @param {?} fileName
* @return {?}
*/
function (fileName) {
/** @type {?} */
var checkRel = true;
for (var 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 {?}
*/
UploadComponent.prototype.getFiles = /**
* @return {?}
*/
function () {
return this.fileUploaders.map((/**
* @param {?} fileUploader
* @return {?}
*/
function (fileUploader) {
return fileUploader.file;
}));
};
/**
* @return {?}
*/
UploadComponent.prototype.upload = /**
* @return {?}
*/
function () {
/** @type {?} */
var uploads = this.fileUploaders
.filter((/**
* @param {?} fileUploader
* @return {?}
*/
function (fileUploader) { return fileUploader.status !== UploadStatus.uploaded; }))
.map((/**
* @param {?} fileUploader
* @return {?}
*/
function (fileUploader) {
return rxjs.from(fileUploader.send());
}));
if (uploads.length > 0) {
return rxjs.merge.apply(void 0, __spread(uploads)).pipe(operators.toArray());
}
return rxjs.from(Promise.reject('no files'));
};
/**
* @param {?} file
* @return {?}
*/
UploadComponent.prototype.deleteFile = /**
* @param {?} file
* @return {?}
*/
function (file) {
this.fileUploaders = this.fileUploaders.filter((/**
* @param {?} fileUploader
* @return {?}
*/
function (fileUploader) {
return file !== fileUploader.file;
}));
};
/**
* @return {?}
*/
UploadComponent.prototype.removeFiles = /**
* @return {?}
*/
function () {
this.fileUploaders = [];
this.filesWithSameName = [];
};
/**
* @return {?}
*/
UploadComponent.prototype.getSameNameFiles = /**
* @return {?}
*/
function () {
return this.filesWithSameName.join();
};
/**
* @return {?}
*/
UploadComponent.prototype.resetSameNameFiles = /**
* @return {?}
*/
function () {
this.filesWithSameName = [];
};
return UploadComponent;
}());
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
*/
var UploadedFilesComponent = /** @class */ (function () {
function UploadedFilesComponent(i18n) {
var _this = this;
this.i18n = i18n;
this.uploadedFiles = [];
this.deleteUploadedFileEvent = new core.EventEmitter();
// 解决templateContext 传递method.bind(this)引发模板中内嵌组件initialize问题
this.deleteFileProxy = (/**
* @param {?} filePath
* @return {?}
*/
function (filePath) {
_this.deleteFile(filePath);
});
this.i18nText = this.i18n.getI18nText().upload;
this.i18nSubscription = this.i18n.langChange().subscribe((/**
* @param {?} data
* @return {?}
*/
function (data) {
_this.i18nText = data.upload;
}));
}
/**
* @return {?}
*/
UploadedFilesComponent.prototype.cleanUploadedFiles = /**
* @return {?}
*/
function () {
this.uploadedFiles = [];
};
/**
* @param {?} file
* @return {?}
*/
UploadedFilesComponent.prototype.addAndOverwriteFile = /**
* @param {?} file
* @return {?}
*/
function (file) {
this.cleanUploadedFiles();
this.uploadedFiles.push(file);
};
/**
* @param {?} file
* @return {?}
*/
UploadedFilesComponent.prototype.addFile = /**
* @param {?} file
* @return {?}
*/
function (file) {
this.uploadedFiles.push(file);
};
/**
* @param {?} filePath
* @return {?}
*/
UploadedFilesComponent.prototype.deleteFile = /**
* @param {?} filePath
* @return {?}
*/
function (filePath) {
var _this = this;
this.uploadedFiles = this.uploadedFiles.filter((/**
* @param {?} file
* @return {?}
*/
function (file) {
return filePath !== ((/** @type {?} */ (file)))[_this.filePath];
}));
this.deleteUploadedFileEvent.emit(filePath);
};
/**
* @return {?}
*/
UploadedFilesComponent.prototype.ngOnDestroy = /**
* @return {?}
*/
function () {
if (this.i18nSubscription) {
this.i18nSubscription.unsubscribe();
}
};
UploadedFilesComponent.decorators = [
{ type: core.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 = function () { return [
{ type: i18n.I18nService }
]; };
UploadedFilesComponent.propDecorators = {
uploadedFiles: [{ type: core.Input }],
uploadedFilesRef: [{ type: core.Input }],
filePath: [{ type: core.Input }],
deleteUploadedFileEvent: [{ type: core.Output }]
};
return UploadedFilesComponent;
}());
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
*/
var MultipleUploadViewComponent = /** @class */ (function (_super) {
__extends(MultipleUploadViewComponent, _super);
function MultipleUploadViewComponent(i18n) {
var _this = _super.call(this) || this;
_this.i18n = i18n;
_this.uploadedFiles = [];
_this.deleteUploadedFileEvent = new core.EventEmitter();
_this.UploadStatus = UploadStatus;
_this.fileUploaders = [];
// 解决templateContext 传递method.bind(this)引发模板中内嵌组件initialize问题
_this.deleteFileProxy = (/**
* @param {?} file
* @return {?}
*/
function (file) {
_this.deleteFile(file);
});
_this.i18nText = _this.i18n.getI18nText().upload;
_this.i18nSubscription = _this.i18n.langChange().subscribe((/**
* @param {?} data
* @return {?}
*/
function (data) {
_this.i18nText = data.upload;
}));
return _this;
}
/**
* @param {?} file
* @return {?}
*/
MultipleUploadViewComponent.prototype.addFile = /**
* @param {?} file
* @return {?}
*/
function (file) {
_super.prototype.addFile.call(this, file, this.uploadOptions);
};
/**
* @param {?} file
* @return {?}
*/
MultipleUploadViewComponent.prototype.deleteFile = /**
* @param {?} file
* @return {?}
*/
function (file) {
_super.prototype.deleteFile.call(this, file);
this.deleteUploadedFileEvent.emit(file);
};
/**
* @return {?}
*/
MultipleUploadViewComponent.prototype.removeFiles = /**
* @return {?}
*/
function () {
_super.prototype.removeFiles.call(this);
};
/**
* @param {?} filePath
* @return {?}
*/
MultipleUploadViewComponent.prototype._onDeleteUploadedFile = /**
* @param {?} filePath
* @return {?}
*/
function (filePath) {
this.deleteUploadedFileEvent.emit(filePath);
};
/**
* @return {?}
*/
MultipleUploadViewComponent.prototype.ngOnDestroy = /**
* @return {?}
*/
function () {
if (this.i18nSubscription) {
this.i18nSubscription.unsubscribe();
}
};
MultipleUploadViewComponent.decorators = [
{ type: core.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 = function () { return [
{ type: i18n.I18nService }
]; };
MultipleUploadViewComponent.propDecorators = {
uploadedFilesComponent: [{ type: core.ViewChild, args: ['dUploadedFiles', { static: true },] }],
uploadOptions: [{ type: core.Input }],
preloadFilesRef: [{ type: core.Input }],
uploadedFiles: [{ type: core.Input }],
uploadedFilesRef: [{ type: core.Input }],
filePath: [{ type: core.Input }],
deleteUploadedFileEvent: [{ type: core.Output }]
};
return MultipleUploadViewComponent;
}(UploadComponent));
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
*/
var SingleUploadViewComponent = /** @class */ (function (_super) {
__extends(SingleUploadViewComponent, _super);
function SingleUploadViewComponent() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.uploadedFiles = [];
_this.deleteUploadedFileEvent = new core.EventEmitter();
_this.UploadStatus = UploadStatus;
_this.fileUploaders = [];
// 解决templateContext 传递method.bind(this)引发模板中内嵌组件initialize问题
_this.deleteFileProxy = (/**
* @param {?} file
* @return {?}
*/
function (file) {
_this.deleteFile(file);
});
return _this;
}
/**
* @param {?} file
* @return {?}
*/
SingleUploadViewComponent.prototype.addFile = /**
* @param {?} file
* @return {?}
*/
function (file) {
this.fileUploaders = [];
_super.prototype.addFile.call(this, file, this.uploadOptions);
};
/**
* @param {?} file
* @return {?}
*/
SingleUploadViewComponent.prototype.deleteFile = /**
* @param {?} file
* @return {?}
*/
function (file) {
_super.prototype.deleteFile.call(this, file);
this.deleteUploadedFileEvent.emit(file);
};
/**
* @param {?} filePath
* @return {?}
*/
SingleUploadViewComponent.prototype._onDeleteUploadedFile = /**
* @param {?} filePath
* @return {?}
*/
function (filePath) {
this.deleteUploadedFileEvent.emit(filePath);
};
SingleUploadViewComponent.decorators = [
{ type: core.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: core.Input }],
preloadFilesRef: [{ type: core.Input }],
uploadedFiles: [{ type: core.Input }],
uploadedFilesRef: [{ type: core.Input }],
filePath: [{ type: core.Input }],
deleteUploadedFileEvent: [{ type: core.Output }],
uploadedFilesComponent: [{ type: core.ViewChild, args: ['dUploadedFiles', { static: true },] }]
};
return SingleUploadViewComponent;
}(UploadComponent));
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
*/
var SelectFiles = /** @class */ (function () {
function SelectFiles(i18n) {
var _this = this;
this.i18n = i18n;
this.selectFiles = (/**
* @param {?} __0
* @return {?}
*/
function (_a) {
var multiple = _a.multiple, accept = _a.accept;
return new Promise((/**
* @param {?} resolve
* @return {?}
*/
function (resolve) {
/** @type {?} */
var tempNode = document.getElementById('d-upload-temp');
if (tempNode) {
document.body.removeChild(tempNode);
}
/** @type {?} */
var 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 {?}
*/
function (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 {?}
*/
function (accept, file) {
if (accept) {
/** @type {?} */
var acceptArr = accept.split(',');
return acceptArr.reduce((/**
* @param {?} result
* @param {?} item
* @return {?}
*/
function (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 {?}
*/
function (fileSize, maximumSize) {
if (maximumSize) {
return fileSize > 1000000 * maximumSize;
}
return false;
});
this.triggerSelectFiles = (/**
* @param {?} fileOptions
* @param {?} uploadOptions
* @return {?}
*/
function (fileOptions, uploadOptions) {
var multiple = fileOptions.multiple, accept = fileOptions.accept;
return _this._validateFiles(rxjs.from(_this.selectFiles({ multiple: multiple, accept: accept })), accept, uploadOptions);
});
this.triggerDropFiles = (/**
* @param {?} fileOptions
* @param {?} uploadOptions
* @param {?} files
* @return {?}
*/
function (fileOptions, uploadOptions, files) {
var multiple = fileOptions.multiple, accept = fileOptions.accept;
return _this._validateFiles(new rxjs.Observable((/**
* @param {?} observer
* @return {?}
*/
function (observer) { return observer.next(files); })), accept, uploadOptions);
});
this.i18nText = this.i18n.getI18nText().upload;
this.i18nSubscription = this.i18n.langChange().subscribe((/**
* @param {?} data
* @return {?}
*/
function (data) {
_this.i18nText = data.upload;
}));
}
/**
* @param {?} observable
* @param {?} accept
* @param {?} uploadOptions
* @return {?}
*/
SelectFiles.prototype._validateFiles = /**
* @param {?} observable
* @param {?} accept
* @param {?} uploadOptions
* @return {?}
*/
function (observable, accept, uploadOptions) {
var _this = this;
return observable.pipe(operators.mergeMap((/**
* @param {?} file
* @return {?}
*/
function (file) { return (/** @type {?} */ (file)); })), operators.map((/**
* @param {?} file
* @return {?}
*/
function (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 {?}
*/
SelectFiles.prototype.simulateClickEvent = /**
* @param {?} input
* @return {?}
*/
function (input) {
/** @type {?} */
var 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: core.Injectable }
];
/** @nocollapse */
SelectFiles.ctorParameters = function () { return [
{ type: i18n.I18nService }
]; };
return SelectFiles;
}());
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
*/
var SingleUploadComponent = /** @class */ (function () {
function SingleUploadComponent(modalService, i18n, selectFiles) {
var _this = this;
this.modalService = modalService;
this.i18n = i18n;
this.selectFiles = selectFiles;
this.autoUpload = false;
this.withoutBtn = false;
this.uploadedFiles = [];
this.enableDrop = false;
this.successEvent = new core.EventEmitter();
this.errorEvent = new core.EventEmitter();
this.deleteUploadedFileEvent = new core.EventEmitter();
this.fileDrop = new core.EventEmitter();
this.fileOver = new core.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 {?}
*/
function (data) {
_this.i18nText = data.upload;
_this.i18nCommonText = data.common;
}));
}
/**
* @param {?} observale
* @return {?}
*/
SingleUploadComponent.prototype._dealFiles = /**
* @param {?} observale
* @return {?}
*/
function (observale) {
var _this = this;
observale.pipe(operators.map((/**
* @param {?} file
* @return {?}
*/
function (file) {
_this.singleUploadViewComponent.addFile((/** @type {?} */ (file)));
return file;
}))).subscribe((/**
* @return {?}
*/
function () {
_this.singleUploadViewComponent.uploadedFilesComponent.cleanUploadedFiles();
if (_this.autoUpload) {
_this.upload();
}
}), (/**
* @param {?} error
* @return {?}
*/
fun