1 | import { Component, OnInit, ViewChild, Inject, Output, EventEmitter } from '@angular/core';
|
---|
2 | import { Pharmacy } from '../models/Pharmacy';
|
---|
3 | import { MatTableDataSource } from '@angular/material/table';
|
---|
4 | import { MatPaginator } from '@angular/material/paginator';
|
---|
5 | import { MatSort } from '@angular/material/sort';
|
---|
6 | import { HealthFacilities } from '../models/HealthFacilities';
|
---|
7 | import { HttpClient } from '@angular/common/http';;
|
---|
8 | import { MatDialog } from '@angular/material/dialog';
|
---|
9 | import { MatSnackBar, MatSnackBarRef, SimpleSnackBar } from '@angular/material/snack-bar';
|
---|
10 | import { Router, RouterModule } from '@angular/router';
|
---|
11 | import { HomeComponent } from '../home/home.component';
|
---|
12 |
|
---|
13 | @Component({
|
---|
14 | selector: 'app-dashboard',
|
---|
15 | templateUrl: './dashboard.component.html',
|
---|
16 | styleUrls: ['./dashboard.component.css']
|
---|
17 | })
|
---|
18 | export class DashboardComponent implements OnInit {
|
---|
19 | public facilities: HealthFacilities[];
|
---|
20 | displayedColumns = ['Име','Општина','Адреса', 'Тип', 'Е-пошта', 'Телефон'];
|
---|
21 | dataSource = new MatTableDataSource<HealthFacilities>();
|
---|
22 |
|
---|
23 | @ViewChild(MatPaginator, {static: true}) paginator: MatPaginator;
|
---|
24 | @ViewChild(MatSort) sort: MatSort;
|
---|
25 |
|
---|
26 | constructor(http: HttpClient, @Inject('BASE_URL') baseUrl: string, private dialog: MatDialog, private _snackBar: MatSnackBar, private router: Router) {
|
---|
27 | http.get<HealthFacilities[]>(baseUrl + 'HealthFacilities/Get?').subscribe(result => {
|
---|
28 | this.facilities = result;
|
---|
29 | console.log(this.facilities);
|
---|
30 | this.dataSource = new MatTableDataSource<HealthFacilities>(this.facilities);
|
---|
31 | }, error => console.error(error));
|
---|
32 | }
|
---|
33 | ngOnInit(): void {
|
---|
34 | }
|
---|
35 |
|
---|
36 | ngAfterViewInit(): void {
|
---|
37 | this.dataSource.paginator = this.paginator;
|
---|
38 | this.dataSource.sort = this.sort;
|
---|
39 | }
|
---|
40 |
|
---|
41 | applyFilter(filterValue: string) {
|
---|
42 | filterValue = filterValue.trim();
|
---|
43 | filterValue = filterValue.toLowerCase();
|
---|
44 | this.dataSource.filter = filterValue;
|
---|
45 | }
|
---|
46 | test(): void {
|
---|
47 | console.log('Snackbar works!');
|
---|
48 | this.openSnackBar("Are you sure?", "Yes").onAction().subscribe(() => {
|
---|
49 | this.router.navigate(['/']);
|
---|
50 | });
|
---|
51 | }
|
---|
52 |
|
---|
53 | openDialog():void {
|
---|
54 | let dialogRef = this.dialog.open(HomeComponent, {
|
---|
55 | width: '70%'
|
---|
56 | });
|
---|
57 | dialogRef.afterClosed().subscribe(result => {
|
---|
58 | if(result) {
|
---|
59 | this.openSnackBar("Success", "OK");
|
---|
60 | }
|
---|
61 | });
|
---|
62 | }
|
---|
63 |
|
---|
64 | openSnackBar(message: string, action: string) : MatSnackBarRef<SimpleSnackBar> {
|
---|
65 | return this._snackBar.open(message, action, {
|
---|
66 | duration: 10000,
|
---|
67 | });
|
---|
68 | }
|
---|
69 | }
|
---|