import { DataPager } from './data-pager' ; import { DataSort } from './data-sort' ; import { DataFilter } from './data-filter' ; import { Settings } from './settings' ; import { Row } from './row' ; export class LocalDataSource { localRows : Row [ ] = [ ] ; constructor ( private readonly dataFilter , private readonly pager , private readonly sorter , private readonly settings ) { } setRows ( data ) { this . dataFilter . clear ( ) ; this . sorter . clear ( ) ; this . pager . current = 1 ; this . localRows = ( data ) ? data . slice ( 0 ) : [ ] ; } getRows ( ) { if ( this . localRows ) { const data = this . dataFilter . filterRows ( this . localRows ) ; this . pager . total = data . length ; let rows = this . sorter . sortRows ( data ) ; if ( ! this . settings . virtualScroll ) { rows = this . pager . pager ( rows ) ; } return rows ; } return [ ] ; } post ( newRow ) { this . localRows . push ( newRow ) ; } put ( row ) { const rowIndex = this . localRows . findIndex ( x => x . $$uid === row . $$uid ) ; this . localRows [ rowIndex ] = row ; } delete ( row ) { const rowIndex = this . localRows . findIndex ( x => x . $$uid === row . $$uid ) ; this . localRows . splice ( rowIndex , 1 ) ; } }