1 | import { Component, OnInit } from '@angular/core';
|
---|
2 | import { IHealthFacilities, IHealthcareWorkers } from '../shared/interfaces';
|
---|
3 | import { DataService } from '../shared/data.service';
|
---|
4 | import { MatDialog } from '@angular/material/dialog';
|
---|
5 | import { FacilityDialogComponent } from '../dialogs/facility-dialog/facility-dialog.component';
|
---|
6 | import { WorkerDialogComponent } from '../dialogs/worker-dialog/worker-dialog.component';
|
---|
7 |
|
---|
8 | @Component({
|
---|
9 | selector: 'app-counter-component',
|
---|
10 | templateUrl: './counter.component.html',
|
---|
11 | styleUrls: ['./counter.component.css']
|
---|
12 | })
|
---|
13 | export class CounterComponent implements OnInit {
|
---|
14 | public facilities: IHealthFacilities[] = [];
|
---|
15 | public workers: IHealthcareWorkers[] = [];
|
---|
16 | public filteredFacilities: IHealthFacilities[] = [];
|
---|
17 | public filteredWorkers: IHealthcareWorkers[] = [];
|
---|
18 |
|
---|
19 | constructor(private dataService: DataService, private dialog: MatDialog) {
|
---|
20 |
|
---|
21 | }
|
---|
22 |
|
---|
23 | ngOnInit(): void {
|
---|
24 | this.dataService.getFacilities()
|
---|
25 | .subscribe((facility: IHealthFacilities[]) => {
|
---|
26 | this.facilities = this.filteredFacilities = facility;
|
---|
27 | },
|
---|
28 | (err: any) => console.log(err),
|
---|
29 | () => console.log('Facility data retrieved!'));
|
---|
30 |
|
---|
31 | this.dataService.getWorkers()
|
---|
32 | .subscribe((worker: IHealthcareWorkers[]) => {
|
---|
33 | this.workers = this.filteredWorkers = worker;
|
---|
34 | },
|
---|
35 | (err: any) => console.log(err),
|
---|
36 | () => console.log('Facility data retrieved!'));
|
---|
37 | }
|
---|
38 |
|
---|
39 | applyFilterFacilities(filterValue: string) {
|
---|
40 | console.log("applyFilterFacilities works!")
|
---|
41 | if(filterValue) {
|
---|
42 | this.dataService.searchFacilities(filterValue)
|
---|
43 | .subscribe((facility: IHealthFacilities[]) => {
|
---|
44 | this.filteredFacilities = facility;
|
---|
45 | },
|
---|
46 | (err: any) => console.log(err),
|
---|
47 | () => console.log('Facility data retrieved!'));
|
---|
48 | }
|
---|
49 | else {
|
---|
50 | this.filteredFacilities = this.facilities;
|
---|
51 | }
|
---|
52 | }
|
---|
53 |
|
---|
54 | applyFilterWorkers(filterValue: string) {
|
---|
55 | console.log("applyFilterWorkers works!")
|
---|
56 | if(filterValue) {
|
---|
57 | this.dataService.searchWorkers(filterValue)
|
---|
58 | .subscribe((worker: IHealthcareWorkers[]) => {
|
---|
59 | this.filteredWorkers = worker;
|
---|
60 | },
|
---|
61 | (err: any) => console.log(err),
|
---|
62 | () => console.log('Worker data retrieved!'));
|
---|
63 | }
|
---|
64 | else {
|
---|
65 | this.filteredWorkers = this.workers;
|
---|
66 | }
|
---|
67 | }
|
---|
68 |
|
---|
69 | openFacilityDialog(facility: IHealthFacilities): void {
|
---|
70 | this.dialog.open(FacilityDialogComponent, {
|
---|
71 | width: '450px',
|
---|
72 | data: facility
|
---|
73 | });
|
---|
74 | }
|
---|
75 |
|
---|
76 | openWorkerDialog(worker: IHealthcareWorkers): void {
|
---|
77 | this.dialog.open(WorkerDialogComponent, {
|
---|
78 | width: '450px',
|
---|
79 | data: worker
|
---|
80 | });
|
---|
81 | }
|
---|
82 | }
|
---|