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

#613: Custom PDF templates #125

Merged
merged 13 commits into from
Aug 24, 2022
Merged

#613: Custom PDF templates #125

merged 13 commits into from
Aug 24, 2022

Conversation

TickleThePanda
Copy link
Contributor

@TickleThePanda TickleThePanda commented Aug 23, 2022

Description

Adds a new way of generating a proposal PDF based off a user officer input. This uses the custom template associated with a call as a template and renders with the proposal data data. To make it easier for the user officer to select the answers they want, the data is manipulated into a new object answers which is passed into the render, with subtemplates included in subobjects.

Introduces a PDF factory picker so that the PdfWorkflowManager can choose between auto or custom templates. Keeps the old factory constructor option to the PdfWorkflowManager to simplify the code for samples and visits.

Moves a lot of the proposal PDF code into its own files to make discovery easier.

Motivation and Context

Refs UserOfficeProject/issue-tracker#613

How Has This Been Tested

Tested locally with the following and by adding new tests.

Proposal template

{"metadata":{"version":"1.2.0","exportDate":"2022-08-23T09:40:46.953Z"},"data":{"template":{"templateId":1,"groupId":"PROPOSAL","name":"default template","description":"original template","isArchived":false},"templateSteps":[{"topic":{"id":1,"title":"New proposal","templateId":1,"sortOrder":0,"isEnabled":true},"fields":[{"question":{"categoryId":1,"id":"proposal_basis","naturalKey":"proposal_basis","dataType":"PROPOSAL_BASIS","question":"Proposal basic information","config":{"tooltip":"","required":false,"small_label":""}},"topicId":1,"sortOrder":0,"config":{"tooltip":"","required":false,"small_label":""},"dependencies":[],"dependenciesOperator":"AND"},{"question":{"categoryId":1,"id":"text_input_1661195968328","naturalKey":"text_input_1661195968328","dataType":"TEXT_INPUT","question":"New question","config":{"required":false,"small_label":"","tooltip":"","htmlQuestion":"","isHtmlQuestion":false,"min":null,"max":null,"multiline":false,"placeholder":"","isCounterHidden":false}},"topicId":1,"sortOrder":1,"config":{"required":false,"small_label":"","tooltip":"","htmlQuestion":"","isHtmlQuestion":false,"min":null,"max":null,"multiline":false,"placeholder":"","isCounterHidden":false},"dependencies":[],"dependenciesOperator":"AND"}]},{"topic":{"id":3,"title":"New Topic","templateId":1,"sortOrder":1,"isEnabled":true},"fields":[{"question":{"categoryId":1,"id":"generic_template_1661237580553","naturalKey":"generic_template_1661237580553","dataType":"GENERIC_TEMPLATE","question":"New question","config":{"addEntryButtonLabel":"Add","templateCategory":"GENERIC_TEMPLATE","templateId":3,"small_label":"","required":false,"maxEntries":null,"minEntries":null}},"topicId":3,"sortOrder":0,"config":{"addEntryButtonLabel":"Add","templateCategory":"GENERIC_TEMPLATE","templateId":3,"small_label":"","required":false,"maxEntries":null,"minEntries":null},"dependencies":[],"dependenciesOperator":"AND"},{"question":{"categoryId":1,"id":"selection_from_options_1661240836804","naturalKey":"multiple_select","dataType":"SELECTION_FROM_OPTIONS","question":"Multiple seleect","config":{"small_label":"","required":false,"tooltip":"","variant":"dropdown","options":["A","B","C"],"isMultipleSelect":true}},"topicId":3,"sortOrder":1,"config":{"small_label":"","required":false,"tooltip":"","variant":"dropdown","options":["A","B","C"],"isMultipleSelect":true},"dependencies":[],"dependenciesOperator":"AND"},{"question":{"categoryId":1,"id":"generic_template_1661241012105","naturalKey":"generic_template_1661241012105","dataType":"GENERIC_TEMPLATE","question":"New question","config":{"addEntryButtonLabel":"Add","templateCategory":"GENERIC_TEMPLATE","templateId":3,"small_label":"","required":false,"maxEntries":null,"minEntries":null}},"topicId":3,"sortOrder":2,"config":{"addEntryButtonLabel":"Add","templateCategory":"GENERIC_TEMPLATE","templateId":3,"small_label":"","required":false,"maxEntries":null,"minEntries":null},"dependencies":[],"dependenciesOperator":"AND"}]}],"questions":[{"categoryId":1,"id":"proposal_basis","naturalKey":"proposal_basis","dataType":"PROPOSAL_BASIS","question":"Proposal basic information","config":{"tooltip":"","required":false,"small_label":""}},{"categoryId":1,"id":"generic_template_1661237580553","naturalKey":"generic_template_1661237580553","dataType":"GENERIC_TEMPLATE","question":"New question","config":{"addEntryButtonLabel":"Add","templateCategory":"GENERIC_TEMPLATE","templateId":3,"small_label":"","required":false,"maxEntries":null,"minEntries":null}},{"categoryId":1,"id":"text_input_1661195968328","naturalKey":"text_input_1661195968328","dataType":"TEXT_INPUT","question":"New question","config":{"required":false,"small_label":"","tooltip":"","htmlQuestion":"","isHtmlQuestion":false,"min":null,"max":null,"multiline":false,"placeholder":"","isCounterHidden":false}},{"categoryId":1,"id":"selection_from_options_1661240836804","naturalKey":"multiple_select","dataType":"SELECTION_FROM_OPTIONS","question":"Multiple seleect","config":{"small_label":"","required":false,"tooltip":"","variant":"dropdown","options":["A","B","C"],"isMultipleSelect":true}},{"categoryId":1,"id":"generic_template_1661241012105","naturalKey":"generic_template_1661241012105","dataType":"GENERIC_TEMPLATE","question":"New question","config":{"addEntryButtonLabel":"Add","templateCategory":"GENERIC_TEMPLATE","templateId":3,"small_label":"","required":false,"maxEntries":null,"minEntries":null}}],"subTemplates":[{"template":{"templateId":3,"groupId":"GENERIC_TEMPLATE","name":"Test","description":"Test","isArchived":false},"templateSteps":[{"topic":{"id":2,"title":"New Sub Topic","templateId":3,"sortOrder":0,"isEnabled":true},"fields":[{"question":{"categoryId":7,"id":"generic_template_basis","naturalKey":"generic_template_basis","dataType":"GENERIC_TEMPLATE_BASIS","question":"Template basic information","config":{"titlePlaceholder":"Title","questionLabel":"","tooltip":"","required":false,"small_label":""}},"topicId":2,"sortOrder":0,"config":{"titlePlaceholder":"Title","questionLabel":"","tooltip":"","required":false,"small_label":""},"dependencies":[],"dependenciesOperator":"AND"},{"question":{"categoryId":7,"id":"text_input_1661237874466","naturalKey":"text_input_1661237874466","dataType":"TEXT_INPUT","question":"New question","config":{"required":false,"small_label":"","tooltip":"","htmlQuestion":"","isHtmlQuestion":false,"min":null,"max":null,"multiline":false,"placeholder":"","isCounterHidden":false}},"topicId":2,"sortOrder":1,"config":{"required":false,"small_label":"","tooltip":"","htmlQuestion":"","isHtmlQuestion":false,"min":null,"max":null,"multiline":false,"placeholder":"","isCounterHidden":false},"dependencies":[],"dependenciesOperator":"AND"}]}],"questions":[{"categoryId":7,"id":"generic_template_basis","naturalKey":"generic_template_basis","dataType":"GENERIC_TEMPLATE_BASIS","question":"Template basic information","config":{"titlePlaceholder":"Title","questionLabel":"","tooltip":"","required":false,"small_label":""}},{"categoryId":7,"id":"text_input_1661237874466","naturalKey":"text_input_1661237874466","dataType":"TEXT_INPUT","question":"New question","config":{"required":false,"small_label":"","tooltip":"","htmlQuestion":"","isHtmlQuestion":false,"min":null,"max":null,"multiline":false,"placeholder":"","isCounterHidden":false}}],"subTemplates":[]},{"template":{"templateId":3,"groupId":"GENERIC_TEMPLATE","name":"Test","description":"Test","isArchived":false},"templateSteps":[{"topic":{"id":2,"title":"New Sub Topic","templateId":3,"sortOrder":0,"isEnabled":true},"fields":[{"question":{"categoryId":7,"id":"generic_template_basis","naturalKey":"generic_template_basis","dataType":"GENERIC_TEMPLATE_BASIS","question":"Template basic information","config":{"titlePlaceholder":"Title","questionLabel":"","tooltip":"","required":false,"small_label":""}},"topicId":2,"sortOrder":0,"config":{"titlePlaceholder":"Title","questionLabel":"","tooltip":"","required":false,"small_label":""},"dependencies":[],"dependenciesOperator":"AND"},{"question":{"categoryId":7,"id":"text_input_1661237874466","naturalKey":"text_input_1661237874466","dataType":"TEXT_INPUT","question":"New question","config":{"required":false,"small_label":"","tooltip":"","htmlQuestion":"","isHtmlQuestion":false,"min":null,"max":null,"multiline":false,"placeholder":"","isCounterHidden":false}},"topicId":2,"sortOrder":1,"config":{"required":false,"small_label":"","tooltip":"","htmlQuestion":"","isHtmlQuestion":false,"min":null,"max":null,"multiline":false,"placeholder":"","isCounterHidden":false},"dependencies":[],"dependenciesOperator":"AND"}]}],"questions":[{"categoryId":7,"id":"generic_template_basis","naturalKey":"generic_template_basis","dataType":"GENERIC_TEMPLATE_BASIS","question":"Template basic information","config":{"titlePlaceholder":"Title","questionLabel":"","tooltip":"","required":false,"small_label":""}},{"categoryId":7,"id":"text_input_1661237874466","naturalKey":"text_input_1661237874466","dataType":"TEXT_INPUT","question":"New question","config":{"required":false,"small_label":"","tooltip":"","htmlQuestion":"","isHtmlQuestion":false,"min":null,"max":null,"multiline":false,"placeholder":"","isCounterHidden":false}}],"subTemplates":[]}]}}

PDF template

<div>
  Title: {{ proposal.title }}
<div>
<div>
  Test question: {{ answers.text_input_1661195968328 }}
</div>
<div>
  Subtemplate:
  {{#each answers.generic_template_1661237580553}}
    {{ generic_template_basis }}
    {{ text_input_1661237874466 }}
  {{/each}}
</div>
<div>
  Multiple choice:
  {{#each answers.multiple_select}}
    {{ . }}
  {{/each}}
</div>
<div>
  <div>
    {{ principalInvestigator.preferredname }} ({{ principalInvestigator.organisation }})
  </div>
  <div>
    {{#each coProposers}}
      {{ preferredname }} ({{ organisation }})
    {{/each}}
  </div>
</div>

Depends on

New template generation will not work until follow up PRs for UserOfficeProject/user-office-backend#716 and UserOfficeProject/user-office-frontend#988 have been merged but it will not break current template generation.

Tests included/Docs Updated?

  • I have added tests to cover my changes.
  • All relevant doc has been updated

@TickleThePanda TickleThePanda marked this pull request as draft August 23, 2022 12:58
@TickleThePanda TickleThePanda changed the title 613 custom pdf templates #613: Custom PDF templates Aug 23, 2022
@TickleThePanda TickleThePanda marked this pull request as ready for review August 23, 2022 15:37
@TickleThePanda TickleThePanda added the review: please A request for an ad-hoc review. label Aug 23, 2022
Copy link
Contributor

@jekabs-karklins jekabs-karklins left a comment

Choose a reason for hiding this comment

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

Just small comments, but looks good

src/template/helpers/debug.ts Outdated Show resolved Hide resolved
src/types.ts Outdated Show resolved Hide resolved
@TickleThePanda TickleThePanda merged commit 95a9f97 into develop Aug 24, 2022
@TickleThePanda TickleThePanda deleted the 613_custom_pdf_templates branch August 24, 2022 10:33
@TickleThePanda TickleThePanda restored the 613_custom_pdf_templates branch August 24, 2022 10:34
@TickleThePanda TickleThePanda deleted the 613_custom_pdf_templates branch August 24, 2022 10:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
review: please A request for an ad-hoc review.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants