[ACA-2005] Trash - display library name (#805)

* library title and tooltip

* test
This commit is contained in:
Cilibiu Bogdan
2018-11-16 21:40:14 +02:00
committed by Denys Vuika
parent 8b1b7a78cc
commit 760de2f762
2 changed files with 124 additions and 4 deletions

View File

@@ -26,7 +26,89 @@
import { TrashcanNameColumnComponent } from './trashcan-name-column.component';
describe('TrashcanNameColumnComponent', () => {
it('should be defined', () => {
expect(TrashcanNameColumnComponent).toBeDefined();
let component;
beforeEach(() => {
component = new TrashcanNameColumnComponent();
});
it('should set displayText for content files', () => {
const context = {
data: { rows: [] },
row: {
node: {
entry: {
name: 'contentName',
nodeType: 'content'
}
}
}
};
component.context = context;
component.ngOnInit();
expect(component.displayText).toBe('contentName');
});
it('should set displayText for library', () => {
const context = {
data: {
rows: []
},
row: {
node: {
entry: {
nodeType: 'st:site',
properties: {
'cm:title': 'libraryTitle'
}
}
}
}
};
component.context = context;
component.ngOnInit();
expect(component.displayText).toBe('libraryTitle');
});
it('should set custom displayText for libraries with same name', () => {
const context = {
data: {
rows: [
{
node: {
entry: {
id: 'id1',
name: 'name1',
nodeType: 'st:site',
properties: {
'cm:title': 'bogus'
}
}
}
}
]
},
row: {
node: {
entry: {
id: 'id2',
name: 'name1',
nodeType: 'st:site',
properties: {
'cm:title': 'bogus'
}
}
}
}
};
component.context = context;
component.ngOnInit();
expect(component.displayText).toBe('bogus (name1)');
});
});

View File

@@ -30,12 +30,18 @@ import {
OnInit,
Input
} from '@angular/core';
import { ShareDataRow } from '@alfresco/adf-content-services';
import { MinimalNodeEntity } from 'alfresco-js-api';
@Component({
selector: 'app-trashcan-name-column',
template: `
<span title="{{ node | adfNodeNameTooltip }}">{{ displayText }}</span>
<ng-container *ngIf="!isLibrary">
<span title="{{ node | adfNodeNameTooltip }}">{{ displayText }}</span>
</ng-container>
<ng-container *ngIf="isLibrary">
<span title="{{ displayTooltip }}">{{ displayText }}</span>
</ng-container>
`,
changeDetection: ChangeDetectionStrategy.OnPush,
encapsulation: ViewEncapsulation.None,
@@ -45,13 +51,45 @@ export class TrashcanNameColumnComponent implements OnInit {
@Input()
context: any;
isLibrary = false;
displayText: string;
displayTooltip: string;
node: MinimalNodeEntity;
ngOnInit() {
this.node = this.context.row.node;
const rows: Array<ShareDataRow> = this.context.data.rows || [];
if (this.node && this.node.entry) {
this.displayText = this.node.entry.name || this.node.entry.id;
this.isLibrary = this.node.entry.nodeType === 'st:site';
if (this.isLibrary) {
const { properties } = this.node.entry;
this.displayText = this.makeLibraryTitle(this.node.entry, rows);
this.displayTooltip =
properties['cm:description'] || properties['cm:title'];
} else {
this.displayText = this.node.entry.name || this.node.entry.id;
}
}
}
makeLibraryTitle(library: any, rows: Array<ShareDataRow>): string {
const entries = rows.map((r: ShareDataRow) => r.node.entry);
const { id } = library;
const title = library.properties['cm:title'];
let isDuplicate = false;
if (entries) {
isDuplicate = entries.some((entry: any) => {
return entry.id !== id && entry.properties['cm:title'] === title;
});
}
return isDuplicate
? `${library.properties['cm:title']} (${library.name})`
: `${library.properties['cm:title']}`;
}
}