diff --git a/client/src/app/core/ui-services/html-to-pdf.service.ts b/client/src/app/core/ui-services/html-to-pdf.service.ts index bdb993ad7..99a5465e5 100644 --- a/client/src/app/core/ui-services/html-to-pdf.service.ts +++ b/client/src/app/core/ui-services/html-to-pdf.service.ts @@ -136,6 +136,19 @@ export class HtmlToPdfService { } } + /** + * Function to convert plain html text without linenumbering. + * + * @param text The html text that should be converted to PDF. + * + * @returns {object} The converted html as DocDef. + */ + public addPlainText(text: string): object { + return { + columns: [{ stack: this.convertHtml(text, LineNumberingMode.None) }] + }; + } + /** * Takes an HTML string, converts to HTML using a DOM parser and recursivly parses * the content into pdfmake compatible doc definition diff --git a/client/src/app/core/ui-services/pdf-document.service.ts b/client/src/app/core/ui-services/pdf-document.service.ts index 3799c6d4b..b19d89784 100644 --- a/client/src/app/core/ui-services/pdf-document.service.ts +++ b/client/src/app/core/ui-services/pdf-document.service.ts @@ -8,6 +8,14 @@ import { TranslateService } from '@ngx-translate/core'; import { ConfigService } from './config.service'; import { HttpService } from '../core-services/http.service'; +/** + * Enumeration to define possible values for the styling. + */ +export enum StyleType { + DEFAULT = 'tocEntry', + CATEGORY_SECTION = 'tocCategorySection' +} + /** * Custom PDF error class to handle errors in a safer way */ @@ -594,4 +602,92 @@ export class PdfDocumentService { pdfMake.vfs[url] = base64; } } + + /** + * Creates the title for the motion list as pdfmake doc definition + * + * @returns The motion list title for the PDF document + */ + public createTitle(configVariable: string): object { + const titleText = this.translate.instant(this.configService.instant(configVariable)); + return { + text: titleText, + style: 'title' + }; + } + + /** + * Creates the preamble for the motion list as pdfmake doc definition + * + * @returns The motion list preamble for the PDF document + */ + public createPreamble(configVariable: string): object { + const preambleText = this.configService.instant(configVariable); + + if (preambleText) { + return { + text: preambleText, + style: 'preamble' + }; + } else { + return {}; + } + } + + public getPageBreak(): Object { + return { + text: '', + pageBreak: 'after' + }; + } + + /** + * Generates the table definition for the TOC + * + * @param tocBody the body of the table + * @returns The table of contents as doc definition + */ + public createTocTableDef(tocBody: object, style: StyleType = StyleType.DEFAULT): object { + return { + table: { + widths: ['auto', '*', 'auto'], + body: tocBody + }, + layout: 'noBorders', + style: style + }; + } + + /** + * Function, that creates a line for the 'Table of contents' + * + * @param identifier The identifier/prefix for the line + * @param title The name of the line + * @param pageReference Defaults to the page, where the object begins + * @param style Optional style. Defaults to `'tocEntry'` + * + * @returns A line for the toc + */ + public createTocLine( + identifier: string, + title: string, + pageReference: string, + style: StyleType = StyleType.DEFAULT + ): Object { + return [ + { + text: identifier, + style: style + }, + { + text: title, + style: 'tocEntry' + }, + { + pageReference: pageReference, + style: 'tocEntry', + alignment: 'right' + } + ]; + } } diff --git a/client/src/app/site/assignments/components/assignment-detail/assignment-detail.component.html b/client/src/app/site/assignments/components/assignment-detail/assignment-detail.component.html index f7b8fbdc5..fcff271b9 100644 --- a/client/src/app/site/assignments/components/assignment-detail/assignment-detail.component.html +++ b/client/src/app/site/assignments/components/assignment-detail/assignment-detail.component.html @@ -61,7 +61,7 @@

{{ assignment.getTitle() }}

-
+
diff --git a/client/src/app/site/assignments/components/assignment-detail/assignment-detail.component.ts b/client/src/app/site/assignments/components/assignment-detail/assignment-detail.component.ts index f66d8b465..d160a6395 100644 --- a/client/src/app/site/assignments/components/assignment-detail/assignment-detail.component.ts +++ b/client/src/app/site/assignments/components/assignment-detail/assignment-detail.component.ts @@ -2,7 +2,7 @@ import { Component, OnInit } from '@angular/core'; import { FormBuilder, FormGroup } from '@angular/forms'; import { MatSnackBar } from '@angular/material'; import { Router, ActivatedRoute } from '@angular/router'; -import { Title } from '@angular/platform-browser'; +import { Title, DomSanitizer, SafeHtml } from '@angular/platform-browser'; import { TranslateService } from '@ngx-translate/core'; import { BehaviorSubject } from 'rxjs'; @@ -181,7 +181,8 @@ export class AssignmentDetailComponent extends BaseViewComponent implements OnIn private tagRepo: TagRepositoryService, private promptService: PromptService, private pdfService: AssignmentPdfExportService, - private mediafileRepo: MediafileRepositoryService + private mediafileRepo: MediafileRepositoryService, + private sanitizer: DomSanitizer ) { super(title, translate, matSnackBar); this.subscriptions.push( @@ -501,4 +502,15 @@ export class AssignmentDetailComponent extends BaseViewComponent implements OnIn .sortCandidates(listInNewOrder.map(relatedUser => relatedUser.id), this.assignment) .then(null, this.raiseError); } + + /** + * Sanitize the text. + * + * @param text {string} The text to display. + * + * @returns {SafeHtml} the sanitized text. + */ + public getSanitizedText(text: string): SafeHtml { + return this.sanitizer.bypassSecurityTrustHtml(text); + } } diff --git a/client/src/app/site/assignments/components/assignment-list/assignment-list.component.html b/client/src/app/site/assignments/components/assignment-list/assignment-list.component.html index e1c4e374f..906a67527 100644 --- a/client/src/app/site/assignments/components/assignment-list/assignment-list.component.html +++ b/client/src/app/site/assignments/components/assignment-list/assignment-list.component.html @@ -111,6 +111,15 @@ Deselect all + +