Skip to content

Commit

Permalink
feat: New design on producers platform (#8086)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephanegigandet committed Feb 16, 2023
1 parent 24133f3 commit 6fa8b28
Show file tree
Hide file tree
Showing 28 changed files with 403 additions and 468 deletions.
9 changes: 1 addition & 8 deletions cgi/product_multilingual.pl
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,11 @@ ()
if (($server_options{producers_platform})
and not((defined $Owner_id) and (($Owner_id =~ /^org-/) or ($User{moderator}) or $User{pro_moderator})))
{
return "";
display_error_and_exit(lang("no_owner_defined"), 200);
}

my $html = '';
my $template_data_ref_content = {};
$template_data_ref_content->{server_options_producers_platform} = $server_options{producers_platform};

$template_data_ref_content->{display_search_image_form} = display_search_image_form("block_side");
process_template('web/common/includes/display_product_search_or_add.tt.html', $template_data_ref_content, \$html)
Expand Down Expand Up @@ -822,12 +821,7 @@ ($product_ref, $field, $language)
if ( (not((defined $server_options{private_products}) and ($server_options{private_products})))
and (defined $Org_id))
{

# Display a link to the producers platform

my $producers_platform_url = $formatted_subdomain . '/';
$producers_platform_url =~ s/\.open/\.pro\.open/;

$template_data_ref_display->{producers_platform_url} = $producers_platform_url;
}

Expand All @@ -840,7 +834,6 @@ ($product_ref, $field, $language)
if ($User{moderator}) {
}

$template_data_ref_display->{server_options_private_products} = $server_options{private_products};
$template_data_ref_display->{org_id} = $Org_id;
$template_data_ref_display->{label_new_code} = $label_new_code;
$template_data_ref_display->{owner_id} = $Owner_id;
Expand Down
1 change: 0 additions & 1 deletion cgi/session.pl
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
if (defined $User_id) {

$template_data_ref->{user_name} = $User{name};
$template_data_ref->{server_options_producers} = $server_options{producers_platform};

my $next_action = single_param('next_action');
my $code = single_param('code');
Expand Down
2 changes: 0 additions & 2 deletions cgi/user.pl
Original file line number Diff line number Diff line change
Expand Up @@ -385,8 +385,6 @@

$template_data_ref->{user_org} = $user_ref->{org};

$template_data_ref->{server_options_producers_platform} = $server_options{producers_platform};

my $pro_url = "https://" . $subdomain . ".pro." . $server_domain . "/";
$template_data_ref->{add_user_pro_url} = sprintf(lang("add_user_you_can_edit_pro_promo"), $pro_url);

Expand Down
4 changes: 2 additions & 2 deletions docs/how-to-guides/pro-development.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ An explanation of the setup can be found at [pro-dev-setup.md](../explanations/p
If you want to see state of tasks, you can run:

```
docker-compose exec minion /opt/product-opener/scripts/minion.pl minion job
docker-compose exec minion /opt/product-opener/scripts/minion_producers.pl minion job
```
(add --help to see all options), or refer to https://docs.mojolicious.org/Minion/Command/minion/job

Expand All @@ -41,4 +41,4 @@ docker-compose exec postgres psql -U productopener -W minion
```
(password is given by `POSTGRES_PASSWORD` in `.env` and defaults to `productopener`)

Inspecting table minion, should help.
Inspecting table minion, should help.
17 changes: 9 additions & 8 deletions lib/ProductOpener/Config2_docker.pm
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,19 @@ BEGIN {
use vars @EXPORT_OK; # no 'my' keyword for these
use utf8;

# Set PRODUCERS_PLATFORM to a non empty and non 0 value to enable the producers platform
# by default, the producers platform is not activated
$producers_platform = $ENV{PRODUCERS_PLATFORM} ? 1 : 0;

# server constants
my $po_domain = $ENV{PRODUCT_OPENER_DOMAIN};
# $po_domain and $server_domain are prefixed by pro. on the producers platform
my $po_domain = $producers_platform ? "pro." . $ENV{PRODUCT_OPENER_DOMAIN} : $ENV{PRODUCT_OPENER_DOMAIN};
my $po_port = $ENV{PRODUCT_OPENER_PORT};
my $is_localhost = index($po_domain, 'localhost') != -1;

$server_domain = $is_localhost && $po_port != '80' ? "$po_domain:$po_port" : $po_domain;
@ssl_subdomains = $is_localhost ? qw() : qw(*);

# Set PRODUCERS_PLATFORM to a non empty and non 0 value to enable the producers platform
# by default, the producers platform is not activated
$producers_platform = $ENV{PRODUCERS_PLATFORM} ? 1 : 0;

# server paths
$data_root = "/mnt/podata";
$www_root = "/opt/product-opener/html";
Expand Down Expand Up @@ -112,9 +113,9 @@ $redis_url = $ENV{REDIS_URL};
private_products => $producers_platform, # 1 to make products visible only to the owner (producer platform)
producers_platform => $producers_platform,
minion_backend => {Pg => $postgres_url},
minion_local_queue => $producers_platform ? "pro.$server_domain" : $server_domain,
minion_export_queue => $server_domain,
cookie_domain => $po_domain,
minion_local_queue => $server_domain,
minion_export_queue => $ENV{PRODUCT_OPENER_DOMAIN},
cookie_domain => $ENV{PRODUCT_OPENER_DOMAIN},
export_servers => {public => "off", experiment => "off-exp"},
ip_whitelist_session_cookie => ["", ""],
export_data_root => "/mnt/podata/export",
Expand Down
161 changes: 31 additions & 130 deletions lib/ProductOpener/Display.pm
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,8 @@ sub process_template ($template_filename, $template_data_ref, $result_content_re

# Add functions and values that are passed to all templates

$template_data_ref->{server_options_private_products} = $server_options{private_products};
$template_data_ref->{server_options_producers_platform} = $server_options{producers_platform};
$template_data_ref->{producers_platform_url} = $producers_platform_url;
$template_data_ref->{server_domain} = $server_domain;
$template_data_ref->{static_subdomain} = $static_subdomain;
Expand Down Expand Up @@ -831,30 +833,16 @@ CSS

# call format_subdomain($subdomain) only once
$formatted_subdomain = format_subdomain($subdomain);
$producers_platform_url = $formatted_subdomain . '/';

# Change the color of the top nav bar for the platform for producers
# If we are not on the producers platform: add .pro
if ($server_options{producers_platform}) {
$styles .= <<CSS
.top-bar {
background: #a9e7ff;
}
.top-bar-section li:not(.has-form) a:not(.button) {
background: #a9e7ff;
}
.top-bar-section .has-form {
background: #a9e7ff;
}
CSS
;
$producers_platform_url =~ s/\.open/\.pro\.open/;
}

# Enable or disable user food preferences: used to compute attributes and to display
# personalized product scores and search results
if ( ((defined $options{product_type}) and ($options{product_type} eq "food"))
and (not $server_options{producers_platform}))
{
if (((defined $options{product_type}) and ($options{product_type} eq "food"))) {
$request_ref->{user_preferences} = 1;
}
else {
Expand All @@ -878,11 +866,6 @@ CSS
};
}

# Producers platform url

$producers_platform_url = $formatted_subdomain . '/';
$producers_platform_url =~ s/\.open/\.pro\.open/;

$log->debug(
"owner, org and user",
{
Expand Down Expand Up @@ -1030,51 +1013,39 @@ sub display_error_and_exit ($error_message, $status_code) {
# Specific index for producer on the platform for producers
sub display_index_for_producer ($request_ref) {

my $html = "";

# Check if there are data quality issues or improvement opportunities

my $template_data_ref = {facets => []};

foreach my $tagtype ("data_quality_errors_producers", "data_quality_warnings_producers", "improvements") {

my $count = count_products($request_ref, {$tagtype . "_tags" => {'$exists' => true, '$ne' => []}});

if ($count > 0) {
$html
.= "<p>&rarr; <a href=\"/"
. $tag_type_plural{$tagtype}{$lc} . "\">"
. lang("number_of_products_with_" . $tagtype)
. separator_before_colon($lc) . ": "
. $count
. "</a></p>";
push @{$template_data_ref->{facets}},
{
url => "/" . $tag_type_plural{$tagtype}{$lc},
number_of_products => lang("number_of_products_with_" . $tagtype),
count => $count,
};
}
}

$html .= "<h2>" . lang("your_products") . separator_before_colon($lc) . ":" . "</h2>";
$html .= '<p>&rarr; <a href="/cgi/import_file_upload.pl">' . lang("add_or_update_products") . '</a></p>';

# Display a message if some product updates have not been published yet

my $count = count_products($request_ref, {states_tags => "en:to-be-exported"});

my $message = "";

if ($count == 0) {
$message = lang("no_products_to_export");
if ($count == 1) {
$template_data_ref->{products_to_be_exported} = lang("one_product_will_be_exported");
}
elsif ($count == 1) {
$message = lang("one_product_will_be_exported");
}
else {
$message = sprintf(lang("n_products_will_be_exported"), $count);
elsif ($count > 1) {
$template_data_ref->{products_to_be_exported} = sprintf(lang("n_products_will_be_exported"), $count);
}

if ($count > 0) {
$html
.= "<p>"
. lang("some_product_updates_have_not_been_published_on_the_public_database") . "</p>" . "<p>"
. $message . "</p>"
. "&rarr; <a href=\"/cgi/export_products.pl\">$Lang{export_product_data_photos}{$lc}</a><br>";
}
my $html;

process_template('web/common/includes/producers_platform_front_page.tt.html', $template_data_ref, \$html)
|| return "template error: " . $tt->error();

return $html;
}
Expand Down Expand Up @@ -1115,7 +1086,12 @@ sub display_text ($request_ref) {
if (($textid eq 'index-pro') and (defined $Owner_id)) {
my $owner_user_or_org = $Owner_id;
if (defined $Org_id) {
$owner_user_or_org = $Org{name};
if ((defined $Org{name}) and ($Org{name} ne "")) {
$owner_user_or_org = $Org{name};
}
else {
$owner_user_or_org = $Org_id;
}
}
$html =~ s/<\/h1>/ - $owner_user_or_org<\/h1>/;
}
Expand Down Expand Up @@ -5211,16 +5187,16 @@ sub search_and_display_products ($request_ref, $query_ref, $sort_by, $limit, $pa
$fields = single_param('fields') || 'all';
}

my $customized_products = [];
my $customized_products_ref = [];

for my $product_ref (@{$request_ref->{structured_response}{products}}) {

my $customized_product_ref = customize_response_for_product($request_ref, $product_ref, $fields);

push @{$customized_products}, $customized_product_ref;
push @{$customized_products_ref}, $customized_product_ref;
}

$request_ref->{structured_response}{products} = $customized_products;
$request_ref->{structured_response}{products} = $customized_products_ref;

# Disable nested ingredients in ingredients field (bug #2883)

Expand Down Expand Up @@ -6675,39 +6651,6 @@ sub search_and_map_products ($request_ref, $query_ref, $graph_ref) {
return $html;
}

sub display_on_the_blog ($blocks_ref) {

if (open(my $IN, "<:encoding(UTF-8)", "$data_root/lang/$lang/texts/blog-foundation.html")) {

my $html = join('', (<$IN>));
push @{$blocks_ref},
{
'title' => lang("on_the_blog_title"),
'content' => lang("on_the_blog_content") . '<ul class="side-nav">' . $html . '</ul>',
'id' => 'on_the_blog',
};
close $IN;
}

return;
}

sub display_bottom_block ($blocks_ref) {

if (defined $Lang{bottom_content}{$lang}) {

my $html = lang("bottom_content");

push @{$blocks_ref},
{
'title' => lang("bottom_title"),
'content' => $html,
};
}

return;
}

sub display_page ($request_ref) {

$log->trace("Start of display_page") if $log->is_trace();
Expand All @@ -6734,17 +6677,9 @@ sub display_page ($request_ref) {
return;
}

if ($server_options{producers_platform}) {

$template_data_ref->{server_options_producers_platform} = $server_options{producers_platform};
}

not $request_ref->{blocks_ref} and $request_ref->{blocks_ref} = [];

my $title = $request_ref->{title};
my $description = $request_ref->{description};
my $content_ref = $request_ref->{content_ref};
my $blocks_ref = $request_ref->{blocks_ref};

my $meta_description = '';

Expand All @@ -6755,25 +6690,6 @@ sub display_page ($request_ref) {
my $type;
my $id;

# TODO: 2022/10/12 - in the new website design, we removed the side column where we displayed blocks
# Those blocks need to be migrated to the new design (if we want to keep them)
# and the corresponding code needs to be removed

$log->debug("displaying blocks") if $log->is_debug();

display_login_register($blocks_ref);

display_my_block($blocks_ref);

display_on_the_blog($blocks_ref);

#display_top_block($blocks_ref);

# Bottom block is used for donations, do not display it on the producers platform
if (not $server_options{producers_platform}) {
display_bottom_block($blocks_ref);
}

my $site = "<a href=\"/\">" . lang("site_name") . "</a>";

${$content_ref} =~ s/<SITE>/$site/g;
Expand Down Expand Up @@ -6928,15 +6844,6 @@ sub display_page ($request_ref) {
$template_data_ref->{langs} = $langs;
$template_data_ref->{selected_lang} = $selected_lang;

my $blocks = display_blocks($request_ref);
my $aside_blocks = $blocks;

# keep only the login block for off canvas
$aside_blocks =~ s/<!-- end off canvas blocks for small screens -->(.*)//s;

# change ids of the add product image upload form
$aside_blocks =~ s/block_side/block_aside/g;

# Join us on Slack <a href="http://slack.openfoodfacts.org">Slack</a>:
my $join_us_on_slack
= sprintf($Lang{footer_join_us_on}{$lc}, '<a href="https://slack.openfoodfacts.org">Slack</a>');
Expand Down Expand Up @@ -7034,9 +6941,7 @@ sub display_page ($request_ref) {

$template_data_ref->{search_terms} = ${search_terms};
$template_data_ref->{torso_class} = $torso_class;
$template_data_ref->{aside_blocks} = $aside_blocks;
$template_data_ref->{tagline} = $tagline;
$template_data_ref->{blocks} = $blocks;
$template_data_ref->{title} = $title;
$template_data_ref->{content} = $$content_ref;
$template_data_ref->{join_us_on_slack} = $join_us_on_slack;
Expand Down Expand Up @@ -7264,7 +7169,6 @@ sub display_product ($request_ref) {
my $product_id = product_id_for_owner($Owner_id, $code);

my $html = '';
my $blocks_ref = [];
my $title = undef;
my $description = "";

Expand Down Expand Up @@ -7978,8 +7882,6 @@ HTML

if ($server_options{producers_platform}) {

$template_data_ref->{server_options_producers_platform} = $server_options{producers_platform};

$template_data_ref->{display_data_quality_issues_and_improvement_opportunities}
= display_data_quality_issues_and_improvement_opportunities($product_ref);

Expand Down Expand Up @@ -8141,7 +8043,6 @@ JS
$request_ref->{content_ref} = \$html;
$request_ref->{title} = $title;
$request_ref->{description} = $description;
$request_ref->{blocks_ref} = $blocks_ref;
$request_ref->{page_type} = "product";
$request_ref->{page_format} = "banner";

Expand Down
Loading

0 comments on commit 6fa8b28

Please sign in to comment.