From de79e736f69fdb4bece1011c89bd2f1c08ae0f53 Mon Sep 17 00:00:00 2001 From: Denys Vuika Date: Tue, 31 Oct 2017 14:49:13 +0000 Subject: [PATCH] pagination enhancements and fixes (#2579) --- .../document-list.component.spec.ts | 24 ++++++++++++++++++- .../src/components/document-list.component.ts | 16 +++++++++++-- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/ng2-components/ng2-alfresco-documentlist/src/components/document-list.component.spec.ts b/ng2-components/ng2-alfresco-documentlist/src/components/document-list.component.spec.ts index bf6a29dbde..5bf973b9f8 100644 --- a/ng2-components/ng2-alfresco-documentlist/src/components/document-list.component.spec.ts +++ b/ng2-components/ng2-alfresco-documentlist/src/components/document-list.component.spec.ts @@ -18,7 +18,7 @@ import { CUSTOM_ELEMENTS_SCHEMA, NgZone, SimpleChange, TemplateRef } from '@angular/core'; import { async, ComponentFixture, TestBed } from '@angular/core/testing'; import { Pagination } from 'alfresco-js-api'; -import { AlfrescoApiService, AlfrescoTranslationService, CoreModule } from 'ng2-alfresco-core'; +import { AlfrescoApiService, AlfrescoTranslationService, AppConfigService, CoreModule, UserPreferencesService } from 'ng2-alfresco-core'; import { DataColumn, DataTableComponent } from 'ng2-alfresco-datatable'; import { DataTableModule } from 'ng2-alfresco-datatable'; import { Observable, Subject } from 'rxjs/Rx'; @@ -48,6 +48,8 @@ describe('DocumentList', () => { let fixture: ComponentFixture; let element: HTMLElement; let eventMock: any; + let appConfig: AppConfigService; + let userPreferences: UserPreferencesService; beforeEach(async(() => { let zone = new NgZone({enableLongStackTrace: false}); @@ -86,6 +88,9 @@ describe('DocumentList', () => { documentList = fixture.componentInstance; documentListService = TestBed.get(DocumentListService); apiService = TestBed.get(AlfrescoApiService); + userPreferences = TestBed.get(UserPreferencesService); + appConfig = TestBed.get(AppConfigService); + fixture.detectChanges(); }); @@ -996,4 +1001,21 @@ describe('DocumentList', () => { expect(documentList.folderNode).toBeNull(); }); + + it('should fallback to first page size supported', () => { + userPreferences.paginationSize = 10; + appConfig.config = Object.assign(appConfig.config, { + 'document-list': { + supportedPageSizes: [20, 30, 40] + } + }); + + let customFixture = TestBed.createComponent(DocumentListComponent); + let component: DocumentListComponent = customFixture.componentInstance; + + customFixture.detectChanges(); + + expect(component.supportedPageSizes).toEqual([20, 30, 40]); + expect(component.pageSize).toBe(20); + }); }); diff --git a/ng2-components/ng2-alfresco-documentlist/src/components/document-list.component.ts b/ng2-components/ng2-alfresco-documentlist/src/components/document-list.component.ts index ea76222704..d0864d3276 100644 --- a/ng2-components/ng2-alfresco-documentlist/src/components/document-list.component.ts +++ b/ng2-components/ng2-alfresco-documentlist/src/components/document-list.component.ts @@ -167,6 +167,7 @@ export class DocumentListComponent implements OnInit, OnChanges, AfterContentIni private layoutPresets = {}; private currentNodeAllowableOperations: string[] = []; private CREATE_PERMISSION = 'create'; + private defaultPageSizes = [5, 10, 15, 20]; constructor(private documentListService: DocumentListService, private ngZone: NgZone, @@ -174,7 +175,7 @@ export class DocumentListComponent implements OnInit, OnChanges, AfterContentIni private apiService: AlfrescoApiService, private appConfig: AppConfigService, private preferences: UserPreferencesService) { - this.supportedPageSizes = appConfig.get('document-list.supportedPageSizes', [5, 10, 15, 20]); + this.supportedPageSizes = appConfig.get('document-list.supportedPageSizes', this.defaultPageSizes); } getContextActions(node: MinimalNodeEntity) { @@ -203,8 +204,19 @@ export class DocumentListComponent implements OnInit, OnChanges, AfterContentIni return this.columnList && this.columnList.columns && this.columnList.columns.length > 0; } + getDefaultPageSize(): number { + let result = this.preferences.paginationSize; + + const pageSizes = this.supportedPageSizes || this.defaultPageSizes; + if (pageSizes && pageSizes.length > 0 && pageSizes.indexOf(result) < 0) { + result = pageSizes[0]; + } + + return result; + } + ngOnInit() { - this.pageSize = this.preferences.paginationSize; + this.pageSize = this.getDefaultPageSize(); this.loadLayoutPresets(); this.data = new ShareDataTableAdapter(this.documentListService, null, this.getDefaultSorting()); this.data.thumbnails = this.thumbnails;