/** Angular Imports */ import { CollectionViewer , DataSource } from '@angular/cdk/collections' ; /** rxjs Imports */ import { Observable , BehaviorSubject } from 'rxjs' ; /** Custom Services */ import { SystemService } from '../system.service' ; /**
 * Audit Trails custom data source to implement server side filtering, pagination and sorting.
 */ export class AuditTrailsDataSource implements DataSource < any > { /** Audit Trails behavior subject to represent loaded audit trails page. */ private auditTrailsSubject = new BehaviorSubject < any [ ] > ( [ ] ) ; /** Records subject to represent total number of filtered audit trail records. */ private recordsSubject = new BehaviorSubject < number > ( 0 ) ; /** Records observable which can be subscribed to get the value of total number of filtered audit trail records. */ public records$ = this . recordsSubject . asObservable ( ) ; param { SystemService } systemService constructor ( private systemService ) { } param { any } filterBy param { string } orderBy param { string } sortOrder param { number } pageIndex param { number } limit getAuditTrails ( filterBy , orderBy = '' , sortOrder = '' , pageIndex = 0 , limit = 10 ) { this . auditTrailsSubject . next ( [ ] ) ; this . systemService . getAuditTrails ( filterBy , orderBy , sortOrder , pageIndex * limit , limit ) . subscribe ( ( auditTrails ) => { this . recordsSubject . next ( auditTrails . totalFilteredRecords ) ; this . auditTrailsSubject . next ( auditTrails . pageItems ) ; } ) ; } param { CollectionViewer } collectionViewer connect ( collectionViewer ) { return this . auditTrailsSubject . asObservable ( ) ; } param { CollectionViewer } collectionViewer disconnect ( collectionViewer ) { this . auditTrailsSubject . complete ( ) ; this . recordsSubject . complete ( ) ; } }