From 51b940b03ea9ca3ec5559dff8000780338314936 Mon Sep 17 00:00:00 2001 From: mauriziovitale84 Date: Thu, 12 May 2016 20:43:05 +0100 Subject: [PATCH] #46 onSuccess Event Emitter FileUploader --- .../src/components/upload-button.component.js | 199 ++++++++++++++++++ .../components/upload-button.component.js.map | 1 + .../src/components/upload-button.component.ts | 7 +- .../src/services/upload.service.js | 169 +++++++++++++++ .../src/services/upload.service.js.map | 1 + .../src/services/upload.service.ts | 14 +- .../upload-button.component.spec.ts | 8 +- 7 files changed, 388 insertions(+), 11 deletions(-) create mode 100644 ng2-components/ng2-alfresco-upload/src/components/upload-button.component.js create mode 100644 ng2-components/ng2-alfresco-upload/src/components/upload-button.component.js.map create mode 100644 ng2-components/ng2-alfresco-upload/src/services/upload.service.js create mode 100644 ng2-components/ng2-alfresco-upload/src/services/upload.service.js.map diff --git a/ng2-components/ng2-alfresco-upload/src/components/upload-button.component.js b/ng2-components/ng2-alfresco-upload/src/components/upload-button.component.js new file mode 100644 index 0000000000..8ae5e8743d --- /dev/null +++ b/ng2-components/ng2-alfresco-upload/src/components/upload-button.component.js @@ -0,0 +1,199 @@ +/** + * @license + * Copyright 2016 Alfresco Software, Ltd. + * + * 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +System.register(['angular2/core', '../services/upload.service', './file-uploading-dialog.component', 'ng2-translate/ng2-translate'], function(exports_1, context_1) { + "use strict"; + var __moduleName = context_1 && context_1.id; + 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, upload_service_1, file_uploading_dialog_component_1, ng2_translate_1; + var UploadButtonComponent; + return { + setters:[ + function (core_1_1) { + core_1 = core_1_1; + }, + function (upload_service_1_1) { + upload_service_1 = upload_service_1_1; + }, + function (file_uploading_dialog_component_1_1) { + file_uploading_dialog_component_1 = file_uploading_dialog_component_1_1; + }, + function (ng2_translate_1_1) { + ng2_translate_1 = ng2_translate_1_1; + }], + execute: function() { + /** + * + * + * + * This component, provide a set of buttons to upload files to alfresco. + * + * @InputParam {boolean} [true] showDialogUpload - hide/show upload dialog. + * @InputParam {boolean} [true] showUdoNotificationBar - hide/show notification bar. + * @InputParam {boolean} [false] uploadFolders - allow/disallow upload folders (only for chrome). + * @InputParam {boolean} [false] multipleFiles - allow/disallow multiple files. + * @InputParam {string} [*] acceptedFilesType - array of allowed file extensions. + * + * + * @returns {UploadDragAreaComponent} . + */ + UploadButtonComponent = (function () { + function UploadButtonComponent(el, translate) { + this.el = el; + this.showUploadDialog = true; + this.showUdoNotificationBar = true; + this.uploadFolders = false; + this.multipleFiles = false; + this.acceptedFilesType = '*'; + this.uploaddirectory = ''; + this.onSuccess = new core_1.EventEmitter(); + this.filesUploadingList = []; + console.log('UploadComponent constructor', el); + this._uploaderService = new upload_service_1.UploadService({ + url: 'http://192.168.99.100:8080/alfresco/service/api/upload', + withCredentials: true, + authToken: btoa('admin:admin'), + authTokenPrefix: 'Basic', + fieldName: 'filedata', + formFields: { + siteid: 'swsdp', + containerid: 'documentLibrary' + } + }); + this.translationInit(translate); + } + /** + * Method called when files are dropped in the drag area. + * + * @param {File[]} files - files dropped in the drag area. + */ + UploadButtonComponent.prototype.onFilesAdded = function ($event) { + var files = $event.currentTarget.files; + if (files.length) { + var latestFilesAdded = this._uploaderService.addToQueue(files); + this._uploaderService.uploadFilesInTheQueue(this.uploaddirectory, this.onSuccess); + this.filesUploadingList = this._uploaderService.getQueue(); + if (this.showUploadDialog) { + this._showDialog(); + } + if (this.showUdoNotificationBar) { + this._showUndoNotificationBar(latestFilesAdded); + } + } + }; + /** + * Show undo notification bar. + * + * @param {FileModel[]} latestFilesAdded - files in the upload queue enriched with status flag and xhr object. + */ + UploadButtonComponent.prototype._showUndoNotificationBar = function (latestFilesAdded) { + if (componentHandler) { + componentHandler.upgradeAllRegistered(); + } + this.undoNotificationBar.nativeElement.MaterialSnackbar.showSnackbar({ + message: this.translate.get('FILE_UPLOAD.MESSAGES.PROGRESS').value, + timeout: 5000, + actionHandler: function () { + latestFilesAdded.forEach(function (uploadingFileModel) { + uploadingFileModel.setAbort(); + }); + }, + actionText: this.translate.get('FILE_UPLOAD.ACTION.UNDO').value + }); + }; + /** + * Show the upload dialog. + */ + UploadButtonComponent.prototype._showDialog = function () { + this.fileUploadingDialogComponent.showDialog(); + }; + /** + * Initial configuration for Multi language + * @param translate + */ + UploadButtonComponent.prototype.translationInit = function (translate) { + this.translate = translate; + var userLang = navigator.language.split('-')[0]; // use navigator lang if available + userLang = /(fr|en)/gi.test(userLang) ? userLang : 'en'; + this.translate.setDefaultLang(userLang); + this.translate.use(userLang); + }; + __decorate([ + core_1.ViewChild('undoNotificationBar'), + __metadata('design:type', Object) + ], UploadButtonComponent.prototype, "undoNotificationBar", void 0); + __decorate([ + core_1.ViewChild('fileUploadingDialog'), + __metadata('design:type', file_uploading_dialog_component_1.FileUploadingDialogComponent) + ], UploadButtonComponent.prototype, "fileUploadingDialogComponent", void 0); + __decorate([ + core_1.Input(), + __metadata('design:type', Boolean) + ], UploadButtonComponent.prototype, "showUploadDialog", void 0); + __decorate([ + core_1.Input(), + __metadata('design:type', Boolean) + ], UploadButtonComponent.prototype, "showUdoNotificationBar", void 0); + __decorate([ + core_1.Input(), + __metadata('design:type', Boolean) + ], UploadButtonComponent.prototype, "uploadFolders", void 0); + __decorate([ + core_1.Input(), + __metadata('design:type', Boolean) + ], UploadButtonComponent.prototype, "multipleFiles", void 0); + __decorate([ + core_1.Input(), + __metadata('design:type', String) + ], UploadButtonComponent.prototype, "acceptedFilesType", void 0); + __decorate([ + core_1.Input(), + __metadata('design:type', String) + ], UploadButtonComponent.prototype, "uploaddirectory", void 0); + __decorate([ + core_1.Output(), + __metadata('design:type', Object) + ], UploadButtonComponent.prototype, "onSuccess", void 0); + UploadButtonComponent = __decorate([ + core_1.Component({ + selector: 'alfresco-upload-button', + moduleId: __moduleName, + directives: [file_uploading_dialog_component_1.FileUploadingDialogComponent], + templateUrl: './upload-button.component.html', + styleUrls: ['./upload-button.component.css'], + pipes: [ng2_translate_1.TranslatePipe] + }), + __metadata('design:paramtypes', [core_1.ElementRef, ng2_translate_1.TranslateService]) + ], UploadButtonComponent); + return UploadButtonComponent; + }()); + exports_1("UploadButtonComponent", UploadButtonComponent); + } + } +}); +//# sourceMappingURL=upload-button.component.js.map \ No newline at end of file diff --git a/ng2-components/ng2-alfresco-upload/src/components/upload-button.component.js.map b/ng2-components/ng2-alfresco-upload/src/components/upload-button.component.js.map new file mode 100644 index 0000000000..688e5a9e58 --- /dev/null +++ b/ng2-components/ng2-alfresco-upload/src/components/upload-button.component.js.map @@ -0,0 +1 @@ +{"version":3,"file":"upload-button.component.js","sourceRoot":"","sources":["upload-button.component.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YAYH;;;;;;;;;;;;;;;;;;eAkBG;YASH;gBAmCI,+BAAmB,EAAc,EACrB,SAA2B;oBADpB,OAAE,GAAF,EAAE,CAAY;oBAxBjC,qBAAgB,GAAY,IAAI,CAAC;oBAGjC,2BAAsB,GAAY,IAAI,CAAC;oBAGvC,kBAAa,GAA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gBA/GD;oBAAC,gBAAS,CAAC,qBAAqB,CAAC;;kFAAA;gBAGjC;oBAAC,gBAAS,CAAC,qBAAqB,CAAC;;2FAAA;gBAGjC;oBAAC,YAAK,EAAE;;+EAAA;gBAGR;oBAAC,YAAK,EAAE;;qFAAA;gBAGR;oBAAC,YAAK,EAAE;;4EAAA;gBAGR;oBAAC,YAAK,EAAE;;4EAAA;gBAGR;oBAAC,YAAK,EAAE;;gFAAA;gBAGR;oBAAC,YAAK,EAAE;;8EAAA;gBAGR;oBAAC,aAAM,EAAE;;wEAAA;gBApCb;oBAAC,gBAAS,CAAC;wBACP,QAAQ,EAAE,wBAAwB;wBAClC,QAAQ,EAAE,YAAY;wBACtB,UAAU,EAAE,CAAC,8DAA4B,CAAC;wBAC1C,WAAW,EAAE,gCAAgC;wBAC7C,SAAS,EAAE,CAAC,+BAA+B,CAAC;wBAC5C,KAAK,EAAE,CAAC,6BAAa,CAAC;qBACzB,CAAC;;yCAAA;gBAqHF,4BAAC;YAAD,CAAC,AApHD,IAoHC;YApHD,yDAoHC,CAAA"} \ No newline at end of file diff --git a/ng2-components/ng2-alfresco-upload/src/components/upload-button.component.ts b/ng2-components/ng2-alfresco-upload/src/components/upload-button.component.ts index d37be0ef2e..4ab392801e 100644 --- a/ng2-components/ng2-alfresco-upload/src/components/upload-button.component.ts +++ b/ng2-components/ng2-alfresco-upload/src/components/upload-button.component.ts @@ -16,7 +16,7 @@ */ -import { Component, ViewChild, ElementRef, Input } from 'angular2/core'; +import { Component, ViewChild, ElementRef, Input, Output, EventEmitter } from 'angular2/core'; import { UploadService } from '../services/upload.service'; import { FileModel } from '../models/file.model'; import { FileUploadingDialogComponent } from './file-uploading-dialog.component'; @@ -78,6 +78,9 @@ export class UploadButtonComponent { @Input() uploaddirectory: string = ''; + @Output() + onSuccess = new EventEmitter(); + filesUploadingList: FileModel [] = []; translate: TranslateService; @@ -112,7 +115,7 @@ export class UploadButtonComponent { let files = $event.currentTarget.files; if (files.length) { let latestFilesAdded = this._uploaderService.addToQueue(files); - this._uploaderService.uploadFilesInTheQueue(this.uploaddirectory); + this._uploaderService.uploadFilesInTheQueue(this.uploaddirectory, this.onSuccess); this.filesUploadingList = this._uploaderService.getQueue(); if (this.showUploadDialog) { this._showDialog(); diff --git a/ng2-components/ng2-alfresco-upload/src/services/upload.service.js b/ng2-components/ng2-alfresco-upload/src/services/upload.service.js new file mode 100644 index 0000000000..f4c78f68a5 --- /dev/null +++ b/ng2-components/ng2-alfresco-upload/src/services/upload.service.js @@ -0,0 +1,169 @@ +/** + * @license + * Copyright 2016 Alfresco Software, Ltd. + * + * 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +System.register(['../models/file.model'], function(exports_1, context_1) { + "use strict"; + var __moduleName = context_1 && context_1.id; + var file_model_1; + var UploadService; + return { + setters:[ + function (file_model_1_1) { + file_model_1 = file_model_1_1; + }], + execute: function() { + /** + * + * UploadService keep the queue of the file to upload and uploads them. + * + * @returns {UploadService} . + */ + UploadService = (function () { + function UploadService(options) { + this.options = options; + this._method = 'POST'; + this._authTokenPrefix = 'Basic'; + this._authToken = undefined; + this._fieldName = 'file'; + this._formFields = {}; + this._queue = []; + console.log('UploadService constructor'); + this._withCredentials = options.withCredentials != null ? options.withCredentials : this._withCredentials; + this._url = options.url != null ? options.url : this._url; + this._authTokenPrefix = options.authTokenPrefix != null ? options.authTokenPrefix : this._authTokenPrefix; + this._authToken = options.authToken != null ? options.authToken : this._authToken; + this._fieldName = options.fieldName != null ? options.fieldName : this._fieldName; + this._formFields = options.formFields != null ? options.formFields : this._formFields; + } + /** + * Add files to the uploading queue to be uploaded. + * + * @param {File[]} - files to add to the upload queue. + * + * return {FileModel[]} - return the file added to the queue in this call. + */ + UploadService.prototype.addToQueue = function (files) { + var latestFilesAdded = []; + for (var _i = 0, files_1 = files; _i < files_1.length; _i++) { + var file = files_1[_i]; + if (this._isFile(file)) { + var uploadingFileModel = new file_model_1.FileModel(file); + latestFilesAdded.push(uploadingFileModel); + this._queue.push(uploadingFileModel); + } + } + return latestFilesAdded; + }; + /** + * Pick all the files in the queue that are not been uploaded yet and upload it into the directory folder. + */ + UploadService.prototype.uploadFilesInTheQueue = function (directory, elementEmit) { + var _this = this; + var filesToUpload = this._queue.filter(function (uploadingFileModel) { + return !uploadingFileModel.uploading && !uploadingFileModel.done && !uploadingFileModel.abort && !uploadingFileModel.error; + }); + filesToUpload.forEach(function (uploadingFileModel) { + uploadingFileModel.setUploading(); + _this.uploadFile(uploadingFileModel, directory, elementEmit); + }); + }; + ; + /** + * The method create a new XMLHttpRequest instance if doesn't exist + */ + UploadService.prototype._configureXMLHttpRequest = function (uploadingFileModel, elementEmit) { + var _this = this; + if (this._xmlHttpRequest == undefined) { + this._xmlHttpRequest = new XMLHttpRequest(); + this._xmlHttpRequest.upload.onprogress = function (e) { + if (e.lengthComputable) { + var percent = Math.round(e.loaded / e.total * 100); + uploadingFileModel.setProgres({ + total: e.total, + loaded: e.loaded, + percent: percent + }); + } + }; + this._xmlHttpRequest.upload.onabort = function (e) { + uploadingFileModel.setAbort(); + }; + this._xmlHttpRequest.upload.onerror = function (e) { + uploadingFileModel.setError(); + }; + this._xmlHttpRequest.onreadystatechange = function () { + if (_this._xmlHttpRequest.readyState === XMLHttpRequest.DONE) { + elementEmit.emit({ + value: 'File uploaded' + }); + uploadingFileModel.onFinished(_this._xmlHttpRequest.status, _this._xmlHttpRequest.statusText, _this._xmlHttpRequest.response); + } + }; + } + }; + /** + * Upload a file into the directory folder, and enrich it with the xhr. + * + * @param {FileModel} - files to be uploaded. + * + */ + UploadService.prototype.uploadFile = function (uploadingFileModel, directory, elementEmit) { + var _this = this; + var form = new FormData(); + form.append(this._fieldName, uploadingFileModel.file, uploadingFileModel.name); + Object.keys(this._formFields).forEach(function (key) { + form.append(key, _this._formFields[key]); + }); + form.append('uploaddirectory', directory); + this._configureXMLHttpRequest(uploadingFileModel, elementEmit); + uploadingFileModel.setXMLHttpRequest(this._xmlHttpRequest); + this._xmlHttpRequest.open(this._method, this._url, true); + this._xmlHttpRequest.withCredentials = this._withCredentials; + if (this._authToken) { + this._xmlHttpRequest.setRequestHeader('Authorization', this._authTokenPrefix + " " + this._authToken); + } + this._xmlHttpRequest.send(form); + }; + /** + * Return all the files in the uploading queue. + * + * @return {FileModel[]} - files in the upload queue. + */ + UploadService.prototype.getQueue = function () { + return this._queue; + }; + /** + * Check if an item is a file. + * + * @return {boolean} + */ + UploadService.prototype._isFile = function (file) { + return file !== null && (file instanceof Blob || (file.name && file.size)); + }; + /** + * Set XMLHttpRequest method + * @param xhr + */ + UploadService.prototype.setXMLHttpRequest = function (xhr) { + this._xmlHttpRequest = xhr; + }; + return UploadService; + }()); + exports_1("UploadService", UploadService); + } + } +}); +//# sourceMappingURL=upload.service.js.map \ No newline at end of file diff --git a/ng2-components/ng2-alfresco-upload/src/services/upload.service.js.map b/ng2-components/ng2-alfresco-upload/src/services/upload.service.js.map new file mode 100644 index 0000000000..5700ff69b6 --- /dev/null +++ b/ng2-components/ng2-alfresco-upload/src/services/upload.service.js.map @@ -0,0 +1 @@ +{"version":3,"file":"upload.service.js","sourceRoot":"","sources":["upload.service.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;;;;;;;;;;;;YAOH;;;;;eAKG;YACH;gBAYI,uBAAoB,OAAY;oBAAZ,YAAO,GAAP,OAAO,CAAK;oBAVxB,YAAO,GAAW,MAAM,CAAC;oBACzB,qBAAgB,GAAW,OAAO,CAAC;oBACnC,eAAU,GAAW,SAAS,CAAC;oBAC/B,eAAU,GAAW,MAAM,CAAC;oBAC5B,gBAAW,GAAW,EAAE,CAAC;oBAIzB,WAAM,GAAgB,E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C,IAAI,CAAC,wBAAwB,CAAC,kBAAkB,EAAE,WAAW,CAAC,CAAC;oBAC/D,kBAAkB,CAAC,iBAAiB,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;oBAE3D,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;oBACzD,IAAI,CAAC,eAAe,CAAC,eAAe,GAAG,IAAI,CAAC,gBAAgB,CAAC;oBAE7D,EAAE,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC;wBAClB,IAAI,CAAC,eAAe,CAAC,gBAAgB,CAAC,eAAe,EAAK,IAAI,CAAC,gBAAgB,SAAI,IAAI,CAAC,UAAY,CAAC,CAAC;oBAC1G,CAAC;oBAED,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;gBACpC,CAAC;gBAED;;;;mBAIG;gBACH,gCAAQ,GAAR;oBACI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC;gBACvB,CAAC;gBAED;;;;mBAIG;gBACK,+BAAO,GAAf,UAAgB,IAAS;oBACrB,MAAM,CAAC,IAAI,KAAK,IAAI,IAAI,CAAC,IAAI,YAAY,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;gBAC/E,CAAC;gBAED;;;mBAGG;gBACI,yCAAiB,GAAxB,UAAyB,GAAmB;oBACxC,IAAI,CAAC,eAAe,GAAG,GAAG,CAAC;gBAC/B,CAAC;gBACL,oBAAC;YAAD,CAAC,AArJD,IAqJC;YArJD,yCAqJC,CAAA"} \ No newline at end of file diff --git a/ng2-components/ng2-alfresco-upload/src/services/upload.service.ts b/ng2-components/ng2-alfresco-upload/src/services/upload.service.ts index c685ca9812..52d7809c57 100644 --- a/ng2-components/ng2-alfresco-upload/src/services/upload.service.ts +++ b/ng2-components/ng2-alfresco-upload/src/services/upload.service.ts @@ -17,6 +17,7 @@ import { FileModel } from '../models/file.model'; +import { EventEmitter } from 'angular2/core'; /** @@ -71,20 +72,20 @@ export class UploadService { /** * Pick all the files in the queue that are not been uploaded yet and upload it into the directory folder. */ - public uploadFilesInTheQueue(directory: string): void { + public uploadFilesInTheQueue(directory: string, elementEmit: EventEmitter): void { let filesToUpload = this._queue.filter((uploadingFileModel) => { return !uploadingFileModel.uploading && !uploadingFileModel.done && !uploadingFileModel.abort && !uploadingFileModel.error; }); filesToUpload.forEach((uploadingFileModel) => { uploadingFileModel.setUploading(); - this.uploadFile(uploadingFileModel, directory); + this.uploadFile(uploadingFileModel, directory, elementEmit); }); }; /** * The method create a new XMLHttpRequest instance if doesn't exist */ - private _configureXMLHttpRequest(uploadingFileModel: any) { + private _configureXMLHttpRequest(uploadingFileModel: any, elementEmit: EventEmitter) { if (this._xmlHttpRequest === undefined) { this._xmlHttpRequest = new XMLHttpRequest(); this._xmlHttpRequest.upload.onprogress = (e) => { @@ -108,6 +109,9 @@ export class UploadService { this._xmlHttpRequest.onreadystatechange = () => { if (this._xmlHttpRequest.readyState === XMLHttpRequest.DONE) { + elementEmit.emit({ + value: 'File uploaded' + }); uploadingFileModel.onFinished( this._xmlHttpRequest.status, this._xmlHttpRequest.statusText, @@ -124,7 +128,7 @@ export class UploadService { * @param {FileModel} - files to be uploaded. * */ - uploadFile(uploadingFileModel: FileModel, directory?: string): void { + uploadFile(uploadingFileModel: FileModel, directory: string, elementEmit: EventEmitter): void { let form = new FormData(); form.append(this._fieldName, uploadingFileModel.file, uploadingFileModel.name); Object.keys(this._formFields).forEach((key: any) => { @@ -133,7 +137,7 @@ export class UploadService { form.append('uploaddirectory', directory); - this._configureXMLHttpRequest(uploadingFileModel); + this._configureXMLHttpRequest(uploadingFileModel, elementEmit); uploadingFileModel.setXMLHttpRequest(this._xmlHttpRequest); this._xmlHttpRequest.open(this._method, this._url, true); diff --git a/ng2-components/ng2-alfresco-upload/test/components/upload-button.component.spec.ts b/ng2-components/ng2-alfresco-upload/test/components/upload-button.component.spec.ts index 7f1dfac028..48e6c0d93d 100644 --- a/ng2-components/ng2-alfresco-upload/test/components/upload-button.component.spec.ts +++ b/ng2-components/ng2-alfresco-upload/test/components/upload-button.component.spec.ts @@ -18,10 +18,10 @@ import { TEST_BROWSER_PLATFORM_PROVIDERS, TEST_BROWSER_APPLICATION_PROVIDERS } from 'angular2/platform/testing/browser'; import { it, describe, expect, injectAsync, beforeEachProviders, TestComponentBuilder, setBaseTestProviders } from 'angular2/testing'; -import { provide } from 'angular2/core'; -import { TranslateService } from 'ng2-translate/ng2-translate'; -import { TranslationMock } from '../assets/translation.service.mock'; +import { Component, provide, Injector } from 'angular2/core'; import { UploadButtonComponent } from '../../src/components/upload-button.component'; +import { TranslateService, LangChangeEvent } from 'ng2-translate/ng2-translate'; +import { TranslationMock } from '../assets/translation.service.mock'; describe('AlfrescoUploadButton', () => { @@ -44,7 +44,7 @@ describe('AlfrescoUploadButton', () => { }); })); - it('should render upload-multiple-file button if multipleFiles=true', + it('should render upload-multiple-file button if multipleFiles is true', injectAsync([TestComponentBuilder], (tcb: TestComponentBuilder) => { return tcb .createAsync(UploadButtonComponent)