Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 6 commits into from
Nov 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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)');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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']}`;
}
}