source: Farmatiko/ClientApp/src/app/dashboard/dashboard.component.ts@ ef1219a

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

Handled REST API calls, searchbars and paginators implemented, overall frontend improvment

  • Property mode set to 100644
File size: 2.5 KB
Line 
1import { Component, OnInit, ViewChild, Inject, Output, EventEmitter } from '@angular/core';
2import { Pharmacy } from '../models/Pharmacy';
3import { MatTableDataSource } from '@angular/material/table';
4import { MatPaginator } from '@angular/material/paginator';
5import { MatSort } from '@angular/material/sort';
6import { HealthFacilities } from '../models/HealthFacilities';
7import { HttpClient } from '@angular/common/http';;
8import { MatDialog } from '@angular/material/dialog';
9import { MatSnackBar, MatSnackBarRef, SimpleSnackBar } from '@angular/material/snack-bar';
10import { Router, RouterModule } from '@angular/router';
11import { HomeComponent } from '../home/home.component';
12
13@Component({
14 selector: 'app-dashboard',
15 templateUrl: './dashboard.component.html',
16 styleUrls: ['./dashboard.component.css']
17})
18export 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}
Note: See TracBrowser for help on using the repository browser.