From 410994c0e0f734be897c6aacc8948e7bd5c1a61d Mon Sep 17 00:00:00 2001 From: Denys Vuika Date: Mon, 11 Dec 2023 12:53:25 -0500 Subject: [PATCH 1/4] fixes for pdf with https --- .../lib/common/services/nodes-api.service.ts | 6 ++++- .../viewer/components/pdf-viewer.component.ts | 23 ++++++++++++------- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/lib/content-services/src/lib/common/services/nodes-api.service.ts b/lib/content-services/src/lib/common/services/nodes-api.service.ts index 556cdd5cf10..37f0eb05e68 100644 --- a/lib/content-services/src/lib/common/services/nodes-api.service.ts +++ b/lib/content-services/src/lib/common/services/nodes-api.service.ts @@ -186,7 +186,11 @@ export class NodesApiService { } } - return this.createNodeInsideRoot(name || window.crypto.randomUUID(), nodeType, properties, path); + return this.createNodeInsideRoot(name || this.randomNodeName(), nodeType, properties, path); + } + + private randomNodeName(): string { + return `node_${Date.now()}`; } /** diff --git a/lib/core/src/lib/viewer/components/pdf-viewer.component.ts b/lib/core/src/lib/viewer/components/pdf-viewer.component.ts index b9afb6c3769..f5716be40a0 100644 --- a/lib/core/src/lib/viewer/components/pdf-viewer.component.ts +++ b/lib/core/src/lib/viewer/components/pdf-viewer.component.ts @@ -36,13 +36,15 @@ import { LogService } from '../../common/services/log.service'; import { RenderingQueueServices } from '../services/rendering-queue.services'; import { PdfPasswordDialogComponent } from './pdf-viewer-password-dialog'; import { AppConfigService } from '../../app-config/app-config.service'; -import { PDFDocumentProxy } from 'pdfjs-dist'; +import { PDFDocumentProxy, OnProgressParameters } from 'pdfjs-dist'; import { Subject } from 'rxjs'; import { catchError, delay } from 'rxjs/operators'; declare const pdfjsLib: any; declare const pdfjsViewer: any; +export type PdfScaleMode = 'init' | 'page-actual' | 'page-width' | 'page-height' | 'page-fit' | 'auto'; + @Component({ selector: 'adf-pdf-viewer', templateUrl: './pdf-viewer.component.html', @@ -87,7 +89,7 @@ export class PdfViewerComponent implements OnChanges, OnDestroy { totalPages: number; loadingPercent: number; pdfViewer: any; - currentScaleMode: 'init' | 'page-actual' | 'page-width' | 'page-height' | 'page-fit' | 'auto' = 'init'; + currentScaleMode: PdfScaleMode = 'init'; MAX_AUTO_SCALE: number = 1.25; DEFAULT_SCALE_DELTA: number = 1.1; @@ -125,7 +127,8 @@ export class PdfViewerComponent implements OnChanges, OnDestroy { this.onPageChange = this.onPageChange.bind(this); this.onPagesLoaded = this.onPagesLoaded.bind(this); this.onPageRendered = this.onPageRendered.bind(this); - this.randomPdfId = window.crypto.randomUUID(); + + this.randomPdfId = Date.now().toString(); this.pdfjsWorkerDestroy$ .pipe( catchError(() => null), @@ -200,7 +203,7 @@ export class PdfViewerComponent implements OnChanges, OnDestroy { this.onPdfPassword(callback, reason); }; - this.loadingTask.onProgress = (progressData) => { + this.loadingTask.onProgress = (progressData: OnProgressParameters) => { const level = progressData.loaded / progressData.total; this.loadingPercent = Math.round(level * 100); }; @@ -276,10 +279,10 @@ export class PdfViewerComponent implements OnChanges, OnDestroy { * * @param scaleMode - new scale mode */ - scalePage(scaleMode) { + scalePage(scaleMode: PdfScaleMode) { this.currentScaleMode = scaleMode; - const viewerContainer = document.getElementById(`${this.randomPdfId}-viewer-main-container`); + const viewerContainer = this.getMainContainer(); const documentContainer = this.getDocumentContainer(); if (this.pdfViewer && documentContainer) { @@ -348,11 +351,15 @@ export class PdfViewerComponent implements OnChanges, OnDestroy { return this.checkPageFitInContainer(scale); } - private getDocumentContainer() { + private getMainContainer(): HTMLElement { + return document.getElementById(`${this.randomPdfId}-viewer-main-container`); + } + + private getDocumentContainer(): HTMLElement { return document.getElementById(`${this.randomPdfId}-viewer-pdf-viewer`); } - private getViewer() { + private getViewer(): HTMLElement { return document.getElementById(`${this.randomPdfId}-viewer-viewerPdf`); } From b0d2b91eb707fa6fcce814aa6a5f7b73f98398c5 Mon Sep 17 00:00:00 2001 From: Denys Vuika Date: Mon, 11 Dec 2023 18:45:15 -0500 Subject: [PATCH 2/4] [ci:force] cleanup code --- .../viewer/components/pdf-viewer.component.ts | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/lib/core/src/lib/viewer/components/pdf-viewer.component.ts b/lib/core/src/lib/viewer/components/pdf-viewer.component.ts index f5716be40a0..22386c431bf 100644 --- a/lib/core/src/lib/viewer/components/pdf-viewer.component.ts +++ b/lib/core/src/lib/viewer/components/pdf-viewer.component.ts @@ -32,7 +32,6 @@ import { SimpleChanges } from '@angular/core'; import { MatDialog } from '@angular/material/dialog'; -import { LogService } from '../../common/services/log.service'; import { RenderingQueueServices } from '../services/rendering-queue.services'; import { PdfPasswordDialogComponent } from './pdf-viewer-password-dialog'; import { AppConfigService } from '../../app-config/app-config.service'; @@ -120,7 +119,6 @@ export class PdfViewerComponent implements OnChanges, OnDestroy { constructor( private dialog: MatDialog, private renderingQueueServices: RenderingQueueServices, - private logService: LogService, private appConfigService: AppConfigService ) { // needed to preserve "this" context @@ -305,33 +303,37 @@ export class PdfViewerComponent implements OnChanges, OnDestroy { let scale: number; switch (this.currentScaleMode) { - case 'init': + case 'init': { scale = this.getUserScaling(); if (!scale) { scale = this.autoScaling(pageHeightScale, pageWidthScale); } break; - case 'page-actual': + } + case 'page-actual': { scale = 1; break; - case 'page-width': + } + case 'page-width': { scale = pageWidthScale; break; - case 'page-height': + } + case 'page-height': { scale = pageHeightScale; break; - case 'page-fit': + } + case 'page-fit': { scale = this.getUserScaling(); if (!scale) { scale = this.autoScaling(pageHeightScale, pageWidthScale); } break; - case 'auto': + } + case 'auto': { scale = this.autoScaling(pageHeightScale, pageWidthScale); - break; + } default: - this.logService.error(`pdfViewSetScale: '${scaleMode}' is an unknown zoom value.`); return; } From 8298045c24812a3f73b313e21dba2273893c5c4f Mon Sep 17 00:00:00 2001 From: Denys Vuika Date: Mon, 11 Dec 2023 18:58:32 -0500 Subject: [PATCH 3/4] [ci:force] add missing types --- lib/core/src/lib/viewer/components/pdf-viewer.component.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/core/src/lib/viewer/components/pdf-viewer.component.ts b/lib/core/src/lib/viewer/components/pdf-viewer.component.ts index 22386c431bf..3acd35d89d9 100644 --- a/lib/core/src/lib/viewer/components/pdf-viewer.component.ts +++ b/lib/core/src/lib/viewer/components/pdf-viewer.component.ts @@ -35,7 +35,7 @@ import { MatDialog } from '@angular/material/dialog'; import { RenderingQueueServices } from '../services/rendering-queue.services'; import { PdfPasswordDialogComponent } from './pdf-viewer-password-dialog'; import { AppConfigService } from '../../app-config/app-config.service'; -import { PDFDocumentProxy, OnProgressParameters } from 'pdfjs-dist'; +import { PDFDocumentProxy, OnProgressParameters, PDFDocumentLoadingTask } from 'pdfjs-dist'; import { Subject } from 'rxjs'; import { catchError, delay } from 'rxjs/operators'; @@ -95,7 +95,7 @@ export class PdfViewerComponent implements OnChanges, OnDestroy { MIN_SCALE: number = 0.25; MAX_SCALE: number = 10.0; - loadingTask: any; + loadingTask: PDFDocumentLoadingTask; isPanelDisabled = true; showThumbnails: boolean = false; pdfThumbnailsContext: { viewer: any } = { viewer: null }; @@ -208,7 +208,7 @@ export class PdfViewerComponent implements OnChanges, OnDestroy { this.isPanelDisabled = true; this.loadingTask.promise - .then((pdfDocument: PDFDocumentProxy) => { + .then((pdfDocument) => { this.totalPages = pdfDocument.numPages; this.page = 1; this.displayPage = 1; From 979e02cb41d2db7da3ceeed940f1d2fbca4af9a2 Mon Sep 17 00:00:00 2001 From: Denys Vuika Date: Tue, 12 Dec 2023 09:32:29 -0500 Subject: [PATCH 4/4] reduce duplicated code --- .../src/lib/viewer/components/pdf-viewer.component.ts | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/lib/core/src/lib/viewer/components/pdf-viewer.component.ts b/lib/core/src/lib/viewer/components/pdf-viewer.component.ts index 3acd35d89d9..0a19603bc82 100644 --- a/lib/core/src/lib/viewer/components/pdf-viewer.component.ts +++ b/lib/core/src/lib/viewer/components/pdf-viewer.component.ts @@ -303,7 +303,8 @@ export class PdfViewerComponent implements OnChanges, OnDestroy { let scale: number; switch (this.currentScaleMode) { - case 'init': { + case 'init': + case 'page-fit': { scale = this.getUserScaling(); if (!scale) { scale = this.autoScaling(pageHeightScale, pageWidthScale); @@ -322,13 +323,6 @@ export class PdfViewerComponent implements OnChanges, OnDestroy { scale = pageHeightScale; break; } - case 'page-fit': { - scale = this.getUserScaling(); - if (!scale) { - scale = this.autoScaling(pageHeightScale, pageWidthScale); - } - break; - } case 'auto': { scale = this.autoScaling(pageHeightScale, pageWidthScale); break;