From dc27a208421058f4aef21e606b770a63bfa0bac1 Mon Sep 17 00:00:00 2001 From: Maximilian Krambach Date: Wed, 6 Feb 2019 13:13:19 +0100 Subject: [PATCH] export personal note pdf --- .../motion-comments.component.html | 9 +++-- .../personal-note.component.html | 13 +++++-- .../personal-note/personal-note.component.ts | 25 +++++++++++-- .../services/motion-csv-export.service.ts | 5 +-- .../services/motion-pdf-catalog.service.ts | 4 +-- .../services/motion-pdf-export.service.ts | 21 +++++++++-- .../motions/services/motion-pdf.service.ts | 36 +++++++++++++++++-- 7 files changed, 96 insertions(+), 17 deletions(-) diff --git a/client/src/app/site/motions/components/motion-comments/motion-comments.component.html b/client/src/app/site/motions/components/motion-comments/motion-comments.component.html index cd98241c6..9f57a3cd2 100644 --- a/client/src/app/site/motions/components/motion-comments/motion-comments.component.html +++ b/client/src/app/site/motions/components/motion-comments/motion-comments.component.html @@ -21,13 +21,16 @@ - - - diff --git a/client/src/app/site/motions/components/personal-note/personal-note.component.html b/client/src/app/site/motions/components/personal-note/personal-note.component.html index 8f44e9507..9d526d533 100644 --- a/client/src/app/site/motions/components/personal-note/personal-note.component.html +++ b/client/src/app/site/motions/components/personal-note/personal-note.component.html @@ -21,13 +21,20 @@ - - + - diff --git a/client/src/app/site/motions/components/personal-note/personal-note.component.ts b/client/src/app/site/motions/components/personal-note/personal-note.component.ts index 095886f17..4f0e9906c 100644 --- a/client/src/app/site/motions/components/personal-note/personal-note.component.ts +++ b/client/src/app/site/motions/components/personal-note/personal-note.component.ts @@ -4,9 +4,10 @@ import { FormBuilder, FormGroup } from '@angular/forms'; import { Subscription } from 'rxjs'; import { BaseComponent } from '../../../../base.component'; -import { ViewMotion } from '../../models/view-motion'; -import { PersonalNoteService } from 'app/core/ui-services/personal-note.service'; +import { MotionPdfExportService } from '../../services/motion-pdf-export.service'; import { PersonalNoteContent } from 'app/shared/models/users/personal-note'; +import { PersonalNoteService } from 'app/core/ui-services/personal-note.service'; +import { ViewMotion } from '../../models/view-motion'; /** * Component for the motion comments view @@ -65,7 +66,18 @@ export class PersonalNoteComponent extends BaseComponent implements OnDestroy { */ private personalNoteSubscription: Subscription; - public constructor(private personalNoteService: PersonalNoteService, formBuilder: FormBuilder) { + /** + * Constructor. Creates form + * + * @param personalNoteService + * @param formBuilder + * @param pdfService + */ + public constructor( + private personalNoteService: PersonalNoteService, + formBuilder: FormBuilder, + private pdfService: MotionPdfExportService + ) { super(); this.personalNoteForm = formBuilder.group({ note: [''] @@ -113,4 +125,11 @@ export class PersonalNoteComponent extends BaseComponent implements OnDestroy { this.personalNoteSubscription.unsubscribe(); } } + + /** + * Triggers a pdf export of the personal note + */ + public printPersonalNote(): void { + this.pdfService.exportPersonalNote(this.personalNote, this.motion); + } } diff --git a/client/src/app/site/motions/services/motion-csv-export.service.ts b/client/src/app/site/motions/services/motion-csv-export.service.ts index b9b5eb224..1c9b706c0 100644 --- a/client/src/app/site/motions/services/motion-csv-export.service.ts +++ b/client/src/app/site/motions/services/motion-csv-export.service.ts @@ -3,8 +3,9 @@ import { Injectable } from '@angular/core'; import { TranslateService } from '@ngx-translate/core'; import { CsvExportService, CsvColumnDefinitionProperty } from 'app/core/ui-services/csv-export.service'; -import { ViewMotion } from '../models/view-motion'; import { FileExportService } from 'app/core/ui-services/file-export.service'; +import { InfoToExport } from './motion-pdf.service'; +import { ViewMotion } from '../models/view-motion'; /** * Exports CSVs for motions. Collect all CSV types here to have them in one place. @@ -32,7 +33,7 @@ export class MotionCsvExportService { * @param contentToExport content properties to export * @param infoToExport meta info to export */ - public exportMotionList(motions: ViewMotion[], contentToExport: string[], infoToExport: string[]): void { + public exportMotionList(motions: ViewMotion[], contentToExport: string[], infoToExport: InfoToExport[]): void { const propertyList = ['identifier', 'title'].concat(contentToExport, infoToExport); const exportProperties: CsvColumnDefinitionProperty[] = propertyList.map(option => { return { property: option } as CsvColumnDefinitionProperty; diff --git a/client/src/app/site/motions/services/motion-pdf-catalog.service.ts b/client/src/app/site/motions/services/motion-pdf-catalog.service.ts index 05a61361b..879be6f42 100644 --- a/client/src/app/site/motions/services/motion-pdf-catalog.service.ts +++ b/client/src/app/site/motions/services/motion-pdf-catalog.service.ts @@ -3,7 +3,7 @@ import { Injectable } from '@angular/core'; import { TranslateService } from '@ngx-translate/core'; import { ViewMotion, LineNumberingMode, ChangeRecoMode } from '../models/view-motion'; -import { MotionPdfService } from './motion-pdf.service'; +import { MotionPdfService, InfoToExport } from './motion-pdf.service'; import { ConfigService } from 'app/core/ui-services/config.service'; import { Category } from 'app/shared/models/motions/category'; @@ -52,7 +52,7 @@ export class MotionPdfCatalogService { lnMode?: LineNumberingMode, crMode?: ChangeRecoMode, contentToExport?: string[], - infoToExport?: string[] + infoToExport?: InfoToExport[] ): object { let doc = []; const motionDocList = []; diff --git a/client/src/app/site/motions/services/motion-pdf-export.service.ts b/client/src/app/site/motions/services/motion-pdf-export.service.ts index 8816913f2..ba15e95cd 100644 --- a/client/src/app/site/motions/services/motion-pdf-export.service.ts +++ b/client/src/app/site/motions/services/motion-pdf-export.service.ts @@ -2,11 +2,12 @@ import { Injectable } from '@angular/core'; import { TranslateService } from '@ngx-translate/core'; -import { MotionPdfService } from './motion-pdf.service'; +import { MotionPdfService, InfoToExport } from './motion-pdf.service'; import { PdfDocumentService } from 'app/core/ui-services/pdf-document.service'; import { ViewMotion, LineNumberingMode, ChangeRecoMode } from '../models/view-motion'; import { ConfigService } from 'app/core/ui-services/config.service'; import { MotionPdfCatalogService } from './motion-pdf-catalog.service'; +import { PersonalNoteContent } from 'app/shared/models/users/personal-note'; /** * Export service to handle various kind of exporting necessities. @@ -61,7 +62,7 @@ export class MotionPdfExportService { lnMode?: LineNumberingMode, crMode?: ChangeRecoMode, contentToExport?: string[], - infoToExport?: string[] + infoToExport?: InfoToExport[] ): void { const doc = this.pdfCatalogService.motionListToDocDef(motions, lnMode, crMode, contentToExport, infoToExport); const filename = this.translate.instant(this.configService.instant('motions_export_title')); @@ -84,4 +85,20 @@ export class MotionPdfExportService { }; this.pdfDocumentService.downloadLandscape(doc, filename, metadata); } + + /** + * Exports the given personalNote with some short information about the + * motion the note refers to + * + * @param note + * @param motion + */ + public exportPersonalNote(note: PersonalNoteContent, motion: ViewMotion): void { + const doc = this.motionPdfService.textToDocDef(note.note, motion, 'Personal note'); + const filename = `${motion.identifierOrTitle} - ${this.translate.instant('Personal note')}`; + const metadata = { + title: filename + }; + this.pdfDocumentService.download(doc, filename, metadata); + } } diff --git a/client/src/app/site/motions/services/motion-pdf.service.ts b/client/src/app/site/motions/services/motion-pdf.service.ts index 3d9daf86a..a35fe53d1 100644 --- a/client/src/app/site/motions/services/motion-pdf.service.ts +++ b/client/src/app/site/motions/services/motion-pdf.service.ts @@ -8,6 +8,12 @@ import { ConfigService } from 'app/core/ui-services/config.service'; import { ChangeRecommendationRepositoryService } from 'app/core/repositories/motions/change-recommendation-repository.service'; import { ViewUnifiedChange } from '../models/view-unified-change'; import { HtmlToPdfService } from 'app/core/ui-services/html-to-pdf.service'; + +/** + * Type declaring which strings are valid options for metainfos to be exported into a pdf + */ +export type InfoToExport = 'submitters' | 'state' | 'recommendation' | 'category' | 'block' | 'origin' | 'polls'; + /** * Converts a motion to pdf. Can be used from the motion detail view or executed on a list of motions * Provides the public method `motionToDocDef(motion: Motion)` which should be convenient to use. @@ -55,7 +61,7 @@ export class MotionPdfService { lnMode?: LineNumberingMode, crMode?: ChangeRecoMode, contentToExport?: string[], - infoToExport?: string[] + infoToExport?: InfoToExport[] ): object { let motionPdfContent = []; @@ -145,7 +151,7 @@ export class MotionPdfService { * @param motion the target motion * @returns doc def for the meta infos */ - private createMetaInfoTable(motion: ViewMotion, crMode: ChangeRecoMode, infoToExport?: string[]): object { + private createMetaInfoTable(motion: ViewMotion, crMode: ChangeRecoMode, infoToExport?: InfoToExport[]): object { const metaTableBody = []; // submitters @@ -496,4 +502,30 @@ export class MotionPdfService { { text: motion.motion_block ? motion.motion_block.title : '' } ]; } + + /** + * Creates pdfmake definitions for basic information about the motion and + * comments or notes + * + * @param note string optionally containing html layout + * @param motion the ViewMotion this note refers to + * @param noteTitle additional heading to be used (will be translated) + * @returns pdfMake definitions + */ + public textToDocDef(note: string, motion: ViewMotion, noteTitle: string): object { + const title = this.createTitle(motion); + const subtitle = this.createSubtitle(motion); + const metaInfo = this.createMetaInfoTable( + motion, + this.configService.instant('motions_recommendation_text_mode'), + ['submitters', 'state', 'category'] + ); + const noteContent = this.htmlToPdfService.convertHtml(note); + + const subHeading = { + text: this.translate.instant(noteTitle), + style: 'heading2' + }; + return [title, subtitle, metaInfo, subHeading, noteContent]; + } }