Skip to content

Commit

Permalink
feat: show which information is provided by manufacturers in product …
Browse files Browse the repository at this point in the history
…edit form (#10465)
  • Loading branch information
stephanegigandet authored Jun 20, 2024
1 parent b1c3192 commit d057ac4
Show file tree
Hide file tree
Showing 14 changed files with 414 additions and 207 deletions.
8 changes: 8 additions & 0 deletions cgi/product_multilingual.pl
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,8 @@ ($product_ref, $field, $language)
$template_data_ref_field->{display_lc} = $display_lc;
$template_data_ref_field->{autocomplete} = $autocomplete;
$template_data_ref_field->{fieldtype} = $Lang{$fieldtype}{$lc};
$template_data_ref_field->{owner_field} = is_owner_field($product_ref, $field);
$template_data_ref_field->{protected_field} = skip_protected_field($product_ref, $field, $User{moderator});

my $html_field = '';

Expand Down Expand Up @@ -1311,6 +1313,12 @@ ($product_ref, $field, $language)

}

# Determine which field has a value from the manufacturer and if it is protected
$nutriment_ref->{owner_field} = is_owner_field($product_ref, $nid);
$nutriment_ref->{protected_field} = skip_protected_field($product_ref, $nid, $User{moderator});
$nutriment_ref->{protected_field_prepared}
= skip_protected_field($product_ref, $nid . "_prepared", $User{moderator});

$nutriment_ref->{shown} = $shown;
$nutriment_ref->{enid} = $enid;
$nutriment_ref->{enidp} = $enidp;
Expand Down
5 changes: 2 additions & 3 deletions lib/ProductOpener/APIProductWrite.pm
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,8 @@ sub skip_protected_field ($product_ref, $field, $moderator = 0) {
# If we are on the public platform, and the field data has been imported from the producer platform
# ignore the field changes for non tag fields, unless made by a moderator
if ( (not $server_options{producers_platform})
and (defined $product_ref->{owner_fields})
and (defined $product_ref->{owner_fields}{$field})
and (not $moderator))
and (not $moderator)
and (is_owner_field($product_ref, $field)))
{
$log->debug(
"skipping field with a value set by the owner",
Expand Down
15 changes: 8 additions & 7 deletions lib/ProductOpener/Food.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3109,19 +3109,20 @@ sub assign_nutriments_values_from_request_parameters ($product_ref, $nutriment_t

next if $nid =~ /^nutrition-score/;

# Only moderators can update values for fields sent by the producer
if (skip_protected_field($product_ref, $nid, $can_edit_owner_fields)) {
next;
}

# Unit and label are the same for as sold and prepared nutrition table
my $enid = encodeURIComponent($nid);
my $unit = remove_tags_and_quote(decode utf8 => single_param("nutriment_${enid}_unit"));
my $label = remove_tags_and_quote(decode utf8 => single_param("nutriment_${enid}_label"));

# We can have nutrient values for the product as sold, or prepared
foreach my $product_type ("", "_prepared") {

# Only moderators can update values for fields sent by the producer
if (skip_protected_field($product_ref, $nid . $product_type, $can_edit_owner_fields)) {
next;
}

my $unit = remove_tags_and_quote(decode utf8 => single_param("nutriment_${enid}_unit"));
my $label = remove_tags_and_quote(decode utf8 => single_param("nutriment_${enid}_label"));

# do not delete values if the nutriment is not provided
next if (not defined single_param("nutriment_${enid}${product_type}"));

Expand Down
9 changes: 8 additions & 1 deletion lib/ProductOpener/Import.pm
Original file line number Diff line number Diff line change
Expand Up @@ -963,7 +963,14 @@ sub import_nutrients (
and ($Owner_id !~ /^org-database-/)
and ($Owner_id !~ /^org-label-/))
{
$product_ref->{owner_fields}{$nid} = $time;
$product_ref->{owner_fields}{$nid . $type} = $time;
# salt and sodium are linked
if ($nid eq "salt") {
$product_ref->{owner_fields}{"sodium" . $type} = $time;
}
elsif ($nid eq "sodium") {
$product_ref->{owner_fields}{"salt" . $type} = $time;
}
}
}
}
Expand Down
29 changes: 29 additions & 0 deletions lib/ProductOpener/Products.pm
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ BEGIN {
&analyze_and_enrich_product_data
&is_owner_field
); # symbols to export on request
%EXPORT_TAGS = (all => [@EXPORT_OK]);
}
Expand Down Expand Up @@ -3721,3 +3723,30 @@ sub analyze_and_enrich_product_data ($product_ref, $response_ref) {

return;
}

=head2 is_owner_field($product_ref, $field)
Return 1 if the field value was provided by the owner (producer) and the field is not a tag field.
=cut

sub is_owner_field ($product_ref, $field) {

if (
(defined $product_ref->{owner_fields})
and (
(defined $product_ref->{owner_fields}{$field})
# If the producer sent a field value for salt or sodium, the other value was automatically computed
or (($field =~ /^salt/) and (defined $product_ref->{owner_fields}{"sodium" . $'}))
or (($field =~ /^sodium/) and (defined $product_ref->{owner_fields}{"salt" . $'}))
)
# Even if the producer sent a tag field value, it was merged with existing values,
# and may have been updated by a contributor (e.g. to add a more precise category)
# So we don't consider them to be owner fields
and (not defined $tags_fields{$field})
)
{
return 1;
}
return 0;
}
8 changes: 8 additions & 0 deletions po/common/common.pot
Original file line number Diff line number Diff line change
Expand Up @@ -6932,6 +6932,14 @@ msgctxt "open_in_crm"
msgid "Open in CRM"
msgstr "Open in CRM"

msgctxt "information_provided_by_the_manufacturer"
msgid "Information provided by the manufacturer"
msgstr "Information provided by the manufacturer"

msgctxt "information_provided_by_the_manufacturer_edit_form"
msgid "Information identified by a factory icon has been provided by the manufacturer. It can be changed only by the manufacturer and moderators. If it is out of date or incorrect, please let us know."
msgstr "Information identified by a factory icon has been provided by the manufacturer. It can be changed only by the manufacturer and moderators. If it is out of date or incorrect, please let us know."

msgctxt "knowledge_panels_did_you_know"
msgid "Did you know?"
msgstr "Did you know?"
Expand Down
8 changes: 8 additions & 0 deletions po/common/en.po
Original file line number Diff line number Diff line change
Expand Up @@ -6950,6 +6950,14 @@ msgctxt "open_in_crm"
msgid "Open in CRM"
msgstr "Open in CRM"

msgctxt "information_provided_by_the_manufacturer"
msgid "Information provided by the manufacturer"
msgstr "Information provided by the manufacturer"

msgctxt "information_provided_by_the_manufacturer_edit_form"
msgid "Information identified by a factory icon has been provided by the manufacturer. It can be changed only by the manufacturer and moderators. If it is out of date or incorrect, please let us know."
msgstr "Information identified by a factory icon has been provided by the manufacturer. It can be changed only by the manufacturer and moderators. If it is out of date or incorrect, please let us know."

msgctxt "knowledge_panels_did_you_know"
msgid "Did you know?"
msgstr "Did you know?"
Expand Down
7 changes: 5 additions & 2 deletions templates/web/pages/product_edit/display_input_field.tt.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@
[% IF language.defined %]
(<span class="tab_language">[% language %]</span>)
[% END %]
[% IF owner_field %]
<span class="material-icons size-20" title="[% edq(lang("information_provided_by_the_manufacturer")) %]">factory</span>
[% END %]
</label>

[% IF field.match('infocard') || field.match('^packaging_text') || field.match('^ingredients_text') %]
<textarea name="[% field %]" id="[% field %]" lang="${display_lc}">[% value %]</textarea>
<textarea [% IF protected_field %]disabled [% END %] name="[% field %]" id="[% field %]" lang="${display_lc}">[% value %]</textarea>
[% ELSE %]
<input type="text" name="[% field %]" id="[% field %]" class="text [% class %]" value="[% value %]" lang="[% display_lc %]" data-autocomplete="[% autocomplete %]" />
<input type="text" [% IF protected_field %]disabled [% END %]name="[% field %]" id="[% field %]" class="text [% class %]" value="[% value %]" lang="[% display_lc %]" data-autocomplete="[% autocomplete %]" />
[% END %]


Expand Down
29 changes: 22 additions & 7 deletions templates/web/pages/product_edit/product_edit_form_display.tt.html
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,17 @@ <h1>[% title %]</h1>
<a href="#" class="close">&times;</a>
</div>

[% IF product.owner %]
<div data-alert class="alert-box secondary" id="warning_protected_fields">
<p>
<span class="material-icons size-20" title="[% edq(lang("information_provided_by_the_manufacturer")) %]">factory</span>
<span>
[% lang("information_provided_by_the_manufacturer_edit_form") %]
</span>
<a href="#" class="close">&times;</a>
</div>
[% END %]

[% IF moderator %]
<ul id="manage_images_accordion" class="accordion" data-accordion>
<li class="accordion-navigation">
Expand Down Expand Up @@ -212,11 +223,15 @@ <h1>[% title %]</h1>
<td>
<!--label starts-->
[% IF nutriment.name.defined %]
[% IF nutriment.nid == 'energy-kj' || nutriment.nid == 'saturated-fat' || nutriment.nid == 'salt'|| nutriment.nid =='sugars' || nutriment.nid == 'fiber' || nutriment.nid =='fat' || nutriment.nid =='proteins' %]
<label class="nutriment_label" for="nutriment_[% nutriment.enid %]">[% nutriment.prefix %][% nutriment.name %]*</label>
[% ELSE %]
<label class="nutriment_label" for="nutriment_[% nutriment.enid %]">[% nutriment.prefix %][% nutriment.name %]</label>
[% END %]
<label class="nutriment_label" for="nutriment_[% nutriment.enid %]">
[% nutriment.prefix %][% nutriment.name %]
[% IF nutriment.nid == 'energy-kj' || nutriment.nid == 'saturated-fat' || nutriment.nid == 'salt'|| nutriment.nid =='sugars' || nutriment.nid == 'fiber' || nutriment.nid =='fat' || nutriment.nid =='proteins' %]
*
[% END %]
[% IF nutriment.owner_field %]
<span class="material-icons size-20" title="[% edq(lang("information_provided_by_the_manufacturer")) %]">factory</span>
[% END %]
</label>
[% ELSIF nutriment.label_value.defined %]
<input class="nutriment_label" id="nutriment_[% nutriment.enid %]_label" name="nutriment_[% nutriment.enid %]_label" value="[% nutriment.label_value %]" />
[% ELSE %]
Expand All @@ -226,12 +241,12 @@ <h1>[% title %]</h1>
</td>

<td class="nutriment_col" [% column_display_style_nutrition_data %]>
<input class="nutriment_value nutriment_value_as_sold soft-background" id="nutriment_[% nutriment.enid %]" name="nutriment_[% nutriment.enid %]" value="[% nutriment.value %]" [% nutriment.disabled %] autocomplete="off"/>
<input [% IF nutriment.protected_field %]disabled [% END %] class="nutriment_value nutriment_value_as_sold soft-background" id="nutriment_[% nutriment.enid %]" name="nutriment_[% nutriment.enid %]" value="[% nutriment.value %]" [% nutriment.disabled %] autocomplete="off"/>
<span id="nutriment_question_mark_[% nutriment.enid %]" class="question_mark">?</span>
<span id="nutriment_sugars_warning_[% nutriment.enid %]" class="sugars_warning">Please enter a valid value.</span>
</td>
<td class="nutriment_col_prepared" [% column_display_style_nutrition_data_prepared %]>
<input class="nutriment_value nutriment_value_prepared" id="nutriment_[% nutriment.enidp %]" name="nutriment_[% nutriment.enidp %]" value="[% nutriment.valuep %]" [% nutriment.disabled %] autocomplete="off"/>
<input [% IF nutriment.protected_field_p %]disabled [% END %] class="nutriment_value nutriment_value_prepared" id="nutriment_[% nutriment.enidp %]" name="nutriment_[% nutriment.enidp %]" value="[% nutriment.valuep %]" [% nutriment.disabled %] autocomplete="off"/>
</td>

[% IF nutriment.nid == 'alcohol' || nutriment.nid == 'energy-kj' || nutriment.nid == 'energy-kcal' %]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -496,23 +496,6 @@ <h2 class="panel_title_card text-medium">Contribution</h2>


</div>
</div>
<div style="margin-bottom:0.5rem">

<div>




<div class="panel_text">
<ul> <li id="data-error-en:ecoscore-production-system-no-label"> EcoScore - système de production - sans étiquette </li> </ul>
</div>



</div>


</div>
</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@
"product" : {
"_id" : "0200000000035",
"_keywords" : [
"bio",
"brand",
"category",
"changed",
"generic",
"havelaar",
"max",
"name",
"organic",
"product",
"protected",
"some",
"test",
"unknown"
"test"
],
"added_countries_tags" : [],
"additives_n" : 0,
Expand All @@ -36,11 +37,11 @@
"brands_tags" : [
"test-brand"
],
"categories" : "some unknown category",
"categories" : "Changed category",
"categories_hierarchy" : [
"en:some unknown category"
"fr:Changed category"
],
"categories_lc" : "en",
"categories_lc" : "fr",
"categories_properties" : {},
"categories_properties_tags" : [
"all-products",
Expand All @@ -51,7 +52,7 @@
"agribalyse-unknown"
],
"categories_tags" : [
"en:some-unknown-category"
"fr:changed-category"
],
"checkers_tags" : [],
"code" : "0200000000035",
Expand Down Expand Up @@ -93,13 +94,11 @@
"en:food-groups-2-unknown",
"en:food-groups-3-unknown",
"en:nutrition-value-under-0-001-g-salt",
"en:ecoscore-origins-of-ingredients-origins-are-100-percent-unknown",
"en:ecoscore-production-system-no-label"
"en:ecoscore-origins-of-ingredients-origins-are-100-percent-unknown"
],
"data_quality_warnings_tags" : [
"en:nutrition-value-under-0-001-g-salt",
"en:ecoscore-origins-of-ingredients-origins-are-100-percent-unknown",
"en:ecoscore-production-system-no-label"
"en:ecoscore-origins-of-ingredients-origins-are-100-percent-unknown"
],
"ecoscore_data" : {
"adjustments" : {
Expand Down Expand Up @@ -364,9 +363,10 @@
"value" : -8
},
"production_system" : {
"labels" : [],
"value" : 0,
"warning" : "no_label"
"labels" : [
"en:fairtrade-international"
],
"value" : 10
},
"threatened_species" : {
"ingredient" : "en:palm-oil",
Expand All @@ -378,7 +378,6 @@
},
"missing" : {
"agb_category" : 1,
"labels" : 1,
"origins" : 1
},
"missing_agribalyse_match_warning" : 1,
Expand Down Expand Up @@ -543,13 +542,19 @@
"interface_version_created" : "20150316.jqm2",
"interface_version_modified" : "20150316.jqm2",
"known_ingredients_n" : 10,
"labels" : "organic",
"labels" : "Bio, Max Havelaar",
"labels_hierarchy" : [
"en:organic"
"en:fair-trade",
"en:organic",
"en:fairtrade-international",
"en:max-havelaar"
],
"labels_lc" : "en",
"labels_lc" : "fr",
"labels_tags" : [
"en:organic"
"en:fair-trade",
"en:organic",
"en:fairtrade-international",
"en:max-havelaar"
],
"lang" : "en",
"languages" : {
Expand Down
Loading

0 comments on commit d057ac4

Please sign in to comment.