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

fix: added barcode-svg #10242

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

bazylevnik0
Copy link

What

Added support of the barcode SVGs in the page

Screenshot

Screenshot from 2024-05-06 20-08-14

Related issue(s) and discussion

@bazylevnik0 bazylevnik0 requested a review from a team as a code owner May 6, 2024 17:15
@github-actions github-actions bot added Product Page Template::Toolkit The templating toolkit used by product opener. The starting point for HTML/JS/CSS fixes. Site layout labels May 6, 2024
@bazylevnik0 bazylevnik0 marked this pull request as draft May 6, 2024 18:23
@codecov-commenter
Copy link

codecov-commenter commented May 6, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 49.68%. Comparing base (dc04d18) to head (9257cba).
Report is 323 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #10242      +/-   ##
==========================================
+ Coverage   49.54%   49.68%   +0.13%     
==========================================
  Files          67       71       +4     
  Lines       20650    20982     +332     
  Branches     4980     5026      +46     
==========================================
+ Hits        10231    10424     +193     
- Misses       9131     9270     +139     
  Partials     1288     1288              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@bazylevnik0 bazylevnik0 requested a review from teolemon May 6, 2024 18:43
@bazylevnik0 bazylevnik0 marked this pull request as ready for review May 6, 2024 18:45
html/js/JsBarcode.all.min.js Outdated Show resolved Hide resolved
@bazylevnik0 bazylevnik0 marked this pull request as draft May 6, 2024 19:22
@github-actions github-actions bot added the dependencies Pull requests that update a dependency file label May 6, 2024
@bazylevnik0 bazylevnik0 marked this pull request as ready for review May 6, 2024 20:05
//init barcode SVGs if exist on the page
let barcode_svg_elements = document.getElementsByClassName("barcode-svg");
if(barcode_svg_elements.length!=0){
JsBarcode(".barcode-svg").init();
Copy link
Member

Choose a reason for hiding this comment

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

Since you already have the array, this should be enough:

Suggested change
JsBarcode(".barcode-svg").init();
JsBarcode(barcode_svg_elements).init();

JsBarcode seems to do the same by calling getRenderProperties internally. Might save some ms by not running the selector again

@@ -490,6 +490,14 @@ <h3 class="title-5 text-medium">[% lang('footer_discover_the_project') %]</h3>
[% END %]

</body>
<script src="[% static_subdomain %]/js/dist/JsBarcode.all.min.js"></script>
<script>
//init barcode SVGs if exist on the page
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure what the best place for this snippet is, but in general, we tried to remove most direct JS from the templates in the last few months. Maybe display-product.js? cc @alexgarel @stephanegigandet

Copy link
Contributor

Choose a reason for hiding this comment

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

display-product.js would be the right place I think, we don't need to load this script on every page, just product pages.

In fact we probably want to display the barcode only on desktop (not mobile), as on mobile it takes a lot of space for little added value. On desktop it's very useful so that it can be scanned with a mobile app (like ours, or others).

I'm not sure if we could load the script conditionnaly if the screen is big enough though.

@github-actions github-actions bot added the ⭐ top pull request Top pull request. label May 7, 2024
</p>
<svg class="barcode-svg"
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice!

Could you change the display so that it is displayed only on desktop, and at the right of the barcode number, so that we don't lose vertical space? The barcode is very nice to have in order to be able to scan it with a mobile app, but we don't want to push the real content too much down.

e.g. something like that:

image

@bazylevnik0 bazylevnik0 marked this pull request as draft May 7, 2024 08:07
@bazylevnik0
Copy link
Author

bazylevnik0 commented May 8, 2024

After many tryings:

I do not understand how to use display-product.js in this situation. I even couldn't to console.log something. It is sort of async loading, yes? I see connection of this script on the page, but I tried to change something, with failure...

My proposal:

Use a little snippet on the template, ye it is direct js in the template(as i said before, do not understand other way)). I wrote the logic for avoiding the show and initialization for mobiles and with less height.

I see conditions for mobile only in the main page template ([% IF mobile %]). But loading of the library now only on the product page...

Screenshots:
Screenshot from 2024-05-08 16-26-11
Screenshot from 2024-05-08 16-26-25

@bazylevnik0 bazylevnik0 marked this pull request as ready for review May 8, 2024 13:40
Copy link
Member

@alexgarel alexgarel left a comment

Choose a reason for hiding this comment

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

Thanks @bazylevnik0, this is great.

Moving to _off.scss seems the only remaining item to me !

Comment on lines 180 to 190
<style>
#barcode_div_code,#barcode_div_svg{
display: inline-block;
vertical-align: top;
}
@media only screen and (max-width: 600px) {
#barcode_div_svg,#barcode_br {
display: none;
}
}
</style>
Copy link
Member

Choose a reason for hiding this comment

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

we should put it in the main _off.scss file.

Copy link
Author

Choose a reason for hiding this comment

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

Fixed. But I moved styles to _product-page.scss.

I think it is more reasonable because script is also only on the product page template.

@bazylevnik0 bazylevnik0 marked this pull request as draft May 17, 2024 08:43
@github-actions github-actions bot added the CSS label May 17, 2024
Copy link

sonarcloud bot commented May 17, 2024

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

@bazylevnik0 bazylevnik0 marked this pull request as ready for review May 17, 2024 12:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CSS dependencies Pull requests that update a dependency file 🎁 donations Product Page 🤖 Robotoff Site layout ⭐ top pull request Top pull request. Template::Toolkit The templating toolkit used by product opener. The starting point for HTML/JS/CSS fixes.
Development

Successfully merging this pull request may close these issues.

Show barcode image on product page
6 participants