import { Component, OnInit } from '@angular/core'; import { SortDescriptor, orderBy } from '@progress/kendo-data-query'; import { GridDataResult, PageChangeEvent } from '@progress/kendo-angular-grid'; import { AuthenticationService } from '../../../_services/authentication.service'; import { RootService } from '../../../_services/root.service'; import { from } from 'rxjs/observable/from'; import { delay } from 'rxjs/operators/delay'; import { switchMap } from 'rxjs/operators/switchMap'; import { map } from 'rxjs/operators/map'; import { UserService } from '../user.service'; import { LocalService } from '../../../_services/local.service'; @Component({ selector: 'app-list', templateUrl: './list.component.html', styles: [] }) export class ListComponent implements OnInit { //loading flag public loading = false; //grid data public gridView: GridDataResult; public users: any[] = []; //sorting variable public multiple = false; public allowUnsort = true; public sort: SortDescriptor[] = []; //Pagination variables public pageSizes = [5, 10, 25, 50]; public totalRecords = 0; public pageSize = 10; public skip = 0; private company:any; constructor(private _rootService: RootService, private _userService: UserService, private _authenticationService: AuthenticationService, private _localService: LocalService) { } ngOnInit() { this.company = this._localService.get('com'); this.loadUsers(); this.checkUserSubscription(); } public canCreateUser:any = true; public checkUserSubscription() { console.log(this.company); this._userService.checkClientSubscription(this.company.Id).subscribe((res) => { console.log(res); this.canCreateUser = res; }, (err) => { console.log(err); }); } private loadUsers() { this.loading = true; this._userService.getUsersforClients(this.company.Id).subscribe( response => this.handleResponse(response), err => this.handleError(err) ); } private handleResponse(response: any) { this.users = []; this.users = response.List; this.totalRecords = response.Count; this.gridView = { data: this.users, total: this.totalRecords }; console.log(this.users); this.loading = false; } private handleError(err: any) { this.loading = false; if (err.status == 403) { this._authenticationService.logout(); } } public onSearch() { } public sortChange(sort: SortDescriptor[]): void { if (sort[0].field == 'asd') { return; } this.sort = sort; this.sortData(); } private sortData() { this.gridView = { data: orderBy(this.users, this.sort), total: this.totalRecords }; } public pageChange(event: PageChangeEvent): void { this.skip = event.skip; this.loadUsers(); } public changePagesize(value: any) { this.pageSize = +value; this.skip = 0; this.loadUsers(); } // helpers get showInitialPageSize() { return this.pageSizes .filter(num => num === Number(this.pageSize)) .length === 0; } }