diff --git a/src/main/webapp/app/lecture/pdf-preview/pdf-preview-thumbnail-grid/pdf-preview-thumbnail-grid.component.ts b/src/main/webapp/app/lecture/pdf-preview/pdf-preview-thumbnail-grid/pdf-preview-thumbnail-grid.component.ts index 50bd4e11433d..e20bd50d9f08 100644 --- a/src/main/webapp/app/lecture/pdf-preview/pdf-preview-thumbnail-grid/pdf-preview-thumbnail-grid.component.ts +++ b/src/main/webapp/app/lecture/pdf-preview/pdf-preview-thumbnail-grid/pdf-preview-thumbnail-grid.component.ts @@ -1,4 +1,4 @@ -import { Component, ElementRef, effect, inject, input, output, signal, viewChild } from '@angular/core'; +import { Component, ElementRef, OnChanges, SimpleChanges, effect, inject, input, output, signal, viewChild } from '@angular/core'; import * as PDFJS from 'pdfjs-dist'; import 'pdfjs-dist/build/pdf.worker'; import { ArtemisSharedModule } from 'app/shared/shared.module'; @@ -14,7 +14,7 @@ import { clone } from 'lodash-es'; standalone: true, imports: [ArtemisSharedModule, PdfPreviewEnlargedCanvasComponent], }) -export class PdfPreviewThumbnailGridComponent { +export class PdfPreviewThumbnailGridComponent implements OnChanges { pdfContainer = viewChild.required>('pdfContainer'); readonly DEFAULT_SLIDE_WIDTH = 250; @@ -42,10 +42,15 @@ export class PdfPreviewThumbnailGridComponent { // Injected services private readonly alertService = inject(AlertService); + ngOnChanges(changes: SimpleChanges): void { + if (changes['hiddenPages']) { + this.newHiddenPages.set(clone(this.hiddenPages()!)); + } + } + constructor() { effect( () => { - this.newHiddenPages.set(clone(this.hiddenPages()!)); this.loadOrAppendPdf(this.currentPdfUrl()!, this.appendFile()); }, { allowSignalWrites: true }, diff --git a/src/main/webapp/app/lecture/pdf-preview/pdf-preview.component.html b/src/main/webapp/app/lecture/pdf-preview/pdf-preview.component.html index 5ed0f41459f8..b4b2ec510e1a 100644 --- a/src/main/webapp/app/lecture/pdf-preview/pdf-preview.component.html +++ b/src/main/webapp/app/lecture/pdf-preview/pdf-preview.component.html @@ -48,7 +48,7 @@

(isPdfLoading)="isPdfLoading.set($event)" (selectedPagesOutput)="selectedPages.set($event)" (totalPagesOutput)="totalPages.set($event)" - (newHiddenPagesOutput)="newHiddenPages.set($event)" + (newHiddenPagesOutput)="hiddenPages.set($event)" /> } @else {
diff --git a/src/main/webapp/app/lecture/pdf-preview/pdf-preview.component.ts b/src/main/webapp/app/lecture/pdf-preview/pdf-preview.component.ts index b113c8dea87b..cb41ce2f1f8a 100644 --- a/src/main/webapp/app/lecture/pdf-preview/pdf-preview.component.ts +++ b/src/main/webapp/app/lecture/pdf-preview/pdf-preview.component.ts @@ -114,7 +114,8 @@ export class PdfPreviewComponent implements OnInit, OnDestroy { * Triggers the file input to select files. */ triggerFileInput(): void { - this.fileInput().nativeElement.click(); + //this.fileInput().nativeElement.click(); + console.log(this.hiddenPages()); } /** @@ -228,9 +229,9 @@ export class PdfPreviewComponent implements OnInit, OnDestroy { const pagesToDelete = Array.from(this.selectedPages()!) .map((page) => page - 1) .sort((a, b) => b - a); - pagesToDelete.forEach((pageIndex) => { - pdfDoc.removePage(pageIndex); - }); + + this.updateHiddenPages(pagesToDelete); + pagesToDelete.forEach((pageIndex) => pdfDoc.removePage(pageIndex)); this.isFileChanged.set(true); const pdfBytes = await pdfDoc.save(); @@ -248,6 +249,27 @@ export class PdfPreviewComponent implements OnInit, OnDestroy { } } + /** + * Updates hidden pages after selected pages are deleted. + * @param pagesToDelete - Array of pages to be deleted (0-indexed). + */ + private updateHiddenPages(pagesToDelete: number[]) { + const updatedHiddenPages = new Set(); + this.hiddenPages().forEach((hiddenPage) => { + // Adjust hiddenPage based on the deleted pages + const adjustedPage = pagesToDelete.reduce((acc, pageIndex) => { + if (acc === pageIndex + 1) { + return; + } + return pageIndex < acc - 1 ? acc - 1 : acc; + }, hiddenPage); + if (adjustedPage !== -1) { + updatedHiddenPages.add(adjustedPage!); + } + }); + this.hiddenPages.set(updatedHiddenPages); + } + /** * Adds a selected PDF file at the end of the current PDF document. * @param event - The event containing the file input.