source: Farmatiko/ClientApp/src/app/dialogs/list-medicines-dialog/list-medicines-dialog.component.ts@ db484c9

Last change on this file since db484c9 was 8e74e2f, checked in by DimitarSlezenkovski <dslezenkovski@…>, 4 years ago

Fix bugs, add some more.

  • Property mode set to 100644
File size: 1.7 KB
Line 
1import { Component, OnInit } from '@angular/core';
2import { MatDialogRef } from '@angular/material/dialog';
3import { IMedicine } from '../../shared';
4import { DataService } from '../../shared/data.service';
5
6@Component({
7 selector: 'app-list-medicines-dialog-component',
8 templateUrl: './list-medicines-dialog.component.html',
9 styleUrls: ['./list-medicines-dialog.component.css']
10})
11export class ListMedicinesDialogComponent implements OnInit {
12 medicines: IMedicine[] = [];
13 listMedicines: IMedicine[];
14 filteredListMedicines: IMedicine[];
15
16 constructor(private dialogRef: MatDialogRef<ListMedicinesDialogComponent>, private dataService: DataService) {
17 }
18
19 ngOnInit(): void {
20 this.dataService.getMedicines()
21 .subscribe((medicine: IMedicine[]) => {
22 this.listMedicines = this.filteredListMedicines = medicine;
23 },
24 (err: any) => console.log(err),
25 () => console.log('Medicine data retrieved'));
26 }
27
28 selectMedicine(selectedMedicine: IMedicine) {
29 if(this.medicines.filter(x => x == selectedMedicine)) {
30 this.medicines = this.medicines.filter(x => x != selectedMedicine);
31 }
32 this.medicines.push(selectedMedicine);
33 }
34
35 save() {
36 console.log(this.medicines);
37 this.dialogRef.close(this.medicines);
38 }
39
40 close() {
41 this.dialogRef.close();
42 }
43
44 applyFilterMedicines(filterValue: string) {
45 if(filterValue) {
46 this.dataService.searchMedicines(filterValue)
47 .subscribe((medicine: IMedicine[]) => {
48 this.filteredListMedicines = medicine;
49 },
50 (err: any) => console.log(err),
51 () => console.log('Medicine data retrieved'));
52 }
53 else {
54 this.filteredListMedicines = this.listMedicines;
55 }
56 }
57
58}
Note: See TracBrowser for help on using the repository browser.