From a615b04eb4c040b09a3ba91829b42c596e79eb41 Mon Sep 17 00:00:00 2001 From: envoyr Date: Fri, 22 Apr 2022 10:59:56 +0200 Subject: [PATCH] add function to manage table columns --- admin_admins.php | 2 +- admin_cronjobs.php | 2 +- admin_customers.php | 2 +- admin_domains.php | 2 +- admin_ipsandports.php | 2 +- admin_logger.php | 2 +- admin_phpsettings.php | 4 +-- admin_plans.php | 2 +- customer_domains.php | 2 +- customer_email.php | 2 +- customer_extras.php | 6 ++-- customer_ftp.php | 2 +- customer_logger.php | 2 +- customer_mysql.php | 2 +- dns_editor.php | 2 +- lib/Froxlor/Ajax/Ajax.php | 15 +++++++++ lib/Froxlor/UI/Listing.php | 9 ++++-- .../admin/tablelisting.customers.php | 5 +++ .../admin/tablelisting.domains.php | 5 +++ lng/english.lng.php | 2 ++ lng/german.lng.php | 2 ++ ssl_certificates.php | 2 +- .../Froxlor/src/js/components/tablecolumns.js | 21 +++++++++++++ templates/Froxlor/src/js/main.js | 1 + .../Froxlor/src/scss/variables/_main.scss | 3 +- templates/Froxlor/table/table.html.twig | 31 +++++++++++++++++++ 26 files changed, 110 insertions(+), 22 deletions(-) create mode 100644 templates/Froxlor/src/js/components/tablecolumns.js diff --git a/admin_admins.php b/admin_admins.php index 0dfda215..87b37b8b 100644 --- a/admin_admins.php +++ b/admin_admins.php @@ -42,7 +42,7 @@ if ($page == 'admins' && $userinfo['change_serversettings'] == '1') { } UI::view('user/table.html.twig', [ - 'listing' => \Froxlor\UI\Listing::format($collection, $admin_list_data['admin_list']), + 'listing' => \Froxlor\UI\Listing::format($collection, $admin_list_data, 'admin_list') , 'actions_links' => [[ 'href' => $linker->getLink(['section' => 'admins', 'page' => $page, 'action' => 'add']), 'label' => $lng['admin']['admin_add'] diff --git a/admin_cronjobs.php b/admin_cronjobs.php index fc25ff90..2fa9aaa2 100644 --- a/admin_cronjobs.php +++ b/admin_cronjobs.php @@ -37,7 +37,7 @@ if ($page == 'cronjobs' || $page == 'overview') { } UI::view('user/table-note.html.twig', [ - 'listing' => \Froxlor\UI\Listing::format($collection, $cron_list_data['cron_list']), + 'listing' => \Froxlor\UI\Listing::format($collection, $cron_list_data, 'cron_list') , // alert-box 'type' => 'warning', 'alert_msg' => $lng['cron']['changewarning'] diff --git a/admin_customers.php b/admin_customers.php index 762a5749..7e3dae48 100644 --- a/admin_customers.php +++ b/admin_customers.php @@ -52,7 +52,7 @@ if ($page == 'customers' && $userinfo['customers'] != '0') { } UI::view('user/table.html.twig', [ - 'listing' => \Froxlor\UI\Listing::format($collection, $customer_list_data['customer_list']), + 'listing' => \Froxlor\UI\Listing::format($collection, $customer_list_data, 'customer_list') , 'actions_links' => $actions_links ]); } elseif ($action == 'su' && $id != 0) { diff --git a/admin_domains.php b/admin_domains.php index 056d512f..b5e5cb47 100644 --- a/admin_domains.php +++ b/admin_domains.php @@ -59,7 +59,7 @@ if ($page == 'domains' || $page == 'overview') { } UI::view('user/table.html.twig', [ - 'listing' => \Froxlor\UI\Listing::format($collection, $domain_list_data['domain_list']), + 'listing' => \Froxlor\UI\Listing::format($collection, $domain_list_data, 'domain_list') , 'actions_links' => $actions_links ]); } elseif ($action == 'delete' && $id != 0) { diff --git a/admin_ipsandports.php b/admin_ipsandports.php index e99ca65e..8ba5e0d5 100644 --- a/admin_ipsandports.php +++ b/admin_ipsandports.php @@ -39,7 +39,7 @@ if ($page == 'ipsandports' || $page == 'overview') { } UI::view('user/table.html.twig', [ - 'listing' => \Froxlor\UI\Listing::format($collection, $ipsandports_list_data['ipsandports_list']), + 'listing' => \Froxlor\UI\Listing::format($collection, $ipsandports_list_data, 'ipsandports_list') , 'actions_links' => [[ 'href' => $linker->getLink(['section' => 'ipsandports', 'page' => $page, 'action' => 'add']), 'label' => $lng['admin']['ipsandports']['add'] diff --git a/admin_logger.php b/admin_logger.php index 94e37e66..e89af3b0 100644 --- a/admin_logger.php +++ b/admin_logger.php @@ -35,7 +35,7 @@ if ($page == 'log' && $userinfo['change_serversettings'] == '1') { } UI::view('user/table.html.twig', [ - 'listing' => \Froxlor\UI\Listing::format($collection, $syslog_list_data['syslog_list']), + 'listing' => \Froxlor\UI\Listing::format($collection, $syslog_list_data, 'syslog_list') , 'actions_links' => [[ 'href' => $linker->getLink(['section' => 'logger', 'page' => 'log', 'action' => 'truncate']), 'label' => $lng['logger']['truncate'], diff --git a/admin_phpsettings.php b/admin_phpsettings.php index 35202887..a6f76744 100644 --- a/admin_phpsettings.php +++ b/admin_phpsettings.php @@ -41,7 +41,7 @@ if ($page == 'overview') { } UI::view('user/table.html.twig', [ - 'listing' => \Froxlor\UI\Listing::format($collection, $phpconf_list_data['phpconf_list']), + 'listing' => \Froxlor\UI\Listing::format($collection, $phpconf_list_data, 'phpconf_list') , 'actions_links' => (bool)$userinfo['change_serversettings'] ? [[ 'href' => $linker->getLink(['section' => 'phpsettings', 'page' => $page, 'action' => 'add']), 'label' => $lng['admin']['phpsettings']['addnew'] @@ -185,7 +185,7 @@ if ($page == 'overview') { } UI::view('user/table.html.twig', [ - 'listing' => \Froxlor\UI\Listing::format($collection, $fpmconf_list_data['fpmconf_list']), + 'listing' => \Froxlor\UI\Listing::format($collection, $fpmconf_list_data, 'fpmconf_list') , 'actions_links' => (bool)$userinfo['change_serversettings'] ? [[ 'href' => $linker->getLink(['section' => 'phpsettings', 'page' => $page, 'action' => 'add']), 'label' => $lng['admin']['fpmsettings']['addnew'] diff --git a/admin_plans.php b/admin_plans.php index 30567aca..f68fc84d 100644 --- a/admin_plans.php +++ b/admin_plans.php @@ -41,7 +41,7 @@ if ($page == '' || $page == 'overview') { } UI::view('user/table.html.twig', [ - 'listing' => \Froxlor\UI\Listing::format($collection, $plan_list_data['plan_list']), + 'listing' => \Froxlor\UI\Listing::format($collection, $plan_list_data, 'plan_list') , 'actions_links' => [[ 'href' => $linker->getLink(['section' => 'plans', 'page' => $page, 'action' => 'add']), 'label' => $lng['admin']['plans']['add'] diff --git a/customer_domains.php b/customer_domains.php index a0803f3d..e6918a93 100644 --- a/customer_domains.php +++ b/customer_domains.php @@ -57,7 +57,7 @@ if ($page == 'overview' || $page == 'domains') { } UI::view('user/table.html.twig', [ - 'listing' => \Froxlor\UI\Listing::format($collection, $domain_list_data['domain_list']), + 'listing' => \Froxlor\UI\Listing::format($collection, $domain_list_data, 'domain_list') , 'actions_links' => $actions_links, 'entity_info' => $lng['domains']['description'] ]); diff --git a/customer_email.php b/customer_email.php index ee6fabee..27778ab5 100644 --- a/customer_email.php +++ b/customer_email.php @@ -65,7 +65,7 @@ if ($page == 'overview' || $page == 'emails') { } UI::view('user/table.html.twig', [ - 'listing' => \Froxlor\UI\Listing::format($collection, $email_list_data['email_list']), + 'listing' => \Froxlor\UI\Listing::format($collection, $email_list_data, 'email_list') , 'actions_links' => $actions_links, 'entity_info' => $lng['emails']['description'] ]); diff --git a/customer_extras.php b/customer_extras.php index 9fb89e81..eb502fe2 100644 --- a/customer_extras.php +++ b/customer_extras.php @@ -55,7 +55,7 @@ if ($page == 'overview' || $page == 'htpasswds') { } UI::view('user/table.html.twig', [ - 'listing' => \Froxlor\UI\Listing::format($collection, $htpasswd_list_data['htpasswd_list']), + 'listing' => \Froxlor\UI\Listing::format($collection, $htpasswd_list_data, 'htpasswd_list') , 'actions_links' => [[ 'href' => $linker->getLink(['section' => 'extras', 'page' => 'htpasswds', 'action' => 'add']), 'label' => $lng['extras']['directoryprotection_add'] @@ -171,7 +171,7 @@ if ($page == 'overview' || $page == 'htpasswds') { } UI::view('user/table.html.twig', [ - 'listing' => \Froxlor\UI\Listing::format($collection, $htaccess_list_data['htaccess_list']), + 'listing' => \Froxlor\UI\Listing::format($collection, $htaccess_list_data, 'htaccess_list'), 'actions_links' => [[ 'href' => $linker->getLink(['section' => 'extras', 'page' => 'htaccess', 'action' => 'add']), 'label' => $lng['extras']['pathoptions_add'] @@ -311,7 +311,7 @@ if ($page == 'overview' || $page == 'htpasswds') { UI::view('user/form-datatable.html.twig', [ 'formaction' => $linker->getLink(array('section' => 'extras')), 'formdata' => $backup_data['backup'], - 'tabledata' => \Froxlor\UI\Listing::format($collection, $backup_list_data['backup_list']), + 'tabledata' => \Froxlor\UI\Listing::format($collection, $backup_list_data, 'backup_list') , ]); } } diff --git a/customer_ftp.php b/customer_ftp.php index 58bd9f99..740f2c52 100644 --- a/customer_ftp.php +++ b/customer_ftp.php @@ -52,7 +52,7 @@ if ($page == 'overview' || $page == 'accounts') { } UI::view('user/table.html.twig', [ - 'listing' => \Froxlor\UI\Listing::format($collection, $ftp_list_data['ftp_list']), + 'listing' => \Froxlor\UI\Listing::format($collection, $ftp_list_data, 'ftp_list') , 'actions_links' => $actions_links, 'entity_info' => $lng['ftp']['description'] ]); diff --git a/customer_logger.php b/customer_logger.php index 2c6525f1..2d09efb8 100644 --- a/customer_logger.php +++ b/customer_logger.php @@ -38,7 +38,7 @@ if ($page == 'log') { \Froxlor\UI\Response::dynamic_error($e->getMessage()); } UI::view('user/table.html.twig', [ - 'listing' => \Froxlor\UI\Listing::format($collection, $syslog_list_data['syslog_list']) + 'listing' => \Froxlor\UI\Listing::format($collection, $syslog_list_data, 'syslog_list') ]); } } diff --git a/customer_mysql.php b/customer_mysql.php index 17f35a2f..a56e90c7 100644 --- a/customer_mysql.php +++ b/customer_mysql.php @@ -67,7 +67,7 @@ if ($page == 'overview' || $page == 'mysqls') { } UI::view('user/table.html.twig', [ - 'listing' => \Froxlor\UI\Listing::format($collection, $mysql_list_data['mysql_list']), + 'listing' => \Froxlor\UI\Listing::format($collection, $mysql_list_data, 'mysql_list') , 'actions_links' => $actions_links, 'entity_info' => $lng['mysql']['description'] ]); diff --git a/dns_editor.php b/dns_editor.php index 37c31071..6b812053 100644 --- a/dns_editor.php +++ b/dns_editor.php @@ -95,7 +95,7 @@ $zonefile = implode("\n", $result); $dns_add_data = include_once dirname(__FILE__) . '/lib/formfields/formfield.dns_add.php'; UI::view('user/dns-editor.html.twig', [ - 'listing' => \Froxlor\UI\Listing::format($collection, $dns_list_data['dns_list']), + 'listing' => \Froxlor\UI\Listing::format($collection, $dns_list_data, 'dns_list') , 'actions_links' => [[ 'class' => 'btn-secondary', 'href' => $linker->getLink(['section' => 'domains', 'page' => 'domains', 'action' => 'edit', 'id' => $domain_id]), diff --git a/lib/Froxlor/Ajax/Ajax.php b/lib/Froxlor/Ajax/Ajax.php index b11652c6..de9123a5 100644 --- a/lib/Froxlor/Ajax/Ajax.php +++ b/lib/Froxlor/Ajax/Ajax.php @@ -5,6 +5,7 @@ namespace Froxlor\Ajax; use Exception; use Froxlor\Http\HttpClient; use Froxlor\Settings; +use Froxlor\UI\Listing; use Froxlor\UI\Panel\UI; use Froxlor\UI\Request; @@ -107,6 +108,8 @@ class Ajax return $this->getUpdateCheck(); case 'searchglobal': return $this->searchGlobal(); + case 'tablelisting': + return $this->updateTablelisting(); default: return $this->errorResponse('Action not found!'); } @@ -236,4 +239,16 @@ class Ajax header("Content-type: application/json"); echo json_encode($result); } + + private function updateTablelisting() + { + $columns = []; + foreach (Request::get('columns') as $requestedColumn => $value) { + $columns[] = $requestedColumn; + } + + Listing::storeColumnListingForUser([Request::get('listing') => $columns]); + + return json_encode($columns); + } } diff --git a/lib/Froxlor/UI/Listing.php b/lib/Froxlor/UI/Listing.php index 0d88c4ad..98abd469 100644 --- a/lib/Froxlor/UI/Listing.php +++ b/lib/Froxlor/UI/Listing.php @@ -24,11 +24,13 @@ use Froxlor\CurrentUser; */ class Listing { - public static function format(Collection $collection, array $tabellisting): array + public static function format(Collection $collection, array $tabellisting, string $id): array { + $tabellisting = $tabellisting[$id]; $collection_data = $collection->get(); return [ + 'id' => $id, 'title' => $tabellisting['title'], 'description' => $tabellisting['description'] ?? null, 'icon' => $tabellisting['icon'] ?? null, @@ -186,7 +188,10 @@ class Listing $result = []; if (isset($tabellisting['columns'])) { foreach ($tabellisting['columns'] as $column => $coldata) { - $result[$column] = $coldata['label']; + $result[$column] = [ + 'label' => $coldata['label'], + 'checked' => in_array($column, $tabellisting['visible_columns']), + ]; } } return $result; diff --git a/lib/tablelisting/admin/tablelisting.customers.php b/lib/tablelisting/admin/tablelisting.customers.php index 6ae7ce0e..34acd63e 100644 --- a/lib/tablelisting/admin/tablelisting.customers.php +++ b/lib/tablelisting/admin/tablelisting.customers.php @@ -29,6 +29,11 @@ return [ 'icon' => 'fa-solid fa-user', 'self_overview' => ['section' => 'customers', 'page' => 'customers'], 'columns' => [ + 'c.customerid' => [ + 'label' => 'ID', + 'field' => 'customerid', + 'sortable' => true, + ], 'c.name' => [ 'label' => $lng['customer']['name'], 'field' => 'name', diff --git a/lib/tablelisting/admin/tablelisting.domains.php b/lib/tablelisting/admin/tablelisting.domains.php index f3bb8243..2590d6c0 100644 --- a/lib/tablelisting/admin/tablelisting.domains.php +++ b/lib/tablelisting/admin/tablelisting.domains.php @@ -28,6 +28,11 @@ return [ 'empty_msg' => $lng['admin']['domain_nocustomeraddingavailable'], 'self_overview' => ['section' => 'domains', 'page' => 'domains'], 'columns' => [ + 'd.id' => [ + 'label' => 'ID', + 'field' => 'id', + 'sortable' => true, + ], 'd.domain_ace' => [ 'label' => $lng['domains']['domainname'], 'field' => 'domain_ace', diff --git a/lng/english.lng.php b/lng/english.lng.php index 730c5055..43fb1ca1 100644 --- a/lng/english.lng.php +++ b/lng/english.lng.php @@ -2167,3 +2167,5 @@ $lng['panel']['settingsmodebasic'] = 'Basic'; $lng['panel']['settingsmodeadvanced'] = 'Advanced'; $lng['panel']['settingsmodetoggle'] = 'Click to toggle mode'; $lng['panel']['modalclose'] = 'Close'; +$lng['panel']['managetablecolumnsmodal']['title'] = 'Manage Table columns'; +$lng['panel']['managetablecolumnsmodal']['description'] = 'Here you can individualise the table columns for yourself.'; diff --git a/lng/german.lng.php b/lng/german.lng.php index 62113868..f9720c73 100644 --- a/lng/german.lng.php +++ b/lng/german.lng.php @@ -1805,3 +1805,5 @@ $lng['panel']['settingsmodebasic'] = 'Einfach'; $lng['panel']['settingsmodeadvanced'] = 'Erweitert'; $lng['panel']['settingsmodetoggle'] = 'Modus umschalten'; $lng['panel']['modalclose'] = 'Schließen'; +$lng['panel']['managetablecolumnsmodal']['title'] = 'Tabellenspalten verwalten'; +$lng['panel']['managetablecolumnsmodal']['description'] = 'Hier kannst du die Tabellenspalten für dich selbst individualisieren.'; diff --git a/ssl_certificates.php b/ssl_certificates.php index e1902074..1fdc4d13 100644 --- a/ssl_certificates.php +++ b/ssl_certificates.php @@ -62,5 +62,5 @@ try { } UI::view('user/table.html.twig', [ - 'listing' => Listing::format($collection, $certificates_list_data['sslcertificates_list']), + 'listing' => Listing::format($collection, $certificates_list_data, 'sslcertificates_list') , ]); diff --git a/templates/Froxlor/src/js/components/tablecolumns.js b/templates/Froxlor/src/js/components/tablecolumns.js new file mode 100644 index 00000000..09da15a0 --- /dev/null +++ b/templates/Froxlor/src/js/components/tablecolumns.js @@ -0,0 +1,21 @@ +$(document).ready(function () { + /* + * table columns - manage columns modal + */ + let form = $('#manageColumnsModal form'); + form.submit(function (event) { + $.ajax({ + url: 'lib/ajax.php?action=tablelisting&listing=' + form.data('listing') + '&theme=' + window.$theme, + type : 'POST', + dataType : 'json', + data : form.serialize(), + success : function (result) { + window.location.reload(); + }, + error: function (xhr, resp, text) { + console.log(xhr, resp, text); + } + }); + event.preventDefault(); + }); +}); diff --git a/templates/Froxlor/src/js/main.js b/templates/Froxlor/src/js/main.js index f5d4cf9c..613523ed 100644 --- a/templates/Froxlor/src/js/main.js +++ b/templates/Froxlor/src/js/main.js @@ -15,6 +15,7 @@ require('./components/search') require('./components/newsfeed') require('./components/updatecheck') require('./components/customer') +require('./components/tablecolumns') require('./components/ipsandports') require('./components/domains') require('./components/configfiles') diff --git a/templates/Froxlor/src/scss/variables/_main.scss b/templates/Froxlor/src/scss/variables/_main.scss index ec827443..bc7b8bd3 100644 --- a/templates/Froxlor/src/scss/variables/_main.scss +++ b/templates/Froxlor/src/scss/variables/_main.scss @@ -24,8 +24,9 @@ $input-bg: lighten($light-bg, 5%); $font-size-root: 16px; -// Space +// Spacing $spacer: 1.25rem; +$enable-negative-margins: true; // Body $body-bg: $light-bg; diff --git a/templates/Froxlor/table/table.html.twig b/templates/Froxlor/table/table.html.twig index 0f404b91..92ab6803 100644 --- a/templates/Froxlor/table/table.html.twig +++ b/templates/Froxlor/table/table.html.twig @@ -10,6 +10,11 @@

{{ listing.empty_msg|default(lng('panel.listing_empty'))|raw }}

{% else %} +
+
+ +
+
@@ -57,4 +62,30 @@ {% endif %} + + {% endmacro %}