Merge branch 'master' into dev-denys-coverage-fixes

# Conflicts:
#
ng2-components/ng2-alfresco-documentlist/src/components/document-list.ts
This commit is contained in:
Denys Vuika 2016-05-16 13:59:17 +01:00
commit 242d13add7
7 changed files with 87 additions and 74 deletions

View File

@ -1,5 +1,6 @@
<alfresco-upload-drag-area [showUploadDialog]="true" uploaddirectory="{{relativePath}}" > <alfresco-upload-drag-area [showUploadDialog]="true" uploaddirectory="{{relativePath}}"
<alfresco-document-list (folderClick)="refreshDirectyory($event)"> (onSuccess)="refreshDocumentList($event)">
<alfresco-document-list (folderClick)="refreshDirectyory($event)" currentFolderPath="{{absolutePath}}">
<content-columns> <content-columns>
<content-column source="$thumbnail"></content-column> <content-column source="$thumbnail"></content-column>
<content-column <content-column
@ -76,3 +77,5 @@
</content-actions> </content-actions>
</alfresco-document-list> </alfresco-document-list>
</alfresco-upload-drag-area> </alfresco-upload-drag-area>
<alfresco-upload-button uploaddirectory="{{relativePath}}" (onSuccess)="refreshDocumentList($event)"></alfresco-upload-button>

View File

@ -39,7 +39,7 @@ export class FilesComponent {
breadcrumb: boolean = false; breadcrumb: boolean = false;
navigation: boolean = true; navigation: boolean = true;
events: any[] = []; events: any[] = [];
absolutePath: string = ''; absolutePath: string = '/Sites/swsdp/documentLibrary';
relativePath: string = ''; relativePath: string = '';
constructor(documentActions: DocumentActionsService) { constructor(documentActions: DocumentActionsService) {
@ -63,11 +63,15 @@ export class FilesComponent {
this.relativePath = this.getRelativeDirectory(this.absolutePath); this.relativePath = this.getRelativeDirectory(this.absolutePath);
} }
refreshDocumentList(event: Object) {
this.absolutePath += '/';
}
getRelativeDirectory(currentFolderPath: string): string { getRelativeDirectory(currentFolderPath: string): string {
if(currentFolderPath.indexOf('swsdp/documentLibrary/') !=-1) { if(currentFolderPath.indexOf('/Sites/swsdp/documentLibrary/') !=-1) {
return currentFolderPath.replace('swsdp/documentLibrary/', '') return currentFolderPath.replace('/Sites/swsdp/documentLibrary/', '')
} else { } else {
return currentFolderPath.replace('swsdp/documentLibrary', '') return currentFolderPath.replace('/Sites/swsdp/documentLibrary', '')
} }
} }
} }

View File

@ -24,7 +24,6 @@ import {
AfterContentInit, AfterContentInit,
AfterViewChecked AfterViewChecked
} from 'angular2/core'; } from 'angular2/core';
import { AlfrescoService } from './../services/alfresco.service'; import { AlfrescoService } from './../services/alfresco.service';
import { MinimalNodeEntity, NodePaging } from './../models/document-library.model'; import { MinimalNodeEntity, NodePaging } from './../models/document-library.model';
import { ContentActionModel } from './../models/content-action.model'; import { ContentActionModel } from './../models/content-action.model';
@ -42,6 +41,8 @@ declare let __moduleName: string;
}) })
export class DocumentList implements OnInit, AfterViewChecked, AfterContentInit { export class DocumentList implements OnInit, AfterViewChecked, AfterContentInit {
DEFAULT_ROOT_FOLDER: string = '/Sites/swsdp/documentLibrary';
@Input() @Input()
navigate: boolean = true; navigate: boolean = true;
@ -58,10 +59,13 @@ export class DocumentList implements OnInit, AfterViewChecked, AfterContentInit
folderClick: EventEmitter<any> = new EventEmitter(); folderClick: EventEmitter<any> = new EventEmitter();
rootFolder = { rootFolder = {
name: 'Document Library', name: '',
path: 'Sites/swsdp/documentLibrary' path: ''
}; };
currentFolderPath: string = 'Sites/swsdp/documentLibrary';
@Input()
currentFolderPath: string;
folder: NodePaging; folder: NodePaging;
errorMessage; errorMessage;
@ -82,11 +86,26 @@ export class DocumentList implements OnInit, AfterViewChecked, AfterContentInit
constructor(private _alfrescoService: AlfrescoService) { constructor(private _alfrescoService: AlfrescoService) {
} }
_createRootFolder(): any {
let folderArray = this.currentFolderPath.split('/');
let nameFolder = folderArray[folderArray.length - 1];
return {
name: nameFolder,
path: this.currentFolderPath
};
}
ngOnInit() { ngOnInit() {
this.currentFolderPath = this.currentFolderPath || this.DEFAULT_ROOT_FOLDER;
this.rootFolder = this._createRootFolder();
this.route.push(this.rootFolder); this.route.push(this.rootFolder);
this.displayFolderContent(this.rootFolder.path); this.displayFolderContent(this.rootFolder.path);
} }
ngOnChanges(change) {
this.reload();
}
ngAfterContentInit() { ngAfterContentInit() {
if (!this.columns || this.columns.length === 0) { if (!this.columns || this.columns.length === 0) {
this.setupDefaultColumns(); this.setupDefaultColumns();
@ -133,6 +152,9 @@ export class DocumentList implements OnInit, AfterViewChecked, AfterContentInit
this.route.pop(); this.route.pop();
let parent = this.route.length > 0 ? this.route[this.route.length - 1] : this.rootFolder; let parent = this.route.length > 0 ? this.route[this.route.length - 1] : this.rootFolder;
if (parent) { if (parent) {
this.folderClick.emit({
value: parent.path
});
this.displayFolderContent(parent.path); this.displayFolderContent(parent.path);
} }
} }
@ -152,8 +174,8 @@ export class DocumentList implements OnInit, AfterViewChecked, AfterContentInit
value: item value: item
}); });
if (this.navigate && item) { if (this.navigate && item && item.entry) {
if (item.entry && item.entry.isFolder) { if (item.entry.isFolder) {
let path = this.getNodePath(item); let path = this.getNodePath(item);
this.folderClick.emit({ this.folderClick.emit({

View File

@ -68,26 +68,14 @@ export class AlfrescoService {
} }
private getNodesPromise(folder: string) { private getNodesPromise(folder: string) {
let alfrescoClient = this.getAlfrescoClient(); let alfrescoClient = this.getAlfrescoClient();
return new Promise(function (resolve, reject) {
let apiInstance = new AlfrescoApi.NodesApi(alfrescoClient); let apiInstance = new AlfrescoApi.NodesApi(alfrescoClient);
let nodeId = '-root-'; let nodeId = '-root-';
let opts = { let opts = {
relativePath: folder, relativePath: folder,
include: ['path'] include: ['path']
}; };
let callback = function (error, data /*, response*/) { return apiInstance.getNodeChildren(nodeId, opts);
if (error) {
console.error(error);
reject(error);
} else {
console.log('API returned data', data);
resolve(data);
}
};
apiInstance.getNodeChildren(nodeId, opts, callback);
});
} }
/** /**

View File

@ -22,7 +22,7 @@ import { AlfrescoAuthenticationService } from '../../src/services/alfresco-authe
export class AuthenticationMock { export class AuthenticationMock {
login(method: string, username: string, password: string) { login(username: string, password: string) {
if (username === 'fake-username' && password === 'fake-password') { if (username === 'fake-username' && password === 'fake-password') {
return Observable.of(true); return Observable.of(true);
} else { } else {

View File

@ -33,8 +33,6 @@ declare let __moduleName: string;
}) })
export class AlfrescoLoginComponent { export class AlfrescoLoginComponent {
@Input()
method: string = 'POST';
@Output() @Output()
onSuccess = new EventEmitter(); onSuccess = new EventEmitter();
@Output() @Output()
@ -97,7 +95,7 @@ export class AlfrescoLoginComponent {
if (event) { if (event) {
event.preventDefault(); event.preventDefault();
} }
this.auth.login(this.method, value.username, value.password) this.auth.login(value.username, value.password)
.subscribe( .subscribe(
(token: any) => { (token: any) => {
try { try {

View File

@ -29,7 +29,7 @@ export class AlfrescoAuthenticationService {
token: string; token: string;
private _host: string = 'http://192.168.99.100:8080'; private _host: string = 'http://192.168.99.100:8080';
private _baseUrl: string = this._host + '/alfresco/service/api/'; private _baseUrl: string = this._host + '/alfresco/api/-default-/public/authentication/versions/1';
/** /**
* Constructor * Constructor
@ -48,40 +48,13 @@ export class AlfrescoAuthenticationService {
} }
/** /**
* Method to delegate GET or POST login * Method to delegate to POST login
* @param method
* @param username * @param username
* @param password * @param password
* @returns {Observable<R>|Observable<T>} * @returns {Observable<R>|Observable<T>}
*/ */
login(method: string, username: string, password: string) { login(username: string, password: string) {
if (method === 'GET') {
return this.loginGet(username, password);
} else if (method === 'POST') {
return this.loginPost(username, password); return this.loginPost(username, password);
} else {
return Observable.throw('Invalid method name the value should be GET or POST');
}
}
/**
* The method provide the login with GET Request
* @param username
* @param password
* @returns {Observable<R>|Observable<T>}
*/
loginGet(username: string, password: string) {
const searchParams = new URLSearchParams();
searchParams.set('u', username);
searchParams.set('pw', password);
return this.http.get(this._baseUrl + 'login', {search: searchParams})
.map((res: any) => {
let data = JSON.parse(xml2json(res.text(), ' '));
this.token = data.ticket;
this.saveJwt(this.token);
})
.catch(this.handleError);
} }
/** /**
@ -91,22 +64,43 @@ export class AlfrescoAuthenticationService {
* @returns {Observable<R>|Observable<T>} * @returns {Observable<R>|Observable<T>}
*/ */
loginPost(username: string, password: string) { loginPost(username: string, password: string) {
let credentials = '{ username: ' + username + ', password: ' + password + ' }'; let credentials = '{ "userId": "' + username + '", "password": "' + password + '" }';
let headers = new Headers(); let headers = new Headers();
headers.append('Content-Type', 'application/json'); headers.append('Content-Type', 'application/json');
headers.append('Accept', 'application/json');
return this.http.post(this._baseUrl + 'login', credentials, { return this.http.post(this._baseUrl + '/tickets', credentials, {
headers: headers headers: headers
}) })
.map((res: any) => { .map((res: any) => {
let response = res.json(); let response = res.json();
this.token = response.data.ticket; this.token = response.entry.id;
this.saveJwt(this.token); this.saveJwt(this.token);
}) })
.catch(this.handleError); .catch(this.handleError);
} }
/**
* Delete the current login ticket from the server
*
* @returns {Observable<R>|Observable<T>}
*/
loginDelete() {
let headers = new Headers();
headers.append('Content-Type', 'application/json');
headers.append('Authorization', 'Basic ' + btoa(this.token));
return this.http.delete(this._baseUrl + '/tickets/-me-', {
headers: headers
})
.map((res: any) => {
this.removeJwt();
this.token = undefined;
})
.catch(this.handleError);
}
/** /**
* The method save the toke in the localStorage * The method save the toke in the localStorage
* @param jwt * @param jwt
@ -117,15 +111,19 @@ export class AlfrescoAuthenticationService {
} }
} }
/**
* Remove the login token from localStorage
*/
removeJwt() {
localStorage.removeItem('token');
}
/** /**
* The method remove the token from the local storage * The method remove the token from the local storage
* @returns {Observable<T>} * @returns {Observable<T>}
*/ */
logout() { logout() {
this.token = undefined; return this.loginDelete();
localStorage.removeItem('token');
return Observable.of(true);
} }
/** /**
@ -134,7 +132,7 @@ export class AlfrescoAuthenticationService {
* @returns {ErrorObservable} * @returns {ErrorObservable}
*/ */
private handleError(error: Response) { private handleError(error: Response) {
console.error(error.json().message); console.error('Error when logging in', error);
return Observable.throw(error.json().message || 'Server error'); return Observable.throw(error.json().message || 'Server error');
} }
} }