source: Farmatiko/ClientApp/src/app/home/home.component.ts@ 5d02859

Last change on this file since 5d02859 was ee137aa, checked in by Mile Jankuloski <mile.jankuloski@…>, 4 years ago

Added DataService and dialogs, all bindings needed implemented

  • Property mode set to 100644
File size: 2.5 KB
Line 
1import { Component, OnInit } from '@angular/core';
2import { IMedicine, IPharmacy } from '../shared/interfaces';
3import { DataService } from '../shared/data.service';
4import { MatDialog } from '@angular/material/dialog';
5import { MedicineDialogComponent } from '../dialogs/medicine-dialog/medicine-dialog.component';
6import { PharmacyDialogComponent } from '../dialogs/pharmacy-dialog/pharmacy-dialog.component';
7
8@Component({
9 selector: 'app-home',
10 templateUrl: './home.component.html',
11 styleUrls: ['./home.component.css']
12})
13export class HomeComponent implements OnInit {
14 public medicines: IMedicine[] = [];
15 public pharmacies: IPharmacy[] = [];
16 public filteredMedicines: IMedicine[] = [];
17 public filteredPharmacies: IPharmacy[] = [];
18
19 constructor(private dataService: DataService, private dialog: MatDialog) {
20
21 }
22
23 ngOnInit(): void {
24 this.dataService.getMedicines()
25 .subscribe((medicine: IMedicine[]) => {
26 this.medicines = this.filteredMedicines = medicine;
27 },
28 (err: any) => console.log(err),
29 () => console.log('Medicine data retrieved'));
30
31 this.dataService.getPharmacies()
32 .subscribe((pharmacy: IPharmacy[]) => {
33 this.pharmacies = this.filteredPharmacies = pharmacy;
34 },
35 (err: any) => console.log(err),
36 () => console.log('Pharmacy data retrieved'));
37 }
38
39 applyFilterMedicines(filterValue: string) {
40 console.log("applyFilterMedicines works!")
41 if(filterValue) {
42 this.dataService.searchMedicines(filterValue)
43 .subscribe((medicine: IMedicine[]) => {
44 this.filteredMedicines = medicine;
45 },
46 (err: any) => console.log(err),
47 () => console.log('Medicine data retrieved'));
48 }
49 else {
50 this.filteredMedicines = this.medicines;
51 }
52 }
53
54 applyFilterPharmacies(filterValue: string) {
55 console.log("applyFilterPharmacies works!")
56 if(filterValue) {
57 this.dataService.searchPharmacies(filterValue)
58 .subscribe((pharmacy: IPharmacy[]) => {
59 this.filteredPharmacies = pharmacy;
60 },
61 (err: any) => console.log(err),
62 () => console.log('Pharmacy data retrieved'));
63 }
64 else {
65 this.filteredPharmacies = this.pharmacies;
66 }
67 }
68
69 openMedicineDialog(medicine: IMedicine): void {
70 this.dialog.open(MedicineDialogComponent, {
71 width: '450px',
72 data: medicine
73 });
74 }
75
76 openPharmacyDialog(pharmacy: IPharmacy): void {
77 this.dialog.open(PharmacyDialogComponent, {
78 width: '450px',
79 data: pharmacy
80 });
81 }
82}
Note: See TracBrowser for help on using the repository browser.