Merge branch 'RED-8623' into 'master'

RED-8623: filtered out check requests on certain pages.

See merge request redactmanager/red-ui!331
This commit is contained in:
Dan Percic 2024-03-06 14:37:06 +01:00
commit 7a496a39df
4 changed files with 27 additions and 8 deletions

View File

@ -11,6 +11,8 @@ import { DashboardStatsService } from '../dossier-templates/dashboard-stats.serv
import { CHANGED_CHECK_INTERVAL } from '@utils/constants'; import { CHANGED_CHECK_INTERVAL } from '@utils/constants';
import { List } from '@iqser/common-ui/lib/utils'; import { List } from '@iqser/common-ui/lib/utils';
import { DossiersCacheService } from '@services/dossiers/dossiers-cache.service'; import { DossiersCacheService } from '@services/dossiers/dossiers-cache.service';
import { Router } from '@angular/router';
import { filterEventsOnPages } from '@utils/operators';
@Injectable({ providedIn: 'root' }) @Injectable({ providedIn: 'root' })
export class DossiersChangesService extends GenericService<Dossier> implements OnDestroy { export class DossiersChangesService extends GenericService<Dossier> implements OnDestroy {
@ -20,6 +22,7 @@ export class DossiersChangesService extends GenericService<Dossier> implements O
readonly #dashboardStatsService = inject(DashboardStatsService); readonly #dashboardStatsService = inject(DashboardStatsService);
readonly #logger = inject(NGXLogger); readonly #logger = inject(NGXLogger);
readonly #dossierCache = inject(DossiersCacheService); readonly #dossierCache = inject(DossiersCacheService);
readonly #router = inject(Router);
protected readonly _defaultModelPath = 'dossier'; protected readonly _defaultModelPath = 'dossier';
loadOnlyChanged(): Observable<IDossierChanges> { loadOnlyChanged(): Observable<IDossierChanges> {
@ -60,6 +63,7 @@ export class DossiersChangesService extends GenericService<Dossier> implements O
initialize() { initialize() {
this.#logger.info('[DOSSIERS_CHANGES] Initialize timer'); this.#logger.info('[DOSSIERS_CHANGES] Initialize timer');
const subscription = timer(CHANGED_CHECK_INTERVAL, CHANGED_CHECK_INTERVAL).pipe( const subscription = timer(CHANGED_CHECK_INTERVAL, CHANGED_CHECK_INTERVAL).pipe(
filterEventsOnPages(this.#router),
switchMap(() => this.loadOnlyChanged()), switchMap(() => this.loadOnlyChanged()),
tap(changes => { tap(changes => {
this.#activeDossiersService.emitFileChanges(changes); this.#activeDossiersService.emitFileChanges(changes);

View File

@ -12,6 +12,8 @@ import { DossiersCacheService } from './dossiers/dossiers-cache.service';
import dayjs from 'dayjs'; import dayjs from 'dayjs';
import { List, mapEach } from '@iqser/common-ui/lib/utils'; import { List, mapEach } from '@iqser/common-ui/lib/utils';
import { APP_BASE_HREF } from '@angular/common'; import { APP_BASE_HREF } from '@angular/common';
import { Router } from '@angular/router';
import { filterEventsOnPages } from '@utils/operators';
const INCLUDE_SEEN = false; const INCLUDE_SEEN = false;
@ -33,6 +35,7 @@ export class NotificationsService extends EntitiesService<INotification, Notific
private readonly _translateService: TranslateService, private readonly _translateService: TranslateService,
private readonly _userService: UserService, private readonly _userService: UserService,
private readonly _dossiersCacheService: DossiersCacheService, private readonly _dossiersCacheService: DossiersCacheService,
private readonly _router: Router,
) { ) {
super(); super();
@ -81,35 +84,39 @@ export class NotificationsService extends EntitiesService<INotification, Notific
const downloadHref = `${this.#appBaseHref}/main/downloads`; const downloadHref = `${this.#appBaseHref}/main/downloads`;
return this._translateService.instant(translation, { return this._translateService.instant(translation, {
fileHref: this._getFileHref(dossier, fileId), fileHref: this.#getFileHref(dossier, fileId),
dossierHref: this._getDossierHref(dossier), dossierHref: this.#getDossierHref(dossier),
dossierName: dossierName ?? this._translateService.instant(_('notifications.deleted-dossier')), dossierName: dossierName ?? this._translateService.instant(_('notifications.deleted-dossier')),
fileName: fileName ?? this._translateService.instant(_('file')), fileName: fileName ?? this._translateService.instant(_('file')),
user: this._getUsername(notification.userId), user: this.#getUsername(notification.userId),
downloadHref: downloadHref, downloadHref: downloadHref,
}); });
} }
private _getFileHref(dossier: Dossier, fileId: string): string { #getFileHref(dossier: Dossier, fileId: string): string {
return dossier ? `${this._getDossierHref(dossier)}/file/${fileId}` : null; return dossier ? `${this.#getDossierHref(dossier)}/file/${fileId}` : null;
} }
private _getDossierHref(dossier: Dossier): string { #getDossierHref(dossier: Dossier): string {
return dossier ? `${dossier.routerLink}` : null; return dossier ? `${dossier.routerLink}` : null;
} }
private _getUsername(userId: string | undefined) { #getUsername(userId: string | undefined) {
return this._userService.getName(userId) || this._translateService.instant(_('unknown')); return this._userService.getName(userId) || this._translateService.instant(_('unknown'));
} }
#initTimerAndChanges() { #initTimerAndChanges() {
const timer$ = timer(0, CHANGED_CHECK_INTERVAL).pipe( const timer$ = timer(0, CHANGED_CHECK_INTERVAL).pipe(
filterEventsOnPages(this._router),
switchMap(() => (this._dossiersCacheService.empty ? this._dossiersCacheService.load() : of(null))), switchMap(() => (this._dossiersCacheService.empty ? this._dossiersCacheService.load() : of(null))),
switchMap(() => this.#loadNotificationsIfChanged()), switchMap(() => this.#loadNotificationsIfChanged()),
); );
// Rebuild notifications when cached dossiers are updated // Rebuild notifications when cached dossiers are updated
const changed$ = this._dossiersCacheService.changed$.pipe(tap(() => this.setEntities(this.all.map(e => this._new(e))))); const changed$ = this._dossiersCacheService.changed$.pipe(
filterEventsOnPages(this._router),
tap(() => this.setEntities(this.all.map(e => this._new(e)))),
);
return merge(timer$, changed$); return merge(timer$, changed$);
} }

View File

@ -1,6 +1,7 @@
import { DynamicCaches } from '@iqser/common-ui'; import { DynamicCaches } from '@iqser/common-ui';
export const CHANGED_CHECK_INTERVAL = 5000; export const CHANGED_CHECK_INTERVAL = 5000;
export const NO_CHECK_PAGES = ['admin', 'account', 'downloads', 'trash'];
export const FALLBACK_COLOR = '#CCCCCC'; export const FALLBACK_COLOR = '#CCCCCC';
export const UI_CACHES: DynamicCaches = [ export const UI_CACHES: DynamicCaches = [

View File

@ -0,0 +1,7 @@
import { filter } from 'rxjs/operators';
import { NO_CHECK_PAGES } from '@utils/constants';
import { Router } from '@angular/router';
export function filterEventsOnPages(router: Router) {
return filter(() => !NO_CHECK_PAGES.some(route => router.url.includes(route)));
}