Changeset 993189e


Ignore:
Timestamp:
10/30/20 02:04:06 (2 years ago)
Author:
Mile Jankuloski <mile.jankuloski@…>
Branches:
master
Children:
1f4846d
Parents:
6f203af
Message:

Auth guards and services, refactored components

Location:
Farmatiko/ClientApp/src/app
Files:
2 added
8 edited

Legend:

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

    r6f203af r993189e  
    1818  public heads: IPharmacyHead[] = [];
    1919  public requests: IPharmacyHeadRequest[] = [];
    20   public head: IPharmacyHead;
     20  public head: IPharmacyHead = {
     21    id: '',
     22    PharmacyMedicines: null,
     23    Pharmacy: null,
     24    Email: '',
     25    Passwd: '',
     26    Name: ''
     27  };
    2128
    2229  constructor(private dataService: DataService, private dialog: MatDialog, private snackBar: MatSnackBar, private router: Router) {
     
    5057        (err: any) => console.log(err),
    5158        () => console.log("PharmacyHead inserted"));
    52     this.head = null;
     59    this.head = {
     60      id: '',
     61      PharmacyMedicines: null,
     62      Pharmacy: null,
     63      Email: '',
     64      Passwd: '',
     65      Name: ''
     66    };
    5367  }
    5468
  • Farmatiko/ClientApp/src/app/app.module.ts

    r6f203af r993189e  
    2525import { EditPharmacyHeadDialogComponent } from './dialogs/edit-pharmacy-head-dialog/edit-pharmacy-head-dialog.component';
    2626import { PharmacyHeadDialogComponent } from './nav-menu/dialogs/pharmacy-head-dialog/pharmacy-head-dialog.component';
     27import { AuthGuard } from './shared/auth.guard';
    2728
    2829@NgModule({
     
    5354      { path: 'koronavirus', component: KoronaComponent },
    5455      { path: 'admin', component: AdminComponent },
    55       { path: 'dashboard', component: DashboardComponent },
    56       { path: 'dashboard/:token', component: DashboardComponent },
     56      { path: 'dashboard', component: DashboardComponent, canActivate: [AuthGuard] },
    5757      { path: 'login', component: LoginComponent }
    5858    ]),
  • Farmatiko/ClientApp/src/app/dashboard/dashboard.component.ts

    r6f203af r993189e  
    88import { MedicineDialogComponent } from '../dialogs/medicine-dialog/medicine-dialog.component';
    99import { ActivatedRoute, Router } from '@angular/router';
     10import { AuthService } from '../shared/auth.service';
    1011
    1112@Component({
     
    2021  public filteredMedicines: IMedicine[] = [];
    2122  public request: IPharmacyHeadRequest;
    22   public token: string;
    2323
    24   constructor(private dataService: DataService, private dialog: MatDialog, private snackBar: MatSnackBar, private router: Router, private route: ActivatedRoute) {
     24  constructor(private dataService: DataService, private authService: AuthService, private dialog: MatDialog, private snackBar: MatSnackBar, private router: Router, private route: ActivatedRoute) {
    2525
    2626  }
    2727
    2828  ngOnInit(): void {
    29     this.token = this.route.snapshot.params['token'];
    30     this.dataService.getPharmacyHead(this.token)
    31         .subscribe((hd: IPharmacyHead) => {
    32           this.head = hd;
    33         },
    34         (err: any) => console.log(err),
    35         () => console.log('Head data retrieved'));
    36 
     29    this.head = this.authService.headValue;
    3730    this.dataService.getPharmacies()
    3831        .subscribe((pharmacy: IPharmacy[]) => {
  • Farmatiko/ClientApp/src/app/korona/korona.component.html

    r6f203af r993189e  
    55    <br />
    66    <div class="col text-center">
    7       <h2>{{korona[0].name}}</h2>
     7      <h2>{{korona.name}}</h2>
    88      <p>статистика</p>
    99    </div>
     
    1212    <div class="col">
    1313      <div class="counter" *ngIf="korona">
    14         <i class="fa fa-code fa-2x">{{korona[0].totalMK}}</i>
     14        <i class="fa fa-code fa-2x">{{korona.totalMK}}</i>
    1515        <h2 class="timer count-title count-number"></h2>
    1616        <p class="count-text ">Вкупно случаи во земјата</p>
     
    1919    <div class="col">
    2020      <div class="counter" *ngIf="korona">
    21         <i class="fa fa-coffee fa-2x">{{korona[0].activeMK}}</i>
     21        <i class="fa fa-coffee fa-2x">{{korona.activeMK}}</i>
    2222        <h2 class="timer count-title count-number"></h2>
    2323        <p class="count-text ">Активни случаи во земјата</p>
     
    2626    <div class="col">
    2727      <div class="counter" *ngIf="korona">
    28         <i class="fa fa-lightbulb-o fa-2x">{{korona[0].deathsMK}}</i>
     28        <i class="fa fa-lightbulb-o fa-2x">{{korona.deathsMK}}</i>
    2929        <h2 class="timer count-title count-number"></h2>
    3030        <p class="count-text ">Смртни случаи во земјата</p>
     
    3333    <div class="col">
    3434      <div class="counter" *ngIf="korona">
    35         <i class="fa fa-bug fa-2x">{{korona[0].newMK}}</i>
     35        <i class="fa fa-bug fa-2x">{{korona.newMK}}</i>
    3636        <h2 class="timer count-title count-number"></h2>
    3737        <p class="count-text ">Нови случаи во земјата</p>
     
    4242    <div class="col">
    4343      <div class="counter" *ngIf="korona">
    44         <i class="fa fa-bug fa-2x">{{korona[0].totalGlobal}}</i>
     44        <i class="fa fa-bug fa-2x">{{korona.totalGlobal}}</i>
    4545        <h2 class="timer count-title count-number"></h2>
    4646        <p class="count-text ">Вкупно случаи глобално</p>
     
    4949    <div class="col">
    5050      <div class="counter" *ngIf="korona">
    51         <i class="fa fa-bug fa-2x">{{korona[0].activeGlobal}}</i>
     51        <i class="fa fa-bug fa-2x">{{korona.activeGlobal}}</i>
    5252        <h2 class="timer count-title count-number"></h2>
    5353        <p class="count-text ">Активни случаи глобално</p>
     
    5656    <div class="col">
    5757      <div class="counter" *ngIf="korona">
    58         <i class="fa fa-bug fa-2x">{{korona[0].deathsGlobal}}</i>
     58        <i class="fa fa-bug fa-2x">{{korona.deathsGlobal}}</i>
    5959        <h2 class="timer count-title count-number"></h2>
    6060        <p class="count-text ">Смртни случаи глобално</p>
  • Farmatiko/ClientApp/src/app/korona/korona.component.ts

    r6f203af r993189e  
    99})
    1010export class KoronaComponent implements OnInit {
    11   public korona: IPandemic[];
     11  public korona: IPandemic;
    1212
    1313  constructor(private dataService: DataService) {
     
    1717  ngOnInit(): void {
    1818    this.dataService.getPandemic()
    19         .subscribe((res: IPandemic[]) => {
     19        .subscribe((res: IPandemic) => {
    2020          this.korona = res;
    2121          console.log(this.korona);
  • Farmatiko/ClientApp/src/app/login/login.component.ts

    r6f203af r993189e  
    22import { FormGroup, FormControl, Validators } from '@angular/forms';
    33import { Router, ActivatedRoute } from '@angular/router';
    4 import { DataService } from '../shared/data.service';
     4import { first } from 'rxjs/operators';
     5import { AuthService } from '../shared/auth.service';
    56
    67@Component({
     
    1516  errorMessage: string;
    1617
    17   constructor(private dataService: DataService,private router: Router, private route: ActivatedRoute) {
     18  constructor(private authService: AuthService,private router: Router, private route: ActivatedRoute) {
    1819    this.loginForm = new FormGroup({
    1920      email: new FormControl('', [Validators.required, Validators.email]),
     
    2627
    2728  loginPharmacyHead() {
    28     this.dataService.loginPharmacyHead(this.email, this.passwd)
    29                 .subscribe((id: Number) => {
    30                   if(id) {
    31                     this.router.navigate(['/dashboard/' + id]);
    32                   }
    33                   else {
    34                     this.errorMessage = 'There was a problem signing in!';
    35                     console.log(this.errorMessage);
    36                   }
    37                 },
    38                 (err: any) => console.log(err));
     29    this.authService.login(this.email,this.passwd)
     30        .pipe(first())
     31        .subscribe((data) => {
     32            if(data) {
     33              this.router.navigate(['/dashboard']);
     34            }},
     35            (err: any) => {
     36                this.errorMessage = err.toString();
     37            });
     38    this.loginForm.reset();
    3939  }
    4040}
  • Farmatiko/ClientApp/src/app/shared/data.service.ts

    r6f203af r993189e  
    1 import { Injectable, } from '@angular/core';
     1import { Injectable } from '@angular/core';
    22import { HttpClient, HttpErrorResponse } from '@angular/common/http';
    33
     
    9595
    9696
    97     getPandemic() : Observable<IPandemic[]> {
    98         return this.http.get<IPandemic[]>(this.basePandemicUrl)
     97    getPandemic() : Observable<IPandemic> {
     98        return this.http.get<IPandemic>(this.basePandemicUrl)
    9999                   .pipe(catchError(this.handleError));
    100100    }
     
    143143                        catchError(this.handleError)
    144144                   );
    145     }
    146     loginPharmacyHead(email: string, passwd: string) : Observable<any> {
    147         let postData = {email : email ,password :passwd};
    148         return this.http.post<any>(this.basePharmacyHead + '/login', postData)
    149                    .pipe(
    150                         map((data) => {
    151                             return data;
    152                         }),
    153                         catchError(this.handleError)
    154                     );
    155     }
    156     getPharmacyHead(id: string) : Observable<IPharmacyHead> {
    157         return this.http.get<IPharmacyHead>(this.basePharmacyHead + '/' + id)
    158                    .pipe(catchError(this.handleError));
    159145    }
    160146    //PharmacyHead POST
  • Farmatiko/ClientApp/src/app/shared/interfaces.ts

    r6f203af r993189e  
    2929
    3030export interface IPandemic {
     31    id?: string;
    3132    name?: string;
    3233    totalMK?: number;
Note: See TracChangeset for help on using the changeset viewer.