import { Component, OnInit, Input } from '@angular/core'; import { SortDescriptor, orderBy } from '@progress/kendo-data-query'; import { PageChangeEvent, GridDataResult } from '@progress/kendo-angular-grid'; import { HealthFacilityService } from '../../../health-facility.service'; import { AuthenticationService } from '../../../../../_services/authentication.service'; @Component({ selector: 'app-hf-wards', templateUrl: './hf-wards.component.html', styles: [` .table th, .table td{ border: none !important; vertical-align: middle !important; } .table tbody tr { border-top: 1px solid #c8ced3 !important; border-bottom: 1px solid #c8ced3 !important; } .table tbody tr:last-child { border-bottom: none !important; } `] }) export class HFWardsComponent implements OnInit { @Input() public hfWards: any[] = []; public multiple = false; public allowUnsort = true; public savingWard = false; public sort: SortDescriptor[] = []; public gridView: GridDataResult; public currentUser: any; public pageSize = 5; public skip = 0; public selectedWard: any; public wardDialogOpened: boolean = false; constructor(private _healthFacilityService: HealthFacilityService, private _authenticationService: AuthenticationService) { } ngOnInit() { this.currentUser = this._authenticationService.getUser(); this.loadWards(); } public changePagesize(value: any) { this.pageSize = +value; this.loadWards(); } public dropValChanged(event: any) { console.log(event); } public sortChange(sort: SortDescriptor[]): void { if (sort[0].field == 'asd') { return; } this.sort = sort; this.loadWards(); } private loadWards(): void { this.gridView = { data: orderBy(this.hfWards, this.sort), total: this.hfWards.length }; } public pageChange(event: PageChangeEvent): void { this.skip = event.skip; this.loadWards(); } public onPageChange(state: any): void { this.pageSize = state.take; } public editWard() { this._healthFacilityService.editHfWard(this.selectedWard, this.selectedWard.Id).subscribe((response: any) => { console.log(response); if (response == true) { this.savingWard = false; this.closeWardWindow(); } }, err => { console.log(err); }); } public closeWardWindow() { this.wardDialogOpened = false; } public openWardWindow(ward: any) { this.selectedWard = ward; this.wardDialogOpened = true; } }