Merge pull request #4277 from tsiegleauq/pdf-for-motion-statutes

Export statute amendments with diff
This commit is contained in:
Emanuel Schütze 2019-02-08 11:01:19 +01:00 committed by GitHub
commit 1188a94e85
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 9 deletions

View File

@ -408,9 +408,11 @@ export class MotionRepositoryService extends BaseRepository<ViewMotion, Motion>
lineLength: number lineLength: number
): string { ): string {
const origParagraph = paragraphs.find(paragraph => paragraph.id === amendment.statute_paragraph_id); const origParagraph = paragraphs.find(paragraph => paragraph.id === amendment.statute_paragraph_id);
let diffHtml = this.diff.diff(origParagraph.text, amendment.text); if (origParagraph) {
diffHtml = this.lineNumbering.insertLineBreaksWithoutNumbers(diffHtml, lineLength, true); let diffHtml = this.diff.diff(origParagraph.text, amendment.text);
return diffHtml; diffHtml = this.lineNumbering.insertLineBreaksWithoutNumbers(diffHtml, lineLength, true);
return diffHtml;
}
} }
/** /**

View File

@ -1111,7 +1111,9 @@ export class MotionDetailComponent extends BaseViewComponent implements OnInit {
* Click handler for the pdf button * Click handler for the pdf button
*/ */
public onDownloadPdf(): void { 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);
} }
/** /**

View File

@ -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 { HtmlToPdfService } from 'app/core/ui-services/html-to-pdf.service';
import { MotionPollService, CalculablePollKey } from './motion-poll.service'; import { MotionPollService, CalculablePollKey } from './motion-poll.service';
import { MotionRepositoryService } from 'app/core/repositories/motions/motion-repository.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 { ViewMotion, LineNumberingMode, ChangeRecoMode } from '../models/view-motion';
import { ViewUnifiedChange } from '../models/view-unified-change'; import { ViewUnifiedChange } from '../models/view-unified-change';
@ -35,6 +36,7 @@ export class MotionPdfService {
* *
* @param translate handle translations * @param translate handle translations
* @param motionRepo get parent motions * @param motionRepo get parent motions
* @param statureRepo To get formated stature paragraphs
* @param changeRecoRepo to get the change recommendations * @param changeRecoRepo to get the change recommendations
* @param configService Read config variables * @param configService Read config variables
* @param htmlToPdfService To convert HTML text into pdfmake doc def * @param htmlToPdfService To convert HTML text into pdfmake doc def
@ -43,6 +45,7 @@ export class MotionPdfService {
public constructor( public constructor(
private translate: TranslateService, private translate: TranslateService,
private motionRepo: MotionRepositoryService, private motionRepo: MotionRepositoryService,
private statureRepo: StatuteParagraphRepositoryService,
private changeRecoRepo: ChangeRecommendationRepositoryService, private changeRecoRepo: ChangeRecommendationRepositoryService,
private configService: ConfigService, private configService: ConfigService,
private htmlToPdfService: HtmlToPdfService, private htmlToPdfService: HtmlToPdfService,
@ -412,8 +415,15 @@ export class MotionPdfService {
*/ */
private createText(motion: ViewMotion, lnMode: LineNumberingMode, crMode: ChangeRecoMode): object { private createText(motion: ViewMotion, lnMode: LineNumberingMode, crMode: ChangeRecoMode): object {
let motionText: string; let motionText: string;
// get the line length from the config
const lineLength = this.configService.instant<number>('motions_line_length');
if (motion.isParagraphBasedAmendment()) { if (motion.isParagraphBasedAmendment()) {
// TODO: special docs for special amendment // 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 { } else {
// lead motion or normal amendments // lead motion or normal amendments
// TODO: Consider tile change recommendation // TODO: Consider tile change recommendation
@ -421,15 +431,10 @@ export class MotionPdfService {
[], [],
this.changeRecoRepo.getChangeRecoOfMotion(motion.id) this.changeRecoRepo.getChangeRecoOfMotion(motion.id)
); );
// changes need to be sorted, by "line from". // changes need to be sorted, by "line from".
// otherwise, formatMotion will make unexpected results by messing up the // otherwise, formatMotion will make unexpected results by messing up the
// order of changes applied to the motion // order of changes applied to the motion
changes.sort((a, b) => a.getLineFrom() - b.getLineFrom()); changes.sort((a, b) => a.getLineFrom() - b.getLineFrom());
// get the line length from the config
const lineLength = this.configService.instant<number>('motions_line_length');
motionText = this.motionRepo.formatMotion(motion.id, crMode, changes, lineLength); motionText = this.motionRepo.formatMotion(motion.id, crMode, changes, lineLength);
} }