source: Farmatiko/ClientApp/src/app/admin/admin.component.ts@ f554983

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

Minor logging fixes

  • Property mode set to 100644
File size: 4.9 KB
RevLine 
[ee137aa]1import { Component, OnInit } from '@angular/core';
[de18858]2import { MatDialog } from '@angular/material/dialog';
3import { MatSnackBar, MatSnackBarRef, SimpleSnackBar } from '@angular/material/snack-bar';
[ee137aa]4import { Router } from '@angular/router';
5import { IPharmacyHead, IPharmacyHeadRequest, IPharmacy } from '../shared/interfaces';
[ad60966]6import { DataService } from '../shared/data.service';
[ee137aa]7import { EditPharmacyHeadDialogComponent } from '../dialogs/edit-pharmacy-head-dialog/edit-pharmacy-head-dialog.component';
8import { PharmacyDialogComponent } from '../dialogs/pharmacy-dialog/pharmacy-dialog.component';
[8e74e2f]9import { PharmacyHeadDialogComponent } from '../dialogs/pharmacy-head-dialog/pharmacy-head-dialog.component';
10import { AuthService } from '../shared/services/auth.service';
[785b8bd]11
[de18858]12
[785b8bd]13@Component({
14 selector: 'app-admin',
15 templateUrl: './admin.component.html',
16 styleUrls: ['./admin.component.css']
17})
18export class AdminComponent implements OnInit {
[ee137aa]19 public heads: IPharmacyHead[] = [];
20 public requests: IPharmacyHeadRequest[] = [];
[993189e]21 public head: IPharmacyHead = {
22 Email: '',
23 Passwd: '',
24 Name: ''
25 };
[8e74e2f]26 public adminHead: IPharmacyHead;
[ee137aa]27
[8e74e2f]28 constructor(private dataService: DataService, private authService: AuthService, private dialog: MatDialog, private snackBar: MatSnackBar, private router: Router) {
[785b8bd]29
[de18858]30 }
[785b8bd]31
32 ngOnInit(): void {
[8e74e2f]33 this.authService.getUser()
34 .subscribe((data) => {
35 console.log(data);
36 this.adminHead = data;
37 },
38 (err: any) => console.log(err),
39 () => console.log('User data retrieved'));
40
[ee137aa]41 this.dataService.getPharmacyHeads()
42 .subscribe((pHeads: IPharmacyHead[]) => {
43 this.heads = pHeads;
44 },
45 (err: any) => console.log(err),
46 () => console.log("PharmacyHead data retrieved"));
47
48 this.dataService.getClaimingRequests()
[8e74e2f]49 .subscribe((pRequests: IPharmacyHeadRequest[]) => {
50 this.requests = pRequests;
51 },
52 (err: any) => console.log(err),
53 () => console.log("PharmacyHead data retrieved"));
[de18858]54 }
55
56 createHead() {
[ee137aa]57 this.dataService.insertPharmacyHead(this.head)
[dae4cde]58 .subscribe((cHead) => {
[ee137aa]59 this.heads.push(cHead);
60 this.openSnackBar("New head created!","OK");
61 },
62 (err: any) => console.log(err),
63 () => console.log("PharmacyHead inserted"));
[993189e]64 this.head = {
65 Email: '',
66 Passwd: '',
67 Name: ''
68 };
[de18858]69 }
70
[ee137aa]71 deletePharmacyHead(dHead: IPharmacyHead) {
72 this.dataService.deletePharmacyHead(dHead.id)
73 .subscribe((status: boolean) => {
74 if(status) {
75 this.openSnackBar("Head deleted!","OK");
76 }
77 },
78 (err: any) => console.log(err),
[dae4cde]79 () => {
80 console.log("PharmacyHead deleted");
81 location.reload();
82 });
[de18858]83 }
84
[ee137aa]85 openEditPharmacyHeadDialog(eHead: IPharmacyHead) {
86 let dialogRef = this.dialog.open(EditPharmacyHeadDialogComponent, {
87 width: '450px',
88 data: eHead
89 });
90 dialogRef.afterClosed().subscribe((editedHead: IPharmacyHead) => {
[dae4cde]91 if(editedHead) {
92 console.log(editedHead);
93 this.heads = this.heads.filter(x => x !== eHead);
94 this.heads.push(editedHead);
95 this.dataService.updatePharmacyHead(editedHead)
96 .subscribe((hd: IPharmacyHead) => {
97 this.openSnackBar("Success! PharmacyHead edited", "OK").onAction().subscribe(() => {
98 location.reload();
99 });
100 },
101 (err: any) => console.log(err),
102 () => console.log('PharmacyHead data updated'));
[ee137aa]103 }
104 });
105 }
[de18858]106
[ee137aa]107 openPharmacyDialog(pharmacy: IPharmacy): void {
108 this.dialog.open(PharmacyDialogComponent, {
109 width: '450px',
110 data: pharmacy
111 });
[de18858]112 }
113
[ee137aa]114 openPharmacyHeadDialog(hd: IPharmacyHead): void {
115 this.dialog.open(PharmacyHeadDialogComponent, {
116 width: '450px',
117 data: hd
118 });
119 }
[de18858]120
[ee137aa]121 rejectRequest(req: IPharmacyHeadRequest) {
[e0cdea2]122 this.dataService.deleteClaimingRequest(req)
[ee137aa]123 .subscribe((status: boolean) => {
124 if(status) {
[dae4cde]125 this.openSnackBar("Request processed!","OK");
[ee137aa]126 }
127 },
128 (err: any) => console.log(err),
[dae4cde]129 () => {
130 console.log("PharmacyHeadRequest deleted");
131 location.reload();
132 });
[de18858]133 }
134
[ee137aa]135 approveRequest(req: IPharmacyHeadRequest) {
136 if(req) {
[e0cdea2]137 if (req.PharmacyHead.Pharmacy == null){
138 req.PharmacyHead.Pharmacy = [];
139 }
[ee137aa]140 req.PharmacyHead.Pharmacy.push(req.Pharmacy);
141 this.dataService.updatePharmacyHead(req.PharmacyHead)
142 .subscribe(() => {
[1454207]143 this.rejectRequest(req);
[ee137aa]144 },
145 (err: any) => console.log(err),
[dae4cde]146 () => {
147 console.log("PharmacyHead updated");
148 location.reload();
149 })
[ee137aa]150 }
151 }
[de18858]152
[8e74e2f]153 logout() {
154 this.authService.logout();
155 }
156
[ee137aa]157 openSnackBar(message: string, action: string) : MatSnackBarRef<SimpleSnackBar> {
158 return this.snackBar.open(message, action, {
159 duration: 5000,
160 });
[785b8bd]161 }
162
163}
Note: See TracBrowser for help on using the repository browser.