mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-31 17:38:48 +00:00
Merge pull request #240 from Alfresco/dev-mvitale-233
Fixed regression on upload folder #233
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
/*!
|
||||
* @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.
|
||||
*/
|
||||
|
||||
export class AlfrescoSettingsServiceMock {
|
||||
|
||||
static DEFAULT_HOST_ADDRESS: string = 'fakehost';
|
||||
static DEFAULT_CONTEXT_PATH: string = '/fake-path-alfresco';
|
||||
static DEFAULT_BASE_API_PATH: string = '/fake-api/fake-public/fake-alfresco/fake-versions/1';
|
||||
|
||||
private _host: string = AlfrescoSettingsServiceMock.DEFAULT_HOST_ADDRESS;
|
||||
private _contextPath = AlfrescoSettingsServiceMock.DEFAULT_CONTEXT_PATH;
|
||||
private _apiBasePath: string = AlfrescoSettingsServiceMock.DEFAULT_BASE_API_PATH;
|
||||
|
||||
public get host(): string {
|
||||
return this._host;
|
||||
}
|
||||
|
||||
public set host(value: string) {
|
||||
this._host = value;
|
||||
}
|
||||
|
||||
getApiBaseUrl(): string {
|
||||
return this._host + this._contextPath + this._apiBasePath;
|
||||
}
|
||||
}
|
@@ -244,7 +244,7 @@ export class UploadButtonComponent {
|
||||
* @returns {string}
|
||||
*/
|
||||
private getErrorMessage(response: any): string {
|
||||
if (response.body.error.statusCode === ERROR_FOLDER_ALREADY_EXIST ) {
|
||||
if (response.body && response.body.error.statusCode === ERROR_FOLDER_ALREADY_EXIST ) {
|
||||
let errorMessage: any;
|
||||
errorMessage = this.translate.get('FILE_UPLOAD.MESSAGES.FOLDER_ALREADY_EXIST');
|
||||
return errorMessage.value;
|
||||
|
@@ -15,9 +15,12 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { it, describe, beforeEach, expect } from '@angular/core/testing';
|
||||
import { it, describe, inject, beforeEach, beforeEachProviders } from '@angular/core/testing';
|
||||
import { UploadService } from './upload.service';
|
||||
import { provide } from '@angular/core';
|
||||
import { FileModel } from './../models/file.model';
|
||||
import { AlfrescoSettingsService } from 'ng2-alfresco-core';
|
||||
import { AlfrescoSettingsServiceMock } from '../assets/AlfrescoSettingsService.service.mock';
|
||||
import { AlfrescoApiMock } from '../assets/AlfrescoApi.mock';
|
||||
|
||||
|
||||
@@ -30,6 +33,10 @@ let errorFn = jasmine.createSpy('error');
|
||||
|
||||
class MockUploadService extends UploadService {
|
||||
|
||||
constructor(settings: AlfrescoSettingsService) {
|
||||
super(settings);
|
||||
}
|
||||
|
||||
createXMLHttpRequestInstance() {
|
||||
let xhr = new XMLHttpRequest();
|
||||
xhr.onreadystatechange = function () {
|
||||
@@ -45,9 +52,7 @@ class MockUploadService extends UploadService {
|
||||
}
|
||||
|
||||
describe('AlfrescoUploadService', () => {
|
||||
let service: MockUploadService,
|
||||
serviceUpload: UploadService,
|
||||
options: any;
|
||||
let service, options: any;
|
||||
|
||||
options = {
|
||||
host: 'fakehost',
|
||||
@@ -59,12 +64,17 @@ describe('AlfrescoUploadService', () => {
|
||||
}
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
window['AlfrescoApi'] = AlfrescoApiMock;
|
||||
|
||||
beforeEachProviders(() => [
|
||||
provide(AlfrescoSettingsService, {useClass: AlfrescoSettingsServiceMock}),
|
||||
provide(UploadService, {useClass: MockUploadService})
|
||||
]);
|
||||
|
||||
beforeEach( inject([UploadService], (uploadService: UploadService) => {
|
||||
jasmine.Ajax.install();
|
||||
window['AlfrescoApi'] = AlfrescoApiMock;
|
||||
service = new MockUploadService(options);
|
||||
serviceUpload = new UploadService(options);
|
||||
});
|
||||
service = uploadService;
|
||||
}));
|
||||
|
||||
afterEach(() => {
|
||||
jasmine.Ajax.uninstall();
|
||||
@@ -74,15 +84,13 @@ describe('AlfrescoUploadService', () => {
|
||||
let empty = {};
|
||||
service.setOptions(empty);
|
||||
expect(service.getUrl()).toEqual('/alfresco/service/api/upload');
|
||||
expect(service.getBaseUrl()).toEqual('/alfresco/api/-default-/public/alfresco/versions/1');
|
||||
let formFields: Object = {};
|
||||
expect(service.getFormFileds()).toEqual(formFields);
|
||||
});
|
||||
|
||||
it('should set the basic option an empty queue if no elements are added', () => {
|
||||
it('should show the option passed as input', () => {
|
||||
service.setOptions(options);
|
||||
expect(service.getUrl()).toEqual('/some/cool/url');
|
||||
expect(service.getBaseUrl()).toEqual('fakebasepath');
|
||||
expect(service.getFormFileds()).toEqual({
|
||||
siteid: 'fakeSite',
|
||||
containerid: 'fakeFolder'
|
||||
@@ -207,15 +215,4 @@ describe('AlfrescoUploadService', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('should create an XHR object ', () => {
|
||||
service.setOptions(options);
|
||||
let filesFake = {name: 'fake-name', size: 10};
|
||||
let uploadingFileModel = new FileModel(filesFake);
|
||||
let xhrRequest = serviceUpload.createXMLHttpRequestInstance(uploadingFileModel, null);
|
||||
expect(xhrRequest.upload).toBeDefined();
|
||||
expect(xhrRequest.upload.onabort).toBeDefined();
|
||||
expect(xhrRequest.upload.onprogress).toBeDefined();
|
||||
expect(xhrRequest.upload.onerror).toBeDefined();
|
||||
expect(xhrRequest.onreadystatechange).toBeDefined();
|
||||
});
|
||||
});
|
||||
|
@@ -33,7 +33,6 @@ declare let AlfrescoApi: any;
|
||||
*/
|
||||
@Injectable()
|
||||
export class UploadService {
|
||||
private _baseUrlPath: string = '/alfresco/api/-default-/public/alfresco/versions/1';
|
||||
private _url: string = '/alfresco/service/api/upload';
|
||||
|
||||
private _method: string = 'POST';
|
||||
@@ -66,7 +65,6 @@ export class UploadService {
|
||||
*/
|
||||
public setOptions(options: any): void {
|
||||
this._url = options.url || this._url;
|
||||
this._baseUrlPath = options.baseUrlPath || this._baseUrlPath;
|
||||
this._formFields = options.formFields != null ? options.formFields : this._formFields;
|
||||
}
|
||||
|
||||
@@ -86,14 +84,6 @@ export class UploadService {
|
||||
return this._url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the base url
|
||||
* @returns {string}
|
||||
*/
|
||||
public getBaseUrl(): string {
|
||||
return this._baseUrlPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the form fields
|
||||
* @returns {Object}
|
||||
@@ -115,7 +105,7 @@ export class UploadService {
|
||||
* @returns {AlfrescoApi.ApiClient}
|
||||
*/
|
||||
private getAlfrescoClient() {
|
||||
return AlfrescoApi.getClientWithTicket(this.getBaseUrl(), this.getAlfrescoTicket());
|
||||
return AlfrescoApi.getClientWithTicket(this.settings.getApiBaseUrl(), this.getAlfrescoTicket());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -224,7 +214,7 @@ export class UploadService {
|
||||
let xmlHttpRequest = this.createXMLHttpRequestInstance(uploadingFileModel, elementEmit);
|
||||
uploadingFileModel._xmlHttpRequest = xmlHttpRequest;
|
||||
|
||||
xmlHttpRequest.open(this._method, this.getHost() + this._url, true);
|
||||
xmlHttpRequest.open(this._method, this.getHost() + this.getUrl(), true);
|
||||
let authToken = btoa(basicAuth.username + ':' + basicAuth.password);
|
||||
if (authToken) {
|
||||
xmlHttpRequest.setRequestHeader('Authorization', `${basicAuth.type} ${authToken}`);
|
||||
|
Reference in New Issue
Block a user