-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
migracja dyrektyw do nowego angulara (ngIf, ngFor)
poprawienie logiki logowania loading spinner
- Loading branch information
Showing
25 changed files
with
532 additions
and
388 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,43 @@ | ||
import {Injectable} from '@angular/core'; | ||
import { | ||
HttpErrorResponse, | ||
HttpEvent, | ||
HttpHandler, | ||
HttpHeaders, | ||
HttpInterceptor, | ||
HttpRequest | ||
} from '@angular/common/http'; | ||
import {Observable, tap} from 'rxjs'; | ||
import {HttpErrorResponse, HttpEvent, HttpHandler, HttpInterceptor, HttpRequest} from '@angular/common/http'; | ||
import {finalize, Observable, tap} from 'rxjs'; | ||
import {AuthService} from "./auth.service"; | ||
import {Router} from "@angular/router"; | ||
import {LoadingService} from "../service/loading.service"; | ||
|
||
@Injectable() | ||
export class JwtInterceptor implements HttpInterceptor { | ||
private totalRequests = 0; | ||
|
||
constructor(private authService: AuthService, | ||
private router: Router) { | ||
private router: Router, | ||
private loadingService: LoadingService) { | ||
} | ||
|
||
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> { | ||
// add auth header with jwt if account is logged in and request is to the api url | ||
let httpHeaders = new HttpHeaders(); | ||
// const account = this.authService.user.value; | ||
// const isLoggedIn = account?.token; | ||
// if (isLoggedIn) { | ||
// httpHeaders = httpHeaders.append('Authorization', `Bearer ${account.token}`); | ||
// } | ||
|
||
// const xsrfHeader = window.sessionStorage.getItem('XSRF-TOKEN'); | ||
// console.log(xsrfHeader); | ||
// if (xsrfHeader) { | ||
// httpHeaders = httpHeaders.append('X-XSRF-TOKEN', xsrfHeader); | ||
// } | ||
|
||
this.loadingService.setLoading(true); | ||
this.totalRequests++; | ||
request = request.clone({ | ||
headers: httpHeaders, | ||
withCredentials: true | ||
}); | ||
|
||
return next.handle(request).pipe(tap({ | ||
error: (err: any) => { | ||
if (err instanceof HttpErrorResponse) { | ||
if (err.status === 401 || err.status === 403) { | ||
console.log('redirect'); | ||
this.authService.logout(); | ||
this.router.navigate(['login']); | ||
return next.handle(request).pipe( | ||
finalize(() => { | ||
this.totalRequests--; | ||
if (this.totalRequests == 0) { | ||
this.loadingService.setLoading(false); | ||
} | ||
}), | ||
tap({ | ||
error: (err: any) => { | ||
if (err instanceof HttpErrorResponse) { | ||
if (err.status === 401 || err.status === 403) { | ||
console.log('redirect'); | ||
this.authService.logout(); | ||
this.router.navigate(['login']); | ||
} | ||
} | ||
} | ||
} | ||
})); | ||
})); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,3 @@ | ||
<div class="container"> | ||
<dashboard></dashboard> | ||
</div> | ||
<!-- | ||
<div class="container"> | ||
<div class="float-start">Komornik</div> | ||
<div *ngIf="loggedUser" class="float-end">Witaj {{loggedUser.groupName}}!</div> | ||
<header-menu (loggedOut)="onLoggedOut()"></header-menu> | ||
</div> | ||
--> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
src/main/frontend/src/app/component/common/spinner/spinner.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
@if (loadingService.isLoading()) { | ||
<div class="cssload-container"> | ||
<div class="cssload-speeding-wheel"></div> | ||
</div> | ||
} |
65 changes: 65 additions & 0 deletions
65
src/main/frontend/src/app/component/common/spinner/spinner.component.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
.cssload-container { | ||
position: fixed; | ||
width: 100%; | ||
left: 0; | ||
right: 0; | ||
top: 0; | ||
bottom: 0; | ||
background-color: rgba(255, 255, 255, 0.7); | ||
z-index: 9999; | ||
} | ||
|
||
.cssload-speeding-wheel { | ||
content: ""; | ||
display: block; | ||
position: absolute; | ||
left: 48%; | ||
top: 40%; | ||
width: 63px; | ||
height: 63px; | ||
margin: 0 auto; | ||
border: 4px solid rgb(0, 0, 0); | ||
border-radius: 50%; | ||
border-left-color: transparent; | ||
border-right-color: transparent; | ||
animation: cssload-spin 500ms infinite linear; | ||
-o-animation: cssload-spin 500ms infinite linear; | ||
-ms-animation: cssload-spin 500ms infinite linear; | ||
-webkit-animation: cssload-spin 500ms infinite linear; | ||
-moz-animation: cssload-spin 500ms infinite linear; | ||
} | ||
|
||
@keyframes cssload-spin { | ||
100% { | ||
transform: rotate(360deg); | ||
transform: rotate(360deg); | ||
} | ||
} | ||
|
||
@-o-keyframes cssload-spin { | ||
100% { | ||
-o-transform: rotate(360deg); | ||
transform: rotate(360deg); | ||
} | ||
} | ||
|
||
@-ms-keyframes cssload-spin { | ||
100% { | ||
-ms-transform: rotate(360deg); | ||
transform: rotate(360deg); | ||
} | ||
} | ||
|
||
@-webkit-keyframes cssload-spin { | ||
100% { | ||
-webkit-transform: rotate(360deg); | ||
transform: rotate(360deg); | ||
} | ||
} | ||
|
||
@-moz-keyframes cssload-spin { | ||
100% { | ||
-moz-transform: rotate(360deg); | ||
transform: rotate(360deg); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/frontend/src/app/component/common/spinner/spinner.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import {Component} from '@angular/core'; | ||
import {LoadingService} from "../../../service/loading.service"; | ||
import {NgIf} from "@angular/common"; | ||
|
||
@Component({ | ||
selector: 'spinner', | ||
templateUrl: './spinner.component.html', | ||
standalone: true, | ||
imports: [ | ||
NgIf | ||
], | ||
styleUrl: './spinner.component.scss' | ||
}) | ||
export class SpinnerComponent { | ||
constructor(protected loadingService: LoadingService) { | ||
} | ||
|
||
} |
Oops, something went wrong.