import { Component, OnInit, OnDestroy } from '@angular/core'; import { AuthenticationService } from '../../../_services/authentication.service'; import { HealthFacilityService } from '../health-facility.service'; import { RootService } from '../../../_services/root.service'; import { Subscription } from 'rxjs/Subscription'; import { ActivatedRoute, Router } from '@angular/router'; @Component({ selector: 'app-view', templateUrl: './view.component.html' }) export class ViewComponent implements OnInit, OnDestroy { public customTempFlags: boolean[] = [true, true, true, true, true, true, true, true, true]; public showMoreInfoFlag: boolean = false; public showMoreProfilesFlag: boolean = false; public dashboardView: boolean = false; public showMoreServicesFlag: boolean = false; public hfPhotoLoaded: boolean = false; public currentUser: any; public hfPhoto = new Image(); private subscription: Subscription; public hfmisCode: string = '0'; public selectedTab: string = 'General'; public healthFacility: any; public employementModes: any[] = []; constructor(private _rootService: RootService, private _hfService: HealthFacilityService, private _authenticationService: AuthenticationService, private router: Router, private route: ActivatedRoute) { } ngOnInit() { this.currentUser = this._authenticationService.getUser(); this.fetchParams(); } private fetchParams() { this.subscription = this.route.params.subscribe( (params: any) => { if (params.hasOwnProperty('hfcode')) { this.hfmisCode = params['hfcode']; this.fetchData(this.hfmisCode); this.getEmploymentModes(); } } ); } private fetchData(hfmisCode) { this.healthFacility = null; this._hfService.getHealthFacilitiyDashboard(hfmisCode).subscribe( res => { console.log(res); this.healthFacility = res; this.hfPhoto.src = 'http://beta.hrmis.pshealth.punjab.gov.pk/Uploads/Files/HFPics/' + this.healthFacility.HFPhoto.ImagePath; this.hfPhoto.onload = () => { this.hfPhotoLoaded = true; } }, err => { this.handleError(err); } ) } private getEmploymentModes = () => { this._rootService.getEmploymentModes().subscribe((res: any) => { this.employementModes = res; }, err => { this.handleError(err); } ); } public onTabSelect(e) { console.log(e); //this.selectedTab = e.heading; } public dashifyCNIC(cnic: string) { 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]; } private handleError(err: any) { this.router.navigate(['/health-facility/list']); if (err.status == 403) { this._authenticationService.logout(); } } ngOnDestroy() { this.subscription.unsubscribe(); } }