pagination enhancements and fixes (#2579)

This commit is contained in:
Denys Vuika 2017-10-31 14:49:13 +00:00 committed by Eugenio Romano
parent 4d8dd7ebb5
commit de79e736f6
2 changed files with 37 additions and 3 deletions

View File

@ -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<DocumentListComponent>;
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>(DocumentListComponent);
let component: DocumentListComponent = customFixture.componentInstance;
customFixture.detectChanges();
expect(component.supportedPageSizes).toEqual([20, 30, 40]);
expect(component.pageSize).toBe(20);
});
});

View File

@ -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;