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..0a19603bc82 100644 --- a/lib/core/src/lib/viewer/components/pdf-viewer.component.ts +++ b/lib/core/src/lib/viewer/components/pdf-viewer.component.ts @@ -32,17 +32,18 @@ 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'; -import { PDFDocumentProxy } from 'pdfjs-dist'; +import { PDFDocumentProxy, OnProgressParameters, PDFDocumentLoadingTask } 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,14 +88,14 @@ 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; MIN_SCALE: number = 0.25; MAX_SCALE: number = 10.0; - loadingTask: any; + loadingTask: PDFDocumentLoadingTask; isPanelDisabled = true; showThumbnails: boolean = false; pdfThumbnailsContext: { viewer: any } = { viewer: null }; @@ -118,14 +119,14 @@ export class PdfViewerComponent implements OnChanges, OnDestroy { constructor( private dialog: MatDialog, private renderingQueueServices: RenderingQueueServices, - private logService: LogService, private appConfigService: AppConfigService ) { // needed to preserve "this" context 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,14 +201,14 @@ 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); }; this.isPanelDisabled = true; this.loadingTask.promise - .then((pdfDocument: PDFDocumentProxy) => { + .then((pdfDocument) => { this.totalPages = pdfDocument.numPages; this.page = 1; this.displayPage = 1; @@ -276,10 +277,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) { @@ -303,32 +304,30 @@ export class PdfViewerComponent implements OnChanges, OnDestroy { let scale: number; switch (this.currentScaleMode) { case 'init': + case 'page-fit': { 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': - 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; } @@ -348,11 +347,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`); }