feat: enhance NavMenuComponent with updateService integration

- Added MatBadgeModule for update count display.
- Integrated `updateService` to show update count in the save button.
- Added change listener to update button count dynamically.
- Improved HTML structure with updated menu and button functionalities.
This commit is contained in:
Developer 02
2024-08-06 15:32:51 +02:00
parent 0fe9cb7126
commit e00c113bee
3 changed files with 12 additions and 5 deletions

View File

@@ -31,7 +31,7 @@
<div class="navbar-collapse justify-content-end me-5">
<a class="navbar-brand" [routerLink]="['/']">User Manager Portal</a>
<button *ngIf="isLogedIn()" class="btn">
<mat-icon class="scale-pulse" (click)="updateService.executeAll()">save</mat-icon>
<mat-icon class="scale-pulse" [matBadge]="updateActCount === 0 ? '' : updateActCount" (click)="updateService.executeAll()">save</mat-icon>
</button>
<button *ngIf="isLogedIn()" class="btn">
<mat-icon class="scale-pulse" (click)="creationService.openDialog()">add_to_photos</mat-icon>

View File

@@ -9,10 +9,11 @@ import { MatIconModule } from '@angular/material/icon';
import { RefreshService } from '../../services/refresh.service';
import { CreationService } from '../../services/creation.service';
import { UpdateService } from '../../services/update.service';
import {MatBadgeModule} from '@angular/material/badge';
@Component({
standalone: true,
imports: [RouterModule, CommonModule, ColorModeBttnComponent, MatIconModule],
imports: [RouterModule, CommonModule, ColorModeBttnComponent, MatIconModule, MatBadgeModule],
selector: 'app-nav-menu',
templateUrl: './nav-menu.component.html',
styleUrls: ['./nav-menu.component.css']
@@ -23,8 +24,14 @@ export class NavMenuComponent {
}
isExpanded = false;
updateActCount: number;
constructor(private dialog: MatDialog, private authService: AuthenticationService, public refreshService: RefreshService, public creationService : CreationService, public updateService: UpdateService) {
this.authService.isAuthenticated().then().catch()
this.updateActCount = this.updateService.totalCount;
this.updateService.addChangeListener(() => {
this.updateActCount = updateService.totalCount;
})
}
get isDarkTheme(): boolean {

View File

@@ -51,9 +51,9 @@ export class UpdateService {
}
//change listeners
private changeListeners: Array<(updateService: UpdateService) => void> = new Array();
private changeListeners: Array<() => void> = new Array();
addChangeListener(action: (updateService: UpdateService) => void) {
addChangeListener(action: () => void) {
this.changeListeners.push(action)
}
@@ -62,6 +62,6 @@ export class UpdateService {
}
private executeAllChangeListeners() {
this.changeListeners.forEach(e => e(this));
this.changeListeners.forEach(e => e());
}
}