Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pdf export of visible amendments in motion detail view #4493

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import { AmendmentListFilterService } from '../../../../../../services/list/amen
import { AmendmentListSortService } from '../../../../../../services/list/amendment-list-sort.service/amendment-list-sort.service';
import { MotionListFilterService } from '../../../../../../services/list/motion-list-filter.service/motion-list-filter.service';
import { MotionListSortService } from '../../../../../../services/list/motion-list-sort.service/motion-list-sort.service';
import { MotionDetailViewService } from '../../../../services/motion-detail-view.service';
import { MotionDetailViewOriginUrlService } from '../../../../services/motion-detail-view-originurl.service';

@Component({
Expand Down Expand Up @@ -74,6 +75,10 @@ export class MotionViewComponent extends BaseMeetingComponent implements OnInit,
return this.unifiedChanges$.value;
}

public get showAllChanges(): boolean {
return this.motionDetailService.currentShowAllAmendmentsState;
}

/**
* preloaded next motion for direct navigation
*/
Expand Down Expand Up @@ -143,7 +148,8 @@ export class MotionViewComponent extends BaseMeetingComponent implements OnInit,
private changeRecoRepo: MotionChangeRecommendationControllerService,
private cd: ChangeDetectorRef,
private pdfExport: MotionPdfExportService,
private originUrlService: MotionDetailViewOriginUrlService
private originUrlService: MotionDetailViewOriginUrlService,
private motionDetailService: MotionDetailViewService
) {
super();

Expand Down Expand Up @@ -321,7 +327,8 @@ export class MotionViewComponent extends BaseMeetingComponent implements OnInit,
: this.lineNumberingMode,
crMode: this.changeRecoMode,
// export all comment fields as well as personal note
comments: this.motion.usedCommentSectionIds.concat([PERSONAL_NOTE_ID])
comments: this.motion.usedCommentSectionIds.concat([PERSONAL_NOTE_ID]),
showAllChanges: this.showAllChanges
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ interface DifferedViewArguments extends Arguments {
* The first line affected for a motion or a unified change
*/
firstLine: number;
showAllChanges: boolean;
}

interface FormatMotionConfig extends Arguments {
Expand All @@ -57,6 +58,7 @@ interface FormatMotionConfig extends Arguments {
* The first line affected for a motion or a unified change
*/
firstLine?: number;
showAllChanges?: boolean;
}

@Injectable({
Expand Down Expand Up @@ -96,7 +98,11 @@ export class MotionFormatService {
throw new Error(`unrecognized ChangeRecoMode option (${crMode})`);
}

return fn(targetMotion, { ...args, firstLine: args.firstLine || targetMotion.start_line_number });
return fn(targetMotion, {
...args,
firstLine: args.firstLine || targetMotion.start_line_number,
showAllChanges: args.showAllChanges
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not needed because args is already spread.

Suggested change
showAllChanges: args.showAllChanges

});
}

public getUnifiedChanges(motion: ViewMotion, lineLength: number): ViewUnifiedChange[] {
Expand Down Expand Up @@ -216,9 +222,9 @@ export class MotionFormatService {
};

private getDiffView = (targetMotion: MotionFormattingRepresentation, args: DifferedViewArguments): string => {
const { changes, lineLength, highlightedLine, firstLine }: DifferedViewArguments = args;
const { changes, lineLength, highlightedLine, firstLine, showAllChanges }: DifferedViewArguments = args;
const text: string[] = [];
const changesToShow = changes.filter(change => change.showInDiffView());
const changesToShow = changes.filter(change => change.showInDiffView() || showAllChanges);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const changesToShow = changes.filter(change => change.showInDiffView() || showAllChanges);
const changesToShow = showAllChanges ? changes : changes.filter(change => change.showInDiffView());

const motionText = this.lineNumberingService.insertLineNumbers({
html: targetMotion.text,
lineLength,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export interface MotionExportInfo {
metaInfo?: InfoToExport[];
pdfOptions?: string[];
comments?: number[];
showAllChanges?: boolean;
}

@Injectable({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ interface CreateTextData {
crMode: ChangeRecoMode;
lineHeight: number;
onlyChangedLines?: boolean;
showAllChanges?: boolean;
}

interface MotionToDocDefData {
Expand Down Expand Up @@ -106,6 +107,7 @@ export class MotionPdfService {
const infoToExport = exportInfo ? exportInfo.metaInfo : null;
const contentToExport = exportInfo ? exportInfo.content : null;
let commentsToExport = exportInfo ? exportInfo.comments : null;
const showAllChanges = exportInfo ? exportInfo.showAllChanges : null;

// get the line length from the config
const lineLength = this.meetingSettingsService.instant(`motions_line_length`) as number;
Expand Down Expand Up @@ -140,7 +142,8 @@ export class MotionPdfService {
lineLength,
crMode,
infoToExport,
optionToFollowRecommendation
optionToFollowRecommendation,
showAllChanges
);
motionPdfContent.push(metaInfo);
}
Expand All @@ -157,7 +160,8 @@ export class MotionPdfService {
lnMode,
crMode,
lineHeight,
onlyChangedLines
onlyChangedLines,
showAllChanges
});
motionPdfContent.push(text);
}
Expand Down Expand Up @@ -251,7 +255,8 @@ export class MotionPdfService {
lineLength: number,
crMode: ChangeRecoMode,
infoToExport: InfoToExport[] | null | undefined,
optionToFollowRecommendation?: boolean
optionToFollowRecommendation?: boolean,
showAllChanges?: boolean
): Content {
const metaTableBody = [];

Expand Down Expand Up @@ -529,13 +534,13 @@ export class MotionPdfService {
} else if (change.getChangeType() === ViewUnifiedChangeType.TYPE_AMENDMENT) {
const amendment = change as ViewMotionAmendedParagraph;
let summaryText = `(${this.translate.instant(`Amendment`)} ${amendment.getNumber()}) -`;
if (amendment.isRejected()) {
summaryText += ` ${this.translate.instant(`Rejected`)}`;
} else if (amendment.isAccepted()) {
if (showAllChanges || amendment.isAccepted()) {
summaryText += ` ${this.translate.instant(amendment.stateName)}`;
// only append line and change, if the merge of the state of the amendment is accepted.
columnLineNumbers.push(`${this.translate.instant(`Line`)} ${line} `);
columnChangeType.push(summaryText);
} else if (amendment.isRejected()) {
summaryText += ` ${this.translate.instant(`Rejected`)}`;
}
}
}
Expand Down Expand Up @@ -635,7 +640,15 @@ export class MotionPdfService {
* @param crMode determine the used change Recommendation mode
* @returns doc def for the "the assembly may decide" preamble
*/
private createText({ crMode, lineHeight, lineLength, lnMode, motion, onlyChangedLines }: CreateTextData): Content {
private createText({
crMode,
lineHeight,
lineLength,
lnMode,
motion,
onlyChangedLines,
showAllChanges
}: CreateTextData): Content {
let htmlText = ``;

if (motion.isParagraphBasedAmendment()) {
Expand Down Expand Up @@ -680,7 +693,8 @@ export class MotionPdfService {
crMode,
changes: textChanges,
lineLength,
firstLine: motion.firstLine
firstLine: motion.firstLine,
showAllChanges: showAllChanges
});
// reformat motion text to split long HTML elements to easier convert into PDF
htmlText += this.linenumberingService.splitInlineElementsAtLineBreaks(formattedText);
Expand Down
Loading