mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-05-12 17:04:57 +00:00
[AAE-10775] remove js-api dependency for pagination (#8046)
* remove js-api dependency for pagination * fix lint
This commit is contained in:
parent
d476f16a0d
commit
8efbd70679
@ -73,8 +73,9 @@ Description
|
||||
How to fix it:
|
||||
|
||||
## Deprecated items
|
||||
|
||||
|
||||
### PaginationModel
|
||||
``Pagination`` model from ```@alfresco/js-api``` has been now deprecated in favour of internal implementated model ```PaginationModel``` evrywhere
|
||||
|
||||
## Relocated classes
|
||||
|
||||
|
@ -15,13 +15,16 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { Pagination } from '@alfresco/js-api';
|
||||
export class PaginationModel {
|
||||
|
||||
export class PaginationModel extends Pagination {
|
||||
merge?: boolean;
|
||||
count?: number;
|
||||
hasMoreItems?: boolean;
|
||||
totalItems?: number;
|
||||
skipCount?: number;
|
||||
maxItems?: number;
|
||||
|
||||
constructor(input?: any) {
|
||||
super(input);
|
||||
if (input) {
|
||||
this.count = input.count;
|
||||
this.hasMoreItems = input.hasMoreItems ? input.hasMoreItems : false;
|
||||
|
@ -17,14 +17,13 @@
|
||||
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { By } from '@angular/platform-browser';
|
||||
import { Pagination } from '@alfresco/js-api';
|
||||
import { PaginationModel } from '../models/pagination.model';
|
||||
import { InfinitePaginationComponent } from './infinite-pagination.component';
|
||||
import { PaginatedComponent } from './paginated-component.interface';
|
||||
import { BehaviorSubject } from 'rxjs';
|
||||
import { setupTestBed } from '../testing/setup-test-bed';
|
||||
import { CoreTestingModule } from '../testing/core.testing.module';
|
||||
import { Component, ChangeDetectorRef } from '@angular/core';
|
||||
import { PaginationModel } from '../models/pagination.model';
|
||||
import { RequestPaginationModel } from '../models/request-pagination.model';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
|
||||
@ -57,7 +56,7 @@ describe('InfinitePaginationComponent', () => {
|
||||
|
||||
let fixture: ComponentFixture<InfinitePaginationComponent>;
|
||||
let component: InfinitePaginationComponent;
|
||||
let pagination: Pagination;
|
||||
let pagination: PaginationModel;
|
||||
let changeDetectorRef: ChangeDetectorRef;
|
||||
|
||||
setupTestBed({
|
||||
@ -119,7 +118,7 @@ describe('InfinitePaginationComponent', () => {
|
||||
});
|
||||
|
||||
it('should NOT show the load more button if there are no more elements to load', (done) => {
|
||||
pagination = { maxItems: 444, skipCount: 25, totalItems: 30, hasMoreItems: false };
|
||||
pagination = {maxItems: 444, skipCount: 25, totalItems: 30, hasMoreItems: false};
|
||||
|
||||
component.target.pagination.next(pagination);
|
||||
|
||||
@ -135,7 +134,7 @@ describe('InfinitePaginationComponent', () => {
|
||||
});
|
||||
|
||||
it('should show the load more button if there are more elements to load', (done) => {
|
||||
pagination = { maxItems: 444, skipCount: 25, totalItems: 55, hasMoreItems: true };
|
||||
pagination = {maxItems: 444, skipCount: 25, totalItems: 55, hasMoreItems: true};
|
||||
|
||||
component.target.pagination.next(pagination);
|
||||
|
||||
@ -160,7 +159,7 @@ describe('InfinitePaginationComponent', () => {
|
||||
});
|
||||
|
||||
it('should trigger the loadMore event with skipcount 0 to reload all the elements', (done) => {
|
||||
pagination = { maxItems: 444, skipCount: 25, totalItems: 55, hasMoreItems: true };
|
||||
pagination = {maxItems: 444, skipCount: 25, totalItems: 55, hasMoreItems: true};
|
||||
|
||||
component.target.pagination.next(pagination);
|
||||
|
||||
@ -168,7 +167,7 @@ describe('InfinitePaginationComponent', () => {
|
||||
component.pageSize = 5;
|
||||
changeDetectorRef.detectChanges();
|
||||
|
||||
component.loadMore.subscribe((newPagination: Pagination) => {
|
||||
component.loadMore.subscribe((newPagination: PaginationModel) => {
|
||||
expect(newPagination.skipCount).toBe(0);
|
||||
done();
|
||||
});
|
||||
@ -178,7 +177,7 @@ describe('InfinitePaginationComponent', () => {
|
||||
});
|
||||
|
||||
it('should trigger the loadMore event with merge false to reload all the elements', (done) => {
|
||||
pagination = { maxItems: 444, skipCount: 25, totalItems: 55, hasMoreItems: true };
|
||||
pagination = {maxItems: 444, skipCount: 25, totalItems: 55, hasMoreItems: true};
|
||||
|
||||
component.target.pagination.next(pagination);
|
||||
|
||||
@ -201,7 +200,7 @@ describe('InfinitePaginationComponent', () => {
|
||||
let spyTarget;
|
||||
|
||||
beforeEach(() => {
|
||||
pagination = { maxItems: 444, skipCount: 0, totalItems: 888, hasMoreItems: true };
|
||||
pagination = {maxItems: 444, skipCount: 0, totalItems: 888, hasMoreItems: true};
|
||||
|
||||
spyTarget = spyOn(component.target, 'updatePagination').and.callThrough();
|
||||
});
|
||||
@ -249,7 +248,7 @@ describe('InfinitePaginationComponent', () => {
|
||||
fixture.destroy();
|
||||
|
||||
const emitNewPaginationEvent = () => {
|
||||
const newPagination = { maxItems: 1, skipCount: 0, totalItems: 2, hasMoreItems: true };
|
||||
const newPagination = {maxItems: 1, skipCount: 0, totalItems: 2, hasMoreItems: true};
|
||||
component.target.pagination.next(newPagination);
|
||||
};
|
||||
|
||||
|
@ -26,10 +26,9 @@ import {
|
||||
import { PaginatedComponent } from './paginated-component.interface';
|
||||
import { Subject } from 'rxjs';
|
||||
import { PaginationComponentInterface } from './pagination-component.interface';
|
||||
import { PaginationModel } from '../models/pagination.model';
|
||||
import { RequestPaginationModel } from '../models/request-pagination.model';
|
||||
import { UserPreferencesService, UserPreferenceValues } from '../services/user-preferences.service';
|
||||
import { Pagination } from '@alfresco/js-api';
|
||||
import { PaginationModel } from '../models/pagination.model';
|
||||
import { takeUntil } from 'rxjs/operators';
|
||||
|
||||
@Component({
|
||||
@ -42,7 +41,7 @@ import { takeUntil } from 'rxjs/operators';
|
||||
})
|
||||
export class InfinitePaginationComponent implements OnInit, OnDestroy, PaginationComponentInterface {
|
||||
|
||||
static DEFAULT_PAGINATION: Pagination = new Pagination({
|
||||
static DEFAULT_PAGINATION: PaginationModel = new PaginationModel({
|
||||
skipCount: 0,
|
||||
maxItems: 25,
|
||||
totalItems: 0
|
||||
|
@ -17,15 +17,15 @@
|
||||
|
||||
import { NO_ERRORS_SCHEMA } from '@angular/core';
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { Pagination } from '@alfresco/js-api';
|
||||
import { PaginationComponent } from './pagination.component';
|
||||
import { PaginatedComponent } from './paginated-component.interface';
|
||||
import { BehaviorSubject } from 'rxjs';
|
||||
import { setupTestBed } from '../testing/setup-test-bed';
|
||||
import { CoreTestingModule } from '../testing/core.testing.module';
|
||||
import { TranslateModule } from '@ngx-translate/core';
|
||||
import { PaginationModel } from '../models/pagination.model';
|
||||
|
||||
class FakePaginationInput implements Pagination {
|
||||
class FakePaginationInput implements PaginationModel {
|
||||
count = 25;
|
||||
hasMoreItems = false;
|
||||
totalItems = 0;
|
||||
@ -257,10 +257,10 @@ describe('PaginationComponent', () => {
|
||||
describe('with paginated component', () => {
|
||||
|
||||
it('should take pagination from the external component', () => {
|
||||
const pagination: Pagination = {};
|
||||
const pagination: PaginationModel = {};
|
||||
|
||||
const customComponent = {
|
||||
pagination: new BehaviorSubject<Pagination>({})
|
||||
pagination: new BehaviorSubject<PaginationModel>({})
|
||||
} as PaginatedComponent;
|
||||
|
||||
component.target = customComponent;
|
||||
@ -271,11 +271,11 @@ describe('PaginationComponent', () => {
|
||||
});
|
||||
|
||||
it('should update pagination by subscription', () => {
|
||||
const pagination1: Pagination = {};
|
||||
const pagination2: Pagination = {};
|
||||
const pagination1: PaginationModel = {};
|
||||
const pagination2: PaginationModel = {};
|
||||
|
||||
const customComponent = {
|
||||
pagination: new BehaviorSubject<Pagination>({})
|
||||
pagination: new BehaviorSubject<PaginationModel>({})
|
||||
} as PaginatedComponent;
|
||||
|
||||
component.target = customComponent;
|
||||
@ -290,7 +290,7 @@ describe('PaginationComponent', () => {
|
||||
|
||||
it('should send pagination event to paginated component', () => {
|
||||
const customComponent = {
|
||||
pagination: new BehaviorSubject<Pagination>({}),
|
||||
pagination: new BehaviorSubject<PaginationModel>({}),
|
||||
updatePagination: () => {},
|
||||
supportedPageSizes: [],
|
||||
rows: []
|
||||
@ -311,7 +311,7 @@ describe('PaginationComponent', () => {
|
||||
it('should go to previous page if current page has 0 items', () => {
|
||||
const customComponent = {
|
||||
updatePagination: () => {},
|
||||
pagination: new BehaviorSubject<Pagination>({}),
|
||||
pagination: new BehaviorSubject<PaginationModel>({}),
|
||||
rows: []
|
||||
} as PaginatedComponent;
|
||||
|
||||
@ -336,9 +336,9 @@ describe('PaginationComponent', () => {
|
||||
});
|
||||
|
||||
it('should not show pagination when external component count is zero', () => {
|
||||
const pagination: Pagination = {};
|
||||
const pagination: PaginationModel = {};
|
||||
const customComponent = {
|
||||
pagination: new BehaviorSubject<Pagination>({ count: 0, maxItems: 5, totalItems: 5 })
|
||||
pagination: new BehaviorSubject<PaginationModel>({ count: 0, maxItems: 5, totalItems: 5 })
|
||||
} as PaginatedComponent;
|
||||
component.target = customComponent;
|
||||
component.ngOnInit();
|
||||
|
Loading…
x
Reference in New Issue
Block a user