Pull request #360: VM/RED-3608
Merge in RED/ui from VM/RED-3608 to master * commit '3b9923b4dfa946e51994cc9c37c3e5d36d3d0861': removed "FilePreviewGuard" as it's no longer used removed comment handled deleted file when click on notification file link
This commit is contained in:
commit
7793226ae7
@ -1,31 +0,0 @@
|
||||
import { Injectable, Injector, ProviderToken } from '@angular/core';
|
||||
import { ActivatedRouteSnapshot, CanActivate, Router } from '@angular/router';
|
||||
import { FilesMapService } from '@services/entity-services/files-map.service';
|
||||
import { DOSSIER_ID, FILE_ID } from '@utils/constants';
|
||||
import { DossiersService } from '@services/dossiers/dossiers.service';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class FilePreviewGuard implements CanActivate {
|
||||
constructor(
|
||||
private readonly _filesMapService: FilesMapService,
|
||||
private readonly _router: Router,
|
||||
private readonly _injector: Injector,
|
||||
) {}
|
||||
|
||||
async canActivate(route: ActivatedRouteSnapshot): Promise<boolean> {
|
||||
const token: ProviderToken<DossiersService> = route.data.dossiersService;
|
||||
const dossiersService: DossiersService = this._injector.get<DossiersService>(token);
|
||||
|
||||
const dossierId = route.paramMap.get(DOSSIER_ID);
|
||||
const fileId = route.paramMap.get(FILE_ID);
|
||||
|
||||
const dossier = dossiersService.find(dossierId);
|
||||
|
||||
if (!this._filesMapService.get(dossierId, fileId)) {
|
||||
await this._router.navigate([dossier.routerLink]);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -6,7 +6,6 @@ import { DOSSIER_ID, FILE_ID } from '@utils/constants';
|
||||
import { CompositeRouteGuard } from '@iqser/common-ui';
|
||||
import { ARCHIVED_DOSSIERS_SERVICE } from '../../tokens';
|
||||
import { DossierFilesGuard } from '@guards/dossier-files-guard';
|
||||
import { FilePreviewGuard } from '@guards/file-preview.guard';
|
||||
|
||||
const routes: Routes = [
|
||||
{
|
||||
@ -29,7 +28,7 @@ const routes: Routes = [
|
||||
path: `:${DOSSIER_ID}/file/:${FILE_ID}`,
|
||||
canActivate: [CompositeRouteGuard],
|
||||
data: {
|
||||
routeGuards: [DossierFilesGuard, FilePreviewGuard],
|
||||
routeGuards: [DossierFilesGuard],
|
||||
breadcrumbs: [BreadcrumbTypes.archive, BreadcrumbTypes.dossier, BreadcrumbTypes.file],
|
||||
dossiersService: ARCHIVED_DOSSIERS_SERVICE,
|
||||
},
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
import { NgModule } from '@angular/core';
|
||||
import { RouterModule, Routes } from '@angular/router';
|
||||
import { FilePreviewGuard } from '@guards/file-preview.guard';
|
||||
import { DossierFilesGuard } from '@guards/dossier-files-guard';
|
||||
import { CompositeRouteGuard } from '@iqser/common-ui';
|
||||
import { BreadcrumbTypes } from '@red/domain';
|
||||
@ -22,7 +21,7 @@ const routes: Routes = [
|
||||
path: `:${DOSSIER_ID}/file/:${FILE_ID}`,
|
||||
canActivate: [CompositeRouteGuard],
|
||||
data: {
|
||||
routeGuards: [DossierFilesGuard, FilePreviewGuard],
|
||||
routeGuards: [DossierFilesGuard],
|
||||
breadcrumbs: [BreadcrumbTypes.main, BreadcrumbTypes.dossier, BreadcrumbTypes.file],
|
||||
dossiersService: ACTIVE_DOSSIERS_SERVICE,
|
||||
},
|
||||
|
||||
@ -202,7 +202,8 @@ export class FilePreviewScreenComponent extends AutoUnsubscribe implements OnIni
|
||||
async ngOnAttach(previousRoute: ActivatedRouteSnapshot): Promise<boolean> {
|
||||
const file = await this.stateService.file;
|
||||
if (!file.canBeOpened) {
|
||||
return this._router.navigate([this._dossiersService.find(this.dossierId)?.routerLink]);
|
||||
this._navigateToDossier();
|
||||
return;
|
||||
}
|
||||
this._viewModeService.compareMode = false;
|
||||
this._viewModeService.switchToStandard();
|
||||
@ -214,18 +215,23 @@ export class FilePreviewScreenComponent extends AutoUnsubscribe implements OnIni
|
||||
}
|
||||
|
||||
async ngOnInit(): Promise<void> {
|
||||
this.ready = false;
|
||||
this._loadingService.start();
|
||||
await this.userPreferenceService.saveLastOpenedFileForDossier(this.dossierId, this.fileId);
|
||||
this._subscribeToFileUpdates();
|
||||
|
||||
const file = await this.stateService.file;
|
||||
if (file?.analysisRequired && !file.excludedFromAutomaticAnalysis) {
|
||||
const reanalyzeFiles = this._reanalysisService.reanalyzeFilesForDossier([file], this.dossierId, { force: true });
|
||||
await firstValueFrom(reanalyzeFiles);
|
||||
}
|
||||
|
||||
this.displayPdfViewer = true;
|
||||
if (!file) {
|
||||
this._handleDeletedFile();
|
||||
} else {
|
||||
this.ready = false;
|
||||
this._loadingService.start();
|
||||
await this.userPreferenceService.saveLastOpenedFileForDossier(this.dossierId, this.fileId);
|
||||
this._subscribeToFileUpdates();
|
||||
|
||||
if (file?.analysisRequired && !file.excludedFromAutomaticAnalysis) {
|
||||
const reanalyzeFiles = this._reanalysisService.reanalyzeFilesForDossier([file], this.dossierId, { force: true });
|
||||
await firstValueFrom(reanalyzeFiles);
|
||||
}
|
||||
|
||||
this.displayPdfViewer = true;
|
||||
}
|
||||
}
|
||||
|
||||
async rebuildFilters() {
|
||||
@ -604,7 +610,13 @@ export class FilePreviewScreenComponent extends AutoUnsubscribe implements OnIni
|
||||
|
||||
private _handleDeletedFile(): void {
|
||||
this._errorService.set(
|
||||
new CustomError(_('error.deleted-entity.file.label'), _('error.deleted-entity.file.action'), 'iqser:expand'),
|
||||
new CustomError(
|
||||
_('error.deleted-entity.file.label'),
|
||||
_('error.deleted-entity.file.action'),
|
||||
'iqser:expand',
|
||||
null,
|
||||
this._navigateToDossier.bind(this),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@ -677,4 +689,8 @@ export class FilePreviewScreenComponent extends AutoUnsubscribe implements OnIni
|
||||
annotation['FillColor'] = color;
|
||||
});
|
||||
}
|
||||
|
||||
private _navigateToDossier() {
|
||||
this._router.navigate([this._dossiersService.find(this.dossierId)?.routerLink]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -102,12 +102,7 @@ export class FileDataService {
|
||||
async loadAnnotations() {
|
||||
const file = await this._state.file;
|
||||
|
||||
if (!file) {
|
||||
const dossier = await this._state.dossier;
|
||||
return this._router.navigate([dossier.routerLink]);
|
||||
}
|
||||
|
||||
if (file.isUnprocessed) {
|
||||
if (!file || file.isUnprocessed) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user