Show errors during PDF generation

A lot of PDF-Erros are resolveable by the users themselves.
This helpes users to show them, which of their motions have
malformated HTML
This commit is contained in:
Sean Engelhardt 2019-04-26 15:34:27 +02:00
parent 7c503024cc
commit 680b6e04e4
5 changed files with 59 additions and 27 deletions

View File

@ -8,6 +8,19 @@ import { TranslateService } from '@ngx-translate/core';
import { ConfigService } from './config.service'; import { ConfigService } from './config.service';
import { HttpService } from '../core-services/http.service'; import { HttpService } from '../core-services/http.service';
/**
* Custom PDF error class to handle errors in a safer way
*/
export class PdfError extends Error {
public __proto__: PdfError;
public constructor(public message: string) {
super(message);
const trueProto = new.target.prototype;
this.__proto__ = trueProto;
}
}
/** /**
* Provides the general document structure for PDF documents, such as page margins, header, footer and styles. * Provides the general document structure for PDF documents, such as page margins, header, footer and styles.
* Also provides general purpose open and download functions. * Also provides general purpose open and download functions.

View File

@ -1315,13 +1315,8 @@ export class MotionDetailComponent extends BaseViewComponent implements OnInit,
* Click handler for the pdf button * Click handler for the pdf button
*/ */
public onDownloadPdf(): void { public onDownloadPdf(): void {
// TODO: apparently statue amendments never have line numbers and are always in crMode
if (this.motion.isStatuteAmendment()) {
this.pdfExport.exportSingleMotion(this.motion, LineNumberingMode.None, ChangeRecoMode.Diff);
} else {
this.pdfExport.exportSingleMotion(this.motion, this.lnMode, this.crMode); this.pdfExport.exportSingleMotion(this.motion, this.lnMode, this.crMode);
} }
}
/** /**
* Click handler for attachments * Click handler for attachments

View File

@ -30,6 +30,7 @@ import { MotionMultiselectService } from 'app/site/motions/services/motion-multi
import { MotionXlsxExportService } from 'app/site/motions/services/motion-xlsx-export.service'; import { MotionXlsxExportService } from 'app/site/motions/services/motion-xlsx-export.service';
import { LocalPermissionsService } from 'app/site/motions/services/local-permissions.service'; import { LocalPermissionsService } from 'app/site/motions/services/local-permissions.service';
import { StorageService } from 'app/core/core-services/storage.service'; import { StorageService } from 'app/core/core-services/storage.service';
import { PdfError } from 'app/core/ui-services/pdf-document.service';
/** /**
* Interface to describe possible values and changes for * Interface to describe possible values and changes for
@ -251,6 +252,7 @@ export class MotionListComponent extends ListViewBaseComponent<ViewMotion, Motio
if (result && result.format) { if (result && result.format) {
const data = this.isMultiSelect ? this.selectedRows : this.dataSource.filteredData; const data = this.isMultiSelect ? this.selectedRows : this.dataSource.filteredData;
if (result.format === 'pdf') { if (result.format === 'pdf') {
try {
this.pdfExport.exportMotionCatalog( this.pdfExport.exportMotionCatalog(
data, data,
result.lnMode, result.lnMode,
@ -259,6 +261,13 @@ export class MotionListComponent extends ListViewBaseComponent<ViewMotion, Motio
result.metaInfo, result.metaInfo,
result.comments result.comments
); );
} catch (err) {
if (err instanceof PdfError) {
this.raiseError(err.message);
} else {
throw err;
}
}
} else if (result.format === 'csv') { } else if (result.format === 'csv') {
const content = ['identifier', ...result.content, ...result.metaInfo]; const content = ['identifier', ...result.content, ...result.metaInfo];
this.motionCsvExport.exportMotionList(data, content); this.motionCsvExport.exportMotionList(data, content);

View File

@ -6,6 +6,7 @@ import { ViewMotion, LineNumberingMode, ChangeRecoMode } from '../models/view-mo
import { MotionPdfService, InfoToExport } from './motion-pdf.service'; import { MotionPdfService, InfoToExport } from './motion-pdf.service';
import { ConfigService } from 'app/core/ui-services/config.service'; import { ConfigService } from 'app/core/ui-services/config.service';
import { ViewCategory } from '../models/view-category'; import { ViewCategory } from '../models/view-category';
import { PdfError } from 'app/core/ui-services/pdf-document.service';
/** /**
* Service to export a list of motions. * Service to export a list of motions.
@ -64,6 +65,7 @@ export class MotionPdfCatalogService {
const motionDocList = []; const motionDocList = [];
for (let motionIndex = 0; motionIndex < motions.length; ++motionIndex) { for (let motionIndex = 0; motionIndex < motions.length; ++motionIndex) {
try {
const motionDocDef: any = this.motionPdfService.motionToDocDef( const motionDocDef: any = this.motionPdfService.motionToDocDef(
motions[motionIndex], motions[motionIndex],
lnMode, lnMode,
@ -81,6 +83,13 @@ export class MotionPdfCatalogService {
if (motionIndex < motions.length - 1) { if (motionIndex < motions.length - 1) {
motionDocList.push(this.pageBreak); motionDocList.push(this.pageBreak);
} }
} catch (err) {
const errorText = `${this.translate.instant('Error during PDF creation of motion:')} ${
motions[motionIndex].identifierOrTitle
}`;
console.error(`${errorText}\nDebugInfo:\n`, err);
throw new PdfError(errorText);
}
} }
// print extra data (title, preamble, categories, toc) only if there are more than 1 motion // print extra data (title, preamble, categories, toc) only if there are more than 1 motion

View File

@ -90,6 +90,12 @@ export class MotionPdfService {
): object { ): object {
let motionPdfContent = []; let motionPdfContent = [];
// Enforces that statutes should always have Diff Mode and no line numbers
if (motion.isStatuteAmendment()) {
lnMode = LineNumberingMode.None;
crMode = ChangeRecoMode.Diff;
}
// determine the default lnMode if not explicitly given // determine the default lnMode if not explicitly given
if (!lnMode) { if (!lnMode) {
lnMode = this.configService.instant('motions_default_line_numbering'); lnMode = this.configService.instant('motions_default_line_numbering');