diff --git a/apps/red-ui/src/app/app-routing.module.ts b/apps/red-ui/src/app/app-routing.module.ts index a9c7fc151..7f0060461 100644 --- a/apps/red-ui/src/app/app-routing.module.ts +++ b/apps/red-ui/src/app/app-routing.module.ts @@ -17,7 +17,7 @@ import { DashboardGuard } from '@guards/dashboard-guard.service'; const routes: Routes = [ { path: '', - redirectTo: 'main/dashboard', + redirectTo: 'main', pathMatch: 'full', }, { @@ -106,7 +106,7 @@ const routes: Routes = [ }, { path: '**', - redirectTo: 'main/dashboard', + redirectTo: 'main', pathMatch: 'full', }, ]; diff --git a/apps/red-ui/src/app/app.module.ts b/apps/red-ui/src/app/app.module.ts index 90bd1aba0..07c42e3e1 100644 --- a/apps/red-ui/src/app/app.module.ts +++ b/apps/red-ui/src/app/app.module.ts @@ -163,6 +163,7 @@ const components = [AppComponent, AuthErrorComponent, NotificationsComponent, Sp multi: true, useFactory: configurationInitializer, deps: [ + BASE_HREF, KeycloakService, Title, ConfigService, diff --git a/apps/red-ui/src/app/modules/auth/auth.guard.ts b/apps/red-ui/src/app/modules/auth/auth.guard.ts index 12803b3b0..6701e12cc 100644 --- a/apps/red-ui/src/app/modules/auth/auth.guard.ts +++ b/apps/red-ui/src/app/modules/auth/auth.guard.ts @@ -1,5 +1,5 @@ import { Inject, Injectable } from '@angular/core'; -import { ActivatedRouteSnapshot, Router, RouterStateSnapshot } from '@angular/router'; +import { ActivatedRouteSnapshot, Router } from '@angular/router'; import { KeycloakAuthGuard, KeycloakService } from 'keycloak-angular'; import { UserService } from '@services/user.service'; import { ConfigService } from '@services/config.service'; @@ -19,12 +19,12 @@ export class AuthGuard extends KeycloakAuthGuard { super(_router, _keycloak); } - async isAccessAllowed(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Promise { + async isAccessAllowed(route: ActivatedRouteSnapshot): Promise { if (!this.authenticated) { const kcIdpHint = route.queryParamMap.get('kc_idp_hint'); await this._keycloak.login({ idpHint: kcIdpHint ?? this._configService.values.OAUTH_IDP_HINT, - redirectUri: window.location.origin + this._baseHref + state.url, + redirectUri: window.location.href, }); return false; } diff --git a/apps/red-ui/src/app/modules/dashboard/dashboard-screen/dashboard-screen.component.ts b/apps/red-ui/src/app/modules/dashboard/dashboard-screen/dashboard-screen.component.ts index e413f5d90..94c2046d1 100644 --- a/apps/red-ui/src/app/modules/dashboard/dashboard-screen/dashboard-screen.component.ts +++ b/apps/red-ui/src/app/modules/dashboard/dashboard-screen/dashboard-screen.component.ts @@ -1,6 +1,7 @@ -import { ChangeDetectionStrategy, Component } from '@angular/core'; -import { UserService } from '../../../services/user.service'; +import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core'; +import { UserService } from '@services/user.service'; import { DashboardStatsService } from '@services/dossier-templates/dashboard-stats.service'; +import { UserPreferenceService } from '@services/user-preference.service'; @Component({ selector: 'redaction-dashboard-screen', @@ -8,9 +9,17 @@ import { DashboardStatsService } from '@services/dossier-templates/dashboard-sta styleUrls: ['./dashboard-screen.component.scss'], changeDetection: ChangeDetectionStrategy.OnPush, }) -export class DashboardScreenComponent { +export class DashboardScreenComponent implements OnInit { readonly currentUser = this._userService.currentUser; readonly stats$ = this._dashboardStatsService.all$; - constructor(private readonly _userService: UserService, private readonly _dashboardStatsService: DashboardStatsService) {} + constructor( + private readonly _userService: UserService, + private readonly _dashboardStatsService: DashboardStatsService, + private readonly _userPreferenceService: UserPreferenceService, + ) {} + + async ngOnInit(): Promise { + await this._userPreferenceService.saveLastDossierTemplate(null); + } } diff --git a/apps/red-ui/src/app/modules/dossiers-listing/screen/dossiers-listing-screen.component.html b/apps/red-ui/src/app/modules/dossiers-listing/screen/dossiers-listing-screen.component.html index 9f0d65e65..a1051a9f8 100644 --- a/apps/red-ui/src/app/modules/dossiers-listing/screen/dossiers-listing-screen.component.html +++ b/apps/red-ui/src/app/modules/dossiers-listing/screen/dossiers-listing-screen.component.html @@ -29,7 +29,7 @@ - + diff --git a/apps/red-ui/src/app/modules/dossiers-listing/screen/dossiers-listing-screen.component.ts b/apps/red-ui/src/app/modules/dossiers-listing/screen/dossiers-listing-screen.component.ts index fe52199c6..895ac8c2a 100644 --- a/apps/red-ui/src/app/modules/dossiers-listing/screen/dossiers-listing-screen.component.ts +++ b/apps/red-ui/src/app/modules/dossiers-listing/screen/dossiers-listing-screen.component.ts @@ -6,11 +6,11 @@ import { ButtonConfig, DefaultListingServices, ListingComponent, OnAttach, Table import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker'; import { ConfigService } from '../config.service'; import { ActiveDossiersService } from '@services/dossiers/active-dossiers.service'; -import { DossierTemplatesService } from '@services/dossier-templates/dossier-templates.service'; import { tap } from 'rxjs/operators'; import { DossiersDialogService } from '../../dossier/shared/services/dossiers-dialog.service'; import { Router } from '@angular/router'; import { DOSSIER_TEMPLATE_ID } from '@utils/constants'; +import { UserPreferenceService } from '@services/user-preference.service'; @Component({ templateUrl: './dossiers-listing-screen.component.html', @@ -23,13 +23,13 @@ export class DossiersListingScreenComponent extends ListingComponent im readonly tableColumnConfigs = this._configService.tableConfig; readonly tableHeaderLabel = _('dossier-listing.table-header.title'); readonly buttonConfigs: ButtonConfig[]; + readonly dossierTemplateId: string; @ViewChild('needsWorkFilterTemplate', { read: TemplateRef, static: true, }) private readonly _needsWorkFilterTemplate: TemplateRef; @ViewChild(TableComponent) private readonly _tableComponent: TableComponent; - private readonly _dossierTemplateId: string; constructor( protected readonly _injector: Injector, @@ -37,28 +37,25 @@ export class DossiersListingScreenComponent extends ListingComponent im readonly permissionsService: PermissionsService, private readonly _activeDossiersService: ActiveDossiersService, private readonly _configService: ConfigService, - private readonly _dossierTemplatesService: DossierTemplatesService, private readonly _dialogService: DossiersDialogService, private readonly _router: Router, + private readonly _userPreferenceService: UserPreferenceService, ) { super(_injector); - this._dossierTemplateId = this._router.routerState.snapshot.root.firstChild.firstChild.paramMap.get(DOSSIER_TEMPLATE_ID); + this.dossierTemplateId = this._router.routerState.snapshot.root.firstChild.firstChild.paramMap.get(DOSSIER_TEMPLATE_ID); this._router.routeReuseStrategy.shouldReuseRoute = () => false; - this.buttonConfigs = this._configService.buttonsConfig(this._dossierTemplateId); - } - - get defaultDossierTemplateId(): string { - return this._dossierTemplatesService.all[0].id; + this.buttonConfigs = this._configService.buttonsConfig(this.dossierTemplateId); } openAddDossierDialog(): void { - this._dialogService.openDialog('addDossier', null, { dossierTemplateId: this._dossierTemplateId }); + this._dialogService.openDialog('addDossier', null, { dossierTemplateId: this.dossierTemplateId }); } - ngOnInit(): void { + async ngOnInit(): Promise { + await this._userPreferenceService.saveLastDossierTemplate(this.dossierTemplateId); this.addSubscription = this.entitiesService.all$.pipe(tap(() => this._computeAllFilters())).subscribe(); this.addSubscription = this._activeDossiersService.all$ - .pipe(tap(dossiers => this.entitiesService.setEntities(dossiers.filter(d => d.dossierTemplateId === this._dossierTemplateId)))) + .pipe(tap(dossiers => this.entitiesService.setEntities(dossiers.filter(d => d.dossierTemplateId === this.dossierTemplateId)))) .subscribe(); } diff --git a/apps/red-ui/src/app/services/user-preference.service.ts b/apps/red-ui/src/app/services/user-preference.service.ts index 7ae1d333d..5df934cac 100644 --- a/apps/red-ui/src/app/services/user-preference.service.ts +++ b/apps/red-ui/src/app/services/user-preference.service.ts @@ -8,6 +8,7 @@ const KEYS = { language: 'Language', dossierRecent: 'Dossier-Recent', filePreviewTooltips: 'File-Preview-Tooltips', + lastDossierTemplate: 'Last-Dossier-Template', } as const; @Injectable({ @@ -30,38 +31,36 @@ export class UserPreferenceService extends GenericService { } getLastOpenedFileForDossier(dossierId: string): string { - const key = `${KEYS.dossierRecent}-${dossierId}`; - return this._getAttribute(key); + return this._getAttribute(`${KEYS.dossierRecent}-${dossierId}`); } async saveLastOpenedFileForDossier(dossierId: string, fileId: string): Promise { - const key = `${KEYS.dossierRecent}-${dossierId}`; - this.userAttributes[key] = [fileId]; - await firstValueFrom(this.savePreferences([fileId], key)); + await this._save(`${KEYS.dossierRecent}-${dossierId}`, fileId); + } + + getLastDossierTemplate(): string { + return this._getAttribute(KEYS.lastDossierTemplate); + } + + async saveLastDossierTemplate(dossierTemplateId: string): Promise { + await this._save(KEYS.lastDossierTemplate, dossierTemplateId); } getLanguage(): string { - const key = KEYS.language; - return this._getAttribute(key); + return this._getAttribute(KEYS.language); } async saveLanguage(language: string): Promise { - const key = KEYS.language; - this.userAttributes[key] = [language]; - await firstValueFrom(this.savePreferences([language], key)); + await this._save(KEYS.language, language); } getFilePreviewTooltipsPreference(): boolean { - const key = KEYS.filePreviewTooltips; - return this._getAttribute(key, 'false') === 'true'; + return this._getAttribute(KEYS.filePreviewTooltips, 'false') === 'true'; } async toggleFilePreviewTooltipsPreference(): Promise { - const key = KEYS.filePreviewTooltips; - const currentValue = this.getFilePreviewTooltipsPreference(); - const nextValue = [(!currentValue).toString()]; - this.userAttributes[key] = nextValue; - await firstValueFrom(this.savePreferences(nextValue, key)); + const nextValue = (!this.getFilePreviewTooltipsPreference()).toString(); + await this._save(KEYS.filePreviewTooltips, nextValue); } toggleDevFeatures(): void { @@ -79,6 +78,11 @@ export class UserPreferenceService extends GenericService { return this._put(body, `${this._defaultModelPath}/${key}`); } + private async _save(key: string, value: string): Promise { + this.userAttributes[key] = [value]; + await firstValueFrom(this.savePreferences([value], key)); + } + private _getAttribute(key: string, defaultValue = ''): string { if (this.userAttributes[key]?.length > 0) { return this.userAttributes[key][0]; diff --git a/apps/red-ui/src/app/utils/configuration.initializer.ts b/apps/red-ui/src/app/utils/configuration.initializer.ts index bbd074151..849145c01 100644 --- a/apps/red-ui/src/app/utils/configuration.initializer.ts +++ b/apps/red-ui/src/app/utils/configuration.initializer.ts @@ -9,7 +9,16 @@ import { UserPreferenceService } from '@services/user-preference.service'; import { UserService } from '@services/user.service'; import { FeaturesService } from '@services/features.service'; +function lastDossierTemplateRedirect(baseHref: string, userPreferenceService: UserPreferenceService) { + const url = window.location.href.split('/').filter(s => s.length > 0); + const lastDossierTemplate = userPreferenceService.getLastDossierTemplate(); + if (lastDossierTemplate && [baseHref, 'main'].includes(url[url.length - 1])) { + window.location.href = `/${baseHref}/main/${lastDossierTemplate}`; + } +} + export function configurationInitializer( + baseHref: string, keycloakService: KeycloakService, title: Title, configService: ConfigService, @@ -36,6 +45,9 @@ export function configurationInitializer( title.setTitle('RedactManager'); return of({}); }), + tap(() => { + lastDossierTemplateRedirect(baseHref.replace('/', ''), userPreferenceService); + }), switchMap(() => languageService.chooseAndSetInitialLanguage()), tap(() => userService.initialize()), take(1), diff --git a/apps/red-ui/src/assets/config/config.json b/apps/red-ui/src/assets/config/config.json index 0cb5f13c3..684210fa7 100644 --- a/apps/red-ui/src/assets/config/config.json +++ b/apps/red-ui/src/assets/config/config.json @@ -1,7 +1,7 @@ { "ADMIN_CONTACT_NAME": null, "ADMIN_CONTACT_URL": null, - "API_URL": "https://dev-04.iqser.cloud/redaction-gateway-v1", + "API_URL": "https://dev-08.iqser.cloud/redaction-gateway-v1", "APP_NAME": "RedactManager", "AUTO_READ_TIME": 3, "BACKEND_APP_VERSION": "4.4.40", @@ -17,7 +17,7 @@ "MAX_RETRIES_ON_SERVER_ERROR": 3, "OAUTH_CLIENT_ID": "redaction", "OAUTH_IDP_HINT": null, - "OAUTH_URL": "https://dev-04.iqser.cloud/auth/realms/redaction", + "OAUTH_URL": "https://dev-08.iqser.cloud/auth/realms/redaction", "RECENT_PERIOD_IN_HOURS": 24, "SELECTION_MODE": "structural", "MANUAL_BASE_URL": "https://docs.redactmanager.com/preview"