From 153ff9b5ea6a664ad81046a7b3c0b9eea2646ee1 Mon Sep 17 00:00:00 2001 From: Tamara Steinwender <tamara.steinwender@tugraz.at> Date: Tue, 6 Jul 2021 15:24:18 +0200 Subject: [PATCH] Add an Error Message to pdf preview if pdf is invalid --- src/dbp-pdf-preview.js | 16 +++++++++++++++- src/i18n/de/translation.json | 3 ++- src/i18n/en/translation.json | 3 ++- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/dbp-pdf-preview.js b/src/dbp-pdf-preview.js index 17395c1..cb00864 100644 --- a/src/dbp-pdf-preview.js +++ b/src/dbp-pdf-preview.js @@ -25,6 +25,7 @@ export class PdfPreview extends ScopedElementsMixin(DBPLitElement) { this.totalPages = 0; this.isShowPage = false; this.isPageLoaded = false; + this.showErrorMessage = false; this.isPageRenderingInProgress = false; this.isShowPlacement = true; this.canvas = null; @@ -60,6 +61,7 @@ export class PdfPreview extends ScopedElementsMixin(DBPLitElement) { isShowPage: { type: Boolean, attribute: false }, isPageRenderingInProgress: { type: Boolean, attribute: false }, isPageLoaded: { type: Boolean, attribute: false }, + showErrorMessage: { type: Boolean, attribute: false }, isShowPlacement: { type: Boolean, attribute: false }, placeholder: { type: String, attribute: 'signature-placeholder-image-src' }, signature_width: { type: Number, attribute: 'signature-width' }, @@ -195,6 +197,7 @@ export class PdfPreview extends ScopedElementsMixin(DBPLitElement) { async showPDF(file, isShowPlacement = false, placementData = {}) { let item = this.getSignatureRect(); this.isPageLoaded = false; // prevent redisplay of previous pdf + this.showErrorMessage = false; // move signature if placementData was set if (item !== undefined) { @@ -225,6 +228,7 @@ export class PdfPreview extends ScopedElementsMixin(DBPLitElement) { this.pdfDoc = await pdfjs.getDocument({data: data}).promise; } catch (error) { console.error(error); + this.showErrorMessage = true; return; } @@ -561,6 +565,13 @@ export class PdfPreview extends ScopedElementsMixin(DBPLitElement) { .button.is-cancel { color: #e4154b; } + + .error-message{ + text-align: center; + border: 1px solid black; + border-top: 0px; + padding: 15px; + } `; } @@ -575,7 +586,10 @@ export class PdfPreview extends ScopedElementsMixin(DBPLitElement) { </form> --> <div id="pdf-main-container" class="${classMap({hidden: !this.isShowPage})}"> - <dbp-mini-spinner class="${classMap({hidden: this.isPageLoaded})}"></dbp-mini-spinner> + <dbp-mini-spinner class="${classMap({hidden: this.isPageLoaded || this.showErrorMessage})}"></dbp-mini-spinner> + <div class="error-message ${classMap({hidden: !this.showErrorMessage || this.isPageLoaded})}"> + ${i18n.t('pdf-preview.error-message')} + </div> <div class="${classMap({hidden: !this.isPageLoaded})}"> <div id="pdf-meta"> <div class="buttons ${classMap({hidden: !this.isPageLoaded})}"> diff --git a/src/i18n/de/translation.json b/src/i18n/de/translation.json index 48be74f..85a9eaa 100644 --- a/src/i18n/de/translation.json +++ b/src/i18n/de/translation.json @@ -114,7 +114,8 @@ "page-count": "von {{totalPages}}", "rotate-signature": "Signatur im Uhrzeigersinn rotieren", "rotate": "Signatur rotieren", - "continue": "Platzierung bestätigen" + "continue": "Platzierung bestätigen", + "error-message": "Fehler: Dieses Dokument ist beschädigt." }, "annotation-view": { "delete-all-button-text": "Alle entfernen", diff --git a/src/i18n/en/translation.json b/src/i18n/en/translation.json index 5e9227c..d95e0d7 100644 --- a/src/i18n/en/translation.json +++ b/src/i18n/en/translation.json @@ -114,7 +114,8 @@ "page-count": "of {{totalPages}}", "rotate-signature": "Rotate signature clockwise", "rotate": "Rotate signature", - "continue": "Confirm placement" + "continue": "Confirm placement", + "error-message": "Error: This document is incorrect." }, "annotation-view": { "delete-all-button-text": "Clear all", -- GitLab