From 34a6c2c4902ddd92c2ba78f11f78b28dff507f2e Mon Sep 17 00:00:00 2001 From: TheSussex Date: Mon, 12 Aug 2024 09:30:50 +0100 Subject: [PATCH 1/6] make improvements to org table --- cgi/display_org_table.pl | 35 +++++++++++++++++-- po/common/common.pot | 10 +++++- po/common/en.po | 7 ++++ po/common/fr.po | 6 +++- templates/web/common/site_layout.tt.html | 5 +++ .../dashboard/display_orgs_table.tt.html | 2 +- 6 files changed, 59 insertions(+), 6 deletions(-) diff --git a/cgi/display_org_table.pl b/cgi/display_org_table.pl index 16c2bc66195f7..51a45779fca05 100644 --- a/cgi/display_org_table.pl +++ b/cgi/display_org_table.pl @@ -54,11 +54,14 @@ $query_ref->{name} = qr/\Q$name\E/i if defined $name && $name ne ''; $query_ref->{valid_org} = $valid_org if defined $valid_org && $valid_org ne ''; +$template_data_ref->{name} = $name; +$template_data_ref->{valid_org} = $valid_org; $template_data_ref->{query_filters} = [] unless defined $template_data_ref->{query_filters}; @orgs = $orgs_collection->find($query_ref)->sort({created_t => -1})->all; -$template_data_ref = {orgs => \@orgs, has_orgs => scalar @orgs > 0}; +$template_data_ref->{orgs} = \@orgs; +$template_data_ref->{has_orgs} = scalar @orgs > 0; my $html; process_template('web/pages/dashboard/display_orgs_table.tt.html', $template_data_ref, \$html) or $html = ''; @@ -73,22 +76,48 @@ info: "_TOTAL_ labels", infoFiltered: " - out of _MAX_" }, - paging: false, + paging: true, order: [[ 0, "asc" ]], + scrollX: true, + dom: 'Bfrtip', + buttons: [ + { + extend: 'colvis', + text: 'Column visibility', + columns: ':gt(1)' + } + ] }); JS ; $request_ref->{scripts} .= < + + SCRIPTS ; $request_ref->{header} .= <
+ + HEADER ; -$request_ref->{title} = "Organization List"; +$request_ref->{title} = lang("organization_list"); $request_ref->{content_ref} = \$html; display_page($request_ref); diff --git a/po/common/common.pot b/po/common/common.pot index 2c531d42c7b12..0f7db23190578 100644 --- a/po/common/common.pot +++ b/po/common/common.pot @@ -7106,4 +7106,12 @@ msgstr "Improvements" msgctxt "products_with_changes_since_last_export" msgid "Products with changes since last export" -msgstr "Products with changes since last export" \ No newline at end of file +msgstr "Products with changes since last export" + +msgctxt "organization_list" +msgid "Organization list" +msgstr "Organization list" + +msgctxt "serial_no" +msgid "S.No" +msgstr "S.No" \ No newline at end of file diff --git a/po/common/en.po b/po/common/en.po index 88a4be5211060..19aff479e7d3e 100644 --- a/po/common/en.po +++ b/po/common/en.po @@ -7094,3 +7094,10 @@ msgctxt "improvements_navigation" msgid "Improvements" msgstr "Improvements" +msgctxt "organization_list" +msgid "Organization list" +msgstr "Organization list" + +msgctxt "serial_no" +msgid "S.No" +msgstr "S.No" \ No newline at end of file diff --git a/po/common/fr.po b/po/common/fr.po index 6543b5efed0d3..92b71931174a0 100644 --- a/po/common/fr.po +++ b/po/common/fr.po @@ -6950,4 +6950,8 @@ msgstr "Glissez" msgctxt "select_product_data_file" msgid "Select a file with product data" -msgstr "Choisissez un fichier avec les données des produits" \ No newline at end of file +msgstr "Choisissez un fichier avec les données des produits" + +msgctxt "organization_list" +msgid "Liste des organisations" +msgstr "Liste des organisations" \ No newline at end of file diff --git a/templates/web/common/site_layout.tt.html b/templates/web/common/site_layout.tt.html index 7fcd9e2a74d6d..7cc61493bf7c4 100644 --- a/templates/web/common/site_layout.tt.html +++ b/templates/web/common/site_layout.tt.html @@ -76,6 +76,11 @@
  • [% lang('graphs_and_maps') %]
  • + [% IF pro_moderator or admin %] +
  • + [% lang('organization_list') %] +
  • + [% END %] diff --git a/templates/web/pages/dashboard/display_orgs_table.tt.html b/templates/web/pages/dashboard/display_orgs_table.tt.html index c519d8b38efc2..b216d3c47dcc1 100644 --- a/templates/web/pages/dashboard/display_orgs_table.tt.html +++ b/templates/web/pages/dashboard/display_orgs_table.tt.html @@ -24,7 +24,7 @@ - + [% IF has_orgs %] From f0959385481dc7165cb60e5c53711aa1e030167b Mon Sep 17 00:00:00 2001 From: TheSussex Date: Mon, 12 Aug 2024 12:47:40 +0100 Subject: [PATCH 2/6] replace creator with creator_email --- lib/ProductOpener/Orgs.pm | 10 +++ .../2024_08_update_org_with_creator_email.pl | 70 +++++++++++++++++++ .../dashboard/display_orgs_table.tt.html | 2 +- 3 files changed, 81 insertions(+), 1 deletion(-) create mode 100755 scripts/migrations/2024_08_update_org_with_creator_email.pl diff --git a/lib/ProductOpener/Orgs.pm b/lib/ProductOpener/Orgs.pm index 8aba9553d4983..c5f27fe332aa9 100644 --- a/lib/ProductOpener/Orgs.pm +++ b/lib/ProductOpener/Orgs.pm @@ -168,6 +168,16 @@ sub store_org ($org_ref) { # retrieve eventual previous values my $previous_org_ref = retrieve("$BASE_DIRS{ORGS}/" . $org_ref->{org_id} . ".sto"); + if (defined $org_ref->{creator}) { + my $creator_user_ref = retrieve_user($org_ref->{creator}); + if (defined $creator_user_ref) { + my $creator_email = $creator_user_ref->{email}; + if (defined $creator_email) { + $org_ref->{creator_email} = $creator_email; + } + } + } + if ( (defined $previous_org_ref) && $previous_org_ref->{valid_org} ne 'accepted' && $org_ref->{valid_org} eq 'accepted') diff --git a/scripts/migrations/2024_08_update_org_with_creator_email.pl b/scripts/migrations/2024_08_update_org_with_creator_email.pl new file mode 100755 index 0000000000000..5e30db9889249 --- /dev/null +++ b/scripts/migrations/2024_08_update_org_with_creator_email.pl @@ -0,0 +1,70 @@ +#!/usr/bin/perl -w + +# This file is part of Product Opener. +# +# Product Opener +# Copyright (C) 2011-2023 Association Open Food Facts +# Contact: contact@openfoodfacts.org +# Address: 21 rue des Iles, 94100 Saint-Maur des Fossés, France +# +# Product Opener is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +use Modern::Perl '2017'; +use utf8; +use ProductOpener::Data qw/:all/; +use ProductOpener::Orgs qw/list_org_ids retrieve_org/; +use ProductOpener::Users qw/retrieve_user/; +use ProductOpener::Paths qw/%BASE_DIRS/; +use ProductOpener::Store qw/:all/; + + +my $orgs_collection = get_orgs_collection(); + +sub main { + my @orgs = list_org_ids(); + my $count = scalar @orgs; + my $i = 0; + + foreach my $org_id (@orgs) { + my $org_ref = retrieve_org($org_id); + next if not defined $org_ref; + + my $creator_username = $org_ref->{creator}; + next if not defined $creator_username; + + my $creator_user_ref = retrieve_user($creator_username); + next if not defined $creator_user_ref; + + my $creator_email = $creator_user_ref->{email}; + next if not defined $creator_email; + + $org_ref->{creator_email} = $creator_email; + + my $return = $orgs_collection->update_one( + {"org_id" => $org_ref->{org_id}}, + {'$set' => {"creator_email" => $creator_email}} + ); + store("$BASE_DIRS{ORGS}/" . $org_ref->{org_id} . ".sto", $org_ref); + + print STDERR "Updated organization $org_id with creator's email $creator_email. Return: $return\n"; + $i++; + } + + print STDERR "$count organizations to update - $i organizations not empty or deleted\n"; + return; +} + +main(); + +exit(0); diff --git a/templates/web/pages/dashboard/display_orgs_table.tt.html b/templates/web/pages/dashboard/display_orgs_table.tt.html index b216d3c47dcc1..2b977ba0fbe5d 100644 --- a/templates/web/pages/dashboard/display_orgs_table.tt.html +++ b/templates/web/pages/dashboard/display_orgs_table.tt.html @@ -59,7 +59,7 @@ [% count %] [% org.name %] - [% org.creator %] + [% org.creator_email %] [% org.org_id %] From 50c521f91d6b3366a46a9ab1e51864330cd923d0 Mon Sep 17 00:00:00 2001 From: TheSussex Date: Mon, 19 Aug 2024 08:58:40 +0100 Subject: [PATCH 3/6] add buttons to datatable files --- cgi/display_org_table.pl | 3 - html/js/datatables.css | 1410 ++++++++++++++++++++++++++++-------- html/js/datatables.min.css | 21 +- html/js/datatables.min.js | 367 ++++------ po/common/common.pot | 4 - po/common/en.po | 4 - 6 files changed, 1233 insertions(+), 576 deletions(-) diff --git a/cgi/display_org_table.pl b/cgi/display_org_table.pl index 51a45779fca05..744ad7900db14 100644 --- a/cgi/display_org_table.pl +++ b/cgi/display_org_table.pl @@ -93,14 +93,11 @@ $request_ref->{scripts} .= < - - SCRIPTS ; $request_ref->{header} .= <
    -