mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-05-26 17:24:56 +00:00
pagination enhancements and fixes (#2579)
This commit is contained in:
parent
4d8dd7ebb5
commit
de79e736f6
@ -18,7 +18,7 @@
|
|||||||
import { CUSTOM_ELEMENTS_SCHEMA, NgZone, SimpleChange, TemplateRef } from '@angular/core';
|
import { CUSTOM_ELEMENTS_SCHEMA, NgZone, SimpleChange, TemplateRef } from '@angular/core';
|
||||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
import { Pagination } from 'alfresco-js-api';
|
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 { DataColumn, DataTableComponent } from 'ng2-alfresco-datatable';
|
||||||
import { DataTableModule } from 'ng2-alfresco-datatable';
|
import { DataTableModule } from 'ng2-alfresco-datatable';
|
||||||
import { Observable, Subject } from 'rxjs/Rx';
|
import { Observable, Subject } from 'rxjs/Rx';
|
||||||
@ -48,6 +48,8 @@ describe('DocumentList', () => {
|
|||||||
let fixture: ComponentFixture<DocumentListComponent>;
|
let fixture: ComponentFixture<DocumentListComponent>;
|
||||||
let element: HTMLElement;
|
let element: HTMLElement;
|
||||||
let eventMock: any;
|
let eventMock: any;
|
||||||
|
let appConfig: AppConfigService;
|
||||||
|
let userPreferences: UserPreferencesService;
|
||||||
|
|
||||||
beforeEach(async(() => {
|
beforeEach(async(() => {
|
||||||
let zone = new NgZone({enableLongStackTrace: false});
|
let zone = new NgZone({enableLongStackTrace: false});
|
||||||
@ -86,6 +88,9 @@ describe('DocumentList', () => {
|
|||||||
documentList = fixture.componentInstance;
|
documentList = fixture.componentInstance;
|
||||||
documentListService = TestBed.get(DocumentListService);
|
documentListService = TestBed.get(DocumentListService);
|
||||||
apiService = TestBed.get(AlfrescoApiService);
|
apiService = TestBed.get(AlfrescoApiService);
|
||||||
|
userPreferences = TestBed.get(UserPreferencesService);
|
||||||
|
appConfig = TestBed.get(AppConfigService);
|
||||||
|
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -996,4 +1001,21 @@ describe('DocumentList', () => {
|
|||||||
|
|
||||||
expect(documentList.folderNode).toBeNull();
|
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);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@ -167,6 +167,7 @@ export class DocumentListComponent implements OnInit, OnChanges, AfterContentIni
|
|||||||
private layoutPresets = {};
|
private layoutPresets = {};
|
||||||
private currentNodeAllowableOperations: string[] = [];
|
private currentNodeAllowableOperations: string[] = [];
|
||||||
private CREATE_PERMISSION = 'create';
|
private CREATE_PERMISSION = 'create';
|
||||||
|
private defaultPageSizes = [5, 10, 15, 20];
|
||||||
|
|
||||||
constructor(private documentListService: DocumentListService,
|
constructor(private documentListService: DocumentListService,
|
||||||
private ngZone: NgZone,
|
private ngZone: NgZone,
|
||||||
@ -174,7 +175,7 @@ export class DocumentListComponent implements OnInit, OnChanges, AfterContentIni
|
|||||||
private apiService: AlfrescoApiService,
|
private apiService: AlfrescoApiService,
|
||||||
private appConfig: AppConfigService,
|
private appConfig: AppConfigService,
|
||||||
private preferences: UserPreferencesService) {
|
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) {
|
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;
|
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() {
|
ngOnInit() {
|
||||||
this.pageSize = this.preferences.paginationSize;
|
this.pageSize = this.getDefaultPageSize();
|
||||||
this.loadLayoutPresets();
|
this.loadLayoutPresets();
|
||||||
this.data = new ShareDataTableAdapter(this.documentListService, null, this.getDefaultSorting());
|
this.data = new ShareDataTableAdapter(this.documentListService, null, this.getDefaultSorting());
|
||||||
this.data.thumbnails = this.thumbnails;
|
this.data.thumbnails = this.thumbnails;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user