From bef322d0a4372d3258869f8d81d7693bda170e1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Ho=CC=88=C3=9Fl?= Date: Sat, 6 Mar 2021 19:16:22 +0100 Subject: [PATCH] Don't show diff view on slides if no change recos exist --- .../motions/motion-repository.service.ts | 36 +++++++++++++ .../motion-detail/motion-detail.component.ts | 50 ++++++------------- .../motions/motion/motion-slide.component.ts | 9 +++- 3 files changed, 58 insertions(+), 37 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 78f8b1a01..9d69e12fd 100644 --- a/client/src/app/core/repositories/motions/motion-repository.service.ts +++ b/client/src/app/core/repositories/motions/motion-repository.service.ts @@ -1186,4 +1186,40 @@ export class MotionRepositoryService extends BaseIsAgendaItemAndListOfSpeakersCo }).length > 0 ); } + + /** + * Tries to determine the realistic CR-Mode from a given CR mode + */ + public determineCrMode( + mode: ChangeRecoMode, + hasChangingObjects: boolean, + isModifiedFinalVersion: boolean, + isParagraphBasedAmendment: boolean, + hasChangeRecommendations: boolean + ): ChangeRecoMode { + if (mode === ChangeRecoMode.Final) { + if (isModifiedFinalVersion) { + return ChangeRecoMode.ModifiedFinal; + /** + * Because without change recos you cannot escape the final version anymore + */ + } else if (!hasChangingObjects) { + return ChangeRecoMode.Original; + } + } else if (mode === ChangeRecoMode.Changed && !hasChangingObjects) { + /** + * Because without change recos you cannot escape the changed version view + * You will not be able to automatically change to the Changed view after creating + * a change reco. The autoupdate has to come "after" this routine + */ + return ChangeRecoMode.Original; + } else if (mode === ChangeRecoMode.Diff && !hasChangeRecommendations && isParagraphBasedAmendment) { + /** + * The Diff view for paragraph-based amendments is only relevant for change recommendations; + * the regular amendment changes are shown in the "original" view. + */ + return ChangeRecoMode.Original; + } + return mode; + } } 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 4f6860657..b0003fec4 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 @@ -643,7 +643,13 @@ export class MotionDetailComponent extends BaseViewComponentDirective implements } private resetCrMode(): void { - this.crMode = this.determineCrMode(this.defaultCrMode); + this.crMode = this.repo.determineCrMode( + this.defaultCrMode, + this.hasChangingObjects(), + !!this.motion?.modified_final_version, + this.motion?.isParagraphBasedAmendment(), + this.changeRecommendations?.length > 0 + ); } /** @@ -720,7 +726,13 @@ export class MotionDetailComponent extends BaseViewComponentDirective implements // first in this case (in the config-listener) and perform the actual check if "diff" is possible now. // Test: "diff" as default view. Open a motion, create an amendment. "Original" should be set automatically. if (this.crMode) { - this.crMode = this.determineCrMode(this.crMode); + this.crMode = this.repo.determineCrMode( + this.crMode, + this.hasChangingObjects(), + !!this.motion?.modified_final_version, + this.motion?.isParagraphBasedAmendment(), + this.changeRecommendations?.length > 0 + ); } this.cd.markForCheck(); @@ -1624,40 +1636,6 @@ export class MotionDetailComponent extends BaseViewComponentDirective implements } } - /** - * Tries to determine the realistic CR-Mode from a given CR mode - */ - private determineCrMode(mode: ChangeRecoMode): ChangeRecoMode { - if (mode === ChangeRecoMode.Final) { - if (this.motion?.modified_final_version) { - return ChangeRecoMode.ModifiedFinal; - /** - * Because without change recos you cannot escape the final version anymore - */ - } else if (!this.hasChangingObjects()) { - return ChangeRecoMode.Original; - } - } else if (mode === ChangeRecoMode.Changed && !this.hasChangingObjects()) { - /** - * Because without change recos you cannot escape the changed version view - * You will not be able to automatically change to the Changed view after creating - * a change reco. The autoupdate has to come "after" this routine - */ - return ChangeRecoMode.Original; - } else if ( - mode === ChangeRecoMode.Diff && - !this.changeRecommendations?.length && - this.motion?.isParagraphBasedAmendment() - ) { - /** - * The Diff view for paragraph-based amendments is only relevant for change recommendations; - * the regular amendment changes are shown in the "original" view. - */ - return ChangeRecoMode.Original; - } - return mode; - } - /** * Function to listen to notifications if the user edits this motion. * Handles the notification messages. diff --git a/client/src/app/slides/motions/motion/motion-slide.component.ts b/client/src/app/slides/motions/motion/motion-slide.component.ts index 1a0d8ce47..5d22af8d6 100644 --- a/client/src/app/slides/motions/motion/motion-slide.component.ts +++ b/client/src/app/slides/motions/motion/motion-slide.component.ts @@ -69,7 +69,6 @@ export class MotionSlideComponent this.lnMode = value.data.line_numbering_mode; this.lineLength = value.data.line_length; this.preamble = value.data.preamble; - this.crMode = value.element.mode || 'original'; this.textDivStyles.width = value.data.show_meta_box ? 'calc(100% - 250px)' : '100%'; @@ -80,6 +79,14 @@ export class MotionSlideComponent } this.recalcUnifiedChanges(); + + this.crMode = this.motionRepo.determineCrMode( + value.element.mode || 'original', + this.allChangingObjects.length > 0, + !!this.data.data.modified_final_version, + this.isParagraphBasedAmendment(), + this.data.data.change_recommendations.length > 0 + ); } public get data(): SlideData {