Ignore:
Timestamp:
07/27/20 23:36:14 (2 years ago)
Author:
Mile Jankuloski <mile.jankuloski@…>
Branches:
master
Children:
e42f61a
Parents:
d2e69be
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • Farmatiko/ClientApp/src/app/dashboard/dashboard.component.ts

    rd2e69be ref1219a  
    1 import { Component, OnInit, Input, ViewChild } from '@angular/core';
     1import { Component, OnInit, ViewChild, Inject, Output, EventEmitter } from '@angular/core';
    22import { Pharmacy } from '../models/Pharmacy';
    33import { MatTableDataSource } from '@angular/material/table';
    44import { MatPaginator } from '@angular/material/paginator';
    55import { 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';
    612
    713@Component({
     
    1117})
    1218export class DashboardComponent implements OnInit {
     19  public facilities: HealthFacilities[];
     20  displayedColumns = ['Име','Општина','Адреса', 'Тип', 'Е-пошта', 'Телефон'];
     21  dataSource = new MatTableDataSource<HealthFacilities>();
    1322
    14   constructor() { }
     23  @ViewChild(MatPaginator, {static: true}) paginator: MatPaginator;
     24  @ViewChild(MatSort) sort: MatSort;
    1525
    16   ngOnInit(): void { }
     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  }
    1769}
Note: See TracChangeset for help on using the changeset viewer.