mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-07 18:25:09 +00:00
Merge branch 'master' into dev-denys-coverage-fixes
# Conflicts: # ng2-components/ng2-alfresco-documentlist/src/components/document-list.ts
This commit is contained in:
commit
242d13add7
@ -1,5 +1,6 @@
|
||||
<alfresco-upload-drag-area [showUploadDialog]="true" uploaddirectory="{{relativePath}}" >
|
||||
<alfresco-document-list (folderClick)="refreshDirectyory($event)">
|
||||
<alfresco-upload-drag-area [showUploadDialog]="true" uploaddirectory="{{relativePath}}"
|
||||
(onSuccess)="refreshDocumentList($event)">
|
||||
<alfresco-document-list (folderClick)="refreshDirectyory($event)" currentFolderPath="{{absolutePath}}">
|
||||
<content-columns>
|
||||
<content-column source="$thumbnail"></content-column>
|
||||
<content-column
|
||||
@ -76,3 +77,5 @@
|
||||
</content-actions>
|
||||
</alfresco-document-list>
|
||||
</alfresco-upload-drag-area>
|
||||
|
||||
<alfresco-upload-button uploaddirectory="{{relativePath}}" (onSuccess)="refreshDocumentList($event)"></alfresco-upload-button>
|
@ -39,7 +39,7 @@ export class FilesComponent {
|
||||
breadcrumb: boolean = false;
|
||||
navigation: boolean = true;
|
||||
events: any[] = [];
|
||||
absolutePath: string = '';
|
||||
absolutePath: string = '/Sites/swsdp/documentLibrary';
|
||||
relativePath: string = '';
|
||||
|
||||
constructor(documentActions: DocumentActionsService) {
|
||||
@ -63,11 +63,15 @@ export class FilesComponent {
|
||||
this.relativePath = this.getRelativeDirectory(this.absolutePath);
|
||||
}
|
||||
|
||||
refreshDocumentList(event: Object) {
|
||||
this.absolutePath += '/';
|
||||
}
|
||||
|
||||
getRelativeDirectory(currentFolderPath: string): string {
|
||||
if(currentFolderPath.indexOf('swsdp/documentLibrary/') !=-1) {
|
||||
return currentFolderPath.replace('swsdp/documentLibrary/', '')
|
||||
if(currentFolderPath.indexOf('/Sites/swsdp/documentLibrary/') !=-1) {
|
||||
return currentFolderPath.replace('/Sites/swsdp/documentLibrary/', '')
|
||||
} else {
|
||||
return currentFolderPath.replace('swsdp/documentLibrary', '')
|
||||
return currentFolderPath.replace('/Sites/swsdp/documentLibrary', '')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -24,7 +24,6 @@ import {
|
||||
AfterContentInit,
|
||||
AfterViewChecked
|
||||
} from 'angular2/core';
|
||||
|
||||
import { AlfrescoService } from './../services/alfresco.service';
|
||||
import { MinimalNodeEntity, NodePaging } from './../models/document-library.model';
|
||||
import { ContentActionModel } from './../models/content-action.model';
|
||||
@ -42,6 +41,8 @@ declare let __moduleName: string;
|
||||
})
|
||||
export class DocumentList implements OnInit, AfterViewChecked, AfterContentInit {
|
||||
|
||||
DEFAULT_ROOT_FOLDER: string = '/Sites/swsdp/documentLibrary';
|
||||
|
||||
@Input()
|
||||
navigate: boolean = true;
|
||||
|
||||
@ -58,10 +59,13 @@ export class DocumentList implements OnInit, AfterViewChecked, AfterContentInit
|
||||
folderClick: EventEmitter<any> = new EventEmitter();
|
||||
|
||||
rootFolder = {
|
||||
name: 'Document Library',
|
||||
path: 'Sites/swsdp/documentLibrary'
|
||||
name: '',
|
||||
path: ''
|
||||
};
|
||||
currentFolderPath: string = 'Sites/swsdp/documentLibrary';
|
||||
|
||||
@Input()
|
||||
currentFolderPath: string;
|
||||
|
||||
folder: NodePaging;
|
||||
errorMessage;
|
||||
|
||||
@ -82,11 +86,26 @@ export class DocumentList implements OnInit, AfterViewChecked, AfterContentInit
|
||||
constructor(private _alfrescoService: AlfrescoService) {
|
||||
}
|
||||
|
||||
_createRootFolder(): any {
|
||||
let folderArray = this.currentFolderPath.split('/');
|
||||
let nameFolder = folderArray[folderArray.length - 1];
|
||||
return {
|
||||
name: nameFolder,
|
||||
path: this.currentFolderPath
|
||||
};
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.currentFolderPath = this.currentFolderPath || this.DEFAULT_ROOT_FOLDER;
|
||||
this.rootFolder = this._createRootFolder();
|
||||
this.route.push(this.rootFolder);
|
||||
this.displayFolderContent(this.rootFolder.path);
|
||||
}
|
||||
|
||||
ngOnChanges(change) {
|
||||
this.reload();
|
||||
}
|
||||
|
||||
ngAfterContentInit() {
|
||||
if (!this.columns || this.columns.length === 0) {
|
||||
this.setupDefaultColumns();
|
||||
@ -133,6 +152,9 @@ export class DocumentList implements OnInit, AfterViewChecked, AfterContentInit
|
||||
this.route.pop();
|
||||
let parent = this.route.length > 0 ? this.route[this.route.length - 1] : this.rootFolder;
|
||||
if (parent) {
|
||||
this.folderClick.emit({
|
||||
value: parent.path
|
||||
});
|
||||
this.displayFolderContent(parent.path);
|
||||
}
|
||||
}
|
||||
@ -152,8 +174,8 @@ export class DocumentList implements OnInit, AfterViewChecked, AfterContentInit
|
||||
value: item
|
||||
});
|
||||
|
||||
if (this.navigate && item) {
|
||||
if (item.entry && item.entry.isFolder) {
|
||||
if (this.navigate && item && item.entry) {
|
||||
if (item.entry.isFolder) {
|
||||
let path = this.getNodePath(item);
|
||||
|
||||
this.folderClick.emit({
|
||||
|
@ -68,26 +68,14 @@ export class AlfrescoService {
|
||||
}
|
||||
|
||||
private getNodesPromise(folder: string) {
|
||||
|
||||
let alfrescoClient = this.getAlfrescoClient();
|
||||
return new Promise(function (resolve, reject) {
|
||||
let apiInstance = new AlfrescoApi.NodesApi(alfrescoClient);
|
||||
let nodeId = '-root-';
|
||||
let opts = {
|
||||
relativePath: folder,
|
||||
include: ['path']
|
||||
};
|
||||
let callback = function (error, data /*, response*/) {
|
||||
if (error) {
|
||||
console.error(error);
|
||||
reject(error);
|
||||
} else {
|
||||
console.log('API returned data', data);
|
||||
resolve(data);
|
||||
}
|
||||
};
|
||||
apiInstance.getNodeChildren(nodeId, opts, callback);
|
||||
});
|
||||
let apiInstance = new AlfrescoApi.NodesApi(alfrescoClient);
|
||||
let nodeId = '-root-';
|
||||
let opts = {
|
||||
relativePath: folder,
|
||||
include: ['path']
|
||||
};
|
||||
return apiInstance.getNodeChildren(nodeId, opts);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -22,7 +22,7 @@ import { AlfrescoAuthenticationService } from '../../src/services/alfresco-authe
|
||||
|
||||
export class AuthenticationMock {
|
||||
|
||||
login(method: string, username: string, password: string) {
|
||||
login(username: string, password: string) {
|
||||
if (username === 'fake-username' && password === 'fake-password') {
|
||||
return Observable.of(true);
|
||||
} else {
|
||||
|
@ -33,8 +33,6 @@ declare let __moduleName: string;
|
||||
|
||||
})
|
||||
export class AlfrescoLoginComponent {
|
||||
@Input()
|
||||
method: string = 'POST';
|
||||
@Output()
|
||||
onSuccess = new EventEmitter();
|
||||
@Output()
|
||||
@ -97,7 +95,7 @@ export class AlfrescoLoginComponent {
|
||||
if (event) {
|
||||
event.preventDefault();
|
||||
}
|
||||
this.auth.login(this.method, value.username, value.password)
|
||||
this.auth.login(value.username, value.password)
|
||||
.subscribe(
|
||||
(token: any) => {
|
||||
try {
|
||||
|
@ -29,7 +29,7 @@ export class AlfrescoAuthenticationService {
|
||||
token: string;
|
||||
|
||||
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
|
||||
@ -48,40 +48,13 @@ export class AlfrescoAuthenticationService {
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to delegate GET or POST login
|
||||
* @param method
|
||||
* Method to delegate to POST login
|
||||
* @param username
|
||||
* @param password
|
||||
* @returns {Observable<R>|Observable<T>}
|
||||
*/
|
||||
login(method: string, username: string, password: string) {
|
||||
if (method === 'GET') {
|
||||
return this.loginGet(username, password);
|
||||
} else if (method === 'POST') {
|
||||
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);
|
||||
login(username: string, password: string) {
|
||||
return this.loginPost(username, password);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -91,22 +64,43 @@ export class AlfrescoAuthenticationService {
|
||||
* @returns {Observable<R>|Observable<T>}
|
||||
*/
|
||||
loginPost(username: string, password: string) {
|
||||
let credentials = '{ username: ' + username + ', password: ' + password + ' }';
|
||||
let credentials = '{ "userId": "' + username + '", "password": "' + password + '" }';
|
||||
|
||||
let headers = new Headers();
|
||||
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
|
||||
})
|
||||
.map((res: any) => {
|
||||
let response = res.json();
|
||||
this.token = response.data.ticket;
|
||||
this.token = response.entry.id;
|
||||
this.saveJwt(this.token);
|
||||
})
|
||||
.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
|
||||
* @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
|
||||
* @returns {Observable<T>}
|
||||
*/
|
||||
logout() {
|
||||
this.token = undefined;
|
||||
localStorage.removeItem('token');
|
||||
|
||||
return Observable.of(true);
|
||||
return this.loginDelete();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -134,7 +132,7 @@ export class AlfrescoAuthenticationService {
|
||||
* @returns {ErrorObservable}
|
||||
*/
|
||||
private handleError(error: Response) {
|
||||
console.error(error.json().message);
|
||||
console.error('Error when logging in', error);
|
||||
return Observable.throw(error.json().message || 'Server error');
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user