This commit is contained in:
Dmitriy Schekhovtsov
2016-09-21 23:12:52 +03:00
parent 8896960a8f
commit 0934079d38
36 changed files with 194 additions and 63505 deletions

View File

@@ -0,0 +1,44 @@
import { FileLikeObject } from './file-like-object.class';
import { FileUploader, ParsedResponseHeaders, FileUploaderOptions } from './file-uploader.class';
export declare class FileItem {
file: FileLikeObject;
_file: File;
alias: string;
url: string;
method: string;
headers: any;
withCredentials: boolean;
formData: any;
isReady: boolean;
isUploading: boolean;
isUploaded: boolean;
isSuccess: boolean;
isCancel: boolean;
isError: boolean;
progress: number;
index: number;
_xhr: XMLHttpRequest;
_form: any;
private uploader;
private some;
private options;
constructor(uploader: FileUploader, some: File, options: FileUploaderOptions);
upload(): void;
cancel(): void;
remove(): void;
onBeforeUpload(): void;
onBuildForm(form: any): any;
onProgress(progress: number): any;
onSuccess(response: string, status: number, headers: ParsedResponseHeaders): any;
onError(response: string, status: number, headers: ParsedResponseHeaders): any;
onCancel(response: string, status: number, headers: ParsedResponseHeaders): any;
onComplete(response: string, status: number, headers: ParsedResponseHeaders): any;
_onBeforeUpload(): void;
_onBuildForm(form: any): void;
_onProgress(progress: number): void;
_onSuccess(response: string, status: number, headers: ParsedResponseHeaders): void;
_onError(response: string, status: number, headers: ParsedResponseHeaders): void;
_onCancel(response: string, status: number, headers: ParsedResponseHeaders): void;
_onComplete(response: string, status: number, headers: ParsedResponseHeaders): void;
_prepareToUploading(): void;
}

View File

@@ -0,0 +1,2 @@
export declare class FileUploadModule {
}

View File

@@ -0,0 +1,89 @@
import { FileLikeObject } from './file-like-object.class';
import { FileItem } from './file-item.class';
export interface Headers {
name: string;
value: string;
}
export declare type ParsedResponseHeaders = {
[headerFieldName: string]: string;
};
export declare type FilterFunction = {
name: string;
fn: (item?: FileLikeObject, options?: FileUploaderOptions) => boolean;
};
export interface FileUploaderOptions {
allowedMimeType?: Array<string>;
allowedFileType?: Array<string>;
autoUpload?: boolean;
isHTML5?: boolean;
filters?: Array<FilterFunction>;
headers?: Array<Headers>;
method?: string;
authToken?: string;
maxFileSize?: number;
queueLimit?: number;
removeAfterUpload?: boolean;
url?: string;
disableMultipart?: boolean;
itemAlias?: string;
}
export declare class FileUploader {
authToken: string;
isUploading: boolean;
queue: Array<FileItem>;
progress: number;
_nextIndex: number;
autoUpload: any;
options: FileUploaderOptions;
private _failFilterIndex;
constructor(options: FileUploaderOptions);
setOptions(options: FileUploaderOptions): void;
addToQueue(files: File[], options?: FileUploaderOptions, filters?: FilterFunction[] | string): void;
removeFromQueue(value: FileItem): void;
clearQueue(): void;
uploadItem(value: FileItem): void;
cancelItem(value: FileItem): void;
uploadAll(): void;
cancelAll(): void;
isFile(value: any): boolean;
isFileLikeObject(value: any): boolean;
getIndexOfItem(value: any): number;
getNotUploadedItems(): Array<any>;
getReadyItems(): Array<any>;
destroy(): void;
onAfterAddingAll(fileItems: any): any;
onBuildItemForm(fileItem: FileItem, form: any): any;
onAfterAddingFile(fileItem: FileItem): any;
onWhenAddingFileFailed(item: FileLikeObject, filter: any, options: any): any;
onBeforeUploadItem(fileItem: FileItem): any;
onProgressItem(fileItem: FileItem, progress: any): any;
onProgressAll(progress: any): any;
onSuccessItem(item: FileItem, response: string, status: number, headers: ParsedResponseHeaders): any;
onErrorItem(item: FileItem, response: string, status: number, headers: ParsedResponseHeaders): any;
onCancelItem(item: FileItem, response: string, status: number, headers: ParsedResponseHeaders): any;
onCompleteItem(item: FileItem, response: string, status: number, headers: ParsedResponseHeaders): any;
onCompleteAll(): any;
_mimeTypeFilter(item: FileLikeObject): boolean;
_fileSizeFilter(item: FileLikeObject): boolean;
_fileTypeFilter(item: FileLikeObject): boolean;
_onErrorItem(item: FileItem, response: string, status: number, headers: ParsedResponseHeaders): void;
_onCompleteItem(item: FileItem, response: string, status: number, headers: ParsedResponseHeaders): void;
protected _headersGetter(parsedHeaders: ParsedResponseHeaders): any;
protected _xhrTransport(item: FileItem): any;
private _getTotalProgress(value?);
private _getFilters(filters);
private _render();
private _queueLimitFilter();
private _isValidFile(file, filters, options);
private _isSuccessCode(status);
private _transformResponse(response, headers);
private _parseHeaders(headers);
private _onWhenAddingFileFailed(item, filter, options);
private _onAfterAddingFile(item);
private _onAfterAddingAll(items);
private _onBeforeUploadItem(item);
private _onBuildItemForm(item, form);
private _onProgressItem(item, progress);
private _onSuccessItem(item, response, status, headers);
private _onCancelItem(item, response, status, headers);
}

View File

@@ -1,4 +1,7 @@
export declare class FileUploadSectionComponent {
name: string;
currentHeading: string;
doc: string;
tabs: any;
select(e: any): void;
}

View File

@@ -0,0 +1,2 @@
export declare class NgFileUploadDemo {
}

View File

@@ -0,0 +1,3 @@
import 'core-js/es6';
import 'core-js/es7/reflect';
import 'ts-helpers';

View File

@@ -0,0 +1,7 @@
import '@angular/common';
import '@angular/core';
import '@angular/forms';
import '@angular/platform-browser';
import '@angular/platform-browser-dynamic';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/mergeMap';

View File

@@ -1,8 +1,4 @@
export * from './components/file-upload/file-select.directive';
export * from './components/file-upload/file-drop.directive';
export * from './components/file-upload/file-uploader.class';
export declare const FILE_UPLOAD_DIRECTIVES: [any];
declare var _default: {
directives: [any][];
};
export default _default;
export { FileUploadModule } from './components/file-upload/file-upload.module';

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

906
angular2-bootstrap.js vendored
View File

@@ -1,906 +0,0 @@
webpackJsonp([2],{
/***/ 0:
/***/ function(module, exports, __webpack_require__) {
module.exports = __webpack_require__(140);
/***/ },
/***/ 28:
/***/ function(module, exports, __webpack_require__) {
"use strict";
var file_like_object_class_1 = __webpack_require__(45);
var file_item_class_1 = __webpack_require__(138);
var file_type_class_1 = __webpack_require__(139);
function isFile(value) {
return (File && value instanceof File);
}
var FileUploader = (function () {
function FileUploader(options) {
this.isUploading = false;
this.queue = [];
this.progress = 0;
this._nextIndex = 0;
this.options = {
autoUpload: false,
isHTML5: true,
filters: [],
removeAfterUpload: false
};
this.setOptions(options);
}
FileUploader.prototype.setOptions = function (options) {
this.options = Object.assign(this.options, options);
this.authToken = options.authToken;
this.autoUpload = options.autoUpload;
this.options.filters.unshift({ name: 'queueLimit', fn: this._queueLimitFilter });
if (this.options.maxFileSize) {
this.options.filters.unshift({ name: 'fileSize', fn: this._fileSizeFilter });
}
if (this.options.allowedFileType) {
this.options.filters.unshift({ name: 'fileType', fn: this._fileTypeFilter });
}
if (this.options.allowedMimeType) {
this.options.filters.unshift({ name: 'mimeType', fn: this._mimeTypeFilter });
}
};
FileUploader.prototype.addToQueue = function (files, options, filters) {
var _this = this;
var list = [];
for (var _i = 0, files_1 = files; _i < files_1.length; _i++) {
var file = files_1[_i];
list.push(file);
}
var arrayOfFilters = this._getFilters(filters);
var count = this.queue.length;
var addedFileItems = [];
list.map(function (some) {
if (!options) {
options = _this.options;
}
var temp = new file_like_object_class_1.FileLikeObject(some);
if (_this._isValidFile(temp, arrayOfFilters, options)) {
var fileItem = new file_item_class_1.FileItem(_this, some, options);
addedFileItems.push(fileItem);
_this.queue.push(fileItem);
_this._onAfterAddingFile(fileItem);
}
else {
var filter = arrayOfFilters[_this._failFilterIndex];
_this._onWhenAddingFileFailed(temp, filter, options);
}
});
if (this.queue.length !== count) {
this._onAfterAddingAll(addedFileItems);
this.progress = this._getTotalProgress();
}
this._render();
if (this.options.autoUpload) {
this.uploadAll();
}
};
FileUploader.prototype.removeFromQueue = function (value) {
var index = this.getIndexOfItem(value);
var item = this.queue[index];
if (item.isUploading) {
item.cancel();
}
this.queue.splice(index, 1);
this.progress = this._getTotalProgress();
};
FileUploader.prototype.clearQueue = function () {
while (this.queue.length) {
this.queue[0].remove();
}
this.progress = 0;
};
FileUploader.prototype.uploadItem = function (value) {
var index = this.getIndexOfItem(value);
var item = this.queue[index];
var transport = this.options.isHTML5 ? '_xhrTransport' : '_iframeTransport';
item._prepareToUploading();
if (this.isUploading) {
return;
}
this.isUploading = true;
this[transport](item);
};
FileUploader.prototype.cancelItem = function (value) {
var index = this.getIndexOfItem(value);
var item = this.queue[index];
var prop = this.options.isHTML5 ? '_xhr' : '_form';
if (item && item.isUploading) {
item[prop].abort();
}
};
FileUploader.prototype.uploadAll = function () {
var items = this.getNotUploadedItems().filter(function (item) { return !item.isUploading; });
if (!items.length) {
return;
}
items.map(function (item) { return item._prepareToUploading(); });
items[0].upload();
};
FileUploader.prototype.cancelAll = function () {
var items = this.getNotUploadedItems();
items.map(function (item) { return item.cancel(); });
};
FileUploader.prototype.isFile = function (value) {
return isFile(value);
};
FileUploader.prototype.isFileLikeObject = function (value) {
return value instanceof file_like_object_class_1.FileLikeObject;
};
FileUploader.prototype.getIndexOfItem = function (value) {
return typeof value === 'number' ? value : this.queue.indexOf(value);
};
FileUploader.prototype.getNotUploadedItems = function () {
return this.queue.filter(function (item) { return !item.isUploaded; });
};
FileUploader.prototype.getReadyItems = function () {
return this.queue
.filter(function (item) { return (item.isReady && !item.isUploading); })
.sort(function (item1, item2) { return item1.index - item2.index; });
};
FileUploader.prototype.destroy = function () {
return void 0;
};
FileUploader.prototype.onAfterAddingAll = function (fileItems) {
return { fileItems: fileItems };
};
FileUploader.prototype.onBuildItemForm = function (fileItem, form) {
return { fileItem: fileItem, form: form };
};
FileUploader.prototype.onAfterAddingFile = function (fileItem) {
return { fileItem: fileItem };
};
FileUploader.prototype.onWhenAddingFileFailed = function (item, filter, options) {
return { item: item, filter: filter, options: options };
};
FileUploader.prototype.onBeforeUploadItem = function (fileItem) {
return { fileItem: fileItem };
};
FileUploader.prototype.onProgressItem = function (fileItem, progress) {
return { fileItem: fileItem, progress: progress };
};
FileUploader.prototype.onProgressAll = function (progress) {
return { progress: progress };
};
FileUploader.prototype.onSuccessItem = function (item, response, status, headers) {
return { item: item, response: response, status: status, headers: headers };
};
FileUploader.prototype.onErrorItem = function (item, response, status, headers) {
return { item: item, response: response, status: status, headers: headers };
};
FileUploader.prototype.onCancelItem = function (item, response, status, headers) {
return { item: item, response: response, status: status, headers: headers };
};
FileUploader.prototype.onCompleteItem = function (item, response, status, headers) {
return { item: item, response: response, status: status, headers: headers };
};
FileUploader.prototype.onCompleteAll = function () {
return void 0;
};
FileUploader.prototype._mimeTypeFilter = function (item) {
return !(this.options.allowedMimeType && this.options.allowedMimeType.indexOf(item.type) === -1);
};
FileUploader.prototype._fileSizeFilter = function (item) {
return !(this.options.maxFileSize && item.size > this.options.maxFileSize);
};
FileUploader.prototype._fileTypeFilter = function (item) {
return !(this.options.allowedFileType &&
this.options.allowedFileType.indexOf(file_type_class_1.FileType.getMimeClass(item)) === -1);
};
FileUploader.prototype._onErrorItem = function (item, response, status, headers) {
item._onError(response, status, headers);
this.onErrorItem(item, response, status, headers);
};
FileUploader.prototype._onCompleteItem = function (item, response, status, headers) {
item._onComplete(response, status, headers);
this.onCompleteItem(item, response, status, headers);
var nextItem = this.getReadyItems()[0];
this.isUploading = false;
if (nextItem) {
nextItem.upload();
return;
}
this.onCompleteAll();
this.progress = this._getTotalProgress();
this._render();
};
FileUploader.prototype._headersGetter = function (parsedHeaders) {
return function (name) {
if (name) {
return parsedHeaders[name.toLowerCase()] || void 0;
}
return parsedHeaders;
};
};
FileUploader.prototype._xhrTransport = function (item) {
var _this = this;
var xhr = item._xhr = new XMLHttpRequest();
var form = new FormData();
this._onBeforeUploadItem(item);
if (typeof item._file.size !== 'number') {
throw new TypeError('The file specified is no longer valid');
}
this._onBuildItemForm(item, form);
form.append(item.alias, item._file, item.file.name);
xhr.upload.onprogress = function (event) {
var progress = Math.round(event.lengthComputable ? event.loaded * 100 / event.total : 0);
_this._onProgressItem(item, progress);
};
xhr.onload = function () {
var headers = _this._parseHeaders(xhr.getAllResponseHeaders());
var response = _this._transformResponse(xhr.response, headers);
var gist = _this._isSuccessCode(xhr.status) ? 'Success' : 'Error';
var method = '_on' + gist + 'Item';
_this[method](item, response, xhr.status, headers);
_this._onCompleteItem(item, response, xhr.status, headers);
};
xhr.onerror = function () {
var headers = _this._parseHeaders(xhr.getAllResponseHeaders());
var response = _this._transformResponse(xhr.response, headers);
_this._onErrorItem(item, response, xhr.status, headers);
_this._onCompleteItem(item, response, xhr.status, headers);
};
xhr.onabort = function () {
var headers = _this._parseHeaders(xhr.getAllResponseHeaders());
var response = _this._transformResponse(xhr.response, headers);
_this._onCancelItem(item, response, xhr.status, headers);
_this._onCompleteItem(item, response, xhr.status, headers);
};
xhr.open(item.method, item.url, true);
xhr.withCredentials = item.withCredentials;
if (this.options.headers) {
for (var _i = 0, _a = this.options.headers; _i < _a.length; _i++) {
var header = _a[_i];
xhr.setRequestHeader(header.name, header.value);
}
}
if (this.authToken) {
xhr.setRequestHeader('Authorization', this.authToken);
}
xhr.send(form);
this._render();
};
FileUploader.prototype._getTotalProgress = function (value) {
if (value === void 0) { value = 0; }
if (this.options.removeAfterUpload) {
return value;
}
var notUploaded = this.getNotUploadedItems().length;
var uploaded = notUploaded ? this.queue.length - notUploaded : this.queue.length;
var ratio = 100 / this.queue.length;
var current = value * ratio / 100;
return Math.round(uploaded * ratio + current);
};
FileUploader.prototype._getFilters = function (filters) {
if (!filters) {
return this.options.filters;
}
if (Array.isArray(filters)) {
return filters;
}
if (typeof filters === 'string') {
var names_1 = filters.match(/[^\s,]+/g);
return this.options.filters
.filter(function (filter) { return names_1.indexOf(filter.name) !== -1; });
}
return this.options.filters;
};
FileUploader.prototype._render = function () {
return void 0;
};
FileUploader.prototype._queueLimitFilter = function () {
return this.options.queueLimit === undefined || this.queue.length < this.options.queueLimit;
};
FileUploader.prototype._isValidFile = function (file, filters, options) {
var _this = this;
this._failFilterIndex = -1;
return !filters.length ? true : filters.every(function (filter) {
_this._failFilterIndex++;
return filter.fn.call(_this, file, options);
});
};
FileUploader.prototype._isSuccessCode = function (status) {
return (status >= 200 && status < 300) || status === 304;
};
FileUploader.prototype._transformResponse = function (response, headers) {
return response;
};
FileUploader.prototype._parseHeaders = function (headers) {
var parsed = {};
var key;
var val;
var i;
if (!headers) {
return parsed;
}
headers.split('\n').map(function (line) {
i = line.indexOf(':');
key = line.slice(0, i).trim().toLowerCase();
val = line.slice(i + 1).trim();
if (key) {
parsed[key] = parsed[key] ? parsed[key] + ', ' + val : val;
}
});
return parsed;
};
FileUploader.prototype._onWhenAddingFileFailed = function (item, filter, options) {
this.onWhenAddingFileFailed(item, filter, options);
};
FileUploader.prototype._onAfterAddingFile = function (item) {
this.onAfterAddingFile(item);
};
FileUploader.prototype._onAfterAddingAll = function (items) {
this.onAfterAddingAll(items);
};
FileUploader.prototype._onBeforeUploadItem = function (item) {
item._onBeforeUpload();
this.onBeforeUploadItem(item);
};
FileUploader.prototype._onBuildItemForm = function (item, form) {
item._onBuildForm(form);
this.onBuildItemForm(item, form);
};
FileUploader.prototype._onProgressItem = function (item, progress) {
var total = this._getTotalProgress(progress);
this.progress = total;
item._onProgress(progress);
this.onProgressItem(item, progress);
this.onProgressAll(total);
this._render();
};
FileUploader.prototype._onSuccessItem = function (item, response, status, headers) {
item._onSuccess(response, status, headers);
this.onSuccessItem(item, response, status, headers);
};
FileUploader.prototype._onCancelItem = function (item, response, status, headers) {
item._onCancel(response, status, headers);
this.onCancelItem(item, response, status, headers);
};
return FileUploader;
}());
exports.FileUploader = FileUploader;
/***/ },
/***/ 44:
/***/ function(module, exports, __webpack_require__) {
"use strict";
var __decorate = (this && this.__decorate) || function (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;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var core_1 = __webpack_require__(1);
var file_uploader_class_1 = __webpack_require__(28);
var FileDropDirective = (function () {
function FileDropDirective(element) {
this.fileOver = new core_1.EventEmitter();
this.onFileDrop = new core_1.EventEmitter();
this.element = element;
}
FileDropDirective.prototype.getOptions = function () {
return this.uploader.options;
};
FileDropDirective.prototype.getFilters = function () {
return {};
};
FileDropDirective.prototype.onDrop = function (event) {
var transfer = this._getTransfer(event);
if (!transfer) {
return;
}
var options = this.getOptions();
var filters = this.getFilters();
this._preventAndStop(event);
this.uploader.addToQueue(transfer.files, options, filters);
this.fileOver.emit(false);
this.onFileDrop.emit(transfer.files);
};
FileDropDirective.prototype.onDragOver = function (event) {
var transfer = this._getTransfer(event);
if (!this._haveFiles(transfer.types)) {
return;
}
transfer.dropEffect = 'copy';
this._preventAndStop(event);
this.fileOver.emit(true);
};
FileDropDirective.prototype.onDragLeave = function (event) {
if (event.currentTarget === this.element[0]) {
return;
}
this._preventAndStop(event);
this.fileOver.emit(false);
};
FileDropDirective.prototype._getTransfer = function (event) {
return event.dataTransfer ? event.dataTransfer : event.originalEvent.dataTransfer;
};
FileDropDirective.prototype._preventAndStop = function (event) {
event.preventDefault();
event.stopPropagation();
};
FileDropDirective.prototype._haveFiles = function (types) {
if (!types) {
return false;
}
if (types.indexOf) {
return types.indexOf('Files') !== -1;
}
else if (types.contains) {
return types.contains('Files');
}
else {
return false;
}
};
__decorate([
core_1.Input(),
__metadata('design:type', file_uploader_class_1.FileUploader)
], FileDropDirective.prototype, "uploader", void 0);
__decorate([
core_1.Output(),
__metadata('design:type', core_1.EventEmitter)
], FileDropDirective.prototype, "fileOver", void 0);
__decorate([
core_1.Output(),
__metadata('design:type', core_1.EventEmitter)
], FileDropDirective.prototype, "onFileDrop", void 0);
__decorate([
core_1.HostListener('drop', ['$event']),
__metadata('design:type', Function),
__metadata('design:paramtypes', [Object]),
__metadata('design:returntype', void 0)
], FileDropDirective.prototype, "onDrop", null);
__decorate([
core_1.HostListener('dragover', ['$event']),
__metadata('design:type', Function),
__metadata('design:paramtypes', [Object]),
__metadata('design:returntype', void 0)
], FileDropDirective.prototype, "onDragOver", null);
__decorate([
core_1.HostListener('dragleave', ['$event']),
__metadata('design:type', Function),
__metadata('design:paramtypes', [Object]),
__metadata('design:returntype', Object)
], FileDropDirective.prototype, "onDragLeave", null);
FileDropDirective = __decorate([
core_1.Directive({ selector: '[ng2FileDrop]' }),
__metadata('design:paramtypes', [core_1.ElementRef])
], FileDropDirective);
return FileDropDirective;
}());
exports.FileDropDirective = FileDropDirective;
/***/ },
/***/ 45:
/***/ function(module, exports) {
"use strict";
function isElement(node) {
return !!(node && (node.nodeName || node.prop && node.attr && node.find));
}
var FileLikeObject = (function () {
function FileLikeObject(fileOrInput) {
var isInput = isElement(fileOrInput);
var fakePathOrObject = isInput ? fileOrInput.value : fileOrInput;
var postfix = typeof fakePathOrObject === 'string' ? 'FakePath' : 'Object';
var method = '_createFrom' + postfix;
this[method](fakePathOrObject);
}
FileLikeObject.prototype._createFromFakePath = function (path) {
this.lastModifiedDate = void 0;
this.size = void 0;
this.type = 'like/' + path.slice(path.lastIndexOf('.') + 1).toLowerCase();
this.name = path.slice(path.lastIndexOf('/') + path.lastIndexOf('\\') + 2);
};
FileLikeObject.prototype._createFromObject = function (object) {
this.size = object.size;
this.type = object.type;
this.name = object.name;
};
return FileLikeObject;
}());
exports.FileLikeObject = FileLikeObject;
/***/ },
/***/ 46:
/***/ function(module, exports, __webpack_require__) {
"use strict";
var __decorate = (this && this.__decorate) || function (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;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var core_1 = __webpack_require__(1);
var file_uploader_class_1 = __webpack_require__(28);
var FileSelectDirective = (function () {
function FileSelectDirective(element) {
this.element = element;
}
FileSelectDirective.prototype.getOptions = function () {
return this.uploader.options;
};
FileSelectDirective.prototype.getFilters = function () {
return void 0;
};
FileSelectDirective.prototype.isEmptyAfterSelection = function () {
return !!this.element.nativeElement.attributes.multiple;
};
FileSelectDirective.prototype.onChange = function () {
var files = this.element.nativeElement.files;
var options = this.getOptions();
var filters = this.getFilters();
this.uploader.addToQueue(files, options, filters);
if (this.isEmptyAfterSelection()) {
}
};
__decorate([
core_1.Input(),
__metadata('design:type', file_uploader_class_1.FileUploader)
], FileSelectDirective.prototype, "uploader", void 0);
__decorate([
core_1.HostListener('change'),
__metadata('design:type', Function),
__metadata('design:paramtypes', []),
__metadata('design:returntype', Object)
], FileSelectDirective.prototype, "onChange", null);
FileSelectDirective = __decorate([
core_1.Directive({ selector: '[ng2FileSelect]' }),
__metadata('design:paramtypes', [core_1.ElementRef])
], FileSelectDirective);
return FileSelectDirective;
}());
exports.FileSelectDirective = FileSelectDirective;
/***/ },
/***/ 138:
/***/ function(module, exports, __webpack_require__) {
"use strict";
var core_1 = __webpack_require__(1);
var file_like_object_class_1 = __webpack_require__(45);
var FileItem = (function () {
function FileItem(uploader, some, options) {
this.alias = 'file';
this.url = '/';
this.method = 'POST';
this.headers = [];
this.withCredentials = true;
this.formData = [];
this.isReady = false;
this.isUploading = false;
this.isUploaded = false;
this.isSuccess = false;
this.isCancel = false;
this.isError = false;
this.progress = 0;
this.index = void 0;
this.uploader = uploader;
this.some = some;
this.options = options;
this.file = new file_like_object_class_1.FileLikeObject(some);
this._file = some;
this.url = uploader.options.url;
this._zone = new core_1.NgZone({ enableLongStackTrace: false });
}
FileItem.prototype.upload = function () {
try {
this.uploader.uploadItem(this);
}
catch (e) {
this.uploader._onCompleteItem(this, '', 0, []);
this.uploader._onErrorItem(this, '', 0, []);
}
};
FileItem.prototype.cancel = function () {
this.uploader.cancelItem(this);
};
FileItem.prototype.remove = function () {
this.uploader.removeFromQueue(this);
};
FileItem.prototype.onBeforeUpload = function () {
return void 0;
};
FileItem.prototype.onBuildForm = function (form) {
return { form: form };
};
FileItem.prototype.onProgress = function (progress) {
return { progress: progress };
};
FileItem.prototype.onSuccess = function (response, status, headers) {
return { response: response, status: status, headers: headers };
};
FileItem.prototype.onError = function (response, status, headers) {
return { response: response, status: status, headers: headers };
};
FileItem.prototype.onCancel = function (response, status, headers) {
return { response: response, status: status, headers: headers };
};
FileItem.prototype.onComplete = function (response, status, headers) {
return { response: response, status: status, headers: headers };
};
FileItem.prototype._onBeforeUpload = function () {
this.isReady = true;
this.isUploading = true;
this.isUploaded = false;
this.isSuccess = false;
this.isCancel = false;
this.isError = false;
this.progress = 0;
this.onBeforeUpload();
};
FileItem.prototype._onBuildForm = function (form) {
this.onBuildForm(form);
};
FileItem.prototype._onProgress = function (progress) {
var _this = this;
this._zone.run(function () {
_this.progress = progress;
});
this.onProgress(progress);
};
FileItem.prototype._onSuccess = function (response, status, headers) {
this.isReady = false;
this.isUploading = false;
this.isUploaded = true;
this.isSuccess = true;
this.isCancel = false;
this.isError = false;
this.progress = 100;
this.index = void 0;
this.onSuccess(response, status, headers);
};
FileItem.prototype._onError = function (response, status, headers) {
this.isReady = false;
this.isUploading = false;
this.isUploaded = true;
this.isSuccess = false;
this.isCancel = false;
this.isError = true;
this.progress = 0;
this.index = void 0;
this.onError(response, status, headers);
};
FileItem.prototype._onCancel = function (response, status, headers) {
this.isReady = false;
this.isUploading = false;
this.isUploaded = false;
this.isSuccess = false;
this.isCancel = true;
this.isError = false;
this.progress = 0;
this.index = void 0;
this.onCancel(response, status, headers);
};
FileItem.prototype._onComplete = function (response, status, headers) {
this.onComplete(response, status, headers);
if (this.uploader.options.removeAfterUpload) {
this.remove();
}
};
FileItem.prototype._prepareToUploading = function () {
this.index = this.index || ++this.uploader._nextIndex;
this.isReady = true;
};
return FileItem;
}());
exports.FileItem = FileItem;
/***/ },
/***/ 139:
/***/ function(module, exports) {
"use strict";
var FileType = (function () {
function FileType() {
}
FileType.getMimeClass = function (file) {
var mimeClass = 'application';
if (this.mime_psd.indexOf(file.type) !== -1) {
mimeClass = 'image';
}
else if (file.type.match('image.*')) {
mimeClass = 'image';
}
else if (file.type.match('video.*')) {
mimeClass = 'video';
}
else if (file.type.match('audio.*')) {
mimeClass = 'audio';
}
else if (file.type === 'application/pdf') {
mimeClass = 'pdf';
}
else if (this.mime_compress.indexOf(file.type) !== -1) {
mimeClass = 'compress';
}
else if (this.mime_doc.indexOf(file.type) !== -1) {
mimeClass = 'doc';
}
else if (this.mime_xsl.indexOf(file.type) !== -1) {
mimeClass = 'xls';
}
else if (this.mime_ppt.indexOf(file.type) !== -1) {
mimeClass = 'ppt';
}
if (mimeClass === 'application') {
mimeClass = this.fileTypeDetection(file.name);
}
return mimeClass;
};
FileType.fileTypeDetection = function (inputFilename) {
var types = {
'jpg': 'image',
'jpeg': 'image',
'tif': 'image',
'psd': 'image',
'bmp': 'image',
'png': 'image',
'nef': 'image',
'tiff': 'image',
'cr2': 'image',
'dwg': 'image',
'cdr': 'image',
'ai': 'image',
'indd': 'image',
'pin': 'image',
'cdp': 'image',
'skp': 'image',
'stp': 'image',
'3dm': 'image',
'mp3': 'audio',
'wav': 'audio',
'wma': 'audio',
'mod': 'audio',
'm4a': 'audio',
'compress': 'compress',
'rar': 'compress',
'7z': 'compress',
'lz': 'compress',
'z01': 'compress',
'pdf': 'pdf',
'xls': 'xls',
'xlsx': 'xls',
'ods': 'xls',
'mp4': 'video',
'avi': 'video',
'wmv': 'video',
'mpg': 'video',
'mts': 'video',
'flv': 'video',
'3gp': 'video',
'vob': 'video',
'm4v': 'video',
'mpeg': 'video',
'm2ts': 'video',
'mov': 'video',
'doc': 'doc',
'docx': 'doc',
'eps': 'doc',
'txt': 'doc',
'odt': 'doc',
'rtf': 'doc',
'ppt': 'ppt',
'pptx': 'ppt',
'pps': 'ppt',
'ppsx': 'ppt',
'odp': 'ppt'
};
var chunks = inputFilename.split('.');
if (chunks.length < 2) {
return 'application';
}
var extension = chunks[chunks.length - 1].toLowerCase();
if (types[extension] === undefined) {
return 'application';
}
else {
return types[extension];
}
};
FileType.mime_doc = [
'application/msword',
'application/msword',
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'application/vnd.openxmlformats-officedocument.wordprocessingml.template',
'application/vnd.ms-word.document.macroEnabled.12',
'application/vnd.ms-word.template.macroEnabled.12'
];
FileType.mime_xsl = [
'application/vnd.ms-excel',
'application/vnd.ms-excel',
'application/vnd.ms-excel',
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
'application/vnd.openxmlformats-officedocument.spreadsheetml.template',
'application/vnd.ms-excel.sheet.macroEnabled.12',
'application/vnd.ms-excel.template.macroEnabled.12',
'application/vnd.ms-excel.addin.macroEnabled.12',
'application/vnd.ms-excel.sheet.binary.macroEnabled.12'
];
FileType.mime_ppt = [
'application/vnd.ms-powerpoint',
'application/vnd.ms-powerpoint',
'application/vnd.ms-powerpoint',
'application/vnd.ms-powerpoint',
'application/vnd.openxmlformats-officedocument.presentationml.presentation',
'application/vnd.openxmlformats-officedocument.presentationml.template',
'application/vnd.openxmlformats-officedocument.presentationml.slideshow',
'application/vnd.ms-powerpoint.addin.macroEnabled.12',
'application/vnd.ms-powerpoint.presentation.macroEnabled.12',
'application/vnd.ms-powerpoint.presentation.macroEnabled.12',
'application/vnd.ms-powerpoint.slideshow.macroEnabled.12'
];
FileType.mime_psd = [
'image/photoshop',
'image/x-photoshop',
'image/psd',
'application/photoshop',
'application/psd',
'zz-application/zz-winassoc-psd'
];
FileType.mime_compress = [
'application/x-gtar',
'application/x-gcompress',
'application/compress',
'application/x-tar',
'application/x-rar-compressed',
'application/octet-stream'
];
return FileType;
}());
exports.FileType = FileType;
/***/ },
/***/ 140:
/***/ function(module, exports, __webpack_require__) {
"use strict";
function __export(m) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
__export(__webpack_require__(46));
__export(__webpack_require__(44));
__export(__webpack_require__(28));
var file_select_directive_2 = __webpack_require__(46);
var file_drop_directive_2 = __webpack_require__(44);
exports.FILE_UPLOAD_DIRECTIVES = [file_select_directive_2.FileSelectDirective, file_drop_directive_2.FileDropDirective];
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = {
directives: [
exports.FILE_UPLOAD_DIRECTIVES
]
};
/***/ }
});
//# sourceMappingURL=angular2-bootstrap.js.map

File diff suppressed because one or more lines are too long

24954
angular2.js vendored

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@@ -1,43 +0,0 @@
import { FileLikeObject } from './file-like-object.class';
import { FileUploader } from './file-uploader.class';
export declare class FileItem {
file: FileLikeObject;
_file: File;
alias: string;
url: string;
method: string;
headers: any;
withCredentials: boolean;
formData: any;
isReady: boolean;
isUploading: boolean;
isUploaded: boolean;
isSuccess: boolean;
isCancel: boolean;
isError: boolean;
progress: number;
index: number;
private _zone;
private uploader;
private some;
private options;
constructor(uploader: FileUploader, some: any, options: any);
upload(): void;
cancel(): void;
remove(): void;
onBeforeUpload(): void;
onBuildForm(form: any): any;
onProgress(progress: number): any;
onSuccess(response: any, status: any, headers: any): any;
onError(response: any, status: any, headers: any): any;
onCancel(response: any, status: any, headers: any): any;
onComplete(response: any, status: any, headers: any): any;
_onBeforeUpload(): void;
_onBuildForm(form: any): void;
_onProgress(progress: number): void;
_onSuccess(response: any, status: any, headers: any): void;
_onError(response: any, status: any, headers: any): void;
_onCancel(response: any, status: any, headers: any): void;
_onComplete(response: any, status: any, headers: any): void;
_prepareToUploading(): void;
}

View File

@@ -1,77 +0,0 @@
import { FileItem } from './file-item.class';
export interface Headers {
name: string;
value: string;
}
export interface FileUploaderOptions {
allowedMimeType?: Array<string>;
allowedFileType?: Array<string>;
autoUpload?: boolean;
isHTML5?: boolean;
filters?: Array<any>;
headers?: Array<Headers>;
maxFileSize?: number;
queueLimit?: number;
removeAfterUpload?: boolean;
url?: string;
}
export declare class FileUploader {
authToken: string;
isUploading: boolean;
queue: Array<any>;
progress: number;
_nextIndex: number;
autoUpload: any;
options: FileUploaderOptions;
private _failFilterIndex;
constructor(options: any);
setOptions(options: any): void;
addToQueue(files: any[], options?: any, filters?: any): void;
removeFromQueue(value: any): void;
clearQueue(): void;
uploadItem(value: FileItem): void;
cancelItem(value: any): void;
uploadAll(): void;
cancelAll(): void;
isFile(value: any): boolean;
isFileLikeObject(value: any): boolean;
getIndexOfItem(value: any): number;
getNotUploadedItems(): Array<any>;
getReadyItems(): Array<any>;
destroy(): void;
onAfterAddingAll(fileItems: any): any;
onBuildItemForm(fileItem: any, form: any): any;
onAfterAddingFile(fileItem: any): any;
onWhenAddingFileFailed(item: any, filter: any, options: any): any;
onBeforeUploadItem(fileItem: any): any;
onProgressItem(fileItem: any, progress: any): any;
onProgressAll(progress: any): any;
onSuccessItem(item: any, response: any, status: any, headers: any): any;
onErrorItem(item: any, response: any, status: any, headers: any): any;
onCancelItem(item: any, response: any, status: any, headers: any): any;
onCompleteItem(item: any, response: any, status: any, headers: any): any;
onCompleteAll(): any;
_mimeTypeFilter(item: any): boolean;
_fileSizeFilter(item: any): boolean;
_fileTypeFilter(item: any): boolean;
_onErrorItem(item: any, response: any, status: any, headers: any): void;
_onCompleteItem(item: any, response: any, status: any, headers: any): void;
protected _headersGetter(parsedHeaders: any): any;
protected _xhrTransport(item: any): any;
private _getTotalProgress(value?);
private _getFilters(filters);
private _render();
private _queueLimitFilter();
private _isValidFile(file, filters, options);
private _isSuccessCode(status);
private _transformResponse(response, headers);
private _parseHeaders(headers);
private _onWhenAddingFileFailed(item, filter, options);
private _onAfterAddingFile(item);
private _onAfterAddingAll(items);
private _onBeforeUploadItem(item);
private _onBuildItemForm(item, form);
private _onProgressItem(item, progress);
private _onSuccessItem(item, response, status, headers);
private _onCancelItem(item, response, status, headers);
}

View File

@@ -34,5 +34,5 @@
Loading...
</app>
<script src="angular2.js"></script><script src="angular2-bootstrap.js"></script><script src="angular2-bootstrap-demo.js"></script></body>
<script type="text/javascript" src="polyfills.c9c700a8d3496d0a70a7.bundle.js"></script><script type="text/javascript" src="vendor.c9c700a8d3496d0a70a7.bundle.js"></script><script type="text/javascript" src="main.c9c700a8d3496d0a70a7.bundle.js"></script></body>
</html>

File diff suppressed because one or more lines are too long

Binary file not shown.

File diff suppressed because one or more lines are too long

Binary file not shown.

File diff suppressed because one or more lines are too long

Binary file not shown.

File diff suppressed because one or more lines are too long

Binary file not shown.

File diff suppressed because one or more lines are too long

Binary file not shown.

File diff suppressed because one or more lines are too long

Binary file not shown.