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

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

fix bugs

  • Property mode set to 100644
File size: 1.7 KB
RevLine 
[8b13eb2]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 else {
33 this.medicines.push(selectedMedicine);
34 }
35 }
36
37 save() {
38 console.log(this.medicines);
39 this.dialogRef.close(this.medicines);
40 }
41
42 close() {
43 this.dialogRef.close();
44 }
45
46 applyFilterMedicines(filterValue: string) {
47 if(filterValue) {
48 this.dataService.searchMedicines(filterValue)
49 .subscribe((medicine: IMedicine[]) => {
50 this.filteredListMedicines = medicine;
51 },
52 (err: any) => console.log(err),
53 () => console.log('Medicine data retrieved'));
54 }
55 else {
56 this.filteredListMedicines = this.listMedicines;
57 }
58 }
59
60}
Note: See TracBrowser for help on using the repository browser.