Ignore:
Timestamp:
08/07/20 10:59:56 (2 years ago)
Author:
Mile Jankuloski <mile.jankuloski@…>
Branches:
master
Children:
63d885e
Parents:
c73269d
Message:

Added DataService and dialogs, all bindings needed implemented

File:
1 edited

Legend:

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

    rc73269d ree137aa  
    1 import { Component, OnInit, ViewChild, Inject, Input } from '@angular/core';
    2 import { HttpClient } from '@angular/common/http';
    3 import { HealthFacilities } from '../models/HealthFacilities';
    4 import { MatTableDataSource } from '@angular/material/table';
    5 import { MatPaginator } from '@angular/material/paginator';
    6 import { MatSort } from '@angular/material/sort';
    7 import { HealthcareWorkers } from '../models/HealthcareWorkers';
     1import { Component, OnInit } from '@angular/core';
     2import { IHealthFacilities, IHealthcareWorkers } from '../shared/interfaces';
     3import { DataService } from '../shared/data.service';
     4import { MatDialog } from '@angular/material/dialog';
     5import { FacilityDialogComponent } from '../dialogs/facility-dialog/facility-dialog.component';
     6import { WorkerDialogComponent } from '../dialogs/worker-dialog/worker-dialog.component';
    87
    98@Component({
     
    1312})
    1413export class CounterComponent implements OnInit {
    15   @Input() facilities: HealthFacilities[];
    16   public workers: HealthcareWorkers[];
    17   displayedColumns = ['id','createdOn','deletedOn','Име','Општина','Адреса', 'Тип', 'Е-пошта', 'Телефон'];
    18   displayedColumnsWorkers = ['Име','Гранка','Установа', 'Назив'];
    19   dataSource = new MatTableDataSource<HealthFacilities>();
    20   dataSourceWorkers = new MatTableDataSource<HealthcareWorkers>();
     14  public facilities: IHealthFacilities[] = [];
     15  public workers: IHealthcareWorkers[] = [];
     16  public filteredFacilities: IHealthFacilities[] = [];
     17  public filteredWorkers: IHealthcareWorkers[] = [];
    2118
    22   @ViewChild(MatPaginator, {static: false}) paginator: MatPaginator;
    23   @ViewChild(MatSort) sort: MatSort;
    24 
    25   constructor(http: HttpClient, @Inject('BASE_URL') baseUrl: string) {
    26     http.get<HealthFacilities[]>(baseUrl + 'HealthFacilities/Get?').subscribe(result => {
    27       this.facilities = result;
    28       console.log(this.facilities);
    29       this.dataSource = new MatTableDataSource<HealthFacilities>(this.facilities);
    30     }, error => console.error(error));
    31     http.get<HealthcareWorkers[]>(baseUrl + 'HealthcareWorker/Get?').subscribe(result => {
    32       this.workers = result;
    33       console.log(this.workers);
    34       this.dataSourceWorkers = new MatTableDataSource<HealthcareWorkers>(this.workers);
    35     }, error => console.error(error));
    36   }
    37   ngOnInit(): void {
     19  constructor(private dataService: DataService, private dialog: MatDialog) {
     20   
    3821  }
    3922
    40   ngAfterViewInit(): void {
    41     this.dataSource.paginator = this.paginator;
    42     this.dataSource.sort = this.sort;
     23  ngOnInit(): void {
     24    this.dataService.getFacilities()
     25        .subscribe((facility: IHealthFacilities[]) => {
     26          this.facilities = this.filteredFacilities = facility;
     27        },
     28        (err: any) => console.log(err),
     29        () => console.log('Facility data retrieved!'));
     30
     31    this.dataService.getWorkers()
     32        .subscribe((worker: IHealthcareWorkers[]) => {
     33          this.workers = this.filteredWorkers = worker;
     34        },
     35        (err: any) => console.log(err),
     36        () => console.log('Facility data retrieved!'));
    4337  }
    4438
    45   applyFilter(filterValue: string) {
    46     filterValue = filterValue.trim();
    47     filterValue = filterValue.toLowerCase();
    48     this.dataSource.filter = filterValue;
     39  applyFilterFacilities(filterValue: string) {
     40    console.log("applyFilterFacilities works!")
     41    if(filterValue) {
     42      this.dataService.searchFacilities(filterValue)
     43          .subscribe((facility: IHealthFacilities[]) => {
     44            this.filteredFacilities = facility;
     45          },
     46          (err: any) => console.log(err),
     47          () => console.log('Facility data retrieved!'));
     48    }
     49    else {
     50      this.filteredFacilities = this.facilities;
     51    }
    4952  }
    5053
    5154  applyFilterWorkers(filterValue: string) {
    52     filterValue = filterValue.trim();
    53     filterValue = filterValue.toLowerCase();
    54     this.dataSourceWorkers.filter = filterValue;
     55    console.log("applyFilterWorkers works!")
     56    if(filterValue) {
     57      this.dataService.searchWorkers(filterValue)
     58          .subscribe((worker: IHealthcareWorkers[]) => {
     59            this.filteredWorkers = worker;
     60          },
     61          (err: any) => console.log(err),
     62          () => console.log('Worker data retrieved!'));
     63    }
     64    else {
     65      this.filteredWorkers = this.workers;
     66    }
     67  }
     68
     69  openFacilityDialog(facility: IHealthFacilities): void {
     70    this.dialog.open(FacilityDialogComponent, {
     71      width: '450px',
     72      data: facility
     73    });
     74  }
     75 
     76  openWorkerDialog(worker: IHealthcareWorkers): void {
     77    this.dialog.open(WorkerDialogComponent, {
     78      width: '450px',
     79      data: worker
     80    });
    5581  }
    5682}
Note: See TracChangeset for help on using the changeset viewer.