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