import { AfterViewInit , Component } from "@angular/core" ; import { UntilDestroy } from "@ngneat/until-destroy" ; import { TranslateService } from "@ngx-translate/core" ; import { isNotEmpty } from "@gauzy/common-angular" ; import { Subject } from "rxjs/internal/Subject" ; import { TranslationBaseComponent } from "../language-base/translation-base.component" ; @ UntilDestroy ( { checkProperties : true } ) @ Component ( { template : '' } ) export class PaginationFilterBaseComponent extends TranslationBaseComponent implements AfterViewInit { protected pagination : any = { totalItems : 0 , activePage : 1 , itemsPerPage : 10 } ; protected subject$ : Subject < any > = new Subject ( ) ; protected _filters : any = { } ; set filters ( val ) { this . _filters = val ; } get filters ( ) { return this . _filters ; } constructor ( public readonly translateService ) { super ( translateService ) ; } ngAfterViewInit ( ) { } protected refreshPagination ( ) { this . pagination [ 'activePage' ] = 1 ; } protected setFilter ( filter , doEmit = true ) { if ( isNotEmpty ( filter . search ) ) { this . filters = { where : { ... this . filters . where , [ filter . field ] : filter . search } } ; } else { if ( `${ filter . field }` in this . filters . where ) { delete this . filters . where [ filter . field ] ; } } if ( doEmit ) { this . subject$ . next ( true ) ; } } protected onPageChange ( selectedPage ) { this . pagination [ 'activePage' ] = selectedPage ; this . subject$ . next ( true ) ; } }