From 6b685924d9fe1b132af3bb802cc3accbe04a5fdf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Ho=CC=88=C3=9Fl?= Date: Sat, 9 Mar 2019 15:00:03 +0100 Subject: [PATCH] Bugfix: Amendment statuses --- .../motions/motion-repository.service.ts | 58 ++++++++++--------- .../models/motions/view-unified-change.ts | 15 +++++ .../models/view-change-recommendation.ts | 8 +++ .../models/view-motion-amended-paragraph.ts | 28 +++++++++ .../motion-detail-diff.component.html | 4 +- .../motion-detail-diff.component.scss | 8 --- .../motion-detail-diff.component.ts | 15 ----- .../motion-detail.component.html | 2 +- .../motion-detail/motion-detail.component.ts | 14 ++++- .../motions/motion/motion-slide-data.ts | 4 +- .../motion-slide-obj-amendment-paragraph.ts | 17 ++++-- .../motion/motion-slide-obj-change-reco.ts | 8 +++ .../motions/motion/motion-slide.component.ts | 15 +++-- openslides/motions/projector.py | 38 +++++++++--- tests/unit/motions/test_projector.py | 1 + 15 files changed, 160 insertions(+), 75 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 cd5f62e18..157d7bc1b 100644 --- a/client/src/app/core/repositories/motions/motion-repository.service.ts +++ b/client/src/app/core/repositories/motions/motion-repository.service.ts @@ -485,32 +485,36 @@ export class MotionRepositoryService extends BaseAgendaContentObjectRepository { - if (idx === 0) { - text += this.extractMotionLineRange( - id, - { - from: 1, - to: change.getLineFrom() - }, - true, - lineLength, - highlightLine - ); - } else if (changes[idx - 1].getLineTo() < change.getLineFrom()) { - text += this.extractMotionLineRange( - id, - { - from: changes[idx - 1].getLineTo(), - to: change.getLineFrom() - }, - true, - lineLength, - highlightLine - ); - } - text += this.diff.getChangeDiff(targetMotion.text, change, lineLength, highlightLine); - }); + changes + .filter(change => { + return change.showInDiffView(); + }) + .forEach((change: ViewUnifiedChange, idx: number) => { + if (idx === 0) { + text += this.extractMotionLineRange( + id, + { + from: 1, + to: change.getLineFrom() + }, + true, + lineLength, + highlightLine + ); + } else if (changes[idx - 1].getLineTo() < change.getLineFrom()) { + text += this.extractMotionLineRange( + id, + { + from: changes[idx - 1].getLineTo(), + to: change.getLineFrom() + }, + true, + lineLength, + highlightLine + ); + } + text += this.diff.getChangeDiff(targetMotion.text, change, lineLength, highlightLine); + }); text += this.diff.getTextRemainderAfterLastChange( targetMotion.text, changes, @@ -519,7 +523,7 @@ export class MotionRepositoryService extends BaseAgendaContentObjectRepository change.isAccepted()); + const appliedChanges: ViewUnifiedChange[] = changes.filter(change => change.showInFinalView()); return this.diff.getTextWithChanges(targetMotion.text, appliedChanges, lineLength, highlightLine); case ChangeRecoMode.ModifiedFinal: if (targetMotion.modified_final_version) { diff --git a/client/src/app/shared/models/motions/view-unified-change.ts b/client/src/app/shared/models/motions/view-unified-change.ts index 2875b3b0f..d7d3d4de5 100644 --- a/client/src/app/shared/models/motions/view-unified-change.ts +++ b/client/src/app/shared/models/motions/view-unified-change.ts @@ -43,4 +43,19 @@ export interface ViewUnifiedChange { * True, if rejected. False, if accepted or undecided. */ isRejected(): boolean; + + /** + * If this object is to be shown in the Diff view. + */ + showInDiffView(): boolean; + + /** + * If this object is to be shown in the Diff view. + */ + showInDiffView(): boolean; + + /** + * If this object is to be shown in the Final view. + */ + showInFinalView(): boolean; } diff --git a/client/src/app/site/motions/models/view-change-recommendation.ts b/client/src/app/site/motions/models/view-change-recommendation.ts index 79cb4feab..b49665ff5 100644 --- a/client/src/app/site/motions/models/view-change-recommendation.ts +++ b/client/src/app/site/motions/models/view-change-recommendation.ts @@ -105,4 +105,12 @@ export class ViewMotionChangeRecommendation extends BaseViewModel implements Vie public isRejected(): boolean { return this.rejected; } + + public showInDiffView(): boolean { + return true; + } + + public showInFinalView(): boolean { + return !this.rejected; + } } diff --git a/client/src/app/site/motions/models/view-motion-amended-paragraph.ts b/client/src/app/site/motions/models/view-motion-amended-paragraph.ts index 43199abac..d49774fd0 100644 --- a/client/src/app/site/motions/models/view-motion-amended-paragraph.ts +++ b/client/src/app/site/motions/models/view-motion-amended-paragraph.ts @@ -79,4 +79,32 @@ export class ViewMotionAmendedParagraph implements ViewUnifiedChange { public getIdentifier(): string { return this.amendment.identifier; } + + public showInDiffView(): boolean { + const mergeState = this.amendment.state + ? this.amendment.state.merge_amendment_into_final + : MergeAmendment.UNDEFINED; + switch (mergeState) { + case MergeAmendment.YES: + return true; + case MergeAmendment.NO: + return false; + default: + const mergeRecommendation = this.amendment.recommendation + ? this.amendment.recommendation.merge_amendment_into_final + : MergeAmendment.UNDEFINED; + switch (mergeRecommendation) { + case MergeAmendment.YES: + return true; + case MergeAmendment.NO: + return false; + default: + return false; + } + } + } + + public showInFinalView(): boolean { + return this.amendment.state && this.amendment.state.merge_amendment_into_final === MergeAmendment.YES; + } } diff --git a/client/src/app/site/motions/modules/motion-detail/components/motion-detail-diff/motion-detail-diff.component.html b/client/src/app/site/motions/modules/motion-detail/components/motion-detail-diff/motion-detail-diff.component.html index 34f60defd..a87bffda4 100644 --- a/client/src/app/site/motions/modules/motion-detail/components/motion-detail-diff/motion-detail-diff.component.html +++ b/client/src/app/site/motions/modules/motion-detail/components/motion-detail-diff/motion-detail-diff.component.html @@ -28,8 +28,8 @@ --> - Rejected - Accepted + Rejected + – {{ change.amendment.state.name | translate }} diff --git a/client/src/app/site/motions/modules/motion-detail/components/motion-detail-diff/motion-detail-diff.component.scss b/client/src/app/site/motions/modules/motion-detail/components/motion-detail-diff/motion-detail-diff.component.scss index abfc8ba43..73ac1b400 100644 --- a/client/src/app/site/motions/modules/motion-detail/components/motion-detail-diff/motion-detail-diff.component.scss +++ b/client/src/app/site/motions/modules/motion-detail/components/motion-detail-diff/motion-detail-diff.component.scss @@ -93,14 +93,6 @@ .status { color: gray; font-style: italic; - - & > *:before { - content: '('; - } - - & > *:after { - content: ')'; - } } .no-changes { diff --git a/client/src/app/site/motions/modules/motion-detail/components/motion-detail-diff/motion-detail-diff.component.ts b/client/src/app/site/motions/modules/motion-detail/components/motion-detail-diff/motion-detail-diff.component.ts index ae6bc5042..786a53e57 100644 --- a/client/src/app/site/motions/modules/motion-detail/components/motion-detail-diff/motion-detail-diff.component.ts +++ b/client/src/app/site/motions/modules/motion-detail/components/motion-detail-diff/motion-detail-diff.component.ts @@ -201,21 +201,6 @@ export class MotionDetailDiffComponent extends BaseViewComponent implements Afte return this.lineNumberingMode === LineNumberingMode.Outside; } - /** - * Returns accepted, rejected or an empty string depending on the state of this change. - * - * @param change - */ - public getAcceptanceValue(change: ViewUnifiedChange): string { - if (change.isAccepted()) { - return 'accepted'; - } - if (change.isRejected()) { - return 'rejected'; - } - return ''; - } - /** * Returns true if the change is an Amendment * 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 e20222143..e9e3692b7 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 @@ -600,7 +600,7 @@ { + return change.showInDiffView(); + }); + } + + public getChangesForFinalMode(): ViewUnifiedChange[] { + return this.allChangingObjects.filter(change => { + return change.showInFinalView(); + }); + } + /** * Trigger to delete the motion. */ @@ -975,7 +987,7 @@ export class MotionDetailComponent extends BaseViewComponent implements OnInit, */ public async createModifiedFinalVersion(): Promise { // Get the final version and remove line numbers - const changes: ViewUnifiedChange[] = Object.assign([], this.allChangingObjects); + const changes: ViewUnifiedChange[] = Object.assign([], this.getChangesForFinalMode()); let finalVersion = this.repo.formatMotion( this.motion.id, ChangeRecoMode.Final, diff --git a/client/src/app/slides/motions/motion/motion-slide-data.ts b/client/src/app/slides/motions/motion/motion-slide-data.ts index d1aebe863..2c3387457 100644 --- a/client/src/app/slides/motions/motion/motion-slide-data.ts +++ b/client/src/app/slides/motions/motion/motion-slide-data.ts @@ -1,5 +1,4 @@ import { ChangeRecoMode, LineNumberingMode } from '../../../site/motions/models/view-motion'; -import { MergeAmendment } from '../../../shared/models/motions/workflow-state'; import { ReferencedMotions } from '../base/base-motion-slide'; /** @@ -10,7 +9,8 @@ export interface MotionSlideDataAmendment { id: number; title: string; amendment_paragraphs: string[]; - merge_amendment_into_final: MergeAmendment; + merge_amendment_into_final: number; + merge_amendment_into_diff: number; } /** diff --git a/client/src/app/slides/motions/motion/motion-slide-obj-amendment-paragraph.ts b/client/src/app/slides/motions/motion/motion-slide-obj-amendment-paragraph.ts index 7845a6059..c81357ad9 100644 --- a/client/src/app/slides/motions/motion/motion-slide-obj-amendment-paragraph.ts +++ b/client/src/app/slides/motions/motion/motion-slide-obj-amendment-paragraph.ts @@ -1,6 +1,5 @@ import { ViewUnifiedChange, ViewUnifiedChangeType } from '../../../shared/models/motions/view-unified-change'; import { MotionSlideDataAmendment } from './motion-slide-data'; -import { MergeAmendment } from '../../../shared/models/motions/workflow-state'; import { LineRange } from '../../../core/ui-services/diff.service'; /** @@ -10,7 +9,8 @@ import { LineRange } from '../../../core/ui-services/diff.service'; export class MotionSlideObjAmendmentParagraph implements ViewUnifiedChange { public id: number; public type: number; - public merge_amendment_into_final: MergeAmendment; + public merge_amendment_into_final: number; + public merge_amendment_into_diff: number; public constructor( data: MotionSlideDataAmendment, @@ -20,6 +20,7 @@ export class MotionSlideObjAmendmentParagraph implements ViewUnifiedChange { ) { this.id = data.id; this.merge_amendment_into_final = data.merge_amendment_into_final; + this.merge_amendment_into_diff = data.merge_amendment_into_diff; } public getChangeId(): string { @@ -43,10 +44,18 @@ export class MotionSlideObjAmendmentParagraph implements ViewUnifiedChange { } public isAccepted(): boolean { - return this.merge_amendment_into_final === MergeAmendment.YES; + return this.merge_amendment_into_final === 1; } public isRejected(): boolean { - return this.merge_amendment_into_final === MergeAmendment.NO; + return this.merge_amendment_into_final === 0; + } + + public showInDiffView(): boolean { + return this.merge_amendment_into_diff === 1; + } + + public showInFinalView(): boolean { + return this.merge_amendment_into_final === 1; } } diff --git a/client/src/app/slides/motions/motion/motion-slide-obj-change-reco.ts b/client/src/app/slides/motions/motion/motion-slide-obj-change-reco.ts index a78d7476b..a68bd3df6 100644 --- a/client/src/app/slides/motions/motion/motion-slide-obj-change-reco.ts +++ b/client/src/app/slides/motions/motion/motion-slide-obj-change-reco.ts @@ -48,4 +48,12 @@ export class MotionSlideObjChangeReco implements MotionSlideDataChangeReco, View public isRejected(): boolean { return this.rejected; } + + public showInDiffView(): boolean { + return true; + } + + public showInFinalView(): boolean { + return !this.rejected; + } } 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 f6c527241..30a0c9658 100644 --- a/client/src/app/slides/motions/motion/motion-slide.component.ts +++ b/client/src/app/slides/motions/motion/motion-slide.component.ts @@ -275,13 +275,16 @@ export class MotionSlideComponent extends BaseMotionSlideComponent { + const changes = this.allChangingObjects.filter(change => { + return change.showInDiffView(); + }); + changes.forEach((change: ViewUnifiedChange, idx: number) => { if (idx === 0) { const lineRange = { from: 1, to: change.getLineFrom() }; text += this.extractMotionLineRange(motion.text, lineRange, true, this.lineLength); - } else if (this.allChangingObjects[idx - 1].getLineTo() < change.getLineFrom()) { + } else if (changes[idx - 1].getLineTo() < change.getLineFrom()) { const lineRange = { - from: this.allChangingObjects[idx - 1].getLineTo(), + from: changes[idx - 1].getLineTo(), to: change.getLineFrom() }; text += this.extractMotionLineRange(motion.text, lineRange, true, this.lineLength); @@ -290,14 +293,14 @@ export class MotionSlideComponent extends BaseMotionSlideComponent - change.isAccepted() + change.showInFinalView() ); return this.diff.getTextWithChanges(motion.text, appliedChanges, this.lineLength, this.highlightedLine); case ChangeRecoMode.ModifiedFinal: @@ -312,7 +315,7 @@ export class MotionSlideComponent extends BaseMotionSlideComponent - change.isAccepted() + change.showInFinalView() ); return this.diff.getTextWithChanges( motion.text, diff --git a/openslides/motions/projector.py b/openslides/motions/projector.py index cf067423d..255c1c983 100644 --- a/openslides/motions/projector.py +++ b/openslides/motions/projector.py @@ -35,31 +35,50 @@ def get_state( ) -def get_amendment_merge_into_motion(all_data, motion, amendment): +def get_amendment_merge_into_motion_diff(all_data, motion, amendment): """ - HINT: This implementation should be consistent to isAccepted() in ViewMotionAmendedParagraph.ts + HINT: This implementation should be consistent to showInDiffView() in ViewMotionAmendedParagraph.ts """ if amendment["state_id"] is None: return 0 state = get_state(all_data, motion, amendment["state_id"]) - if ( - state["merge_amendment_into_final"] == -1 - or state["merge_amendment_into_final"] == 1 - ): - return state["merge_amendment_into_final"] + if state["merge_amendment_into_final"] == -1: + return 0 + if state["merge_amendment_into_final"] == 1: + return 1 if amendment["recommendation_id"] is None: return 0 recommendation = get_state(all_data, motion, amendment["recommendation_id"]) - return recommendation["merge_amendment_into_final"] + if recommendation["merge_amendment_into_final"] == 1: + return 1 + + return 0 + + +def get_amendment_merge_into_motion_final(all_data, motion, amendment): + """ + HINT: This implementation should be consistent to showInFinalView() in ViewMotionAmendedParagraph.ts + """ + if amendment["state_id"] is None: + return 0 + + state = get_state(all_data, motion, amendment["state_id"]) + if state["merge_amendment_into_final"] == 1: + return 1 + + return 0 def get_amendments_for_motion(motion, all_data): amendment_data = [] for amendment_id, amendment in all_data["motions/motion"].items(): if amendment["parent_id"] == motion["id"]: - merge_amendment_into_final = get_amendment_merge_into_motion( + merge_amendment_into_final = get_amendment_merge_into_motion_final( + all_data, motion, amendment + ) + merge_amendment_into_diff = get_amendment_merge_into_motion_diff( all_data, motion, amendment ) amendment_data.append( @@ -68,6 +87,7 @@ def get_amendments_for_motion(motion, all_data): "identifier": amendment["identifier"], "title": amendment["title"], "amendment_paragraphs": amendment["amendment_paragraphs"], + "merge_amendment_into_diff": merge_amendment_into_diff, "merge_amendment_into_final": merge_amendment_into_final, } ) diff --git a/tests/unit/motions/test_projector.py b/tests/unit/motions/test_projector.py index dc5db4cd6..60cadea99 100644 --- a/tests/unit/motions/test_projector.py +++ b/tests/unit/motions/test_projector.py @@ -269,6 +269,7 @@ def test_motion_slide(all_data): "amendment_paragraphs": ["New motion text"], "identifier": "Ä1", "merge_amendment_into_final": 0, + "merge_amendment_into_diff": 0, } ], "amendment_paragraphs": None,