feat: Navigationsleiste angepasst, Logout- und Neuen-Umschlag-Button hinzugefügt

- Navigationsleiste überarbeitet und das Layout optimiert.
- Logout-Button hinzugefügt, um den Benutzern das Abmelden zu erleichtern.
- Button für das Erstellen eines neuen Umschlags hinzugefügt, um die Benutzerfreundlichkeit zu verbessern.
This commit is contained in:
Developer 02 2024-08-19 16:43:24 +02:00
parent 609f7d09fc
commit a14bd78415
6 changed files with 127 additions and 45 deletions

View File

@ -1,23 +1,25 @@
<!-- src/app/components/login/login.component.html -->
<form [formGroup]="loginForm" (ngSubmit)="onSubmit()">
<div class="mb-3">
<mat-form-field>
<mat-label>Username</mat-label>
<input matInput formControlName="username">
</mat-form-field>
</div>
<div class="mb-3">
<mat-form-field>
<mat-label>Enter your password</mat-label>
<input matInput [type]="hide ? 'password' : 'text'" formControlName="password">
<button type="button" mat-icon-button matSuffix (click)="togglePWVisibility($event)" [attr.aria-label]="'Hide password'"
[attr.aria-pressed]="hide">
<mat-icon>{{hide ? 'visibility_off' : 'visibility'}}</mat-icon>
</button>
</mat-form-field>
</div>
<div class="mb-3">
<button mat-flat-button color="primary" type="submit">Log In</button>
</div>
</form>
<div class="mb-3">
<mat-form-field>
<mat-label>Username</mat-label>
<input matInput formControlName="username">
</mat-form-field>
</div>
<div class="mb-3">
<mat-form-field>
<mat-label>Enter your password</mat-label>
<input matInput [type]="hide ? 'password' : 'text'" formControlName="password">
<button type="button" mat-icon-button matSuffix (click)="togglePWVisibility($event)"
[attr.aria-label]="'Hide password'" [attr.aria-pressed]="hide">
<mat-icon>{{hide ? 'visibility_off' : 'visibility'}}</mat-icon>
</button>
</mat-form-field>
</div>
<div class="mb-3">
<button type="submit" class="btn" mat-flat-button color="primary">
<span class="me-2">Anmeldung</span>
<span class="p-0 m-0" [class.spinner-border]="wait4waitRes" [class.spinner-border-sm]="wait4waitRes" aria-hidden="true"></span>
</button>
</div>
</form>

View File

@ -18,6 +18,7 @@ import { ReactiveFormsModule } from '@angular/forms';
export class LoginComponent {
hide = true;
loginForm: FormGroup;
wait4waitRes: boolean = false;
constructor(private fb: FormBuilder, private authService: AuthService, private router: Router) {
this.loginForm = this.fb.group({
@ -33,12 +34,14 @@ export class LoginComponent {
onSubmit() {
if (this.loginForm.valid) {
this.wait4waitRes = true;
this.authService.login(this.loginForm.value).subscribe({
next: () => {
this.router.navigate(['/envelope']);
this.wait4waitRes = false;
this.router.navigate(['/envelope']);
},
error: error => {
console.error('Login failed', error);
this.wait4waitRes = false;
}
});
}

View File

@ -1,6 +1,36 @@
<mat-toolbar color="primary" class="toolbar">
<button mat-icon-button>
<mat-icon>menu</mat-icon>
</button>
<span>signFlow</span>
</mat-toolbar>
<header>
<nav class="navbar navbar-expand-lg bg-body-tertiary fs-5">
<div class="container-fluid">
<a class="navbar-brand fs-2 fw-bold" [routerLink]="['/']">SignFlow</a>
<!-- Navbars -->
<div *ngIf="isLogedIn()" class="navbar-collapse collapse d-sm-inline-flex justify-content-center"
[ngClass]="{ show: isExpanded }">
<ul class=" navbar-nav flex-grow">
<li class="nav-item" [routerLinkActive]="['link-active']" [routerLinkActiveOptions]="{exact: true}">
<button class="btn nav-link d-flex flex-column align-items-center justify-content-center" (click)="router.navigate(['/'])">
<mat-icon>mail</mat-icon>
<span class="fs-6">Neuer Umschlag</span>
</button>
</li>
</ul>
</div>
<!-- Right menu -->
<div class="navbar-collapse justify-content-end me-5">
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target=".navbar-collapse"
aria-label="Toggle navigation" [attr.aria-expanded]="isExpanded" (click)="toggle()">
<span class="navbar-toggler-icon"></span>
</button>
<button class="fs-5 btn d-flex align-items-center ms-2 me-0 pe-0" type="button" (click)="logInOut()">
@if(isLogedIn()){
<mat-icon>logout</mat-icon>
<span class="fs-6 ms-1">Abmelden</span>
}
@else {
<mat-icon>login</mat-icon>
<span class="fs-6 ms-1">Anmelden</span>
}
</button>
</div>
</div>
</nav>
</header>

View File

@ -1,23 +1,55 @@
import { Component } from '@angular/core';
import { MatToolbarModule } from '@angular/material/toolbar';
import { Component, QueryList, ViewChildren } from '@angular/core';
import { Router, RouterModule } from '@angular/router';
import { CommonModule } from '@angular/common';
import { MatBadgeModule } from '@angular/material/badge';
import { MatSlideToggleModule } from '@angular/material/slide-toggle';
import { FormsModule } from '@angular/forms';
import { MatTooltip, MatTooltipModule } from '@angular/material/tooltip';
import { MatButtonModule } from '@angular/material/button';
import { MatIconModule } from '@angular/material/icon';
import { MatSidenavModule } from '@angular/material/sidenav';
import { MatListModule } from '@angular/material/list';
import { AuthService } from '../../services/auth.service'
import { Observable } from 'rxjs';
@Component({
selector: 'app-navbar',
standalone: true,
imports: [
MatToolbarModule,
MatButtonModule,
MatIconModule,
MatSidenavModule,
MatListModule
],
imports: [RouterModule, CommonModule, MatIconModule, MatBadgeModule, MatSlideToggleModule, FormsModule, MatButtonModule, MatTooltipModule],
selector: 'app-navbar',
templateUrl: './navbar.component.html',
styleUrl: './navbar.component.scss'
styleUrls: ['./navbar.component.scss']
})
export class NavbarComponent {
isLogedIn(): boolean {
return this.authService.IsAuthenticated;
}
}
async logInOut(): Promise<void> {
if (this.isLogedIn())
return this.authService.logoutAsync().then(() => {
this.router.navigate(['/']);
})
else
this.router.navigate(['/login']);
}
isExpanded = false;
isChecked = true;
constructor(public router: Router, public authService: AuthService) {
}
get isDarkTheme(): boolean {
return false;
}
collapse() {
this.isExpanded = false;
}
toggle() {
this.isExpanded = !this.isExpanded;
}
@ViewChildren(MatTooltip) tooltips: QueryList<MatTooltip> | undefined;
}

View File

@ -1,6 +1,6 @@
import { Injectable, inject } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
import { Observable, firstValueFrom, tap } from 'rxjs';
import { API_URL } from '../tokens/index';
@Injectable({
@ -22,7 +22,18 @@ export class AuthService {
return this.http.post(`${this.url}/logout`, {});
}
async logoutAsync(): Promise<void> {
return await firstValueFrom(this.logout());
}
isAuthenticated(): Observable<boolean> {
return this.http.get<boolean>(`${this.url}/check`);
return this.http.get<boolean>(`${this.url}/check`).pipe(
tap(isAuthenticated => this.#IsAuthenticated = isAuthenticated)
);
}
#IsAuthenticated = false;
get IsAuthenticated(): boolean {
return this.#IsAuthenticated;
}
}

View File

@ -0,0 +1,4 @@
<svg xmlns="http://www.w3.org/2000/svg" width="3em" height="2.5em" viewBox="0 0 24 24" style="stroke: #a9a8ad;">
<path opacity="0.5" d="M15.9998 2L14.9998 2C12.1714 2 10.7576 2.00023 9.87891 2.87891C9.00023 3.75759 9.00023 5.1718 9.00023 8.00023L9.00023 16.0002C9.00023 18.8287 9.00023 20.2429 9.87891 21.1215C10.7574 22 12.1706 22 14.9976 22L14.9998 22L15.9998 22C18.8282 22 20.2424 22 21.1211 21.1213C21.9998 20.2426 21.9998 18.8284 21.9998 16L21.9998 8L21.9998 7.99998C21.9998 5.17157 21.9998 3.75736 21.1211 2.87868C20.2424 2 18.8282 2 15.9998 2Z" fill="#1C274C"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M1.25098 11.999C1.25098 11.5848 1.58676 11.249 2.00098 11.249L13.9735 11.249L12.0129 9.56845C11.6984 9.29889 11.662 8.82541 11.9315 8.51092C12.2011 8.19642 12.6746 8.16 12.9891 8.42957L16.4891 11.4296C16.6553 11.5721 16.751 11.7801 16.751 11.999C16.751 12.218 16.6553 12.426 16.4891 12.5685L12.9891 15.5685C12.6746 15.838 12.2011 15.8016 11.9315 15.4871C11.662 15.1726 11.6984 14.6991 12.0129 14.4296L13.9735 12.749L2.00098 12.749C1.58676 12.749 1.25098 12.4132 1.25098 11.999Z" fill="#1C274C"/>
</svg>

After

Width:  |  Height:  |  Size: 1.1 KiB