From 6b70e8a4abecf01fd8e9c5ef4f653c04c63ccf24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Ho=CC=88=C3=9Fl?= Date: Sat, 29 Jun 2019 09:59:39 +0200 Subject: [PATCH] Bugfix: Amendment with multiple changed paragraphs shows motion text multiple times when context is shown --- .../motions/motion-repository.service.ts | 40 ++++++++++++++----- .../motion-detail.component.html | 12 +----- .../motion-detail/motion-detail.component.ts | 5 ++- .../motions/services/motion-pdf.service.ts | 2 +- 4 files changed, 36 insertions(+), 23 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 97f822bd1..7ae4992dc 100644 --- a/client/src/app/core/repositories/motions/motion-repository.service.ts +++ b/client/src/app/core/repositories/motions/motion-repository.service.ts @@ -705,25 +705,45 @@ export class MotionRepositoryService extends BaseIsAgendaItemAndListOfSpeakersCo * * @param {ViewMotion} amendment * @param {number} lineLength + * @param {boolean} includeUnchanged * @returns {DiffLinesInParagraph} */ - public getAmendedParagraphs(amendment: ViewMotion, lineLength: number): DiffLinesInParagraph[] { + public getAmendmentParagraphs( + amendment: ViewMotion, + lineLength: number, + includeUnchanged: boolean + ): DiffLinesInParagraph[] { const motion = this.getAmendmentBaseMotion(amendment); const baseParagraphs = this.getTextParagraphs(motion, true, lineLength); return amendment.amendment_paragraphs .map( (newText: string, paraNo: number): DiffLinesInParagraph => { - if (newText === null) { - return null; + if (newText !== null) { + return this.diff.getAmendmentParagraphsLinesByMode( + paraNo, + baseParagraphs[paraNo], + newText, + lineLength + ); + } else { + // Nothing has changed in this paragraph + if (includeUnchanged) { + const paragraph_line_range = this.lineNumbering.getLineNumberRange(baseParagraphs[paraNo]); + return { + paragraphNo: paraNo, + paragraphLineFrom: paragraph_line_range.from, + paragraphLineTo: paragraph_line_range.to, + diffLineFrom: paragraph_line_range.to, + diffLineTo: paragraph_line_range.to, + textPre: baseParagraphs[paraNo], + text: '', + textPost: '' + } as DiffLinesInParagraph; + } else { + return null; // null will make this paragraph filtered out + } } - // Hint: can be either DiffLinesInParagraph or null, if no changes are made - return this.diff.getAmendmentParagraphsLinesByMode( - paraNo, - baseParagraphs[paraNo], - newText, - lineLength - ); } ) .filter((para: DiffLinesInParagraph) => para !== null); diff --git a/client/src/app/site/motions/modules/motion-detail/components/motion-detail/motion-detail.component.html b/client/src/app/site/motions/modules/motion-detail/components/motion-detail/motion-detail.component.html index f0f4e2441..c9a7cfba0 100644 --- a/client/src/app/site/motions/modules/motion-detail/components/motion-detail/motion-detail.component.html +++ b/client/src/app/site/motions/modules/motion-detail/components/motion-detail/motion-detail.component.html @@ -865,11 +865,11 @@
-
+
No changes at the text.
-
-
-
-

- -
-
-
diff --git a/client/src/app/site/motions/modules/motion-detail/components/motion-detail/motion-detail.component.ts b/client/src/app/site/motions/modules/motion-detail/components/motion-detail/motion-detail.component.ts index f484b735c..61ba6e4fa 100644 --- a/client/src/app/site/motions/modules/motion-detail/components/motion-detail/motion-detail.component.ts +++ b/client/src/app/site/motions/modules/motion-detail/components/motion-detail/motion-detail.component.ts @@ -864,10 +864,11 @@ export class MotionDetailComponent extends BaseViewComponent implements OnInit, /** * If `this.motion` is an amendment, this returns the list of all changed paragraphs. * + * @param {boolean} includeUnchanged * @returns {DiffLinesInParagraph[]} */ - public getAmendedParagraphs(): DiffLinesInParagraph[] { - return this.repo.getAmendedParagraphs(this.motion, this.lineLength); + public getAmendmentParagraphs(includeUnchanged: boolean): DiffLinesInParagraph[] { + return this.repo.getAmendmentParagraphs(this.motion, this.lineLength, includeUnchanged); } /** 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 748868d35..f648f1032 100644 --- a/client/src/app/site/motions/services/motion-pdf.service.ts +++ b/client/src/app/site/motions/services/motion-pdf.service.ts @@ -553,7 +553,7 @@ export class MotionPdfService { motionText = ''; // this is logically redundant with the formation of amendments in the motion-detail html. // Should be refactored in a way that a service returns the correct html for both cases - for (const paragraph of this.motionRepo.getAmendedParagraphs(motion, lineLength)) { + for (const paragraph of this.motionRepo.getAmendmentParagraphs(motion, lineLength, false)) { if (paragraph.diffLineTo === paragraph.diffLineFrom + 1) { motionText += `

${this.translate.instant('Line')} ${paragraph.diffLineFrom}: