Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: display orgs data in table #10433

58 changes: 58 additions & 0 deletions cgi/display_org_table.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/usr/bin/perl -w

# This file is part of Product Opener.
#
# Product Opener
# Copyright (C) 2011-2023 Association Open Food Facts
# Contact: [email protected]
# 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 <https://www.gnu.org/licenses/>.

use ProductOpener::PerlStandards;

use CGI::Carp qw(fatalsToBrowser);
use ProductOpener::Config qw/:all/;
use ProductOpener::Display qw/:all/;
use ProductOpener::Lang qw/:all/;
use ProductOpener::Data qw/:all/;
use Log::Any qw($log);

use POSIX qw(strftime);

sub format_date {
my ($timestamp) = @_;
return strftime("%Y-%m-%d %H:%M:%S", localtime($timestamp));
}

TheSussex marked this conversation as resolved.
Show resolved Hide resolved
my $request_ref = ProductOpener::Display::init_request();

my $orgs_collection = get_orgs_collection();
my @orgs = $orgs_collection->find->all;

foreach my $org (@orgs) {
$org->{created_t_readable} = format_date($org->{created_t});
TheSussex marked this conversation as resolved.
Show resolved Hide resolved
}

my $template_data_ref = {lang => \&lang, orgs => \@orgs};
TheSussex marked this conversation as resolved.
Show resolved Hide resolved

my $html;
process_template('web/pages/dashboard/display_orgs_table.tt.html', $template_data_ref, \$html) or $html = '';
if ($tt->error()) {
$html .= '<p>' . $tt->error() . '</p>';
}

$request_ref->{title} = "Organization List";
$request_ref->{content_ref} = \$html;
display_page($request_ref);
16 changes: 16 additions & 0 deletions po/common/common.pot
Original file line number Diff line number Diff line change
Expand Up @@ -6905,3 +6905,19 @@ msgstr "AQUA/WATER, SODIUM LAURETH SULFATE, DISODIUM COCOAMPHODIACETATE, GLYCOL
msgctxt "report_problem_navigation"
msgid "Report a problem"
msgstr "Report a problem"

msgctxt "creator"
msgid "Creator"
msgstr "Creator"

msgctxt "org_id"
msgid "Org Id"
msgstr "Org Id"

msgctxt "verified_status"
msgid "Verified Status"
TheSussex marked this conversation as resolved.
Show resolved Hide resolved
msgstr "Verified Status"

msgctxt "creation_date"
msgid "Creation Date"
msgstr "Creation Date"
16 changes: 16 additions & 0 deletions po/common/en.po
Original file line number Diff line number Diff line change
Expand Up @@ -6923,3 +6923,19 @@ msgstr "AQUA/WATER, SODIUM LAURETH SULFATE, DISODIUM COCOAMPHODIACETATE, GLYCOL
msgctxt "report_problem_navigation"
msgid "Report a problem"
msgstr "Report a problem"

msgctxt "creator"
msgid "Creator"
msgstr "Creator"

msgctxt "org_id"
msgid "Org Id"
msgstr "Org Id"

msgctxt "verified_status"
msgid "Verified Status"
msgstr "Verified Status"

msgctxt "creation_date"
msgid "Creation Date"
msgstr "Creation Date"
15 changes: 15 additions & 0 deletions po/common/fr.po
Original file line number Diff line number Diff line change
Expand Up @@ -6920,3 +6920,18 @@ msgctxt "report_problem_navigation"
msgid "Signaler un problème"
msgstr "Signaler un problème"

msgctxt "creator"
msgid "Créateur"
msgstr "Créateur"

msgctxt "org_id"
msgid "Org Id"
msgstr "Org Id"

msgctxt "verified_status"
msgid "Statut Vérifié"
msgstr "Statut Vérifié"

msgctxt "creation_date"
msgid "Date de Création"
msgstr "Date de Création"
32 changes: 32 additions & 0 deletions templates/web/pages/dashboard/display_orgs_table.tt.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<!-- start templates/[% template.name %] -->

<div style="position:relative">
<table>
<thead>
<tr>
<th>[% lang("serial_no") %]</th>
<th>[% lang("name") %]</th>
<th>[% lang("creator") %]</th>
<th>[% lang("org_id") %]</th>
<th>[% lang("verified_status") %]</th>
<th>[% lang("creation_date") %]</th>
</tr>
</thead>
<tbody>
[% SET count = 1 %]
[% FOREACH org IN orgs %]
<tr>
<td>[% count %].</td>
<td>[% org.name %]</td>
<td>[% org.creator %]</td>
<td>[% org.org_id %]</td>
<td>[% IF org.validated == 0 %]false[% ELSE %]true[% END %]</td>
<td>[% org.created_t_readable %]</td>
</tr>
[% SET count = count + 1 %]
[% END %]
</tbody>
</table>
</div>

<!-- end templates/[% template.name %] -->
Loading