From 18bc495bd8c4c57b64ad64813dc3e6ece27ab268 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Ho=CC=88=C3=9Fl?= Date: Sun, 7 Jun 2020 10:43:05 +0200 Subject: [PATCH] Bugfix: errors with non-paragraph-based amendments --- .../motions/motion-repository.service.ts | 8 +++- .../motion-detail/motion-detail.component.ts | 38 +++++++++---------- 2 files changed, 23 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 ea7a69b79..206d96f50 100644 --- a/client/src/app/core/repositories/motions/motion-repository.service.ts +++ b/client/src/app/core/repositories/motions/motion-repository.service.ts @@ -324,7 +324,7 @@ export class MotionRepositoryService extends BaseIsAgendaItemAndListOfSpeakersCo type: 'custom', ownKey: 'diffLines', get: (motion: Motion, viewMotion: ViewMotion) => { - if (viewMotion.parent) { + if (viewMotion.parent && viewMotion.isParagraphBasedAmendment()) { const changeRecos = viewMotion.changeRecommendations.filter(changeReco => changeReco.showInFinalView() ); @@ -335,6 +335,8 @@ export class MotionRepositoryService extends BaseIsAgendaItemAndListOfSpeakersCo changeRecos, false ); + } else { + return []; } }, getCacheObjectToCheck: (viewMotion: ViewMotion) => viewMotion.parent @@ -835,7 +837,9 @@ export class MotionRepositoryService extends BaseIsAgendaItemAndListOfSpeakersCo } /** - * Returns all paragraph lines that are affected by the given amendment in diff-format, including context + * Returns all paragraph lines that are affected by the given amendment in diff-format, including context. + * + * Should only be called for paragraph-based amendments. * * @param {ViewMotion} amendment * @param {number} lineLength 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 8cf8d31c9..bcfd14fc8 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 @@ -322,11 +322,6 @@ export class MotionDetailComponent extends BaseViewComponent implements OnInit, */ public showAmendmentContext = false; - /** - * Sets the current amendment text mode from the settings - */ - private amendmentTextMode: string; - /** * Show all amendments in the text, not only the ones with the apropriate state */ @@ -540,9 +535,6 @@ export class MotionDetailComponent extends BaseViewComponent implements OnInit, this.configService .get('motions_show_sequential_numbers') .subscribe(shown => (this.showSequential = shown)); - this.configService - .get('motions_amendments_text_mode') - .subscribe(amendmentTextMode => (this.amendmentTextMode = amendmentTextMode)); // Update statute paragraphs this.statuteRepo.getViewModelListObservable().subscribe(newViewStatuteParagraphs => { @@ -649,17 +641,19 @@ export class MotionDetailComponent extends BaseViewComponent implements OnInit, }); } if (this.amendments) { - this.amendments.forEach((amendment: ViewMotion): void => { - const toApplyChanges = (this.amendmentChangeRecos[amendment.id] || []).filter( - // The rejected change recommendations for amendments should not be considered - change => change.showInFinalView() - ); - this.repo - .getAmendmentAmendedParagraphs(amendment, this.lineLength, toApplyChanges) - .forEach((change: ViewUnifiedChange): void => { - this.allChangingObjects.push(change); - }); - }); + this.amendments + .filter(amendment => amendment.isParagraphBasedAmendment()) + .forEach((amendment: ViewMotion): void => { + const toApplyChanges = (this.amendmentChangeRecos[amendment.id] || []).filter( + // The rejected change recommendations for amendments should not be considered + change => change.showInFinalView() + ); + this.repo + .getAmendmentAmendedParagraphs(amendment, this.lineLength, toApplyChanges) + .forEach((change: ViewUnifiedChange): void => { + this.allChangingObjects.push(change); + }); + }); } this.allChangingObjects.sort((a: ViewUnifiedChange, b: ViewUnifiedChange) => { if (a.getLineFrom() < b.getLineFrom()) { @@ -750,7 +744,8 @@ export class MotionDetailComponent extends BaseViewComponent implements OnInit, tags_id: parentMotion.tags_id }); - if (this.amendmentTextMode === 'fulltext') { + const amendmentTextMode = this.configService.instant('motions_amendments_text_mode'); + if (amendmentTextMode === 'fulltext') { defaultMotion.text = parentMotion.text; this.contentForm.patchValue({ text: defaultMotion.text }); } @@ -1219,7 +1214,8 @@ export class MotionDetailComponent extends BaseViewComponent implements OnInit, * Goes to the amendment creation wizard. Executed via click. */ public createAmendment(): void { - if (this.amendmentTextMode === 'paragraph') { + const amendmentTextMode = this.configService.instant('motions_amendments_text_mode'); + if (amendmentTextMode === 'paragraph') { this.router.navigate(['./create-amendment'], { relativeTo: this.route }); } else { this.router.navigate(['./motions/new-amendment'], {