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

Merged
merged 9 commits into from
Jan 10, 2025
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 @@ -12,6 +12,7 @@ import {
MotionDiffService
} from '../../../modules/change-recommendations/services';
import { ViewMotion } from '../../../view-models';
import { ViewMotionAmendedParagraph } from '../../../view-models/view-motion-amended-paragraph';
import { AmendmentControllerService } from '../amendment-controller.service';
import { MotionLineNumberingService } from '../motion-line-numbering.service';

Expand Down Expand Up @@ -42,6 +43,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 +59,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 +99,10 @@ 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
});
}

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 = showAllChanges ? changes : changes.filter(change => change.showInDiffView());
const motionText = this.lineNumberingService.insertLineNumbers({
html: targetMotion.text,
lineLength,
Expand Down Expand Up @@ -287,8 +293,15 @@ export class MotionFormatService {
if (current_text.amend_nr === ``) {
amendmentNr.push(this.translate.instant(`Amendment`));
}
} else if (current_text.getChangeType() === ViewUnifiedChangeType.TYPE_AMENDMENT) {
const amendment = current_text as ViewMotionAmendedParagraph;
amendmentNr.push(amendment.getNumber(), ` - `, amendment.stateName);
} else {
amendmentNr.push(this.translate.instant(`Change recommendation`));
if (current_text.isRejected()) {
amendmentNr.push(this.translate.instant(`Change recommendation - rejected`));
} else {
amendmentNr.push(this.translate.instant(`Change recommendation`));
}
}
amendmentNr.push(`: </span></span>`);
return amendmentNr.join(``);
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