Fixing Angular 21 by migrating all values by signals. (#11)
Some checks failed
Build and Deploy Java Gradle Application / build-and-deploy (push) Failing after 53s

This commit was merged in pull request #11.
This commit is contained in:
2026-02-03 15:07:55 +01:00
parent 1ca2f872f7
commit 0cce8b2982
102 changed files with 4102 additions and 4852 deletions

View File

@@ -1,49 +1,47 @@
import { inject, Injectable } from "@angular/core";
import { PublicationRestService } from "../../core/rest-services/publications/publication.rest-service";
import { BehaviorSubject, Observable } from "rxjs";
import { Publication } from "../../core/rest-services/publications/model/publication";
import { MatSnackBar } from "@angular/material/snack-bar";
import {inject, Injectable, Signal, signal} from "@angular/core";
import {PublicationRestService} from "../../core/rest-services/publications/publication.rest-service";
import {Publication} from "../../core/rest-services/publications/model/publication";
import {MatSnackBar} from "@angular/material/snack-bar";
@Injectable()
export class SearchPublicationsService {
private publicationRestService = inject(PublicationRestService);
private publicationsSubject = new BehaviorSubject<Publication[]>([]);
private isLoadingSubject = new BehaviorSubject<boolean>(false);
private isLoadedSubject = new BehaviorSubject<boolean>(false);
private snackBar = inject(MatSnackBar);
#snackBar = inject(MatSnackBar);
#publicationRestService = inject(PublicationRestService);
#publications = signal<Publication[]>([]);
#isLoading = signal(false);
#isLoaded = signal(false);
get publications$(): Observable<Publication[]> {
return this.publicationsSubject.asObservable();
}
get isLoading$(): Observable<boolean> {
return this.isLoadingSubject.asObservable();
}
get publications(): Signal<Publication[]> {
return this.#publications.asReadonly();
}
get isLoaded$(): Observable<boolean> {
return this.isLoadedSubject.asObservable();
}
get isLoading(): Signal<boolean> {
return this.#isLoading.asReadonly();
}
loadPublications(searchCriteria: string): void {
this.isLoadingSubject.next(true);
this.isLoadedSubject.next(false);
this.publicationsSubject.next([]);
get isLoaded(): Signal<boolean> {
return this.#isLoaded.asReadonly();
}
this.publicationRestService.search(searchCriteria)
.then(publications => {
this.publicationsSubject.next(publications);
})
.catch(error => {
if (error.status !== 404) {
const errorMessage = $localize`An error occured while retrieving publications.`;
console.error(errorMessage, error);
this.snackBar.open(errorMessage, $localize`Close`, { duration: 5000 });
}
})
.finally(() => {
this.isLoadingSubject.next(false);
this.isLoadedSubject.next(true);
});
}
}
loadPublications(searchCriteria: string): void {
this.#isLoading.set(true);
this.#isLoaded.set(false);
this.#publications.set([]);
this.#publicationRestService.search(searchCriteria)
.then(publications => {
this.#publications.set(publications);
})
.catch(error => {
if (error.status !== 404) {
const errorMessage = $localize`An error occured while retrieving publications.`;
console.error(errorMessage, error);
this.#snackBar.open(errorMessage, $localize`Close`, {duration: 5000});
}
})
.finally(() => {
this.#isLoading.set(false);
this.#isLoaded.set(true);
});
}
}