RED-7610 - Back button in Download view does not work correctly (RM & DM)
This commit is contained in:
parent
8649a026ee
commit
c6550bc531
@ -5,8 +5,12 @@ import { keycloakInitializer, KeycloakStatusService, TenantsService } from '@iqs
|
||||
import { KeycloakService } from 'keycloak-angular';
|
||||
import { UserService } from '@users/user.service';
|
||||
import { LicenseService } from '@services/license.service';
|
||||
import { RouterHistoryService } from '@services/router-history.service';
|
||||
import { AsyncGuard } from '@iqser/common-ui';
|
||||
import jwt_decode from 'jwt-decode';
|
||||
|
||||
export interface JwtToken {
|
||||
auth_time: number;
|
||||
}
|
||||
|
||||
export function ifLoggedIn(): AsyncGuard {
|
||||
return async (route: ActivatedRouteSnapshot) => {
|
||||
@ -18,7 +22,6 @@ export function ifLoggedIn(): AsyncGuard {
|
||||
const usersService = inject(UserService);
|
||||
const licenseService = inject(LicenseService);
|
||||
const keycloakStatusService = inject(KeycloakStatusService);
|
||||
const routerHistoryService = inject(RouterHistoryService);
|
||||
|
||||
const keycloakInstance = keycloakService.getKeycloakInstance();
|
||||
const tenant = route.paramMap.get('tenant');
|
||||
@ -37,7 +40,10 @@ export function ifLoggedIn(): AsyncGuard {
|
||||
await tenantsService.selectTenant(tenant);
|
||||
await usersService.initialize();
|
||||
await licenseService.loadLicenses();
|
||||
routerHistoryService.clearRouterHistory();
|
||||
|
||||
const token = await keycloakService.getToken();
|
||||
const authTime = (jwt_decode(token) as JwtToken).auth_time.toString();
|
||||
localStorage.setItem('authTime', authTime);
|
||||
}
|
||||
|
||||
const isLoggedIn = await keycloakService.isLoggedIn();
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
<a
|
||||
*ngIf="stats as dossierTemplate"
|
||||
[class.empty]="dossierTemplate.isEmpty"
|
||||
[routerLink]="dossierTemplate.isEmpty ? null : ['..', dossierTemplate.dossierTemplateId]"
|
||||
[routerLink]="dossierTemplate.isEmpty ? null : ['..', dossierTemplate.dossierTemplateId, 'dossiers']"
|
||||
[attr.help-mode-key]="!dossierTemplate.isEmpty ? 'open_dossier_template' : null"
|
||||
class="dialog"
|
||||
>
|
||||
|
||||
@ -2,6 +2,9 @@ import { Injectable } from '@angular/core';
|
||||
import { NavigationEnd, Router } from '@angular/router';
|
||||
import { filter } from 'rxjs/operators';
|
||||
import { TenantsService } from '@iqser/common-ui/lib/tenants';
|
||||
import jwt_decode from 'jwt-decode';
|
||||
import { KeycloakService } from 'keycloak-angular';
|
||||
import { JwtToken } from '@guards/if-logged-in.guard';
|
||||
|
||||
const LAST_DOSSIERS_SCREEN = 'routerHistory_lastDossiersScreen';
|
||||
|
||||
@ -9,32 +12,48 @@ const LAST_DOSSIERS_SCREEN = 'routerHistory_lastDossiersScreen';
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class RouterHistoryService {
|
||||
private _lastDossiersScreen = localStorage.getItem(LAST_DOSSIERS_SCREEN);
|
||||
|
||||
constructor(
|
||||
private readonly _router: Router,
|
||||
private readonly _tenantsService: TenantsService,
|
||||
private readonly _keycloakService: KeycloakService,
|
||||
) {
|
||||
// eslint-disable-next-line rxjs/no-ignored-subscription
|
||||
this._router.events.pipe(filter(event => event instanceof NavigationEnd)).subscribe((event: NavigationEnd) => {
|
||||
if (event.url.includes('/dossiers') || event.url.includes('/archive')) {
|
||||
this._lastDossiersScreen = event.url;
|
||||
localStorage.setItem(LAST_DOSSIERS_SCREEN, this._lastDossiersScreen);
|
||||
const lastDossiersScreen = event.url;
|
||||
localStorage.setItem(LAST_DOSSIERS_SCREEN, lastDossiersScreen);
|
||||
}
|
||||
if (event.urlAfterRedirects.includes('/dashboard')) {
|
||||
localStorage.removeItem(LAST_DOSSIERS_SCREEN);
|
||||
}
|
||||
});
|
||||
this.#clearRouterHistory();
|
||||
}
|
||||
|
||||
navigateToLastDossiersScreen(): void {
|
||||
if (this._router.url === decodeURI(this._lastDossiersScreen)) {
|
||||
const lastDossiersScreen = localStorage.getItem(LAST_DOSSIERS_SCREEN);
|
||||
if (this._router.url === decodeURI(lastDossiersScreen) || lastDossiersScreen === null) {
|
||||
this._router.navigate(['/' + this._tenantsService.activeTenantId]);
|
||||
} else {
|
||||
const url = decodeURI(this._lastDossiersScreen).split('?')[0];
|
||||
const url = decodeURI(lastDossiersScreen).split('?')[0];
|
||||
// todo links
|
||||
this._router.navigate([url]);
|
||||
}
|
||||
}
|
||||
|
||||
clearRouterHistory() {
|
||||
localStorage.removeItem(LAST_DOSSIERS_SCREEN);
|
||||
#clearRouterHistory() {
|
||||
const interval = window.setInterval(async () => {
|
||||
if (this._tenantsService.activeTenantId) {
|
||||
const token = await this._keycloakService.getToken();
|
||||
const authTime = (jwt_decode(token) as JwtToken).auth_time;
|
||||
const localStorageAuthTime = localStorage.getItem('authTime');
|
||||
|
||||
if (authTime.toString() !== localStorageAuthTime) {
|
||||
localStorage.removeItem(LAST_DOSSIERS_SCREEN);
|
||||
}
|
||||
|
||||
window.clearInterval(interval);
|
||||
}
|
||||
}, 100);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user