feat: UpdateService hinzufügen und in Navbar integrieren
- UpdateService erstellt, um asynchrone und synchrone Aktionen zu verwalten und auszuführen. - Einen Speichern-Button in der Navbar hinzugefügt, der die Ausführung aller Aktionen im UpdateService auslöst. - UpdateService in die Anwendung integriert, um die Aktualisierungslogik zu zentralisieren.
This commit is contained in:
parent
86fae90d49
commit
8d45b60aca
@ -30,6 +30,9 @@
|
||||
<!-- Right menu -->
|
||||
<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>
|
||||
</button>
|
||||
<button *ngIf="isLogedIn()" class="btn">
|
||||
<mat-icon class="scale-pulse" (click)="creationService.openDialog()">add_to_photos</mat-icon>
|
||||
</button>
|
||||
|
||||
@ -8,6 +8,7 @@ import { ColorModeBttnComponent } from '../common/color-mode-bttn/color-mode-btt
|
||||
import { MatIconModule } from '@angular/material/icon';
|
||||
import { RefreshService } from '../../services/refresh.service';
|
||||
import { CreationService } from '../../services/creation.service';
|
||||
import { UpdateService } from '../../services/update.service';
|
||||
|
||||
@Component({
|
||||
standalone: true,
|
||||
@ -22,7 +23,7 @@ export class NavMenuComponent {
|
||||
}
|
||||
isExpanded = false;
|
||||
|
||||
constructor(private dialog: MatDialog, private authService: AuthenticationService, public refreshService: RefreshService, public creationService : CreationService) {
|
||||
constructor(private dialog: MatDialog, private authService: AuthenticationService, public refreshService: RefreshService, public creationService : CreationService, public updateService: UpdateService) {
|
||||
this.authService.isAuthenticated().then().catch()
|
||||
}
|
||||
|
||||
|
||||
@ -0,0 +1,16 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { UpdateService } from './update.service';
|
||||
|
||||
describe('UpdateService', () => {
|
||||
let service: UpdateService;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({});
|
||||
service = TestBed.inject(UpdateService);
|
||||
});
|
||||
|
||||
it('should be created', () => {
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
});
|
||||
@ -0,0 +1,30 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class UpdateService {
|
||||
|
||||
constructor() { }
|
||||
|
||||
private async_actions: Array<() => Promise<void>> = [];
|
||||
private actions: Array<() => void> = [];
|
||||
|
||||
addAsync(action: () => Promise<void>): void {
|
||||
this.async_actions.push(action);
|
||||
}
|
||||
|
||||
add(action: () => void): void {
|
||||
this.actions.push(action);
|
||||
}
|
||||
|
||||
removeAll(): void {
|
||||
this.async_actions = [];
|
||||
}
|
||||
|
||||
async executeAll(): Promise<void> {
|
||||
await Promise.all(this.async_actions.map(action => action()));
|
||||
this.actions.forEach(action => action());
|
||||
this.removeAll();
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user