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

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

Prepared and improved components for data flows

  • Property mode set to 100644
File size: 4.4 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 { HttpClient } from '@angular/common/http';
7import { MatDialog } from '@angular/material/dialog';
8import { MatSnackBar, MatSnackBarRef, SimpleSnackBar } from '@angular/material/snack-bar';
9import { Router, RouterModule } from '@angular/router';
10import { HomeComponent } from '../home/home.component';
11import { Medicine } from '../models/Medicine';
12import { PharmacyHead } from '../models/PharmacyHead';
13import { MedicineList } from '../models/MedicineList';
14
15@Component({
16 selector: 'app-dashboard',
17 templateUrl: './dashboard.component.html',
18 styleUrls: ['./dashboard.component.css']
19})
20export class DashboardComponent implements OnInit {
21 public mymedicines: Medicine[];
22 public hasmymedicines: boolean[];
23 public pharmacies: Pharmacy[];
24 public mypharmacies: Pharmacy[];
25 public head: PharmacyHead;
26 public status: string;
27 displayedColumns = ['Име','Јачина','Форма', 'Начин на издавање', 'Производител', 'Цена', 'Пакување', 'Actions'];
28 displayedColumnsPharmacies = ['Име','Локација','Адреса', 'Actions'];
29 dataSource = new MatTableDataSource<Medicine>();
30 dataSourcePharmacies = new MatTableDataSource<Pharmacy>();
31
32 @ViewChild(MatPaginator, {static: true}) paginator: MatPaginator;
33 @ViewChild(MatSort) sort: MatSort;
34
35 constructor(http: HttpClient, @Inject('BASE_URL') baseUrl: string, private dialog: MatDialog, private _snackBar: MatSnackBar, private router: Router) {
36 http.get<PharmacyHead>(baseUrl + 'PharmacyHead/GetLoggedHead?').subscribe(result => {
37 this.head = result;
38 console.log(this.head);
39 this.mymedicines = this.head.PharmacyMedicines.Medicines;
40 console.log(this.mymedicines);
41 this.mypharmacies = this.head.Pharmacy;
42 console.log(this.mypharmacies);
43 this.dataSource = new MatTableDataSource<Medicine>(this.mymedicines);
44 }, error => console.error(error));
45 http.get<Pharmacy[]>(baseUrl + 'Pharmacy/Get?').subscribe(result => {
46 this.pharmacies = result;
47 console.log(this.pharmacies);
48 this.dataSourcePharmacies = new MatTableDataSource<Pharmacy>(this.pharmacies);
49 }, error => console.error(error));
50 }
51
52 ngOnInit(): void {
53 }
54
55 ngAfterViewInit(): void {
56 this.dataSource.paginator = this.paginator;
57 this.dataSource.sort = this.sort;
58 this.dataSourcePharmacies.paginator = this.paginator;
59 this.dataSourcePharmacies.sort = this.sort;
60 }
61
62 works24hrs(pharmacy: Pharmacy) {
63 console.log(pharmacy);
64 // post request vo prodolzenie
65
66 this.status="Status bar works24hrs";
67 }
68
69 doesntWork24hrs(pharmacy: Pharmacy) {
70 console.log(pharmacy);
71 // post request vo prodolzenie
72
73 this.status="Status bar doesntWork24hrs";
74 }
75
76 claimPharmacy(pharmacy: Pharmacy) {
77 console.log(pharmacy);
78 // post request vo prodolzenie
79
80 this.status="Status bar claimPharmacy";
81 }
82
83 medicineExists(mymedicine: Medicine) {
84 console.log(mymedicine);
85 // post request vo prodolzenie
86
87 this.status="Status bar medicineexists";
88 }
89
90 medicineDoesntSell(mymedicine: Medicine) {
91 console.log(mymedicine);
92 // post request vo prodolzenie
93
94 this.status="Status bar medicineDoesntSell";
95 }
96
97 applyFilter(filterValue: string) {
98 filterValue = filterValue.trim();
99 filterValue = filterValue.toLowerCase();
100 this.dataSource.filter = filterValue;
101 }
102
103 applyFilterPharmacies(filterValue: string) {
104 filterValue = filterValue.trim();
105 filterValue = filterValue.toLowerCase();
106 this.dataSourcePharmacies.filter = filterValue;
107 }
108
109 test(): void {
110 console.log('Snackbar works!');
111 this.openSnackBar("Are you sure?", "Yes").onAction().subscribe(() => {
112 this.router.navigate(['/']);
113 });
114 }
115
116 openDialog():void {
117 let dialogRef = this.dialog.open(HomeComponent, {
118 width: '70%'
119 });
120 dialogRef.afterClosed().subscribe(result => {
121 if(result) {
122 this.openSnackBar("Success", "OK");
123 }
124 });
125 }
126
127 openSnackBar(message: string, action: string) : MatSnackBarRef<SimpleSnackBar> {
128 return this._snackBar.open(message, action, {
129 duration: 10000,
130 });
131 }
132}
Note: See TracBrowser for help on using the repository browser.