Skip to content

Commit

Permalink
fix: Show missing nutrients in Nutri-Score panel (#10655)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephanegigandet authored Aug 13, 2024
1 parent 7fc07fc commit a1b11eb
Show file tree
Hide file tree
Showing 26 changed files with 492 additions and 154 deletions.
15 changes: 14 additions & 1 deletion lib/ProductOpener/Display.pm
Original file line number Diff line number Diff line change
Expand Up @@ -9313,7 +9313,20 @@ sub data_to_display_nutriscore ($product_ref, $version = "2021") {

# Missing nutrition facts?
if (has_tag($product_ref, "misc", "en:nutriscore-missing-nutrition-data")) {
push @nutriscore_warnings, lang("nutriscore_missing_nutrition_data");

my $missing_nutrients = "";
foreach my $misc_tag (@{$product_ref->{misc_tags}}) {
if ($misc_tag =~ /^en:nutriscore-missing-nutrition-data-(.*)$/) {
$missing_nutrients .= display_taxonomy_tag_name($lc, "nutrients", $1) . ", ";
}
}
$missing_nutrients =~ s/, $//;

push @nutriscore_warnings,
lang("nutriscore_missing_nutrition_data") . "<p>"
. lang("nutriscore_missing_nutrition_data_details") . " <b>"
. $missing_nutrients . "</b>" . "</p>";

if (not has_tag($product_ref, "misc", "en:nutriscore-missing-category")) {
$result_data_ref->{nutriscore_unknown_reason} = "missing_nutrition_data";
$result_data_ref->{nutriscore_unknown_reason_short}
Expand Down
4 changes: 4 additions & 0 deletions po/common/common.pot
Original file line number Diff line number Diff line change
Expand Up @@ -5942,6 +5942,10 @@ msgctxt "nutriscore_missing_nutrition_data"
msgid "The nutrition facts of the product must be specified in order to compute the Nutri-Score."
msgstr "The nutrition facts of the product must be specified in order to compute the Nutri-Score."

msgctxt "nutriscore_missing_nutrition_data_details"
msgid "Missing nutrition facts:"
msgstr "Missing nutrition facts:"

msgctxt "nutriscore_missing_category_and_nutrition_data"
msgid "The category and the nutrition facts of the product must be specified in order to compute the Nutri-Score."
msgstr "The category and the nutrition facts of the product must be specified in order to compute the Nutri-Score."
Expand Down
4 changes: 4 additions & 0 deletions po/common/en.po
Original file line number Diff line number Diff line change
Expand Up @@ -5966,6 +5966,10 @@ msgctxt "nutriscore_missing_nutrition_data"
msgid "The nutrition facts of the product must be specified in order to compute the Nutri-Score."
msgstr "The nutrition facts of the product must be specified in order to compute the Nutri-Score."

msgctxt "nutriscore_missing_nutrition_data_details"
msgid "Missing nutrition facts:"
msgstr "Missing nutrition facts:"

msgctxt "nutriscore_missing_category_and_nutrition_data"
msgid "The category and the nutrition facts of the product must be specified in order to compute the Nutri-Score."
msgstr "The category and the nutrition facts of the product must be specified in order to compute the Nutri-Score."
Expand Down
4 changes: 4 additions & 0 deletions po/common/fr.po
Original file line number Diff line number Diff line change
Expand Up @@ -5894,6 +5894,10 @@ msgctxt "nutriscore_missing_nutrition_data"
msgid "The nutrition facts of the product must be specified in order to compute the Nutri-Score."
msgstr "Les données nutritionnelles du produit doivent être spécifiées afin de calculer le Nutri-Score."

msgctxt "nutriscore_missing_nutrition_data_details"
msgid "Missing nutrition facts:"
msgstr "Données nutritionnelles manquantes :"

msgctxt "nutriscore_missing_category_and_nutrition_data"
msgid "The category and the nutrition facts of the product must be specified in order to compute the Nutri-Score."
msgstr "La catégorie et la valeur nutritionnelle du produit doivent être précisées afin de calculer le Nutri-Score."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,19 @@
"grade": "[% panel.nutriscore_grade %]",
},
"elements": [
// Explanation of Nutri-Score
{
"element_type": "panel",
"panel_element": {
"panel_id": "nutriscore_description",
// First display warnings
[% IF panel.nutriscore_warnings %]
[% FOREACH warning IN panel.nutriscore_warnings %]
{
"element_type": "text",
"text_element": {
"type": "warning",
"html": `[% warning %]
`,
}
},
},
[% END %]
[% END %]
// Display actions if we are missing data to compute the Nutri-Score
[% IF panel.nutriscore_unknown_reason == "missing_category" OR panel.nutriscore_unknown_reason == "missing_nutrition_data" OR panel.nutriscore_unknown_reason == "missing_category_and_nutrition_data" %]
{
Expand All @@ -39,6 +45,13 @@
}
},
[% END %]
// Explanation of Nutri-Score
{
"element_type": "panel",
"panel_element": {
"panel_id": "nutriscore_description",
},
},
// Start with negative points first, as the positive points depend on negative points
[% IF product.nutriscore.2023.data.components.negative.size > 0 %]
{
Expand Down
10 changes: 6 additions & 4 deletions templates/web/panels/panel.tt.html
Original file line number Diff line number Diff line change
Expand Up @@ -285,10 +285,12 @@ <h4 class="panel_title">
[% action_element.html %]

[% FOREACH action IN action_element.actions %]
<a class="button small action-[% action %]"
href="[% product_action_url(product.code, action) %]">
[% lang("action_$action") %]
</a>
<div>
<a class="button small action-[% action %]"
href="[% product_action_url(product.code, action) %]">
[% lang("action_$action") %]
</a>
</div>
[% END %]

</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1568,6 +1568,20 @@
},
"nutriscore_2023" : {
"elements" : [
{
"element_type" : "text",
"text_element" : {
"html" : "Warning: the nutrition facts are not specified. They have been estimated from the list of ingredients.\n ",
"type" : "warning"
}
},
{
"element_type" : "text",
"text_element" : {
"html" : "Warning: the amount of fruits, vegetables and nuts is not specified on the label, it was estimated from the list of ingredients: 62\n ",
"type" : "warning"
}
},
{
"element_type" : "panel",
"panel_element" : {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2216,6 +2216,20 @@
},
"nutriscore_2023" : {
"elements" : [
{
"element_type" : "text",
"text_element" : {
"html" : "Warning: the nutrition facts are not specified. They have been estimated from the list of ingredients.\n ",
"type" : "warning"
}
},
{
"element_type" : "text",
"text_element" : {
"html" : "Warning: the amount of fruits, vegetables and nuts is not specified on the label, it was estimated from the list of ingredients: 62\n ",
"type" : "warning"
}
},
{
"element_type" : "panel",
"panel_element" : {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -876,6 +876,20 @@
},
"nutriscore_2023" : {
"elements" : [
{
"element_type" : "text",
"text_element" : {
"html" : "Attention : les valeurs nutritionnelles ne sont pas précisées. Elles ont été estimées à partir de la liste des ingrédients.\n ",
"type" : "warning"
}
},
{
"element_type" : "text",
"text_element" : {
"html" : "Avertissement : Le taux de fruits, légumes et noix n'est pas indiqué sur l'étiquette, il a été estimé en fonction de la liste des ingrédients : 62\n ",
"type" : "warning"
}
},
{
"element_type" : "panel",
"panel_element" : {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -876,6 +876,20 @@
},
"nutriscore_2023" : {
"elements" : [
{
"element_type" : "text",
"text_element" : {
"html" : "Warning: the nutrition facts are not specified. They have been estimated from the list of ingredients.\n ",
"type" : "warning"
}
},
{
"element_type" : "text",
"text_element" : {
"html" : "Warning: the amount of fruits, vegetables and nuts is not specified on the label, it was estimated from the list of ingredients: 62\n ",
"type" : "warning"
}
},
{
"element_type" : "panel",
"panel_element" : {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1570,6 +1570,20 @@
},
"nutriscore_2023" : {
"elements" : [
{
"element_type" : "text",
"text_element" : {
"html" : "Warning: the nutrition facts are not specified. They have been estimated from the list of ingredients.\n ",
"type" : "warning"
}
},
{
"element_type" : "text",
"text_element" : {
"html" : "Warning: the amount of fruits, vegetables and nuts is not specified on the label, it was estimated from the list of ingredients: 62\n ",
"type" : "warning"
}
},
{
"element_type" : "panel",
"panel_element" : {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2218,6 +2218,20 @@
},
"nutriscore_2023" : {
"elements" : [
{
"element_type" : "text",
"text_element" : {
"html" : "Warning: the nutrition facts are not specified. They have been estimated from the list of ingredients.\n ",
"type" : "warning"
}
},
{
"element_type" : "text",
"text_element" : {
"html" : "Warning: the amount of fruits, vegetables and nuts is not specified on the label, it was estimated from the list of ingredients: 62\n ",
"type" : "warning"
}
},
{
"element_type" : "panel",
"panel_element" : {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -877,6 +877,20 @@
},
"nutriscore_2023" : {
"elements" : [
{
"element_type" : "text",
"text_element" : {
"html" : "Attention : les valeurs nutritionnelles ne sont pas précisées. Elles ont été estimées à partir de la liste des ingrédients.\n ",
"type" : "warning"
}
},
{
"element_type" : "text",
"text_element" : {
"html" : "Avertissement : Le taux de fruits, légumes et noix n'est pas indiqué sur l'étiquette, il a été estimé en fonction de la liste des ingrédients : 62\n ",
"type" : "warning"
}
},
{
"element_type" : "panel",
"panel_element" : {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -877,6 +877,20 @@
},
"nutriscore_2023" : {
"elements" : [
{
"element_type" : "text",
"text_element" : {
"html" : "Warning: the nutrition facts are not specified. They have been estimated from the list of ingredients.\n ",
"type" : "warning"
}
},
{
"element_type" : "text",
"text_element" : {
"html" : "Warning: the amount of fruits, vegetables and nuts is not specified on the label, it was estimated from the list of ingredients: 62\n ",
"type" : "warning"
}
},
{
"element_type" : "panel",
"panel_element" : {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -558,9 +558,17 @@
"nutriscore_2023" : {
"elements" : [
{
"element_type" : "panel",
"panel_element" : {
"panel_id" : "nutriscore_description"
"element_type" : "text",
"text_element" : {
"html" : "The category of the product must be specified in order to compute the Nutri-Score.\n ",
"type" : "warning"
}
},
{
"element_type" : "text",
"text_element" : {
"html" : "The nutrition facts of the product must be specified in order to compute the Nutri-Score.<p>Missing nutrition facts: <b>Energy, Fat, Proteins, Saturated fat, Sodium, Sugars</b></p>\n ",
"type" : "warning"
}
},
{
Expand All @@ -572,6 +580,12 @@
"html" : "Could you add the information needed to compute the Nutri-Score?"
},
"element_type" : "action"
},
{
"element_type" : "panel",
"panel_element" : {
"panel_id" : "nutriscore_description"
}
}
],
"level" : "info",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -634,9 +634,10 @@
"nutriscore_2023" : {
"elements" : [
{
"element_type" : "panel",
"panel_element" : {
"panel_id" : "nutriscore_description"
"element_type" : "text",
"text_element" : {
"html" : "The nutrition facts of the product must be specified in order to compute the Nutri-Score.<p>Missing nutrition facts: <b>Fat, Proteins, Saturated fat, Sugars</b></p>\n ",
"type" : "warning"
}
},
{
Expand All @@ -647,6 +648,12 @@
"html" : "Could you add the information needed to compute the Nutri-Score?"
},
"element_type" : "action"
},
{
"element_type" : "panel",
"panel_element" : {
"panel_id" : "nutriscore_description"
}
}
],
"level" : "info",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -552,9 +552,10 @@
"nutriscore_2023" : {
"elements" : [
{
"element_type" : "panel",
"panel_element" : {
"panel_id" : "nutriscore_description"
"element_type" : "text",
"text_element" : {
"html" : "The nutrition facts of the product must be specified in order to compute the Nutri-Score.<p>Missing nutrition facts: <b>Energy, Fat, Proteins, Saturated fat, Sodium, Sugars</b></p>\n ",
"type" : "warning"
}
},
{
Expand All @@ -565,6 +566,12 @@
"html" : "Could you add the information needed to compute the Nutri-Score?"
},
"element_type" : "action"
},
{
"element_type" : "panel",
"panel_element" : {
"panel_id" : "nutriscore_description"
}
}
],
"level" : "info",
Expand Down
Loading

0 comments on commit a1b11eb

Please sign in to comment.