Merge branch 'RED-9171' into 'master'

RED-9171: removed error toaster for non-existing dossier template.

See merge request redactmanager/red-ui!461
This commit is contained in:
Dan Percic 2024-06-18 17:59:00 +02:00
commit a63dd4a846

View File

@ -1,10 +1,11 @@
import { EntitiesService } from '@iqser/common-ui';
import { DashboardStats, IDashboardStats } from '@red/domain';
import { inject, Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { map, switchMap, tap } from 'rxjs/operators';
import { Observable, of } from 'rxjs';
import { catchError, filter, map, switchMap, tap } from 'rxjs/operators';
import { DossierStatesService } from '../entity-services/dossier-states.service';
import { mapEach } from '@iqser/common-ui/lib/utils';
import { Router } from '@angular/router';
const templatesSorter = (a: DashboardStats, b: DashboardStats) => {
if (!a.isEmpty && b.isEmpty) {
@ -20,6 +21,7 @@ const templatesSorter = (a: DashboardStats, b: DashboardStats) => {
})
export class DashboardStatsService extends EntitiesService<IDashboardStats, DashboardStats> {
readonly #dossierStatesService = inject(DossierStatesService);
readonly #router = inject(Router);
protected readonly _defaultModelPath = 'dossier-template/stats';
protected readonly _entityClass = DashboardStats;
@ -35,6 +37,11 @@ export class DashboardStatsService extends EntitiesService<IDashboardStats, Dash
loadForTemplate(dossierTemplateId: string) {
const singleTemplateStatsUrl = `/${this._serviceName}/dossier-template/${dossierTemplateId}/stats`;
return this._http.get<DashboardStats>(singleTemplateStatsUrl).pipe(
catchError(() => {
this.#router.navigate(['/']).then();
return of(null);
}),
filter(entity => !!entity),
map(entity => new DashboardStats(entity)),
switchMap(entity => this.#dossierStatesService.loadAllForTemplate(dossierTemplateId).pipe(map(() => entity))),
tap(entity => this.addEntity(entity)),