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

Added DataService and dialogs, all bindings needed implemented

Location:
Farmatiko/ClientApp/src/app/admin
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • Farmatiko/ClientApp/src/app/admin/admin.component.css

    rc73269d ree137aa  
    1111    width: 30vh;
    1212}
     13
     14h2 {
     15    text-align: center;
     16    padding: 50px;
     17}
  • Farmatiko/ClientApp/src/app/admin/admin.component.html

    rc73269d ree137aa  
    2222        <div class="wrapper">
    2323          <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">
    2525              <thead>
    2626                <tr>
     
    3131              </thead>
    3232              <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>
    3737                </tr>
    3838              </tbody>
     
    4444        <div class="wrapper">
    4545          <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">
    4747              <thead>
    4848                <tr>
     
    5353              <tbody>
    5454                <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>
    5757                </tr>
    5858              </tbody>
     
    6262      </mat-tab>
    6363        <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">
    6566          <mat-form-field appearance="fill">
    6667            <mat-label>Name</mat-label>
    67             <input matInput [(ngModel)]="head.Name">
     68            <input matInput [(ngModel)]="this.head.Name">
    6869          </mat-form-field><br>
    6970          <mat-form-field appearance="fill">
    7071            <mat-label>Email</mat-label>
    71             <input matInput [(ngModel)]="head.Email">
     72            <input matInput [(ngModel)]="this.head.Email">
    7273          </mat-form-field><br>
    7374          <mat-form-field appearance="fill">
    7475            <mat-label>Password</mat-label>
    75             <input matInput [(ngModel)]="head.Passwd">
     76            <input matInput [(ngModel)]="this.head.Passwd">
    7677          </mat-form-field><br>
    7778            <button onclick="createHead()" mat-raised-button color="primary">Create</button>
     
    7980        </mat-tab>
    8081</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';
     1import { Component, OnInit } from '@angular/core';
    42import { MatDialog } from '@angular/material/dialog';
    53import { 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';
     4import { Router } from '@angular/router';
     5import { IPharmacyHead, IPharmacyHeadRequest, IPharmacy } from '../shared/interfaces';
     6import { DataService } from '../shared/data.service';
     7import { EditPharmacyHeadDialogComponent } from '../dialogs/edit-pharmacy-head-dialog/edit-pharmacy-head-dialog.component';
     8import { PharmacyDialogComponent } from '../dialogs/pharmacy-dialog/pharmacy-dialog.component';
     9import { PharmacyHeadDialogComponent } from '../nav-menu/dialogs/pharmacy-head-dialog/pharmacy-head-dialog.component';
    910
    1011
     
    1516})
    1617export 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;
    2021
    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
    2624  }
    2725
    2826  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"));
    3040  }
    3141
    3242  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;
    3853  }
    3954
    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"));
    4564  }
    4665
    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    });
    5090  }
    5191
    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    });
    5697  }
    5798
    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  }
    61105
     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    });
    62136  }
    63137
Note: See TracChangeset for help on using the changeset viewer.