From 0e77ec79c2333b0672a5f54e947f6f99c37b4503 Mon Sep 17 00:00:00 2001 From: Sean Engelhardt Date: Thu, 24 Jan 2019 14:40:05 +0100 Subject: [PATCH] Export a list of motions Ports the "Motion Catalog Content Provider" to OpenSlides 3. Categories and Prefixes are considered as before. Updated to Code to ES6/Typescript. Allows to export all motions from the motion list view. --- .../app/core/services/html-to-pdf.service.ts | 3 +- .../app/core/services/pdf-document.service.ts | 39 ++- .../motion-list/motion-list.component.html | 4 + .../motion-list/motion-list.component.ts | 10 + .../motion-pdf-catalog.service.spec.ts | 17 ++ .../services/motion-pdf-catalog.service.ts | 240 ++++++++++++++++++ .../services/motion-pdf-export.service.ts | 19 ++ .../motions/services/motion-pdf.service.ts | 2 +- .../fullscreen-projector.component.spec.ts | 2 +- 9 files changed, 329 insertions(+), 7 deletions(-) create mode 100644 client/src/app/site/motions/services/motion-pdf-catalog.service.spec.ts create mode 100644 client/src/app/site/motions/services/motion-pdf-catalog.service.ts diff --git a/client/src/app/core/services/html-to-pdf.service.ts b/client/src/app/core/services/html-to-pdf.service.ts index 853952738..1f241ee02 100644 --- a/client/src/app/core/services/html-to-pdf.service.ts +++ b/client/src/app/core/services/html-to-pdf.service.ts @@ -93,7 +93,7 @@ export class HtmlToPdfService { const parser = new DOMParser(); const parsedHtml = parser.parseFromString(htmlText, 'text/html'); // Since the spread operator did not work for HTMLCollection, use Array.from - const htmlArray = Array.from(parsedHtml.body.children); + const htmlArray = Array.from(parsedHtml.body.childNodes); // Parse the children of the current HTML element for (const child of htmlArray) { @@ -219,6 +219,7 @@ export class HtmlToPdfService { } } else { const children = this.parseChildren(element, styles); + newParagraph = { ...this.create('text'), ...this.computeStyle(styles) diff --git a/client/src/app/core/services/pdf-document.service.ts b/client/src/app/core/services/pdf-document.service.ts index 934d6d221..b7fd85b6e 100644 --- a/client/src/app/core/services/pdf-document.service.ts +++ b/client/src/app/core/services/pdf-document.service.ts @@ -308,13 +308,18 @@ export class PdfDocumentService { } /** - * Downloads a pdf. Does not seem to work. + * Downloads a pdf. * * @param docDefinition the structure of the PDF document */ - public download(docDefinition: object, filename: string, metadata?: object): void { - this.getStandardPaper(docDefinition, metadata).then(doc => { - pdfMake.createPdf(doc).getBlob(blob => saveAs(blob, `${filename}.pdf`, { autoBOM: true })); + public async download(docDefinition: object, filename: string, metadata?: object): Promise { + const doc = await this.getStandardPaper(docDefinition, metadata); + await new Promise(resolve => { + const pdf = pdfMake.createPdf(doc); + pdf.getBlob(blob => { + saveAs(blob, `${filename}.pdf`, { autoBOM: true }); + resolve(true); + }); }); } @@ -347,6 +352,9 @@ export class PdfDocumentService { margin: [0, -20, 0, 20], color: 'grey' }, + preamble: { + margin: [0, 0, 0, 10] + }, headerText: { fontSize: 10, margin: [0, 10, 0, 0] @@ -362,10 +370,33 @@ export class PdfDocumentService { smallText: { fontSize: 8 }, + heading2: { + fontSize: 14, + margin: [0, 0, 0, 10], + bold: true + }, heading3: { fontSize: 12, margin: [0, 10, 0, 0], bold: true + }, + tocEntry: { + fontSize: 12, + margin: [0, 0, 0, 0], + bold: false + }, + tocCategoryEntry: { + fontSize: 12, + margin: [10, 0, 0, 0], + bold: false + }, + tocCategoryTitle: { + fontSize: 12, + margin: [0, 0, 0, 4], + bold: true + }, + tocCategorySection: { + margin: [0, 0, 0, 10] } }; } diff --git a/client/src/app/site/motions/components/motion-list/motion-list.component.html b/client/src/app/site/motions/components/motion-list/motion-list.component.html index db46bb07d..3e418fcb1 100644 --- a/client/src/app/site/motions/components/motion-list/motion-list.component.html +++ b/client/src/app/site/motions/components/motion-list/motion-list.component.html @@ -178,6 +178,10 @@ archive Export as CSV +