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

[FEATURE]: Auto Doc | Generate PDF from Template #254

Merged
merged 172 commits into from
Feb 20, 2025

Conversation

salvar3nga
Copy link
Collaborator

@salvar3nga salvar3nga commented Jan 22, 2025

🗒 Description

When the signal list block element is selected, a pdf is generated based on the rows selected.

In the background signalLists are filtered and prepared for such pdf generation

📷 Demo screen recording or Screenshots

  • Not applicable

📋 Checklist

You may remove tasks that do not make sense in this PR.

  • Ticket-ACs are checked and met
  • GitHub labels are assigned
  • Git Ticket / issue is linked with PR
  • Designated PR Reviewers are set
  • Tested by another developer
  • Changelog updated
  • Documentation updated (check Documentation guidelines for further reading )
  • All comments in the PR are resolved / answered

🔦 Useful commits

You can add specific commits which are worth taking a look into

michelguerin and others added 30 commits October 10, 2024 13:10
@salvar3nga salvar3nga marked this pull request as ready for review February 17, 2025 06:04
});
function getValueFromNestedProperty(publisher: MessagePublisher, key: keyof MessagePublisherFilter): string {
const keyMap: Partial<Record<keyof MessagePublisherFilter, string>> = {
LogicalNodeIEDName: "logicalNodeInofrmation.IEDName",
Copy link
Collaborator

Choose a reason for hiding this comment

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

I noticed a typo here Information

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

uh nice spotting. Will rectify it

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oups, your linter has gone wild !
This file is out of scope ;P

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Mhm maybe because in the beginning I check to see how documentation plugin was handling the pdf generation, I don't recall changing anything in the file though

Comment on lines 15 to 46
let y = 10;
const pageHeight = doc.internal.pageSize.height;
const pageSize = doc.internal.pageSize;
const pageWidth = pageSize.width ? pageSize.width : pageSize.getWidth()
const marginBottom = 10;

const blockHandler: Record<ElementType, (block: Element) => void> = {
text: handleTextBlock,
image: () => {},
signalList: processSignalListForPdfGeneration
}

function incrementYPositionForNextLine() {
y+=7;
}

function contentExceedsCurrentPage(y: number,pageHeight: number,marginBottom: number) {
return (y+10) > (pageHeight-marginBottom);
}

function handleTextBlock(block: Element){
const wrappedText : string [] = doc.splitTextToSize(block.textContent ?? "", pageWidth-35);
for(const line of wrappedText){
if (contentExceedsCurrentPage(y, pageHeight, marginBottom)) {
doc.addPage();
y = 10;
}
doc.text(line, 10, y);
incrementYPositionForNextLine();
}
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

There is a lot of magic number here, will we be able to understand them in the future ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The docs explain it, but I think I can improve on it by using explanatory variables

@salvar3nga salvar3nga changed the title FEATURE]: Auto Doc | Generate PDF from Template [FEATURE]: Auto Doc | Generate PDF from Template Feb 20, 2025
@salvar3nga salvar3nga merged commit a30cff3 into main Feb 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Generate pdf document from template
4 participants