From 4023ac82df1c4e43b6093d6f6751e155829b820d Mon Sep 17 00:00:00 2001 From: Sean Engelhardt Date: Fri, 8 Feb 2019 10:39:06 +0100 Subject: [PATCH] Export statute amendments with diff Exports motion statutes amendments with changes to PDF documents. Fixes a small issue where navigating to statues amendments was throwing errors --- .../motions/motion-repository.service.ts | 8 +++++--- .../motion-detail/motion-detail.component.ts | 4 +++- .../site/motions/services/motion-pdf.service.ts | 15 ++++++++++----- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/client/src/app/core/repositories/motions/motion-repository.service.ts b/client/src/app/core/repositories/motions/motion-repository.service.ts index 65c926815..7012af32a 100644 --- a/client/src/app/core/repositories/motions/motion-repository.service.ts +++ b/client/src/app/core/repositories/motions/motion-repository.service.ts @@ -408,9 +408,11 @@ export class MotionRepositoryService extends BaseRepository lineLength: number ): string { const origParagraph = paragraphs.find(paragraph => paragraph.id === amendment.statute_paragraph_id); - let diffHtml = this.diff.diff(origParagraph.text, amendment.text); - diffHtml = this.lineNumbering.insertLineBreaksWithoutNumbers(diffHtml, lineLength, true); - return diffHtml; + if (origParagraph) { + let diffHtml = this.diff.diff(origParagraph.text, amendment.text); + diffHtml = this.lineNumbering.insertLineBreaksWithoutNumbers(diffHtml, lineLength, true); + return diffHtml; + } } /** diff --git a/client/src/app/site/motions/components/motion-detail/motion-detail.component.ts b/client/src/app/site/motions/components/motion-detail/motion-detail.component.ts index 894e2efd6..c720dd721 100644 --- a/client/src/app/site/motions/components/motion-detail/motion-detail.component.ts +++ b/client/src/app/site/motions/components/motion-detail/motion-detail.component.ts @@ -1130,7 +1130,9 @@ export class MotionDetailComponent extends BaseViewComponent implements OnInit { * Click handler for the pdf button */ public onDownloadPdf(): void { - this.pdfExport.exportSingleMotion(this.motion, this.lnMode, this.crMode); + const exportCr = this.motion.isStatuteAmendment() ? ChangeRecoMode.Diff : this.crMode; + // TODO: apparently statue amendments never have line numbers and are always in crMode + this.pdfExport.exportSingleMotion(this.motion, LineNumberingMode.None, exportCr); } /** 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 d9c2bd7b9..f388427f1 100644 --- a/client/src/app/site/motions/services/motion-pdf.service.ts +++ b/client/src/app/site/motions/services/motion-pdf.service.ts @@ -7,6 +7,7 @@ import { ConfigService } from 'app/core/ui-services/config.service'; import { HtmlToPdfService } from 'app/core/ui-services/html-to-pdf.service'; import { MotionPollService, CalculablePollKey } from './motion-poll.service'; import { MotionRepositoryService } from 'app/core/repositories/motions/motion-repository.service'; +import { StatuteParagraphRepositoryService } from 'app/core/repositories/motions/statute-paragraph-repository.service'; import { ViewMotion, LineNumberingMode, ChangeRecoMode } from '../models/view-motion'; import { ViewUnifiedChange } from '../models/view-unified-change'; @@ -35,6 +36,7 @@ export class MotionPdfService { * * @param translate handle translations * @param motionRepo get parent motions + * @param statureRepo To get formated stature paragraphs * @param changeRecoRepo to get the change recommendations * @param configService Read config variables * @param htmlToPdfService To convert HTML text into pdfmake doc def @@ -43,6 +45,7 @@ export class MotionPdfService { public constructor( private translate: TranslateService, private motionRepo: MotionRepositoryService, + private statureRepo: StatuteParagraphRepositoryService, private changeRecoRepo: ChangeRecommendationRepositoryService, private configService: ConfigService, private htmlToPdfService: HtmlToPdfService, @@ -412,8 +415,15 @@ export class MotionPdfService { */ private createText(motion: ViewMotion, lnMode: LineNumberingMode, crMode: ChangeRecoMode): object { let motionText: string; + // get the line length from the config + const lineLength = this.configService.instant('motions_line_length'); + if (motion.isParagraphBasedAmendment()) { // TODO: special docs for special amendment + } else if (motion.isStatuteAmendment()) { + // statute amendments + const statutes = this.statureRepo.getViewModelList(); + motionText = this.motionRepo.formatStatuteAmendment(statutes, motion, lineLength); } else { // lead motion or normal amendments // TODO: Consider tile change recommendation @@ -421,15 +431,10 @@ export class MotionPdfService { [], this.changeRecoRepo.getChangeRecoOfMotion(motion.id) ); - // changes need to be sorted, by "line from". // otherwise, formatMotion will make unexpected results by messing up the // order of changes applied to the motion changes.sort((a, b) => a.getLineFrom() - b.getLineFrom()); - - // get the line length from the config - const lineLength = this.configService.instant('motions_line_length'); - motionText = this.motionRepo.formatMotion(motion.id, crMode, changes, lineLength); }