Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MNT-24098] fixes for pdf with HTTP #9155

Merged
merged 4 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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()}`;
}

/**
Expand Down
49 changes: 29 additions & 20 deletions lib/core/src/lib/viewer/components/pdf-viewer.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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 };
Expand All @@ -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),
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -302,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': {
DenysVuika marked this conversation as resolved.
Show resolved Hide resolved
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;
}

Expand All @@ -348,11 +353,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`);
}

Expand Down
Loading