source: Farmatiko/ClientApp/src/app/home/home.component.ts@ 7d80751

Last change on this file since 7d80751 was ad60966, checked in by Mile Jankuloski <mile.jankuloski@…>, 4 years ago

Auth fixes, bug fixes etc.

  • Property mode set to 100644
File size: 2.5 KB
RevLine 
[ee137aa]1import { Component, OnInit } from '@angular/core';
2import { IMedicine, IPharmacy } from '../shared/interfaces';
[ad60966]3import { DataService } from '../shared/data.service';
[ee137aa]4import { MatDialog } from '@angular/material/dialog';
5import { MedicineDialogComponent } from '../dialogs/medicine-dialog/medicine-dialog.component';
6import { PharmacyDialogComponent } from '../dialogs/pharmacy-dialog/pharmacy-dialog.component';
[ef1219a]7
[30a465f]8@Component({
9 selector: 'app-home',
10 templateUrl: './home.component.html',
[ec6ac45]11 styleUrls: ['./home.component.css']
[30a465f]12})
[ef1219a]13export class HomeComponent implements OnInit {
[ee137aa]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
[ef1219a]21 }
[ee137aa]22
[ef1219a]23 ngOnInit(): void {
[ee137aa]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'));
[ef1219a]30
[ee137aa]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'));
[ef1219a]37 }
38
[ee137aa]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 }
[ef1219a]52 }
[de18858]53
54 applyFilterPharmacies(filterValue: string) {
[ee137aa]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 });
[de18858]81 }
[30a465f]82}
Note: See TracBrowser for help on using the repository browser.