Merge remote-tracking branch 'origin/master'

This commit is contained in:
Valentin Mihai 2023-08-18 16:59:07 +03:00
commit 2e42d491b3
4 changed files with 33 additions and 5 deletions

View File

@ -160,7 +160,7 @@ const mainRoutes: IqserRoutes = [
{
path: 'trash',
loadChildren: () => import('./modules/trash/trash.module').then(m => m.TrashModule),
canActivate: [CompositeRouteGuard, IqserPermissionsGuard, loadActiveDossiersGuard()],
canActivate: [CompositeRouteGuard, IqserPermissionsGuard],
data: {
routeGuards: [IqserAuthGuard, RedRoleGuard, TrashGuard],
permissions: {

View File

@ -1,14 +1,32 @@
import { Injectable } from '@angular/core';
import { CanActivate } from '@angular/router';
import { inject, Injectable } from '@angular/core';
import { CanActivate, CanActivateFn } from '@angular/router';
import { firstValueFrom } from 'rxjs';
import { TrashService } from '@services/entity-services/trash.service';
import { SystemPreferencesService } from '@services/system-preferences.service';
import { ActiveDossiersService } from '@services/dossiers/active-dossiers.service';
import { ACTIVE_DOSSIERS_SERVICE } from '../tokens';
@Injectable({ providedIn: 'root' })
export class TrashGuard implements CanActivate {
constructor(private readonly _trashService: TrashService) {}
constructor(
private readonly _trashService: TrashService,
private readonly _systemPreferences: SystemPreferencesService,
private readonly _activeDossierService: ActiveDossiersService,
) {}
async canActivate(): Promise<boolean> {
await this._systemPreferences.loadPreferencesIfNeeded();
await firstValueFrom(this._activeDossierService.loadAll());
await firstValueFrom(this._trashService.loadAll());
return true;
}
}
export function trashGuard(): CanActivateFn {
return async () => {
await inject(SystemPreferencesService).loadPreferencesIfNeeded();
await firstValueFrom(inject<ActiveDossiersService>(ACTIVE_DOSSIERS_SERVICE).loadAll());
await firstValueFrom(inject(TrashService).loadAll());
return true;
};
}

View File

@ -18,6 +18,12 @@ export class SystemPreferencesService extends GenericService<SystemPreferences>
return this.values;
}
async loadPreferencesIfNeeded() {
if (!this.values) {
await this.loadPreferences();
}
}
async update(value: SystemPreferences) {
await firstValueFrom(this._post(value));
return await this.loadPreferences();

View File

@ -40,7 +40,11 @@ export const mainResolver: ResolveFn<void> = async () => {
const generalConfig$ = inject(GeneralSettingsService).getGeneralConfigurations();
const updatedDisplayName$ = generalConfig$.pipe(tap(config => configService.updateDisplayName(config.displayName)));
await Promise.all([systemPreferencesService.loadPreferences(), userPreferenceService.reload(), firstValueFrom(updatedDisplayName$)]);
await Promise.all([
systemPreferencesService.loadPreferencesIfNeeded(),
userPreferenceService.reload(),
firstValueFrom(updatedDisplayName$),
]);
const lastDossierTemplate = userPreferenceService.getLastDossierTemplate();