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:
parent
7c503024cc
commit
680b6e04e4
@ -8,6 +8,19 @@ import { TranslateService } from '@ngx-translate/core';
|
||||
import { ConfigService } from './config.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.
|
||||
* Also provides general purpose open and download functions.
|
||||
|
@ -1315,13 +1315,8 @@ export class MotionDetailComponent extends BaseViewComponent implements OnInit,
|
||||
* Click handler for the pdf button
|
||||
*/
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Click handler for attachments
|
||||
|
@ -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 { LocalPermissionsService } from 'app/site/motions/services/local-permissions.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
|
||||
@ -251,6 +252,7 @@ export class MotionListComponent extends ListViewBaseComponent<ViewMotion, Motio
|
||||
if (result && result.format) {
|
||||
const data = this.isMultiSelect ? this.selectedRows : this.dataSource.filteredData;
|
||||
if (result.format === 'pdf') {
|
||||
try {
|
||||
this.pdfExport.exportMotionCatalog(
|
||||
data,
|
||||
result.lnMode,
|
||||
@ -259,6 +261,13 @@ export class MotionListComponent extends ListViewBaseComponent<ViewMotion, Motio
|
||||
result.metaInfo,
|
||||
result.comments
|
||||
);
|
||||
} catch (err) {
|
||||
if (err instanceof PdfError) {
|
||||
this.raiseError(err.message);
|
||||
} else {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
} else if (result.format === 'csv') {
|
||||
const content = ['identifier', ...result.content, ...result.metaInfo];
|
||||
this.motionCsvExport.exportMotionList(data, content);
|
||||
|
@ -6,6 +6,7 @@ import { ViewMotion, LineNumberingMode, ChangeRecoMode } from '../models/view-mo
|
||||
import { MotionPdfService, InfoToExport } from './motion-pdf.service';
|
||||
import { ConfigService } from 'app/core/ui-services/config.service';
|
||||
import { ViewCategory } from '../models/view-category';
|
||||
import { PdfError } from 'app/core/ui-services/pdf-document.service';
|
||||
|
||||
/**
|
||||
* Service to export a list of motions.
|
||||
@ -64,6 +65,7 @@ export class MotionPdfCatalogService {
|
||||
const motionDocList = [];
|
||||
|
||||
for (let motionIndex = 0; motionIndex < motions.length; ++motionIndex) {
|
||||
try {
|
||||
const motionDocDef: any = this.motionPdfService.motionToDocDef(
|
||||
motions[motionIndex],
|
||||
lnMode,
|
||||
@ -81,6 +83,13 @@ export class MotionPdfCatalogService {
|
||||
if (motionIndex < motions.length - 1) {
|
||||
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
|
||||
|
@ -90,6 +90,12 @@ export class MotionPdfService {
|
||||
): object {
|
||||
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
|
||||
if (!lnMode) {
|
||||
lnMode = this.configService.instant('motions_default_line_numbering');
|
||||
|
Loading…
Reference in New Issue
Block a user