mirror of
https://github.com/Alfresco/alfresco-content-app.git
synced 2025-09-17 14:21:14 +00:00
improved diplay name and tooltip for Location column
This commit is contained in:
@@ -1,12 +1,14 @@
|
|||||||
import { Component, Input, ChangeDetectionStrategy, OnInit, ViewEncapsulation } from '@angular/core';
|
import { Component, Input, ChangeDetectionStrategy, OnInit, ViewEncapsulation } from '@angular/core';
|
||||||
import { DataColumn, DataRow, DataTableAdapter } from 'ng2-alfresco-datatable';
|
import { DataColumn, DataRow, DataTableAdapter } from 'ng2-alfresco-datatable';
|
||||||
import { PathInfoEntity } from 'alfresco-js-api';
|
import { AlfrescoApiService } from 'ng2-alfresco-core';
|
||||||
|
import { PathInfoEntity, AlfrescoApi } from 'alfresco-js-api';
|
||||||
|
import { Observable } from 'rxjs/Rx';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-location-link',
|
selector: 'app-location-link',
|
||||||
template: `
|
template: `
|
||||||
<a href="" [title]="tooltip" [routerLink]="link">
|
<a href="" [title]="tooltip | async" [routerLink]="link">
|
||||||
{{ displayText }}
|
{{ displayText | async }}
|
||||||
</a>
|
</a>
|
||||||
`,
|
`,
|
||||||
changeDetection: ChangeDetectionStrategy.OnPush,
|
changeDetection: ChangeDetectionStrategy.OnPush,
|
||||||
@@ -25,10 +27,13 @@ export class LocationLinkComponent implements OnInit {
|
|||||||
link: any[];
|
link: any[];
|
||||||
|
|
||||||
@Input()
|
@Input()
|
||||||
displayText = '';
|
displayText: Observable<string>;
|
||||||
|
|
||||||
@Input()
|
@Input()
|
||||||
tooltip = '';
|
tooltip: Observable<string>;
|
||||||
|
|
||||||
|
constructor(private apiService: AlfrescoApiService) {
|
||||||
|
}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
if (this.context) {
|
if (this.context) {
|
||||||
@@ -58,27 +63,81 @@ export class LocationLinkComponent implements OnInit {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private getDisplayText(path: PathInfoEntity): string {
|
// todo: review once 5.2.3 is out
|
||||||
let result = path.elements[path.elements.length - 1].name;
|
private getDisplayText(path: PathInfoEntity): Observable<string> {
|
||||||
|
const elements = path.elements.map(e => e.name);
|
||||||
|
|
||||||
if (result === 'documentLibrary') {
|
// for admin users
|
||||||
result = path.elements[path.elements.length - 2].name;
|
if (elements.length === 1 && elements[0] === 'Company Home') {
|
||||||
|
return Observable.of('Personal Files');
|
||||||
}
|
}
|
||||||
|
|
||||||
result = result.replace('Company Home', 'Personal Files');
|
// for non-admin users
|
||||||
|
if (elements.length === 3 && elements[0] === 'Company Home' && elements[1] === 'User Homes') {
|
||||||
|
return Observable.of('Personal Files');
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
const result = elements[elements.length - 1];
|
||||||
|
|
||||||
|
if (result === 'documentLibrary') {
|
||||||
|
const fragment = path.elements[path.elements.length - 2];
|
||||||
|
|
||||||
|
return new Observable<string>(observer => {
|
||||||
|
this.apiService.nodesApi.getNodeInfo(fragment.id).then(
|
||||||
|
(node) => {
|
||||||
|
observer.next(node.properties['cm:title'] || node.name || fragment.name);
|
||||||
|
observer.complete();
|
||||||
|
},
|
||||||
|
(err) => {
|
||||||
|
observer.next(fragment.name);
|
||||||
|
observer.complete();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return Observable.of(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
// todo: review once 5.2.3 is out
|
// todo: review once 5.2.3 is out
|
||||||
private getTooltip(path: PathInfoEntity): string {
|
private getTooltip(path: PathInfoEntity): Observable<string> {
|
||||||
let result = path.name;
|
const elements = path.elements.map(e => Object.assign({}, e));
|
||||||
|
|
||||||
result = result.replace('documentLibrary/', '');
|
if (elements[0].name === 'Company Home') {
|
||||||
result = result.replace('/documentLibrary', '');
|
if (elements[1].name === 'Sites') {
|
||||||
result = result.replace('/Company Home/Sites', 'File Libraries');
|
const fragment = elements[2];
|
||||||
result = result.replace('/Company Home', 'Personal Files');
|
|
||||||
|
|
||||||
return result;
|
return new Observable<string>(observer => {
|
||||||
|
this.apiService.nodesApi.getNodeInfo(fragment.id).then(
|
||||||
|
(node) => {
|
||||||
|
elements.splice(0, 2);
|
||||||
|
elements[0].name = node.properties['cm:title'] || node.name || fragment.name;
|
||||||
|
elements.splice(1, 1);
|
||||||
|
elements.unshift({ id: null, name: 'File Libraries' });
|
||||||
|
|
||||||
|
observer.next(elements.map(e => e.name).join('/'));
|
||||||
|
observer.complete();
|
||||||
|
},
|
||||||
|
(err) => {
|
||||||
|
elements.splice(0, 2);
|
||||||
|
elements.unshift({ id: null, name: 'File Libraries' });
|
||||||
|
elements.splice(2, 1);
|
||||||
|
|
||||||
|
observer.next(elements.map(e => e.name).join('/'));
|
||||||
|
observer.complete();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
if (elements[1].name === 'User Homes') {
|
||||||
|
elements.splice(0, 3);
|
||||||
|
elements.unshift({ id: null, name: 'Personal Files'});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = elements.map(e => e.name).join('/');
|
||||||
|
return Observable.of(result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user