Skip to content

Commit

Permalink
fix: remove some warnings, fix search form template and Nutri-Score 2…
Browse files Browse the repository at this point in the history
…021 details (#10335)
  • Loading branch information
stephanegigandet authored May 23, 2024
1 parent 52e0246 commit 25cdde6
Show file tree
Hide file tree
Showing 15 changed files with 102 additions and 103 deletions.
46 changes: 23 additions & 23 deletions cgi/product_multilingual.pl
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,10 @@
use File::Copy qw(move);
use Data::Dumper;

my $request_ref = ProductOpener::Display::init_request();

# Function to display a form to add a product with a specific barcode (either typed in a field, or extracted from a barcode photo)
# or without a barcode

sub display_search_or_add_form() {
sub display_search_or_add_form($request_ref) {

# Producer platform and no org or not admin: do not offer to add products
if (($server_options{producers_platform})
Expand Down Expand Up @@ -167,6 +165,8 @@ ($product_ref)
return;
}

my $request_ref = ProductOpener::Display::init_request();

if ($User_id eq 'unwanted-user-french') {
display_error_and_exit(
$request_ref,
Expand Down Expand Up @@ -209,7 +209,7 @@ ($product_ref)

my $title = lang("add_product");

$html = display_search_or_add_form();
$html = display_search_or_add_form($request_ref);

$request_ref->{title} = lang('add_product');
$request_ref->{content_ref} = \$html;
Expand Down Expand Up @@ -956,26 +956,27 @@ ($product_ref, $field, $language)
}

$display_tab_ref->{fields} = \@fields_arr;
}

# For moderators, add a checkbox to move all data and photos to the main language
# this needs to be below the "add (language name) in all field labels" above, so that it does not change this label.
if (($User{moderator}) and ($tabsid eq "front_image")) {
# For moderators, add a checkbox to move all data and photos to the main language
# this needs to be below the "add (language name) in all field labels" above, so that it does not change this label.
if (($User{moderator}) and ($tabsid eq "front_image")) {

my $msg = f_lang(
"f_move_data_and_photos_to_main_language",
{
language => '<span class="tab_language">' . $language . '</span>',
main_language => '<span class="main_language">'
. lang("lang_" . $product_ref->{lc})
. '</span>'
}
);
my $msg = f_lang(
"f_move_data_and_photos_to_main_language",
{
language => '<span class="tab_language">' . $language . '</span>',
main_language => '<span class="main_language">'
. lang("lang_" . $product_ref->{lc})
. '</span>'
}
);

my $moveid = "move_" . $tabid . "_data_and_images_to_main_language";

my $moveid = "move_" . $tabid . "_data_and_images_to_main_language";
$display_tab_ref->{moveid} = $moveid;
$display_tab_ref->{msg} = $msg;
}

$display_tab_ref->{moveid} = $moveid;
$display_tab_ref->{msg} = $msg;
}

push(@display_tabs, $display_tab_ref);
Expand Down Expand Up @@ -1197,9 +1198,8 @@ ($product_ref, $field, $language)
# They may be prefixed with a ! to indicate that the nutrient is always shown when displaying the nutrition facts table
if (($shown) and ($nutriment =~ /^!?-/)) {
$class = 'sub';
$prefix = $Lang{nutrition_data_table_sub}{$lc} . " ";
if ($nutriment =~ /^--/) {
$prefix = "&nbsp; " . $prefix;
$prefix = "&nbsp; ";
}
}

Expand Down Expand Up @@ -1421,7 +1421,7 @@ ($product_ref, $field, $language)
$supports_iu = "true";
}

my $other_nutriment_unit = get_property("nutrients", "zz:$nid", "unit:en");
my $other_nutriment_unit = get_property("nutrients", "zz:$nid", "unit:en") || '';
$other_nutriments
.= '{ "value" : "'
. $other_nutriment_value
Expand Down
5 changes: 4 additions & 1 deletion cgi/search.pl
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,10 @@
my $download = single_param("download") || '';

open(my $OUT, ">>:encoding(UTF-8)", "$BASE_DIRS{LOGS}/search_log_debug");
print $OUT remote_addr() . "\t" . time() . "\t" . decode utf8 => single_param('search_terms') . " - map: $map
print $OUT remote_addr() . "\t"
. time() . "\t"
. (decode utf8 => single_param('search_terms') || "no_search_terms")
. " - map: $map
- graph: $graph - download: $download - page: $page\n";
close($OUT);

Expand Down
2 changes: 1 addition & 1 deletion lib/ProductOpener/API.pm
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ sub customize_packagings ($request_ref, $product_ref) {

my $customized_packaging_ref = dclone($packaging_ref);

if ($request_ref->{api_version} >= 3) {
if ((defined $request_ref->{api_version}) and ($request_ref->{api_version} >= 3)) {
# Shape, material and recycling are localized
foreach my $property ("shape", "material", "recycling") {
if (defined $packaging_ref->{$property}) {
Expand Down
31 changes: 20 additions & 11 deletions lib/ProductOpener/Display.pm
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ BEGIN {
$attributes_options_ref
$knowledge_panels_options_ref
&display_nutriscore_calculation_details
&display_nutriscore_calculation_details_2021
); # symbols to export on request
%EXPORT_TAGS = (all => [@EXPORT_OK]);
}
Expand Down Expand Up @@ -5493,7 +5493,7 @@ sub search_and_display_products ($request_ref, $query_ref, $sort_by, $limit, $pa

# 2021-02-25: we now store only nested ingredients, flatten them if the API is <= 1

if ($request_ref->{api_version} <= 1) {
if ((defined $request_ref->{api_version}) and ($request_ref->{api_version} <= 1)) {

for my $product_ref (@{$request_ref->{structured_response}{products}}) {
if (defined $product_ref->{ingredients}) {
Expand Down Expand Up @@ -5677,8 +5677,6 @@ sub display_pagination ($request_ref, $count, $limit, $page) {
$nofollow = ' nofollow';
}

print STDERR "zzz lc: $lc - request_ref->lc: $request_ref->{lc}\n";

if ((($nb_pages > 1) and (defined $current_link)) and (not defined $request_ref->{product_changes_saved})) {

my $prev = '';
Expand Down Expand Up @@ -8864,7 +8862,9 @@ HTML
return;
}

=head2 display_nutriscore_calculation_details( $nutriscore_data_ref, $version = "2021" )
=head2 display_nutriscore_calculation_details_2021 ( $product_ref )
Warning: This function only works with Nutri-Score 2021.
Generates HTML code with information on how the Nutri-Score was computed for a particular product.
Expand All @@ -8873,7 +8873,12 @@ the rounded value according to the Nutri-Score rules, and the corresponding poin
=cut

sub display_nutriscore_calculation_details ($nutriscore_data_ref, $version = "2021") {
sub display_nutriscore_calculation_details_2021 ($product_ref) {

my $version = "2021";
my $nutriscore_grade = deep_get($product_ref, "nutriscore", $version, "grade");
my $nutriscore_score = deep_get($product_ref, "nutriscore", $version, "score");
my $nutriscore_data_ref = deep_get($product_ref, "nutriscore", $version, "data");

my $beverage_view;

Expand Down Expand Up @@ -8918,8 +8923,8 @@ sub display_nutriscore_calculation_details ($nutriscore_data_ref, $version = "20

nutriscore_protein_info => $nutriscore_protein_info,

score => $nutriscore_data_ref->{score},
grade => uc($nutriscore_data_ref->{grade}),
score => $nutriscore_score,
grade => uc($nutriscore_grade),
positive_points => $nutriscore_data_ref->{positive_points},
negative_points => $nutriscore_data_ref->{negative_points},

Expand Down Expand Up @@ -9207,9 +9212,13 @@ sub data_to_display_nutriscore ($product_ref, $version = "2021") {
$result_data_ref->{nutriscore_warnings} = \@nutriscore_warnings;
}

# Display the details of the computation of the Nutri-Score if we computed one
if ((defined $product_ref->{nutriscore_grade}) and ($product_ref->{nutriscore_grade} =~ /^[a-e]$/)) {
$result_data_ref->{nutriscore_details} = display_nutriscore_calculation_details($nutriscore_data_ref, $version);
# Generate HTML for the details of the computation of the Nutri-Score if we computed one
# only for version 2021
if ( ($version eq "2021")
and (defined $product_ref->{nutriscore_grade})
and ($product_ref->{nutriscore_grade} =~ /^[a-e]$/))
{
$result_data_ref->{nutriscore_details} = display_nutriscore_calculation_details_2021($product_ref);
}

return $result_data_ref;
Expand Down
2 changes: 1 addition & 1 deletion lib/ProductOpener/Products.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2338,7 +2338,7 @@ sub compute_product_history_and_completeness ($product_data_root, $current_produ
my $number_of_units = $packagings_ref->{number_of_units};
my $weight_measured = $packagings_ref->{weight_measured};

$packagings_data_signature .= "number_of_units:" . $number_of_units . ',';
$packagings_data_signature .= "number_of_units:" . ($number_of_units || '') . ',';
foreach my $property (qw(shape material recycling quantity_per_unit)) {
$packagings_data_signature .= $property . ":" . ($packagings_ref->{$property} || '') . ',';
}
Expand Down
1 change: 1 addition & 0 deletions taxonomies/nutrients.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1056,6 +1056,7 @@ zz:unsaturated-fat
xx:Unsaturated fat
en:Unsaturated fat
nl:Onverzadigde vetzuren, Onverzadigd vet, onverzadigde vetten
unit:en: g

zz:monounsaturated-fat
xx:Monounsaturated fat
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
</div>

<!-- row 0 is a template for new row, we do not populate it -->
[% IF packaging_max > 0 %]
[% IF packaging_max.defined && packaging_max > 0 %]
<initjs>
configure_packaging_select2("[% select2_id %]", "[% taxonomy %]", "[% lang("packaging_$property") %]" )

Expand Down
7 changes: 0 additions & 7 deletions templates/web/pages/search_form/search_form.tt.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,6 @@ <h1> [% lang('search_products') %] </h1>
<input type="text" name="search_terms2" id="search_terms2" value="[%search_terms%]" />
</div>
</div>
<!-- Word Search -->
<div class="row">
<div class="large-12 columns">
<label for="search_terms2">[% lang ('search_terms_note') %]</label>
<input type="text" name="search_terms2" id="search_terms2" value="[%search_terms%]" />
</div>
</div>

<!-- Criteria -->

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2057,7 +2057,7 @@ <h1></h1>
<!--label starts-->


<label class="nutriment_label" for="nutriment_saturated-fat"> Acides gras saturés*</label>
<label class="nutriment_label" for="nutriment_saturated-fat">Acides gras saturés*</label>


<!--label ends-->
Expand Down Expand Up @@ -2281,7 +2281,7 @@ <h1></h1>
<!--label starts-->


<label class="nutriment_label" for="nutriment_sugars"> Sucres*</label>
<label class="nutriment_label" for="nutriment_sugars">Sucres*</label>


<!--label ends-->
Expand Down Expand Up @@ -3899,7 +3899,7 @@ <h3 class="title-5 text-medium">Découvrez le projet</h3>
{ "value" : "Acide cérotique", "unit" : "g", "iu": false },
{ "value" : "Acide montanique", "unit" : "g", "iu": false },
{ "value" : "Acide mélissique", "unit" : "g", "iu": false },
{ "value" : "Unsaturated fat", "unit" : "", "iu": false },
{ "value" : "Unsaturated fat", "unit" : "g", "iu": false },
{ "value" : "Acides gras monoinsaturés", "unit" : "g", "iu": false },
{ "value" : "Acides gras Oméga 9", "unit" : "mg", "iu": false },
{ "value" : "Acides gras polyinsaturés", "unit" : "g", "iu": false },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -712,10 +712,10 @@ <h3 id="panel_group_nutrition" class="panel_title_card text-medium">Nutrition</h
<p>Les points pour les protéines ne sont pas comptés car les points négatifs sont supérieurs ou égaux à 11.</p>

<p>
<strong>Score nutritionnel : </strong>
<strong>Score nutritionnel : 12</strong>
(16 - 4)
</p>
<p><strong>Nutri-Score : </strong></p>
<p><strong>Nutri-Score : D</strong></p>

<!-- end templates/web/pages/product/includes/nutriscore_details.tt.html -->
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -727,10 +727,10 @@ <h3 id="panel_group_nutrition" class="panel_title_card text-medium">Nutrition</h
<p>Les points pour les protéines ne sont pas comptés car les points négatifs sont supérieurs ou égaux à 11.</p>

<p>
<strong>Score nutritionnel : </strong>
<strong>Score nutritionnel : 11</strong>
(15 - 4)
</p>
<p><strong>Nutri-Score : </strong></p>
<p><strong>Nutri-Score : D</strong></p>

<!-- end templates/web/pages/product/includes/nutriscore_details.tt.html -->
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,13 +326,6 @@ <h1> Recherche de produits </h1>
<input type="text" name="search_terms2" id="search_terms2" value="" />
</div>
</div>
<!-- Word Search -->
<div class="row">
<div class="large-12 columns">
<label for="search_terms2">Recherche les mots présents dans le nom du produit, le nom générique, les marques, catégories, origines et labels</label>
<input type="text" name="search_terms2" id="search_terms2" value="" />
</div>
</div>

<!-- Criteria -->

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2055,7 +2055,7 @@ <h1></h1>
<!--label starts-->


<label class="nutriment_label" for="nutriment_saturated-fat"> Saturated fat*</label>
<label class="nutriment_label" for="nutriment_saturated-fat">Saturated fat*</label>


<!--label ends-->
Expand Down Expand Up @@ -2279,7 +2279,7 @@ <h1></h1>
<!--label starts-->


<label class="nutriment_label" for="nutriment_sugars"> Sugars*</label>
<label class="nutriment_label" for="nutriment_sugars">Sugars*</label>


<!--label ends-->
Expand Down Expand Up @@ -3897,7 +3897,7 @@ <h3 class="title-5 text-medium">Discover the project</h3>
{ "value" : "Cerotic acid", "unit" : "g", "iu": false },
{ "value" : "Montanic acid", "unit" : "g", "iu": false },
{ "value" : "Melissic acid", "unit" : "g", "iu": false },
{ "value" : "Unsaturated fat", "unit" : "", "iu": false },
{ "value" : "Unsaturated fat", "unit" : "g", "iu": false },
{ "value" : "Monounsaturated fat", "unit" : "g", "iu": false },
{ "value" : "Omega 9 fat", "unit" : "mg", "iu": false },
{ "value" : "Polyunsaturated fat", "unit" : "g", "iu": false },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,13 +326,6 @@ <h1> Products search </h1>
<input type="text" name="search_terms2" id="search_terms2" value="" />
</div>
</div>
<!-- Word Search -->
<div class="row">
<div class="large-12 columns">
<label for="search_terms2">Search for words present in the product name, generic name, brands, categories, origins and labels</label>
<input type="text" name="search_terms2" id="search_terms2" value="" />
</div>
</div>

<!-- Criteria -->

Expand Down
Loading

0 comments on commit 25cdde6

Please sign in to comment.