Skip to content

OBGM-528 Unable to print delivery note#4162

Merged
awalkowiak merged 4 commits intofeature/upgrade-to-grails-3.3.10from
OBGM-528
Jul 18, 2023
Merged

OBGM-528 Unable to print delivery note#4162
awalkowiak merged 4 commits intofeature/upgrade-to-grails-3.3.10from
OBGM-528

Conversation

@kchelstowski
Copy link
Collaborator

@kchelstowski kchelstowski commented Jul 12, 2023

The issue was that the <g:javascript> implementation changed and it seems not to be invoking jquery anymore.

Grails 1:
Screenshot from 2023-07-12 12-15-19

Grails 3:
Screenshot from 2023-07-12 12-15-56

The jquery in those places was not working at all, an error like this could be visible on such pages:
Screenshot from 2023-07-12 12-17-11

It is because those print pages don't use the layout of custom.gsp like: <g:applyLayout name="custom">
and because custom.gsp invokes jquery like this:

<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>

the jquery is still working on most of pages (because they apply the custom layout, which invokes jquery).

To fix the issue I just invoke the jquery manually here, but not to repeat the same code, I've created a custom tag lib <g:jquery> for that, so that if we face this issue in more places, we can reuse it.

script.append("<script src=\"https://code.jquery.com/jquery-3.3.1.slim.min.js\"")
script.append(" integrity=\"sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo\"")
script.append(" crossorigin=\"anonymous\">")
script.append("</script>")
Copy link
Collaborator Author

@kchelstowski kchelstowski Jul 12, 2023

Choose a reason for hiding this comment

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

I decided to use StringBuilder for a better visibility, instead of either using + or pasting whole script in one line

<title><warehouse:message code="default.show.label" args="[entityName]"/></title>
<link rel="stylesheet" href="${resource(dir:'css',file:'buttons.css')}" type="text/css" media="all" />
<g:javascript library="jquery" plugin="jquery" />
<g:jquery />
Copy link
Member

Choose a reason for hiding this comment

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

We can just explicitly include the jquery library we want to use into the print.gsp layout (grails-app/views/layouts/print.gsp), assuming the use of jquery-3.3.1 doesn't break anything.

So replace this

<g:javascript library="jquery" plugin="jquery" />

with this

    <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@jmiranda could you elaborate on this, because I’m confused?
I’m exactly doing this, but assigned it to a „variable” (a custom tag), so that if we ever need to bump up the version, we’ll just have to change it in the taglib, not in every file

…- remove the custom tag lib for jquery injection
@kchelstowski kchelstowski requested a review from jmiranda July 18, 2023 09:57
@awalkowiak awalkowiak merged commit 6a35549 into feature/upgrade-to-grails-3.3.10 Jul 18, 2023
@awalkowiak awalkowiak deleted the OBGM-528 branch July 18, 2023 15:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants