Changeset 1f4846d
- Timestamp:
- 11/01/20 00:55:08 (4 years ago)
- Branches:
- master
- Children:
- d23bf72
- Parents:
- 993189e
- Location:
- Farmatiko/ClientApp/src/app
- Files:
-
- 6 added
- 2 deleted
- 9 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
Farmatiko/ClientApp/src/app/admin/admin.component.ts
r993189e r1f4846d 4 4 import { Router } from '@angular/router'; 5 5 import { IPharmacyHead, IPharmacyHeadRequest, IPharmacy } from '../shared/interfaces'; 6 import { DataService } from '../shared/ data.service';6 import { DataService } from '../shared/services/data.service'; 7 7 import { EditPharmacyHeadDialogComponent } from '../dialogs/edit-pharmacy-head-dialog/edit-pharmacy-head-dialog.component'; 8 8 import { PharmacyDialogComponent } from '../dialogs/pharmacy-dialog/pharmacy-dialog.component'; -
Farmatiko/ClientApp/src/app/app.module.ts
r993189e r1f4846d 7 7 import { ReactiveFormsModule } from '@angular/forms'; 8 8 9 import { DataService } from './shared/data.service';9 import { CoreModule } from './shared/core.module'; 10 10 11 import { AuthGuard } from './shared/guards/auth.guard'; 12 import { DataService } from './shared/services/data.service'; 11 13 import { AppComponent } from './app.component'; 12 14 import { NavMenuComponent } from './nav-menu/nav-menu.component'; … … 25 27 import { EditPharmacyHeadDialogComponent } from './dialogs/edit-pharmacy-head-dialog/edit-pharmacy-head-dialog.component'; 26 28 import { PharmacyHeadDialogComponent } from './nav-menu/dialogs/pharmacy-head-dialog/pharmacy-head-dialog.component'; 27 import { AuthGuard } from './shared/auth.guard';28 29 29 30 @NgModule({ … … 53 54 { path: 'mapa', component: CounterComponent }, 54 55 { path: 'koronavirus', component: KoronaComponent }, 55 { path: 'admin', component: AdminComponent },56 { path: 'admin', component: AdminComponent, canActivate: [AuthGuard] }, 56 57 { path: 'dashboard', component: DashboardComponent, canActivate: [AuthGuard] }, 57 58 { path: 'login', component: LoginComponent } … … 59 60 BrowserAnimationsModule, 60 61 MaterialModule, 61 ReactiveFormsModule 62 ReactiveFormsModule, 63 CoreModule 62 64 ], 63 65 providers: [ -
Farmatiko/ClientApp/src/app/counter/counter.component.ts
r993189e r1f4846d 1 1 import { Component, OnInit } from '@angular/core'; 2 2 import { IHealthFacilities, IHealthcareWorkers } from '../shared/interfaces'; 3 import { DataService } from '../shared/ data.service';3 import { DataService } from '../shared/services/data.service'; 4 4 import { MatDialog } from '@angular/material/dialog'; 5 5 import { FacilityDialogComponent } from '../dialogs/facility-dialog/facility-dialog.component'; -
Farmatiko/ClientApp/src/app/dashboard/dashboard.component.ts
r993189e r1f4846d 3 3 import { MatSnackBar, MatSnackBarRef, SimpleSnackBar } from '@angular/material/snack-bar'; 4 4 import { IPharmacy, IMedicine, IPharmacyHead, IPharmacyHeadRequest } from '../shared/interfaces'; 5 import { DataService } from '../shared/ data.service';5 import { DataService } from '../shared/services/data.service'; 6 6 import { PharmacyDialogComponent } from '../dialogs/pharmacy-dialog/pharmacy-dialog.component'; 7 7 import { EditPharmacyDialogComponent } from '../dialogs/edit-pharmacy-dialog/edit-pharmacy-dialog.component'; 8 8 import { MedicineDialogComponent } from '../dialogs/medicine-dialog/medicine-dialog.component'; 9 9 import { ActivatedRoute, Router } from '@angular/router'; 10 import { AuthService } from '../shared/ auth.service';10 import { AuthService } from '../shared/services/auth.service'; 11 11 12 12 @Component({ … … 27 27 28 28 ngOnInit(): void { 29 this.head = this.authService.headValue; 29 this.authService.getUser().subscribe((data : IPharmacyHead) => { 30 this.head = data; 31 }); 30 32 this.dataService.getPharmacies() 31 33 .subscribe((pharmacy: IPharmacy[]) => { -
Farmatiko/ClientApp/src/app/home/home.component.ts
r993189e r1f4846d 1 1 import { Component, OnInit } from '@angular/core'; 2 2 import { IMedicine, IPharmacy } from '../shared/interfaces'; 3 import { DataService } from '../shared/ data.service';3 import { DataService } from '../shared/services/data.service'; 4 4 import { MatDialog } from '@angular/material/dialog'; 5 5 import { MedicineDialogComponent } from '../dialogs/medicine-dialog/medicine-dialog.component'; -
Farmatiko/ClientApp/src/app/korona/korona.component.ts
r993189e r1f4846d 1 1 import { Component, OnInit } from '@angular/core'; 2 import { DataService } from '../shared/ data.service';2 import { DataService } from '../shared/services/data.service'; 3 3 import { IPandemic } from '../shared/interfaces'; 4 4 -
Farmatiko/ClientApp/src/app/login/login.component.html
r993189e r1f4846d 6 6 <div class="example-container"> 7 7 <mat-form-field> 8 <input matInput placeholder="Email" [(ngModel)]="this. email" formControlName="email">8 <input matInput placeholder="Email" [(ngModel)]="this.username" formControlName="email"> 9 9 </mat-form-field> 10 10 11 11 <mat-form-field> 12 <input matInput type="password" placeholder="Password" [(ngModel)]="this.passw d" formControlName="password">12 <input matInput type="password" placeholder="Password" [(ngModel)]="this.password" formControlName="password"> 13 13 </mat-form-field> 14 14 15 15 <button [disabled]="!loginForm.valid" mat-raised-button color="primary" (click)="loginPharmacyHead()" mat-button>Најави се</button> 16 17 <div class="checkbox mb-3 text-danger" *ngIf="loginError"> 18 Login failed. Please try again. 19 </div> 16 20 </div> 17 21 </form> -
Farmatiko/ClientApp/src/app/login/login.component.ts
r993189e r1f4846d 1 import { Component, OnInit } from '@angular/core';1 import { Component, OnInit, OnDestroy } from '@angular/core'; 2 2 import { FormGroup, FormControl, Validators } from '@angular/forms'; 3 3 import { Router, ActivatedRoute } from '@angular/router'; 4 import { Subscription } from 'rxjs'; 4 5 import { first } from 'rxjs/operators'; 5 import { AuthService } from '../shared/auth.service'; 6 import { AuthService } from '../shared/services/auth.service'; 7 import { finalize } from 'rxjs/operators'; 6 8 7 9 @Component({ … … 10 12 styleUrls: ['./login.component.css'] 11 13 }) 12 export class LoginComponent implements OnInit { 14 export class LoginComponent implements OnInit, OnDestroy { 15 busy = false; 13 16 loginForm: FormGroup; 14 email: string; 15 passwd: string; 16 errorMessage: string; 17 username = ''; 18 password = ''; 19 loginError = false; 20 private subscription: Subscription; 17 21 18 22 constructor(private authService: AuthService,private router: Router, private route: ActivatedRoute) { 19 23 this.loginForm = new FormGroup({ 20 email: new FormControl('', [Validators.required, Validators.email]),24 username: new FormControl('', [Validators.required, Validators.email]), 21 25 password: new FormControl('', [Validators.required]) 22 26 }); 23 27 } 28 ngOnDestroy(): void { 29 this.subscription?.unsubscribe(); 30 } 24 31 25 32 ngOnInit(): void { 33 this.subscription = this.authService.user$.subscribe((x) => { 34 if (this.route.snapshot.url[0].path === 'login') { 35 const accessToken = localStorage.getItem('access_token'); 36 const refreshToken = localStorage.getItem('refresh_token'); 37 if (x && accessToken && refreshToken) { 38 const returnUrl = this.route.snapshot.queryParams['returnUrl'] || ''; 39 this.router.navigate([returnUrl]); 40 } 41 } 42 }); 26 43 } 27 44 28 45 loginPharmacyHead() { 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 }); 46 if (!this.username || !this.password) { 47 return; 48 } 49 this.busy = true; 50 const returnUrl = this.route.snapshot.queryParams['returnUrl'] || ''; 51 this.authService 52 .login(this.username, this.password) 53 .pipe(finalize(() => (this.busy = false))) 54 .subscribe( 55 () => { 56 this.router.navigate(['/dashboard']); 57 }, 58 () => { 59 this.loginError = true; 60 } 61 ); 38 62 this.loginForm.reset(); 39 63 } -
Farmatiko/ClientApp/src/app/shared/interfaces.ts
r993189e r1f4846d 55 55 Passwd: string; 56 56 Name: string; 57 Role?: string; 57 58 } 58 59 -
Farmatiko/ClientApp/src/app/shared/services/data.service.ts
r993189e r1f4846d 5 5 import { map, catchError } from 'rxjs/operators'; 6 6 7 import { IHealthFacilities, IHealthcareWorkers, IMedicine, IPandemic, IPharmacy, IPharmacyHead, IPharmacyHeadRequest } from '. /interfaces';7 import { IHealthFacilities, IHealthcareWorkers, IMedicine, IPandemic, IPharmacy, IPharmacyHead, IPharmacyHeadRequest } from '../interfaces'; 8 8 9 9 @Injectable()
Note:
See TracChangeset
for help on using the changeset viewer.