import { ModalComponentBase } from '@shared/common/modal-component-base' ; import { OnInit , Injector , Directive } from '@angular/core' ; import { AppConsts } from '@shared/AppConsts' ; import { PagedResultDto , PagedRequestDto , } from '@shared/common/paged-listing-component-base' ; @ Directive ( ) export abstract class ModalPagedListingComponentBase < EntityDto > extends ModalComponentBase implements OnInit { dataList : EntityDto [ ] = [ ] ; public pageSize = AppConsts . grid . defaultPageSize ; public pageNumber = 1 ; public totalPages = 1 ; public totalItems : number ; public sorting : string = undefined ; filterText = '' ; public isTableLoading = false ; public allChecked = false ; public allCheckboxDisabled = false ; public checkboxIndeterminate = false ; public selectedDataItems : any [ ] = [ ] ; constructor ( injector ) { super ( injector ) ; } ngOnInit ( ) { this . refresh ( ) ; } refresh ( ) { this . pageNumber = 1 ; this . restCheckStatus ( this . dataList ) ; this . getDataPage ( this . pageNumber ) ; } public showPaging ( result ) { this . totalItems = result . totalCount ; } public getDataPage ( page ) { const req = new PagedRequestDto ( ) ; req . maxResultCount = this . pageSize ; req . skipCount = ( page - 1 ) * this . pageSize ; req . sorting = this . sorting ; this . isTableLoading = true ; this . getDataList ( req , page , ( ) => { this . isTableLoading = false ; this . refreshAllCheckBoxDisabled ( ) ; } ) ; } checkAll ( value ) { this . dataList . forEach ( data => ( ( < any > data ) . checked = this . allChecked ) ) ; this . refreshCheckStatus ( this . dataList ) ; } refreshCheckStatus ( entityList ) { const allChecked = entityList . every ( value => value . checked === true ) ; const allUnChecked = entityList . every ( value => ! value . checked ) ; this . allChecked = allChecked ; this . checkboxIndeterminate = ! allChecked && ! allUnChecked ; this . selectedDataItems = entityList . filter ( value => value . checked ) ; } restCheckStatus ( entityList ) { this . allChecked = false ; this . checkboxIndeterminate = false ; this . selectedDataItems = [ ] ; entityList . forEach ( value => ( value . checked = false ) ) ; } refreshAllCheckBoxDisabled ( ) { this . allCheckboxDisabled = this . dataList . length <= 0 ; } protected abstract getDataList ( request , pageNumber , finishedCallback ) ; }