import { Component, OnInit } from '@angular/core'; import { KGridHelper } from '../../_helpers/k-grid.class'; import { DropDownsHR } from '../../_helpers/dropdowns.class'; import { Subject } from 'rxjs/Subject'; import { RootService } from '../../_services/root.service'; import { ApplicationFtsService } from '../../modules/application-fts/application-fts.service'; import { AuthenticationService } from '../../_services/authentication.service'; import { debounceTime } from 'rxjs/operators/debounceTime'; import { PageChangeEvent } from '@progress/kendo-angular-grid'; import { FileTrackingSystemService } from '../file-tracking-system.service'; @Component({ selector: 'app-my-applications', templateUrl: './my-applications.component.html', styles: [] }) export class MyApplicationsComponent implements OnInit { public kGrid: KGridHelper = new KGridHelper(); public dropDowns: DropDownsHR = new DropDownsHR(); public inputChange: Subject; public searchQuery: string = ''; public office_Id: number = 0; public typeId: number = 0; public statusId: number = 0; public recieveFiles: boolean = false; public selectedApplications: number[] = []; constructor(private _rootService: RootService, private _fileTrackingSystemService: FileTrackingSystemService, private _applicationFtsService: ApplicationFtsService, private _authenticationService: AuthenticationService) { } ngOnInit() { this.kGrid.firstLoad = true; this.inputChange = new Subject(); this.inputChange.pipe(debounceTime(300)).subscribe((query) => { this.searchQuery = query; if (this.searchQuery.length <= 2 && this.searchQuery.length != 0) { return; } this.getApplications(); }); this.initializeProps(); this.loadDropDownValues(); this.getApplications(); } private initializeProps() { this.kGrid.loading = false; this.kGrid.pageSize = 50; this.kGrid.pageSizes = [20,50, 100]; } private loadDropDownValues() { this.getApplicationTypes(); this.getApplicationStatus(); this.getInboxOffices(); } private getApplicationTypes() { this._rootService.getApplicationTypes().subscribe( (response: any) => { this.dropDowns.applicationTypes = response; this.dropDowns.applicationTypesData = this.dropDowns.applicationTypes; }, err => this.handleError(err) ); } private getApplicationStatus() { this._rootService.getApplicationStatus().subscribe( (response: any) => { this.dropDowns.applicationStatus = response; this.dropDowns.applicationStatusData = this.dropDowns.applicationStatus; }, err => this.handleError(err) ); } public dropdownValueChanged = (value, filter) => { if (filter == 'types') { this.typeId = value.Id; } if (filter == 'status') { this.statusId = value.Id; } if (filter == 'office') { this.office_Id = value.Id; } } private getInboxOffices() { this.kGrid.loading = true; /* this._applicationFtsService.getInboxApplications(this.kGrid.skip, this.kGrid.pageSize, this.searchQuery, this.office_Id).subscribe( (response: any) => { this.kGrid.data = []; this.kGrid.data = response.List; this.kGrid.totalRecords = response.Count; this.kGrid.gridView = { data: this.kGrid.data, total: this.kGrid.totalRecords }; this.kGrid.loading = false; console.log(response.List); }, err => this.handleError(err) ); */ } private getApplications() { this.kGrid.loading = true; this._fileTrackingSystemService.getApplications(this.kGrid.skip, this.kGrid.pageSize, this.searchQuery, this.office_Id, false, this.typeId, this.statusId).subscribe( (response: any) => { this.kGrid.data = []; this.kGrid.data = response.List; this.kGrid.totalRecords = response.Count; this.kGrid.gridView = { data: this.kGrid.data, total: this.kGrid.totalRecords }; this.kGrid.loading = false; this.kGrid.firstLoad = false; }, err => this.handleError(err) ); } public generateSlip = () => { this.recieveFiles = true; } public pageChange(event: PageChangeEvent): void { this.kGrid.skip = event.skip; this.getApplications(); } public changePagesize(value: any) { this.kGrid.pageSize = +value; this.kGrid.skip = 0; this.getApplications(); } private handleError(err: any) { this.kGrid.loading = false; if (err.status == 403) { this._authenticationService.logout(); } } public dashifyCNIC(cnic: string) { if (!cnic) return ''; return cnic[0] + cnic[1] + cnic[2] + cnic[3] + cnic[4] + '-' + cnic[5] + cnic[6] + cnic[7] + cnic[8] + cnic[9] + cnic[10] + cnic[11] + '-' + cnic[12]; } }