Merge branch 'master' into VM/RED-3982
This commit is contained in:
commit
f888d59a66
@ -36,6 +36,7 @@ import {
|
||||
IqserHelpModeModule,
|
||||
MANUAL_BASE_URL,
|
||||
MAX_RETRIES_ON_SERVER_ERROR,
|
||||
SERVER_ERROR_SKIP_PATHS,
|
||||
ServerErrorInterceptor,
|
||||
ToastComponent,
|
||||
} from '@iqser/common-ui';
|
||||
@ -203,6 +204,10 @@ const components = [AppComponent, AuthErrorComponent, NotificationsComponent, Sp
|
||||
useFactory: (configService: ConfigService) => configService.values.MAX_RETRIES_ON_SERVER_ERROR,
|
||||
deps: [ConfigService],
|
||||
},
|
||||
{
|
||||
provide: SERVER_ERROR_SKIP_PATHS,
|
||||
useValue: ['redaction-gateway-v1/license'],
|
||||
},
|
||||
{
|
||||
provide: ACTIVE_DOSSIERS_SERVICE,
|
||||
useExisting: ActiveDossiersService,
|
||||
|
||||
@ -1,29 +1,48 @@
|
||||
import { Injectable, Injector, ProviderToken } from '@angular/core';
|
||||
import { ActivatedRouteSnapshot, CanActivate } from '@angular/router';
|
||||
import { ActivatedRouteSnapshot, CanActivate, Router } from '@angular/router';
|
||||
import { firstValueFrom, forkJoin } from 'rxjs';
|
||||
import { take } from 'rxjs/operators';
|
||||
import { ActiveDossiersService } from '@services/dossiers/active-dossiers.service';
|
||||
import { ArchivedDossiersService } from '@services/dossiers/archived-dossiers.service';
|
||||
import { DossiersService } from '@services/dossiers/dossiers.service';
|
||||
import { ARCHIVE_ROUTE, DOSSIER_TEMPLATE_ID } from '@red/domain';
|
||||
import { DashboardStatsService } from '@services/dossier-templates/dashboard-stats.service';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class DossiersGuard implements CanActivate {
|
||||
constructor(
|
||||
private readonly _injector: Injector,
|
||||
private readonly _router: Router,
|
||||
private readonly _dashboardStatsService: DashboardStatsService,
|
||||
private readonly _activeDossiersService: ActiveDossiersService,
|
||||
private readonly _archivedDossiersService: ArchivedDossiersService,
|
||||
) {}
|
||||
|
||||
async canActivate(route: ActivatedRouteSnapshot): Promise<boolean> {
|
||||
const token: ProviderToken<DossiersService> = route.data.dossiersService;
|
||||
if (token) {
|
||||
const dossiersService: DossiersService = this._injector.get<DossiersService>(token);
|
||||
await firstValueFrom(dossiersService.loadAll());
|
||||
} else {
|
||||
if (!token) {
|
||||
const services = [this._archivedDossiersService, this._activeDossiersService];
|
||||
const loading$ = forkJoin(services.map(service => service.loadAll().pipe(take(1))));
|
||||
await firstValueFrom(loading$);
|
||||
return true;
|
||||
}
|
||||
|
||||
const dossiersService: DossiersService = this._injector.get<DossiersService>(token);
|
||||
const isArchive = dossiersService.routerPath === ARCHIVE_ROUTE;
|
||||
const dossierTemplateId = route.paramMap.get(DOSSIER_TEMPLATE_ID);
|
||||
const dossierTemplateStats = this._dashboardStatsService.find(dossierTemplateId);
|
||||
|
||||
if (isArchive && dossierTemplateStats?.numberOfArchivedDossiers === 0) {
|
||||
await this._router.navigate(['main', dossierTemplateId, 'dossiers']);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!isArchive && dossierTemplateStats?.numberOfActiveDossiers === 0) {
|
||||
await this._router.navigate(['main', dossierTemplateId, 'archive']);
|
||||
return false;
|
||||
}
|
||||
|
||||
await firstValueFrom(dossiersService.loadAll());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,3 +4,8 @@
|
||||
height: 0;
|
||||
visibility: hidden;
|
||||
}
|
||||
|
||||
input {
|
||||
position: absolute;
|
||||
right: 300px;
|
||||
}
|
||||
|
||||
@ -1,9 +1,20 @@
|
||||
<a [routerLinkActive]="'active'" [routerLink]="['..', DOSSIERS_ROUTE]" class="red-tab">
|
||||
{{ 'dossiers-type-switch.active' | translate }}
|
||||
</a>
|
||||
|
||||
<a [routerLinkActive]="'active'" [routerLink]="['..', ARCHIVE_ROUTE]" class="red-tab">
|
||||
{{ 'dossiers-type-switch.archive' | translate }}
|
||||
</a>
|
||||
<ng-container *ngIf="dossierTemplate$ | async as dossierTemplate">
|
||||
<button
|
||||
[disabled]="dossierTemplate.numberOfActiveDossiers === 0"
|
||||
[routerLinkActive]="'active'"
|
||||
[routerLink]="['..', DOSSIERS_ROUTE]"
|
||||
class="red-tab"
|
||||
>
|
||||
{{ 'dossiers-type-switch.active' | translate }}
|
||||
</button>
|
||||
|
||||
<button
|
||||
[disabled]="dossierTemplate.numberOfArchivedDossiers === 0"
|
||||
[routerLinkActive]="'active'"
|
||||
[routerLink]="['..', ARCHIVE_ROUTE]"
|
||||
class="red-tab"
|
||||
>
|
||||
{{ 'dossiers-type-switch.archive' | translate }}
|
||||
</button>
|
||||
</ng-container>
|
||||
<div class="separator"></div>
|
||||
|
||||
@ -1,5 +1,8 @@
|
||||
import { ChangeDetectionStrategy, Component } from '@angular/core';
|
||||
import { ARCHIVE_ROUTE, DOSSIERS_ROUTE } from '@red/domain';
|
||||
import { ARCHIVE_ROUTE, DashboardStats, DOSSIER_TEMPLATE_ID, DOSSIERS_ROUTE } from '@red/domain';
|
||||
import { DashboardStatsService } from '@services/dossier-templates/dashboard-stats.service';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
import { Observable } from 'rxjs';
|
||||
|
||||
@Component({
|
||||
selector: 'redaction-dossiers-type-switch',
|
||||
@ -10,4 +13,11 @@ import { ARCHIVE_ROUTE, DOSSIERS_ROUTE } from '@red/domain';
|
||||
export class DossiersTypeSwitchComponent {
|
||||
readonly DOSSIERS_ROUTE = DOSSIERS_ROUTE;
|
||||
readonly ARCHIVE_ROUTE = ARCHIVE_ROUTE;
|
||||
|
||||
readonly dossierTemplate$: Observable<DashboardStats>;
|
||||
|
||||
constructor(private readonly _dashboardStatsService: DashboardStatsService, private readonly _route: ActivatedRoute) {
|
||||
const dossierTemplateId = _route.snapshot.paramMap.get(DOSSIER_TEMPLATE_ID);
|
||||
this.dossierTemplate$ = _dashboardStatsService.getEntityChanged$(dossierTemplateId);
|
||||
}
|
||||
}
|
||||
|
||||
@ -7,9 +7,9 @@ import { map, switchMap, tap } from 'rxjs/operators';
|
||||
import { DossierStatesService } from '../entity-services/dossier-states.service';
|
||||
|
||||
const templatesSorter = (a: DashboardStats, b: DashboardStats) => {
|
||||
if (a.numberOfActiveDossiers > 0 && b.numberOfActiveDossiers === 0) {
|
||||
if (!a.isEmpty && b.isEmpty) {
|
||||
return -1;
|
||||
} else if (a.numberOfActiveDossiers === 0 && b.numberOfActiveDossiers > 0) {
|
||||
} else if (a.isEmpty && !b.isEmpty) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
|
||||
@ -1,9 +1,9 @@
|
||||
import { Injectable, Injector } from '@angular/core';
|
||||
import { GenericService, QueryParam, RequiredParam, Validate } from '@iqser/common-ui';
|
||||
import { ILicense, ILicenseReport, ILicenseReportRequest, ILicenses } from '@red/domain';
|
||||
import { BehaviorSubject, firstValueFrom, Observable } from 'rxjs';
|
||||
import { BehaviorSubject, firstValueFrom, Observable, of } from 'rxjs';
|
||||
import { ConfigService } from './config.service';
|
||||
import { filter, tap } from 'rxjs/operators';
|
||||
import { catchError, filter, tap } from 'rxjs/operators';
|
||||
import { LICENSE_STORAGE_KEY } from '../modules/admin/screens/license/utils/constants';
|
||||
|
||||
export function getStoredReports() {
|
||||
@ -11,6 +11,35 @@ export function getStoredReports() {
|
||||
return JSON.parse(rawStoredReports ?? '{}') as Record<string, ILicenseReport>;
|
||||
}
|
||||
|
||||
const defaultOnError: ILicenses = {
|
||||
activeLicense: 'err',
|
||||
licenses: [
|
||||
{
|
||||
id: 'err',
|
||||
name: 'Error',
|
||||
product: 'Error',
|
||||
licensedTo: 'Error',
|
||||
licensedToEmail: 'Error',
|
||||
validFrom: '01-01-2022',
|
||||
validUntil: '01-01-2023',
|
||||
features: [
|
||||
{
|
||||
name: 'processingPages',
|
||||
type: 'NUMBER',
|
||||
value: '2000000',
|
||||
},
|
||||
{
|
||||
name: 'pdftron',
|
||||
type: 'STRING',
|
||||
value:
|
||||
'S25lY29uIEFHKGVuLmtuZWNvbi5zd2lzcyk6T0VNOkREQS1SOjpCKzpBTVMoMj' +
|
||||
'AyMjEwMjkpOkZGQ0M0RDMzMDdEQUI0RjM4QjMxM0JDOUIyNDMzODJDNEU2RjZGQ0I4M0NEOEFDNTc0MzU4QTk1OTczMEI2MjJGQUJFRjVDNw==',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
@ -77,6 +106,7 @@ export class LicenseService extends GenericService<ILicenseReport> {
|
||||
|
||||
loadLicense() {
|
||||
return this._http.get<ILicenses>('/license').pipe(
|
||||
catchError(() => of(defaultOnError)),
|
||||
tap(licenses => this.#licenseData$.next(licenses)),
|
||||
tap(() => this.setDefaultSelectedLicense()),
|
||||
);
|
||||
|
||||
@ -32,31 +32,29 @@ export function configurationInitializer(
|
||||
userPreferenceService: UserPreferenceService,
|
||||
licenseService: LicenseService,
|
||||
) {
|
||||
return () =>
|
||||
firstValueFrom(
|
||||
keycloakService.keycloakEvents$.pipe(
|
||||
filter(event => event.type === KeycloakEventType.OnReady),
|
||||
map(() => featuresService.loadConfig()),
|
||||
switchMap(() => from(keycloakService.isLoggedIn())),
|
||||
switchMap(loggedIn => (!loggedIn ? throwError('Not Logged In') : of({}))),
|
||||
switchMap(() => from(userService.loadCurrentUser())),
|
||||
switchMap(user => (!user.hasAnyREDRoles ? throwError('Not user has no red roles') : of({}))),
|
||||
mergeMap(() => generalSettingsService.getGeneralConfigurations()),
|
||||
tap(configuration => configService.updateDisplayName(configuration.displayName)),
|
||||
switchMap(() => systemPreferencesService.loadPreferences()),
|
||||
switchMap(() => userPreferenceService.reload()),
|
||||
catchError(e => {
|
||||
console.log('[Redaction] Initialization error:', e);
|
||||
title.setTitle('RedactManager');
|
||||
return of({});
|
||||
}),
|
||||
tap(() => {
|
||||
lastDossierTemplateRedirect(baseHref.replace('/', ''), userPreferenceService);
|
||||
}),
|
||||
switchMap(() => languageService.chooseAndSetInitialLanguage()),
|
||||
tap(() => userService.initialize()),
|
||||
tap(() => firstValueFrom(licenseService.loadLicense())),
|
||||
take(1),
|
||||
),
|
||||
);
|
||||
const setup = keycloakService.keycloakEvents$.pipe(
|
||||
filter(event => event.type === KeycloakEventType.OnReady),
|
||||
map(() => featuresService.loadConfig()),
|
||||
switchMap(() => from(keycloakService.isLoggedIn())),
|
||||
switchMap(loggedIn => (!loggedIn ? throwError('Not Logged In') : of({}))),
|
||||
switchMap(() => from(userService.loadCurrentUser())),
|
||||
switchMap(user => (!user.hasAnyREDRoles ? throwError('Not user has no red roles') : of({}))),
|
||||
mergeMap(() => generalSettingsService.getGeneralConfigurations()),
|
||||
tap(configuration => configService.updateDisplayName(configuration.displayName)),
|
||||
switchMap(() => systemPreferencesService.loadPreferences()),
|
||||
switchMap(() => userPreferenceService.reload()),
|
||||
catchError(e => {
|
||||
console.log('[Redaction] Initialization error:', e);
|
||||
title.setTitle('RedactManager');
|
||||
return of({});
|
||||
}),
|
||||
tap(() => {
|
||||
lastDossierTemplateRedirect(baseHref.replace('/', ''), userPreferenceService);
|
||||
}),
|
||||
switchMap(() => languageService.chooseAndSetInitialLanguage()),
|
||||
tap(() => userService.initialize()),
|
||||
tap(() => firstValueFrom(licenseService.loadLicense())),
|
||||
take(1),
|
||||
);
|
||||
return () => firstValueFrom(setup);
|
||||
}
|
||||
|
||||
@ -1 +1 @@
|
||||
Subproject commit 09dfcac064c6c496bb67cf13e3c5cd6d7819764c
|
||||
Subproject commit e5542086ddd2e1548276d47d36161c89179d64e4
|
||||
@ -41,7 +41,7 @@ export class DashboardStats implements IListable, IDashboardStats {
|
||||
}
|
||||
|
||||
get isEmpty(): boolean {
|
||||
return this.numberOfActiveDossiers === 0;
|
||||
return this.numberOfActiveDossiers === 0 && this.numberOfArchivedDossiers === 0;
|
||||
}
|
||||
|
||||
get id(): string {
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "redaction",
|
||||
"version": "3.514.0",
|
||||
"version": "3.518.0",
|
||||
"private": true,
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
|
||||
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user