RED-3796: Redirect to last opened template

This commit is contained in:
Adina Țeudan 2022-05-10 16:20:53 +03:00
parent 81311dbdb4
commit 87d101e24a
9 changed files with 64 additions and 41 deletions

View File

@ -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',
},
];

View File

@ -163,6 +163,7 @@ const components = [AppComponent, AuthErrorComponent, NotificationsComponent, Sp
multi: true,
useFactory: configurationInitializer,
deps: [
BASE_HREF,
KeycloakService,
Title,
ConfigService,

View File

@ -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<boolean> {
async isAccessAllowed(route: ActivatedRouteSnapshot): Promise<boolean> {
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;
}

View File

@ -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<void> {
await this._userPreferenceService.saveLastDossierTemplate(null);
}
}

View File

@ -29,7 +29,7 @@
</section>
<ng-template #needsWorkFilterTemplate let-filter="filter">
<redaction-type-filter [dossierTemplateId]="defaultDossierTemplateId" [filter]="filter"></redaction-type-filter>
<redaction-type-filter [dossierTemplateId]="dossierTemplateId" [filter]="filter"></redaction-type-filter>
</ng-template>
<ng-template #tableItemTemplate let-dossier="entity">

View File

@ -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<Dossier> 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<unknown>;
@ViewChild(TableComponent) private readonly _tableComponent: TableComponent<Dossier>;
private readonly _dossierTemplateId: string;
constructor(
protected readonly _injector: Injector,
@ -37,28 +37,25 @@ export class DossiersListingScreenComponent extends ListingComponent<Dossier> 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<void> {
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();
}

View File

@ -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<UserAttributes> {
}
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<void> {
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<void> {
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<void> {
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<void> {
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<UserAttributes> {
return this._put(body, `${this._defaultModelPath}/${key}`);
}
private async _save(key: string, value: string): Promise<void> {
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];

View File

@ -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),

View File

@ -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"