Changeset ee137aa for Farmatiko/ClientApp/src/app/admin
- Timestamp:
- 08/07/20 10:59:56 (4 years ago)
- Branches:
- master
- Children:
- 63d885e
- Parents:
- c73269d
- Location:
- Farmatiko/ClientApp/src/app/admin
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
Farmatiko/ClientApp/src/app/admin/admin.component.css
rc73269d ree137aa 11 11 width: 30vh; 12 12 } 13 14 h2 { 15 text-align: center; 16 padding: 50px; 17 } -
Farmatiko/ClientApp/src/app/admin/admin.component.html
rc73269d ree137aa 22 22 <div class="wrapper"> 23 23 <div> 24 <table class='table table-striped table-bordered table-sm' cellspacing="0" width="100%" aria-labelledby="tableLabel" *ngIf=" true">24 <table class='table table-striped table-bordered table-sm' cellspacing="0" width="100%" aria-labelledby="tableLabel" *ngIf="requests"> 25 25 <thead> 26 26 <tr> … … 31 31 </thead> 32 32 <tbody> 33 <tr *ngFor="let head of heads">34 <td>{{ head.Name}} | {{head.Email}}</td>35 <td> {{head.Pharmacy[0].name}}</td>36 <td><a (click)=" Approve()">Approve</a> | <a (click)="Reject()">Reject</a></td>33 <tr *ngFor="let request of requests"> 34 <td>{{request.PharmacyHead.Name}} | {{request.PharmacyHead.Email}}</td> 35 <td><a (click)="openPharmacyDialog(request.Pharmacy)">{{request.Pharmacy.name}}</a></td> 36 <td><a (click)="approveRequest(request)">Approve</a> | <a (click)="rejectRequest(request)">Reject</a></td> 37 37 </tr> 38 38 </tbody> … … 44 44 <div class="wrapper"> 45 45 <div> 46 <table class='table table-striped table-bordered table-sm' cellspacing="0" width="100%" aria-labelledby="tableLabel" *ngIf=" true">46 <table class='table table-striped table-bordered table-sm' cellspacing="0" width="100%" aria-labelledby="tableLabel" *ngIf="heads"> 47 47 <thead> 48 48 <tr> … … 53 53 <tbody> 54 54 <tr *ngFor="let head of heads"> 55 <td> {{head.Name}}| {{head.Email}}</td>56 <td><a (click)=" Del(head)">Delete</a> | <a (click)="ChangeDialog(head)">Change</a></td>55 <td><a (click)="openPharmacyHeadDialog(head)">{{head.Name}}</a> | {{head.Email}}</td> 56 <td><a (click)="deletePharmacyHead(head)">Delete</a> | <a (click)="openEditPharmacyHeadDialog(head)">Change</a></td> 57 57 </tr> 58 58 </tbody> … … 62 62 </mat-tab> 63 63 <mat-tab label="Create new account"> 64 <div class="createform"> 64 <h2 *ngIf="!this.head">Loading form...</h2> 65 <div class="createform" *ngIf="this.head"> 65 66 <mat-form-field appearance="fill"> 66 67 <mat-label>Name</mat-label> 67 <input matInput [(ngModel)]=" head.Name">68 <input matInput [(ngModel)]="this.head.Name"> 68 69 </mat-form-field><br> 69 70 <mat-form-field appearance="fill"> 70 71 <mat-label>Email</mat-label> 71 <input matInput [(ngModel)]=" head.Email">72 <input matInput [(ngModel)]="this.head.Email"> 72 73 </mat-form-field><br> 73 74 <mat-form-field appearance="fill"> 74 75 <mat-label>Password</mat-label> 75 <input matInput [(ngModel)]=" head.Passwd">76 <input matInput [(ngModel)]="this.head.Passwd"> 76 77 </mat-form-field><br> 77 78 <button onclick="createHead()" mat-raised-button color="primary">Create</button> … … 79 80 </mat-tab> 80 81 </mat-tab-group> 81 82 <div class="status">{{status}}</div> -
Farmatiko/ClientApp/src/app/admin/admin.component.ts
rc73269d ree137aa 1 import { Component, OnInit, Inject, Output, EventEmitter } from '@angular/core'; 2 import { Pharmacy } from '../models/Pharmacy'; 3 import { HttpClient } from '@angular/common/http'; 1 import { Component, OnInit } from '@angular/core'; 4 2 import { MatDialog } from '@angular/material/dialog'; 5 3 import { MatSnackBar, MatSnackBarRef, SimpleSnackBar } from '@angular/material/snack-bar'; 6 import { Router, RouterModule } from '@angular/router'; 7 import { PharmacyHead } from '../models/PharmacyHead'; 8 import { FormControl } from '@angular/forms'; 4 import { Router } from '@angular/router'; 5 import { IPharmacyHead, IPharmacyHeadRequest, IPharmacy } from '../shared/interfaces'; 6 import { DataService } from '../shared/data.service'; 7 import { EditPharmacyHeadDialogComponent } from '../dialogs/edit-pharmacy-head-dialog/edit-pharmacy-head-dialog.component'; 8 import { PharmacyDialogComponent } from '../dialogs/pharmacy-dialog/pharmacy-dialog.component'; 9 import { PharmacyHeadDialogComponent } from '../nav-menu/dialogs/pharmacy-head-dialog/pharmacy-head-dialog.component'; 9 10 10 11 … … 15 16 }) 16 17 export class AdminComponent implements OnInit { 17 public heads: PharmacyHead[];18 public head: PharmacyHead;19 public status: string;18 public heads: IPharmacyHead[] = []; 19 public requests: IPharmacyHeadRequest[] = []; 20 public head: IPharmacyHead; 20 21 21 constructor(http: HttpClient, @Inject('BASE_URL') baseUrl: string, private dialog: MatDialog, private _snackBar: MatSnackBar, private router: Router) { 22 http.get<PharmacyHead[]>(baseUrl + 'PharmacyHead/Get?').subscribe(result => { 23 this.heads = result; 24 console.log(this.heads); 25 }, error => console.error(error)); 22 constructor(private dataService: DataService, private dialog: MatDialog, private snackBar: MatSnackBar, private router: Router) { 23 26 24 } 27 25 28 26 ngOnInit(): void { 29 this.head = new PharmacyHead(); 27 this.dataService.getPharmacyHeads() 28 .subscribe((pHeads: IPharmacyHead[]) => { 29 this.heads = pHeads; 30 }, 31 (err: any) => console.log(err), 32 () => console.log("PharmacyHead data retrieved")); 33 34 this.dataService.getClaimingRequests() 35 .subscribe((pRequests: IPharmacyHeadRequest[]) => { 36 this.requests = pRequests; 37 }, 38 (err: any) => console.log(err), 39 () => console.log("PharmacyHead data retrieved")); 30 40 } 31 41 32 42 createHead() { 33 console.log(this.head); 34 // post request vo prodolzenie 35 36 this.status="Status bar createHead"; 37 //window.location.reload(); 43 this.dataService.insertPharmacyHead(this.head) 44 .subscribe((cHead: IPharmacyHead) => { 45 if(cHead) { 46 this.heads.push(cHead); 47 this.openSnackBar("New head created!","OK"); 48 } 49 }, 50 (err: any) => console.log(err), 51 () => console.log("PharmacyHead inserted")); 52 this.head = null; 38 53 } 39 54 40 Del(head: PharmacyHead) { 41 console.log(this.head); 42 // post request vo prodolzenie 43 44 this.status="Status bar Del"; 55 deletePharmacyHead(dHead: IPharmacyHead) { 56 this.dataService.deletePharmacyHead(dHead.id) 57 .subscribe((status: boolean) => { 58 if(status) { 59 this.openSnackBar("Head deleted!","OK"); 60 } 61 }, 62 (err: any) => console.log(err), 63 () => console.log("PharmacyHead deleted")); 45 64 } 46 65 47 ChangeDialog(head: PharmacyHead) { 48 console.log(this.head); 49 66 openEditPharmacyHeadDialog(eHead: IPharmacyHead) { 67 let dialogRef = this.dialog.open(EditPharmacyHeadDialogComponent, { 68 width: '450px', 69 data: eHead 70 }); 71 dialogRef.afterClosed().subscribe((editedHead: IPharmacyHead) => { 72 if(editedHead){ 73 this.heads = this.heads.filter(x => x !== eHead); 74 this.heads.push(editedHead); 75 this.dataService.updatePharmacyHead(editedHead) 76 .subscribe((hd: IPharmacyHead) => { 77 if(hd) { 78 this.openSnackBar("Success! PharmacyHead edited", "OK").onAction().subscribe(() => { 79 window.location.reload(); 80 }); 81 } 82 else { 83 this.openSnackBar("PharmacyHead edit failed", "Try again"); 84 } 85 }, 86 (err: any) => console.log(err), 87 () => console.log('PharmacyHead data updated')); 88 } 89 }); 50 90 } 51 91 52 Reject() { 53 console.log('Rejected'); 54 // post request vo prodolzenie 55 92 openPharmacyDialog(pharmacy: IPharmacy): void { 93 this.dialog.open(PharmacyDialogComponent, { 94 width: '450px', 95 data: pharmacy 96 }); 56 97 } 57 98 58 Approve() { 59 console.log('Approved'); 60 // post request vo prodolzenie 99 openPharmacyHeadDialog(hd: IPharmacyHead): void { 100 this.dialog.open(PharmacyHeadDialogComponent, { 101 width: '450px', 102 data: hd 103 }); 104 } 61 105 106 rejectRequest(req: IPharmacyHeadRequest) { 107 this.dataService.deleteClaimingRequest(req.id) 108 .subscribe((status: boolean) => { 109 if(status) { 110 this.openSnackBar("Request rejected!","OK"); 111 } 112 else { 113 this.openSnackBar("Something went wrong","Try again"); 114 } 115 }, 116 (err: any) => console.log(err), 117 () => console.log("PharmacyHeadRequest deleted")); 118 } 119 120 approveRequest(req: IPharmacyHeadRequest) { 121 if(req) { 122 req.PharmacyHead.Pharmacy.push(req.Pharmacy); 123 this.dataService.updatePharmacyHead(req.PharmacyHead) 124 .subscribe(() => { 125 126 }, 127 (err: any) => console.log(err), 128 () => console.log("PharmacyHead updated")) 129 } 130 } 131 132 openSnackBar(message: string, action: string) : MatSnackBarRef<SimpleSnackBar> { 133 return this.snackBar.open(message, action, { 134 duration: 5000, 135 }); 62 136 } 63 137
Note:
See TracChangeset
for help on using the changeset viewer.