|
| 1 | +import { Component, OnDestroy, OnInit } from '@angular/core'; |
| 2 | +import { Subscription } from 'rxjs'; |
| 3 | +import { Filter, VIEW_OPTIONS } from '../../../_models/common'; |
| 4 | +import { DiseaseBurdenService } from '../../../_services/api/disease-burden'; |
| 5 | +import { FilterService } from '../../../_services/filter.service'; |
| 6 | +import { NotificationService } from '../../../_services/notification.service'; |
| 7 | + |
| 8 | +@Component({ |
| 9 | + selector: 'app-dashboard-disease-burden', |
| 10 | + templateUrl: './dashboard-disease-burden.component.html', |
| 11 | + styleUrls: ['./dashboard-disease-burden.component.scss'], |
| 12 | +}) |
| 13 | +export class DashboardDiseaseBurdenComponent implements OnInit, OnDestroy { |
| 14 | + data: any; |
| 15 | + subscriptions: Subscription[] = []; |
| 16 | + filters: Filter[] = []; |
| 17 | + visible = true; |
| 18 | + viewOptions = VIEW_OPTIONS; |
| 19 | + |
| 20 | + constructor( |
| 21 | + private diseaseBurdenService: DiseaseBurdenService, |
| 22 | + public filterService: FilterService, |
| 23 | + private notificationService: NotificationService |
| 24 | + ) {} |
| 25 | + |
| 26 | + ngOnInit(): void { |
| 27 | + this.subscriptions.push( |
| 28 | + this.filterService.getFilters().subscribe((response) => { |
| 29 | + this.filters = response.filters; |
| 30 | + this.fetchDiseaseBurden(); |
| 31 | + }) |
| 32 | + ); |
| 33 | + } |
| 34 | + |
| 35 | + fetchDiseaseBurden(): void { |
| 36 | + this.subscriptions.push( |
| 37 | + this.diseaseBurdenService.getCalculated(this.filters).subscribe({ |
| 38 | + next: (data: any) => { |
| 39 | + this.data = data; |
| 40 | + }, |
| 41 | + error: (err: any) => { |
| 42 | + this.notificationService.error(err); |
| 43 | + }, |
| 44 | + complete: () => {}, |
| 45 | + }) |
| 46 | + ); |
| 47 | + } |
| 48 | + |
| 49 | + toggleSection(event: any): void { |
| 50 | + this.visible = !event.checked; |
| 51 | + } |
| 52 | + |
| 53 | + ngOnDestroy(): void { |
| 54 | + this.subscriptions.forEach((subscription) => subscription.unsubscribe()); |
| 55 | + } |
| 56 | +} |
0 commit comments