RED-1596: don't reuse component without open file permissions

This commit is contained in:
Dan Percic 2021-06-10 11:39:41 +03:00
parent 821cfe4871
commit 11dfe60451
4 changed files with 104 additions and 109 deletions

View File

@ -78,8 +78,8 @@ export class PdfViewerComponent implements OnInit, AfterViewInit, OnChanges {
}
}
ngAfterViewInit(): void {
this._loadViewer();
async ngAfterViewInit(): Promise<void> {
await this._loadViewer();
}
deselectAllAnnotations() {
@ -135,99 +135,98 @@ export class PdfViewerComponent implements OnInit, AfterViewInit, OnChanges {
return this.instance.annotManager.getAnnotationById(id);
}
private _loadViewer() {
WebViewer(
private async _loadViewer() {
this.instance = await WebViewer(
{
licenseKey: environment.licenseKey ? atob(environment.licenseKey) : null,
path: this._convertPath('/assets/wv-resources'),
css: this._convertPath('/assets/pdftron/stylesheet.css')
},
this.viewer.nativeElement
).then(instance => {
this.instance = instance;
this._setSelectionMode();
this._disableElements();
this._disableHotkeys();
this._configureTextPopup();
);
instance.annotManager.on('annotationSelected', (annotations, action) => {
this.annotationSelected.emit(
instance.annotManager.getSelectedAnnotations().map(ann => ann.Id)
this._setSelectionMode();
this._disableElements();
this._disableHotkeys();
this._configureTextPopup();
this.instance.annotManager.on('annotationSelected', (annotations, action) => {
this.annotationSelected.emit(
this.instance.annotManager.getSelectedAnnotations().map(ann => ann.Id)
);
if (action === 'deselected') {
this._toggleRectangleAnnotationAction(true);
} else {
this._configureAnnotationSpecificActions(annotations);
this._toggleRectangleAnnotationAction(
annotations.length === 1 && annotations[0].ReadOnly
);
if (action === 'deselected') {
this._toggleRectangleAnnotationAction(true);
} else {
this._configureAnnotationSpecificActions(annotations);
this._toggleRectangleAnnotationAction(
annotations.length === 1 && annotations[0].ReadOnly
);
}
});
}
});
instance.annotManager.on('annotationChanged', annotations => {
// when a rectangle is drawn,
// it returns one annotation with tool name 'AnnotationCreateRectangle;
// this will auto select rectangle after drawing
if (
annotations.length === 1 &&
annotations[0].ToolName === 'AnnotationCreateRectangle'
) {
instance.annotManager.selectAnnotations(annotations);
}
});
this.instance.annotManager.on('annotationChanged', annotations => {
// when a rectangle is drawn,
// it returns one annotation with tool name 'AnnotationCreateRectangle;
// this will auto select rectangle after drawing
if (
annotations.length === 1 &&
annotations[0].ToolName === 'AnnotationCreateRectangle'
) {
this.instance.annotManager.selectAnnotations(annotations);
}
});
instance.docViewer.on('pageNumberUpdated', pageNumber => {
if (this.shouldDeselectAnnotationsOnPageChange) {
this.deselectAllAnnotations();
}
this._ngZone.run(() => this.pageChanged.emit(pageNumber));
});
this.instance.docViewer.on('pageNumberUpdated', pageNumber => {
if (this.shouldDeselectAnnotationsOnPageChange) {
this.deselectAllAnnotations();
}
this._ngZone.run(() => this.pageChanged.emit(pageNumber));
});
instance.docViewer.on('documentLoaded', this._documentLoaded);
this.instance.docViewer.on('documentLoaded', this._documentLoaded);
instance.docViewer.on('keyUp', $event => {
// arrows and full-screen
if ($event.target?.tagName?.toLowerCase() !== 'input') {
if ($event.key.startsWith('Arrow') || $event.key === 'f') {
this._ngZone.run(() => {
this.keyUp.emit($event);
});
$event.preventDefault();
$event.stopPropagation();
}
}
if (this._allowedKeyboardShortcuts.indexOf($event.key) < 0) {
this.instance.docViewer.on('keyUp', $event => {
// arrows and full-screen
if ($event.target?.tagName?.toLowerCase() !== 'input') {
if ($event.key.startsWith('Arrow') || $event.key === 'f') {
this._ngZone.run(() => {
this.keyUp.emit($event);
});
$event.preventDefault();
$event.stopPropagation();
}
});
}
instance.docViewer.on('textSelected', (quads, selectedText) => {
this._selectedText = selectedText;
if (selectedText.length > 2 && this.canPerformActions) {
this.instance.enableElements(['add-dictionary', 'add-false-positive']);
} else {
this.instance.disableElements(['add-dictionary', 'add-false-positive']);
}
});
instance.iframeWindow.addEventListener('visibilityChanged', (event: any) => {
if (event.detail.element === 'searchPanel') {
const inputElement = instance.iframeWindow.document.getElementById(
'SearchPanel__input'
) as HTMLInputElement;
setTimeout(() => {
inputElement.value = '';
}, 0);
if (!event.detail.isVisible) {
instance.docViewer.clearSearchResults();
}
}
});
this._loadDocument();
if (this._allowedKeyboardShortcuts.indexOf($event.key) < 0) {
$event.preventDefault();
$event.stopPropagation();
}
});
this.instance.docViewer.on('textSelected', (quads, selectedText) => {
this._selectedText = selectedText;
if (selectedText.length > 2 && this.canPerformActions) {
this.instance.enableElements(['add-dictionary', 'add-false-positive']);
} else {
this.instance.disableElements(['add-dictionary', 'add-false-positive']);
}
});
this.instance.iframeWindow.addEventListener('visibilityChanged', (event: any) => {
if (event.detail.element === 'searchPanel') {
const inputElement = this.instance.iframeWindow.document.getElementById(
'SearchPanel__input'
) as HTMLInputElement;
setTimeout(() => {
inputElement.value = '';
}, 0);
if (!event.detail.isVisible) {
this.instance.docViewer.clearSearchResults();
}
}
});
this._loadDocument();
}
private _setSelectionMode(): void {

View File

@ -242,8 +242,7 @@
(closeDocumentInfoView)="viewDocumentInfo = false"
*ngIf="viewReady && viewDocumentInfo"
[file]="fileData.fileStatus.fileStatus"
>
</redaction-document-info>
></redaction-document-info>
<redaction-file-workload
#fileWorkloadComponent

View File

@ -222,6 +222,11 @@ export class FilePreviewScreenComponent implements OnInit, OnDestroy, OnAttach,
}
async ngOnAttach(previousRoute: ActivatedRouteSnapshot) {
if (!this.permissionsService.canOpenFile(this.appStateService.activeFile)) {
await this._router.navigate(['/main/dossiers/' + this.dossierId]);
return;
}
await this.ngOnInit();
this._lastPage = previousRoute.queryParams.page;
}
@ -325,7 +330,7 @@ export class FilePreviewScreenComponent implements OnInit, OnDestroy, OnAttach,
selectPage(pageNumber: number) {
this._viewerComponent.navigateToPage(pageNumber);
this._workloadComponent.scrollAnnotationsToPage(pageNumber, 'always');
this._workloadComponent?.scrollAnnotationsToPage(pageNumber, 'always');
}
openManualAnnotationDialog($event: ManualRedactionEntryWrapper) {
@ -393,7 +398,7 @@ export class FilePreviewScreenComponent implements OnInit, OnDestroy, OnAttach,
viewerPageChanged($event: any) {
if (typeof $event === 'number') {
this._scrollViews();
if (!this._workloadComponent.multiSelectActive) {
if (!this._workloadComponent?.multiSelectActive) {
this.shouldDeselectAnnotationsOnPageChange = true;
}
@ -583,9 +588,7 @@ export class FilePreviewScreenComponent implements OnInit, OnDestroy, OnAttach,
}
} else {
if (fileDataModel.fileStatus.isError) {
this._router.navigate([
'/main/dossiers/' + this.appStateService.activeDossierId
]);
this._router.navigate(['/main/dossiers/' + this.dossierId]);
} else {
this.loadingMessage = 'file-preview.reanalyse-file';
}
@ -597,8 +600,8 @@ export class FilePreviewScreenComponent implements OnInit, OnDestroy, OnAttach,
@debounce()
private _scrollViews() {
this._workloadComponent.scrollQuickNavigation();
this._workloadComponent.scrollAnnotations();
this._workloadComponent?.scrollQuickNavigation();
this._workloadComponent?.scrollAnnotations();
}
/* Get the documentElement (<html>) to display the page in fullscreen */

View File

@ -31,33 +31,27 @@ export class PdfViewerDataService {
}
loadActiveFileData(): Observable<FileDataModel> {
const fileObs = this.downloadOriginalFile(this._appStateService.activeFile);
const reactionLogObs = this._redactionLogControllerService
.getRedactionLog(
this._appStateService.activeDossierId,
this._appStateService.activeFileId
)
const dossierId = this._appStateService.activeDossierId;
const fileId = this._appStateService.activeFileId;
const file$ = this.downloadOriginalFile(this._appStateService.activeFile);
const reactionLog$ = this._redactionLogControllerService
.getRedactionLog(dossierId, fileId)
.pipe(catchError(() => of({})));
const redactionChangeLogObs = this._redactionLogControllerService
.getRedactionChangeLog(
this._appStateService.activeDossierId,
this._appStateService.activeFileId
)
const redactionChangeLog$ = this._redactionLogControllerService
.getRedactionChangeLog(dossierId, fileId)
.pipe(catchError(() => of({})));
const manualRedactionsObs = this._manualRedactionControllerService
.getManualRedaction(
this._appStateService.activeDossierId,
this._appStateService.activeFileId
)
const manualRedactions$ = this._manualRedactionControllerService
.getManualRedaction(dossierId, fileId)
.pipe(catchError(() => of({})));
const viewedPagesObs = this.getViewedPagesForActiveFile();
const viewedPages$ = this.getViewedPagesForActiveFile();
return forkJoin([
fileObs,
reactionLogObs,
redactionChangeLogObs,
manualRedactionsObs,
viewedPagesObs
file$,
reactionLog$,
redactionChangeLog$,
manualRedactions$,
viewedPages$
]).pipe(map(data => new FileDataModel(this._appStateService.activeFile, ...data)));
}