Merge pull request #5551 from FinnStutzenstein/crInProjector

Always include CRs in motion slide
This commit is contained in:
Emanuel Schütze 2020-09-11 11:38:57 +02:00 committed by GitHub
commit 2759f8ce2b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 45 additions and 24 deletions

View File

@ -1,6 +1,6 @@
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { LineNumberedString, LinenumberingService } from './linenumbering.service'; import { LineNumberedString, LinenumberingService, LineNumberRange } from './linenumbering.service';
import { ViewUnifiedChange } from '../../shared/models/motions/view-unified-change'; import { ViewUnifiedChange } from '../../shared/models/motions/view-unified-change';
const ELEMENT_NODE = 1; const ELEMENT_NODE = 1;
@ -2149,11 +2149,24 @@ export class DiffService {
paragraphNo: number, paragraphNo: number,
origText: string, origText: string,
newText: string, newText: string,
lineLength: number lineLength: number,
changeRecos?: ViewUnifiedChange[]
): DiffLinesInParagraph { ): DiffLinesInParagraph {
const paragraph_line_range = this.lineNumberingService.getLineNumberRange(origText), const paragraph_line_range: LineNumberRange = this.lineNumberingService.getLineNumberRange(origText);
diff = this.diff(origText, newText), let diff = this.diff(origText, newText);
affected_lines = this.detectAffectedLineRange(diff); const affected_lines = this.detectAffectedLineRange(diff);
/**
* If the affect line has change recos, overwirte the diff with the change reco
*/
if (changeRecos && changeRecos.length) {
const recoToThisLine = changeRecos.find(reco => {
return reco.getLineFrom() === affected_lines.from;
});
if (recoToThisLine) {
diff = this.diff(origText, recoToThisLine.getChangeNewText());
}
}
if (affected_lines === null) { if (affected_lines === null) {
return null; return null;

View File

@ -68,7 +68,6 @@
</td> </td>
</tr> </tr>
</table> </table>
</div> </div>
</div> </div>
@ -78,7 +77,8 @@
<span <span
*ngIf="isStatuteAmendment() || isParagraphBasedAmendment() || !!getFormattedText()" *ngIf="isStatuteAmendment() || isParagraphBasedAmendment() || !!getFormattedText()"
class="text-prefix-label" class="text-prefix-label"
>{{ preamble | translate }}</span >
{{ preamble | translate }}</span
> >
<!-- Regular motions or traditional amendments --> <!-- Regular motions or traditional amendments -->

View File

@ -78,6 +78,9 @@ export class MotionSlideComponent extends BaseMotionSlideComponent<MotionSlideDa
); );
} }
console.log('cr mode? ', this.crMode);
console.log('the data: ', this._data);
this.recalcUnifiedChanges(); this.recalcUnifiedChanges();
} }
@ -410,26 +413,28 @@ export class MotionSlideComponent extends BaseMotionSlideComponent<MotionSlideDa
* @returns {DiffLinesInParagraph[]} * @returns {DiffLinesInParagraph[]}
*/ */
public getAmendedParagraphs(): DiffLinesInParagraph[] { public getAmendedParagraphs(): DiffLinesInParagraph[] {
let baseHtml = this.data.data.base_motion.text; const motion = this.data.data;
baseHtml = this.lineNumbering.insertLineNumbers(baseHtml, this.lineLength); const baseHtml = this.lineNumbering.insertLineNumbers(motion.base_motion?.text, this.lineLength);
const baseParagraphs = this.lineNumbering.splitToParagraphs(baseHtml); const baseParagraphs = this.lineNumbering.splitToParagraphs(baseHtml);
return this.data.data.amendment_paragraphs const amendmentParagraphs = motion.amendment_paragraphs
.map( .map(
(newText: string, paraNo: number): DiffLinesInParagraph => { (amendmentText: string, paraNo: number): DiffLinesInParagraph => {
if (newText === null) { if (amendmentText === null) {
return null; return null;
} }
// Hint: can be either DiffLinesInParagraph or null, if no changes are made
return this.diff.getAmendmentParagraphsLines( return this.diff.getAmendmentParagraphsLines(
paraNo, paraNo,
baseParagraphs[paraNo], baseParagraphs[paraNo],
newText, amendmentText,
this.lineLength this.lineLength,
this.crMode === ChangeRecoMode.Diff ? this.getAllTextChangingObjects() : undefined
); );
} }
) )
.filter((para: DiffLinesInParagraph) => para !== null); .filter((para: DiffLinesInParagraph) => para !== null);
return amendmentParagraphs;
} }
/** /**

View File

@ -192,7 +192,6 @@ async def motion_slide(
motions_preamble = await get_config(all_data_provider, "motions_preamble") motions_preamble = await get_config(all_data_provider, "motions_preamble")
# Query all change-recommendation and amendment related things. # Query all change-recommendation and amendment related things.
change_recommendations = [] # type: ignore
amendments = [] # type: ignore amendments = [] # type: ignore
base_motion = None base_motion = None
base_statute = None base_statute = None
@ -201,16 +200,18 @@ async def motion_slide(
elif motion["parent_id"] is not None and motion["amendment_paragraphs"]: elif motion["parent_id"] is not None and motion["amendment_paragraphs"]:
base_motion = await get_amendment_base_motion(motion, all_data_provider) base_motion = await get_amendment_base_motion(motion, all_data_provider)
else: else:
for change_recommendation_id in motion["change_recommendations_id"]:
cr = await get_model(
all_data_provider,
"motions/motion-change-recommendation",
change_recommendation_id,
)
if cr is not None and not cr["internal"]:
change_recommendations.append(cr)
amendments = await get_amendments_for_motion(motion, all_data_provider) amendments = await get_amendments_for_motion(motion, all_data_provider)
change_recommendations = [] # type: ignore
for change_recommendation_id in motion["change_recommendations_id"]:
cr = await get_model(
all_data_provider,
"motions/motion-change-recommendation",
change_recommendation_id,
)
if cr is not None and not cr["internal"]:
change_recommendations.append(cr)
# The base return value. More fields will get added below. # The base return value. More fields will get added below.
return_value = { return_value = {
"identifier": motion["identifier"], "identifier": motion["identifier"],

View File

@ -108,6 +108,7 @@ def all_data_provider():
"created": "2019-01-19T18:37:34.741336+01:00", "created": "2019-01-19T18:37:34.741336+01:00",
"last_modified": "2019-01-19T18:37:34.741368+01:00", "last_modified": "2019-01-19T18:37:34.741368+01:00",
"change_recommendations": [], "change_recommendations": [],
"change_recommendations_id": [],
"amendments_id": [], "amendments_id": [],
}, },
3: { 3: {
@ -142,6 +143,7 @@ def all_data_provider():
"created": "2019-01-19T18:37:34.741336+01:00", "created": "2019-01-19T18:37:34.741336+01:00",
"last_modified": "2019-01-19T18:37:34.741368+01:00", "last_modified": "2019-01-19T18:37:34.741368+01:00",
"change_recommendations": [], "change_recommendations": [],
"change_recommendations_id": [],
"amendments_id": [], "amendments_id": [],
}, },
} }