add function to manage table columns

This commit is contained in:
envoyr
2022-04-22 10:59:56 +02:00
parent 03df082cf2
commit a615b04eb4
26 changed files with 110 additions and 22 deletions

View File

@@ -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']

View File

@@ -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']

View File

@@ -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) {

View File

@@ -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) {

View File

@@ -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']

View File

@@ -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'],

View File

@@ -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']

View File

@@ -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']

View File

@@ -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']
]);

View File

@@ -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']
]);

View File

@@ -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') ,
]);
}
}

View File

@@ -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']
]);

View File

@@ -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')
]);
}
}

View File

@@ -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']
]);

View File

@@ -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]),

View File

@@ -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);
}
}

View File

@@ -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;

View File

@@ -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',

View File

@@ -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',

View File

@@ -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.';

View File

@@ -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.';

View File

@@ -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') ,
]);

View File

@@ -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();
});
});

View File

@@ -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')

View File

@@ -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;

View File

@@ -10,6 +10,11 @@
<p>{{ listing.empty_msg|default(lng('panel.listing_empty'))|raw }}</p>
</div>
{% else %}
<div class="d-flex flex-column align-items-end mt-n2">
<div class="rounded-top bg-white small py-1 px-2 me-3 opacity-75" data-bs-toggle="modal" data-bs-target="#manageColumnsModal">
<i class="fa fa-cog"></i>
</div>
</div>
<div class="card table-responsive">
<table class="table table-borderless table-striped align-middle mb-0 px-3">
<thead>
@@ -57,4 +62,30 @@
{% endif %}
</form>
<!-- Modal -->
<div class="modal fade" id="manageColumnsModal" tabindex="-1" aria-labelledby="manageColumnsModalLabel" aria-hidden="true">
<div class="modal-dialog">
<form method="POST" class="modal-content" data-listing="{{ listing.id }}">
<div class="modal-header">
<h5 class="modal-title" id="manageColumnsModalLabel">{{ lng('panel.managetablecolumnsmodal.title') }}</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<p>{{ lng('panel.managetablecolumnsmodal.description') }}</p>
{% for key, column in listing.available_columns %}
<div class="form-check">
<input class="form-check-input" type="checkbox" value="" id="checkColumn{{ key }}" name="columns[{{ key }}]" {{ column.checked ? 'checked' : '' }}>
<label class="form-check-label" for="checkColumn{{ key }}">
{{ column.label }}
</label>
</div>
{% endfor %}
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">{{ lng('panel.modalclose') }}</button>
<button type="submit" class="btn btn-primary">{{ lng('panel.save') }}</button>
</div>
</form>
</div>
</div>
{% endmacro %}