import { AppComponentBase } from '@shared/common/app-component-base' ; import { Injector , OnInit , Directive } from '@angular/core' ; import { AppConsts } from '@shared/AppConsts' ; export class PagedResultDto { items : any [ ] ; totalCount : number ; } export class EntityDto { id : number ; } export class PagedRequestDto { skipCount : number ; maxResultCount : number ; sorting : string ; } @ Directive ( ) export abstract class PagedListingComponentBase < EntityDto > extends AppComponentBase implements OnInit { public pageSize = AppConsts . grid . defaultPageSize ; public pageNumber = 1 ; public totalPages = 1 ; public totalItems : number ; public isTableLoading = true ; public allChecked = false ; public allCheckboxDisabled = false ; public checkboxIndeterminate = false ; public selectedDataItems : any [ ] = [ ] ; public sorting : string = undefined ; filterText = '' ; dataList : EntityDto [ ] = [ ] ; public booleanFilterList : any [ ] = [ { text : this . l ( 'All' ) , value : 'All' } , { text : this . l ( 'Yes' ) , value : true } , { text : this . l ( 'No' ) , value : false } , ] ; constructor ( injector ) { super ( injector ) ; } ngOnInit ( ) { this . refresh ( ) ; } refresh ( ) { this . pageNumber = 1 ; this . restCheckStatus ( this . dataList ) ; this . getDataPage ( this . pageNumber ) ; } 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 . fetchDataList ( req , page , ( ) => { this . isTableLoading = false ; this . refreshAllCheckBoxDisabled ( ) ; } ) ; } refreshAllCheckBoxDisabled ( ) { this . allCheckboxDisabled = this . dataList . length <= 0 ; } public pageNumberChange ( ) { if ( this . pageNumber > 0 ) { this . restCheckStatus ( this . dataList ) ; this . getDataPage ( this . pageNumber ) ; } } 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 ) ) ; } public showPaging ( result ) { this . totalItems = result . totalCount ; } gridSort ( sort ) { this . sorting = undefined ; let ascOrDesc = sort . value ; const filedName = sort . key ; if ( ascOrDesc ) { ascOrDesc = abp . utils . replaceAll ( ascOrDesc , 'end' , '' ) ; const args = [ '{0} {1}' , filedName , ascOrDesc ] ; const sortingStr = abp . utils . formatString . apply ( this , args ) ; this . sorting = sortingStr ; } this . refresh ( ) ; } isGrantedAny ( ... permissions ) { if ( ! permissions ) { return false ; } for ( const permission of permissions ) { if ( this . isGranted ( permission ) ) { return true ; } } return false ; } protected abstract fetchDataList ( request , pageNumber , finishedCallback ) ; }