1 | import { Component, OnInit, ViewChild, Inject } from '@angular/core';
|
---|
2 | import { HttpClient } from '@angular/common/http';
|
---|
3 | import { Medicine } from '../models/Medicine';
|
---|
4 | import { Pharmacy } from '../models/Pharmacy';
|
---|
5 | import { MatTableDataSource } from '@angular/material/table';
|
---|
6 | import { MatPaginator } from '@angular/material/paginator';
|
---|
7 | import { MatSort } from '@angular/material/sort';
|
---|
8 |
|
---|
9 | @Component({
|
---|
10 | selector: 'app-home',
|
---|
11 | templateUrl: './home.component.html',
|
---|
12 | styleUrls: ['./home.component.css']
|
---|
13 | })
|
---|
14 | export class HomeComponent implements OnInit {
|
---|
15 | public medicines: Medicine[];
|
---|
16 | public pharmacies: Pharmacy[];
|
---|
17 | displayedColumns = ['Име','Јачина','Форма', 'Начин на издавање', 'Производител', 'Цена', 'Пакување'];
|
---|
18 | displayedColumnsPharmacies = ['Име','Локација','Адреса', 'Работи 27/7?'];
|
---|
19 | dataSource = new MatTableDataSource<Medicine>();
|
---|
20 | dataSourcePharmacies = new MatTableDataSource<Pharmacy>();
|
---|
21 |
|
---|
22 | @ViewChild(MatPaginator, {static: true}) paginator: MatPaginator;
|
---|
23 | @ViewChild(MatSort) sort: MatSort;
|
---|
24 |
|
---|
25 | constructor(http: HttpClient, @Inject('BASE_URL') baseUrl: string) {
|
---|
26 | http.get<Medicine[]>(baseUrl + 'Medicine/Get?').subscribe(result => {
|
---|
27 | this.medicines = result;
|
---|
28 | console.log(this.medicines);
|
---|
29 | this.dataSource = new MatTableDataSource<Medicine>(this.medicines);
|
---|
30 | }, error => console.error(error));
|
---|
31 | http.get<Pharmacy[]>(baseUrl + 'Pharmacy/Get?').subscribe(result => {
|
---|
32 | this.pharmacies = result;
|
---|
33 | console.log(this.pharmacies);
|
---|
34 | this.dataSourcePharmacies = new MatTableDataSource<Pharmacy>(this.pharmacies);
|
---|
35 | }, error => console.error(error));
|
---|
36 | }
|
---|
37 | ngOnInit(): void {
|
---|
38 | }
|
---|
39 |
|
---|
40 | ngAfterViewInit(): void {
|
---|
41 | this.dataSource.paginator = this.paginator;
|
---|
42 | this.dataSource.sort = this.sort;
|
---|
43 | this.dataSourcePharmacies.paginator = this.paginator;
|
---|
44 | this.dataSourcePharmacies.sort = this.sort;
|
---|
45 | }
|
---|
46 |
|
---|
47 | applyFilter(filterValue: string) {
|
---|
48 | filterValue = filterValue.trim();
|
---|
49 | filterValue = filterValue.toLowerCase();
|
---|
50 | this.dataSource.filter = filterValue;
|
---|
51 | }
|
---|
52 |
|
---|
53 | applyFilterPharmacies(filterValue: string) {
|
---|
54 | filterValue = filterValue.trim();
|
---|
55 | filterValue = filterValue.toLowerCase();
|
---|
56 | this.dataSourcePharmacies.filter = filterValue;
|
---|
57 | }
|
---|
58 | }
|
---|