separate column templates from doc list (#700)

* use standard date columns

* use standard file size column

* name column component

* library name template

* library status column

* enable tests

* trashcan name column template
This commit is contained in:
Denys Vuika
2018-10-10 10:44:44 +01:00
committed by GitHub
parent d8ad020394
commit 796c6587a8
18 changed files with 561 additions and 204 deletions

View File

@@ -24,7 +24,8 @@
selectionMode="single"
[navigate]="false"
[sorting]="[ 'title', 'asc' ]"
(node-dblclick)="navigateTo($event.detail?.node)">
(node-dblclick)="navigateTo($event.detail?.node)"
(name-click)="navigateTo($event.detail?.node)">
<empty-folder-content>
<ng-template>
@@ -49,12 +50,7 @@
key="title"
title="APP.DOCUMENT_LIST.COLUMNS.TITLE">
<ng-template let-context>
<span
class="adf-datatable-cell dl-link"
title="{{ makeLibraryTooltip(context.row.obj.entry) }}"
(click)="navigateTo(context?.row?.obj)">
{{ makeLibraryTitle(context.row.obj.entry) }}
</span>
<app-library-name-column [context]="context"></app-library-name-column>
</ng-template>
</data-column>
@@ -62,16 +58,8 @@
*ngIf="!isSmallScreen"
key="visibility"
title="APP.DOCUMENT_LIST.COLUMNS.STATUS">
<ng-template let-value="value">
<span *ngIf="(value == 'PUBLIC')" title="{{ 'APP.SITES_VISIBILITY.PUBLIC' | translate }}">
{{ 'APP.SITES_VISIBILITY.PUBLIC' | translate }}
</span>
<span *ngIf="(value == 'PRIVATE')" title="{{ 'APP.SITES_VISIBILITY.PRIVATE' | translate }}">
{{ 'APP.SITES_VISIBILITY.PRIVATE' | translate }}
</span>
<span *ngIf="(value == 'MODERATED')" title="{{ 'APP.SITES_VISIBILITY.MODERATED' | translate }}">
{{ 'APP.SITES_VISIBILITY.MODERATED' | translate }}
</span>
<ng-template let-context>
<app-library-status-column [context]="context"></app-library-status-column>
</ng-template>
</data-column>
</data-columns>

View File

@@ -24,7 +24,6 @@
*/
import { TestBed, ComponentFixture } from '@angular/core/testing';
import { of } from 'rxjs';
import { NO_ERRORS_SCHEMA } from '@angular/core';
import { Router } from '@angular/router';
import {
@@ -36,10 +35,8 @@ import {
AppConfigPipe
} from '@alfresco/adf-core';
import { DocumentListComponent } from '@alfresco/adf-content-services';
import { ShareDataTableAdapter } from '@alfresco/adf-content-services';
import { LibrariesComponent } from './libraries.component';
import { AppTestingModule } from '../../testing/app-testing.module';
import { ContentApiService } from '../../services/content-api.service';
import { ExperimentalDirective } from '../../directives/experimental.directive';
import { EffectsModule } from '@ngrx/effects';
import { LibraryEffects } from 'src/app/store/effects';
@@ -47,11 +44,9 @@ import { LibraryEffects } from 'src/app/store/effects';
describe('LibrariesComponent', () => {
let fixture: ComponentFixture<LibrariesComponent>;
let component: LibrariesComponent;
let contentApi: ContentApiService;
let alfrescoApi: AlfrescoApiService;
let router: Router;
let page;
let node;
beforeEach(() => {
page = {
@@ -60,13 +55,6 @@ describe('LibrariesComponent', () => {
pagination: { data: 'data' }
}
};
node = <any>{
id: 'nodeId',
path: {
elements: []
}
};
});
beforeEach(() => {
@@ -98,100 +86,14 @@ describe('LibrariesComponent', () => {
spyOn(alfrescoApi.peopleApi, 'getSiteMembership').and.returnValue(
Promise.resolve({})
);
contentApi = TestBed.get(ContentApiService);
});
describe('makeLibraryTooltip()', () => {
it('maps tooltip to description', () => {
node.description = 'description';
const tooltip = component.makeLibraryTooltip(node);
expect(tooltip).toBe(node.description);
});
it('maps tooltip to description', () => {
node.title = 'title';
const tooltip = component.makeLibraryTooltip(node);
expect(tooltip).toBe(node.title);
});
it('sets tooltip to empty string', () => {
const tooltip = component.makeLibraryTooltip(node);
expect(tooltip).toBe('');
});
});
describe('makeLibraryTitle()', () => {
it('sets title with id when duplicate nodes title exists in list', () => {
node.title = 'title';
const data = new ShareDataTableAdapter(null, null);
data.setRows([
<any>{ node: { entry: { id: 'some-id', title: 'title' } } }
]);
component.documentList.data = data;
const title = component.makeLibraryTitle(node);
expect(title).toContain('nodeId');
});
it('sets title when no duplicate nodes title exists in list', () => {
node.title = 'title';
const data = new ShareDataTableAdapter(null, null);
data.setRows([
<any>{ node: { entry: { id: 'some-id', title: 'title-some-id' } } }
]);
component.documentList.data = data;
const title = component.makeLibraryTitle(node);
expect(title).toBe('title');
});
});
describe('Node navigation', () => {
it('does not navigate when id is not passed', () => {
spyOn(router, 'navigate').and.stub();
component.navigate(null);
component.navigateTo(null);
expect(router.navigate).not.toHaveBeenCalled();
});
it('navigates to node id', () => {
const document = { id: 'documentId' };
spyOn(router, 'navigate').and.stub();
spyOn(contentApi, 'getNode').and.returnValue(of({ entry: document }));
component.navigate(node.id);
expect(router.navigate).toHaveBeenCalledWith(['libraries', 'documentId']);
});
});
describe('navigateTo', () => {
it('navigates into library folder', () => {
spyOn(component, 'navigate');
const site: any = {
entry: { guid: 'node-guid' }
};
component.navigateTo(site);
expect(component.navigate).toHaveBeenCalledWith('node-guid');
});
it(' does not navigate when library is not provided', () => {
spyOn(component, 'navigate');
component.navigateTo(null);
expect(component.navigate).not.toHaveBeenCalled();
});
});
});

View File

@@ -24,7 +24,6 @@
*/
import { Component, OnInit } from '@angular/core';
import { ShareDataRow } from '@alfresco/adf-content-services';
import { BreakpointObserver, Breakpoints } from '@angular/cdk/layout';
import { PageComponent } from '../page.component';
import { Store } from '@ngrx/store';
@@ -63,35 +62,9 @@ export class LibrariesComponent extends PageComponent implements OnInit {
);
}
makeLibraryTooltip(library: any): string {
const { description, title } = library;
return description || title || '';
}
makeLibraryTitle(library: any): string {
const rows = this.documentList.data.getRows();
const entries = rows.map((r: ShareDataRow) => r.node.entry);
const { title, id } = library;
let isDuplicate = false;
if (entries) {
isDuplicate = entries.some((entry: any) => {
return entry.id !== id && entry.title === title;
});
}
return isDuplicate ? `${title} (${id})` : `${title}`;
}
navigateTo(node: SiteEntry) {
if (node && node.entry.guid) {
this.navigate(node.entry.guid);
if (node && node.entry && node.entry.guid) {
this.store.dispatch(new NavigateLibraryAction(node.entry.guid));
}
}
navigate(libraryId: string) {
this.store.dispatch(new NavigateLibraryAction(libraryId));
}
}