update listing, handle fields with or without callbacks or callbacks only
This commit is contained in:
@@ -28,7 +28,7 @@ class Domain
|
||||
// path or redirect
|
||||
if (preg_match('/^https?\:\/\//', $attributes['fields']['documentroot'])) {
|
||||
return [
|
||||
'type' => 'link',
|
||||
'macro' => 'link',
|
||||
'data' => [
|
||||
'text' => $attributes['fields']['documentroot'],
|
||||
'href' => $attributes['fields']['documentroot'],
|
||||
|
||||
@@ -24,7 +24,7 @@ class Email
|
||||
public static function account(array $attributes)
|
||||
{
|
||||
return [
|
||||
'type' => 'booleanWithInfo',
|
||||
'macro' => 'booleanWithInfo',
|
||||
'data' => [
|
||||
'checked' => $attributes['data'] != 0,
|
||||
'info' => $attributes['data'] != 0 ? PhpHelper::sizeReadable($attributes['fields']['mboxsize'], 'GiB', 'bi', '%01.' . (int)Settings::Get('panel.decimal_places') . 'f %s') : ''
|
||||
|
||||
@@ -26,7 +26,7 @@ class Impersonate
|
||||
if (UI::getCurrentUser()['adminid'] != $attributes['fields']['adminid']) {
|
||||
$linker = UI::getLinker();
|
||||
return [
|
||||
'type' => 'link',
|
||||
'macro' => 'link',
|
||||
'data' => [
|
||||
'text' => $attributes['data'],
|
||||
'href' => $linker->getLink([
|
||||
@@ -45,7 +45,7 @@ class Impersonate
|
||||
{
|
||||
$linker = UI::getLinker();
|
||||
return [
|
||||
'type' => 'link',
|
||||
'macro' => 'link',
|
||||
'data' => [
|
||||
'text' => $attributes['data'],
|
||||
'href' => $linker->getLink([
|
||||
|
||||
@@ -21,7 +21,7 @@ use Froxlor\UI\Panel\UI;
|
||||
*/
|
||||
class PHPConf
|
||||
{
|
||||
public static function domainList(array $attributes)
|
||||
public static function domainList(array $attributes): string
|
||||
{
|
||||
$idna = new IdnaWrapper;
|
||||
$domains = "";
|
||||
@@ -56,7 +56,7 @@ class PHPConf
|
||||
{
|
||||
$linker = UI::getLinker();
|
||||
return [
|
||||
'type' => 'link',
|
||||
'macro' => 'link',
|
||||
'data' => [
|
||||
'text' => $attributes['data'],
|
||||
'href' => $linker->getLink([
|
||||
|
||||
@@ -75,7 +75,7 @@ class ProgressBar
|
||||
}
|
||||
|
||||
return [
|
||||
'type' => 'progressbar',
|
||||
'macro' => 'progressbar',
|
||||
'data' => [
|
||||
'percent' => $percent,
|
||||
'style' => $style,
|
||||
|
||||
@@ -22,7 +22,7 @@ class SSLCertificate
|
||||
public static function domainWithSan(array $attributes): array
|
||||
{
|
||||
return [
|
||||
'type' => 'domainWithSan',
|
||||
'macro' => 'domainWithSan',
|
||||
'data' => [
|
||||
'domain' => $attributes['data'],
|
||||
'san' => implode(', ', $attributes['fields']['san'] ?? []),
|
||||
|
||||
@@ -27,7 +27,7 @@ class Text
|
||||
public static function boolean(array $attributes): array
|
||||
{
|
||||
return [
|
||||
'type' => 'boolean',
|
||||
'macro' => 'boolean',
|
||||
'data' => (bool)$attributes['data']
|
||||
];
|
||||
}
|
||||
|
||||
@@ -65,31 +65,37 @@ class Listing
|
||||
return $heading;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
private static function generateTableRows(array $list, array $tabellisting): array
|
||||
{
|
||||
$rows = [];
|
||||
|
||||
// Create new row from item
|
||||
foreach ($list as $row => $item) {
|
||||
foreach ($list as $row => $fields) {
|
||||
// Generate columns from item
|
||||
foreach ($tabellisting['visible_columns'] as $col => $visible_column) {
|
||||
// Continue if column is not visible
|
||||
if (isset($tabellisting['columns'][$visible_column]['visible']) && !$tabellisting['columns'][$visible_column]['visible']) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$format_callback = $tabellisting['columns'][$visible_column]['format_callback'] ?? null;
|
||||
$column = $tabellisting['columns'][$visible_column]['field'] ?? null;
|
||||
if (empty($column)) {
|
||||
throw new Exception('Column in "visible columns" specified that is not defined in "fields"');
|
||||
}
|
||||
$data = self::getMultiArrayFromString($item, $column);
|
||||
// Get data from filed if it is defined
|
||||
$field = $tabellisting['columns'][$visible_column]['field'] ?? null;
|
||||
$data = self::getMultiArrayFromString($fields, $field);
|
||||
|
||||
if ($format_callback) {
|
||||
$rows[$row]['td'][$col]['data'] = call_user_func($format_callback, ['data' => $data, 'fields' => $item]);
|
||||
} else {
|
||||
// Call user function for given column if defined or return data from field, otherwise throw exception
|
||||
$callback = $tabellisting['columns'][$visible_column]['callback'] ?? null;
|
||||
if ($callback) {
|
||||
$rows[$row]['td'][$col]['data'] = call_user_func($callback, ['data' => $data, 'fields' => $fields]);
|
||||
} elseif ($field) {
|
||||
$rows[$row]['td'][$col]['data'] = $data;
|
||||
} else {
|
||||
throw new Exception('The visible column "'. $visible_column .'" has neither a "callback" nor a "field" set.');
|
||||
}
|
||||
|
||||
// Set class for table-row if defined
|
||||
$rows[$row]['td'][$col]['class'] = $tabellisting['columns'][$visible_column]['class'] ?? null;
|
||||
}
|
||||
|
||||
@@ -97,19 +103,19 @@ class Listing
|
||||
if (isset($tabellisting['format_callback'])) {
|
||||
$class = [];
|
||||
foreach ($tabellisting['format_callback'] as $format_callback) {
|
||||
$class[] = call_user_func($format_callback, ['fields' => $item]);
|
||||
$class[] = call_user_func($format_callback, ['fields' => $fields]);
|
||||
}
|
||||
$rows[$row]['class'] = implode(' ', $class);
|
||||
}
|
||||
|
||||
// Set all actions for row
|
||||
if (isset($tabellisting['actions'])) {
|
||||
$actions = self::setLinks($tabellisting['actions'], $item);
|
||||
$actions = self::setLinks($tabellisting['actions'], $fields);
|
||||
|
||||
$rows[$row]['td'][] = [
|
||||
'class' => 'text-end',
|
||||
'data' => [
|
||||
'type' => 'actions',
|
||||
'macro' => 'actions',
|
||||
'data' => $actions
|
||||
]
|
||||
];
|
||||
@@ -151,14 +157,14 @@ class Listing
|
||||
|
||||
public static function getVisibleColumnsForListing(string $listing, array $default_columns): array
|
||||
{
|
||||
// Hier käme dann die Logik, die das aus der DB zieht ...
|
||||
// alternativ nimmt er die $default_columns, wenn kein Eintrag
|
||||
// in der DB definiert ist
|
||||
// Here would come the logic that pulls this from the DB ...
|
||||
// alternatively, it takes the $default_columns if no entry is
|
||||
// defined in the DB
|
||||
|
||||
return $default_columns;
|
||||
}
|
||||
|
||||
public static function getMultiArrayFromString(array $arr, string $str)
|
||||
public static function getMultiArrayFromString(array $arr, ?string $str)
|
||||
{
|
||||
foreach (explode('.', $str) as $key) {
|
||||
if (!array_key_exists($key, $arr)) {
|
||||
|
||||
@@ -48,18 +48,18 @@ return [
|
||||
'diskspace' => [
|
||||
'label' => $lng['customer']['diskspace'],
|
||||
'field' => 'diskspace',
|
||||
'format_callback' => [ProgressBar::class, 'diskspace'],
|
||||
'callback' => [ProgressBar::class, 'diskspace'],
|
||||
],
|
||||
'traffic' => [
|
||||
'label' => $lng['customer']['traffic'],
|
||||
'field' => 'traffic',
|
||||
'format_callback' => [ProgressBar::class, 'traffic'],
|
||||
'callback' => [ProgressBar::class, 'traffic'],
|
||||
],
|
||||
'deactivated' => [
|
||||
'label' => $lng['admin']['deactivated'],
|
||||
'field' => 'deactivated',
|
||||
'class' => 'text-center',
|
||||
'format_callback' => [Text::class, 'boolean'],
|
||||
'callback' => [Text::class, 'boolean'],
|
||||
],
|
||||
],
|
||||
'visible_columns' => Listing::getVisibleColumnsForListing('admin_list', [
|
||||
@@ -93,7 +93,7 @@ return [
|
||||
],
|
||||
],
|
||||
],
|
||||
'format_callback' => [
|
||||
'callback' => [
|
||||
[Style::class, 'deactivated'],
|
||||
[Style::class, 'diskspaceWarning'],
|
||||
[Style::class, 'trafficWarning']
|
||||
|
||||
@@ -26,12 +26,12 @@ return [
|
||||
'c.description' => [
|
||||
'label' => $lng['cron']['description'],
|
||||
'field' => 'desc_lng_key',
|
||||
'format_callback' => [Text::class, 'crondesc']
|
||||
'callback' => [Text::class, 'crondesc']
|
||||
],
|
||||
'c.lastrun' => [
|
||||
'label' => $lng['cron']['lastrun'],
|
||||
'field' => 'lastrun',
|
||||
'format_callback' => [Text::class, 'timestamp']
|
||||
'callback' => [Text::class, 'timestamp']
|
||||
],
|
||||
'c.interval' => [
|
||||
'label' => $lng['cron']['interval'],
|
||||
@@ -40,7 +40,7 @@ return [
|
||||
'c.isactive' => [
|
||||
'label' => $lng['cron']['isactive'],
|
||||
'field' => 'isactive',
|
||||
'format_callback' => [Text::class, 'boolean']
|
||||
'callback' => [Text::class, 'boolean']
|
||||
],
|
||||
],
|
||||
'visible_columns' => Listing::getVisibleColumnsForListing('cron_list', [
|
||||
|
||||
@@ -30,17 +30,17 @@ return [
|
||||
'c.name' => [
|
||||
'label' => $lng['customer']['name'],
|
||||
'field' => 'name',
|
||||
'format_callback' => [Text::class, 'customerfullname'],
|
||||
'callback' => [Text::class, 'customerfullname'],
|
||||
],
|
||||
'c.loginname' => [
|
||||
'label' => $lng['login']['username'],
|
||||
'field' => 'loginname',
|
||||
'format_callback' => [Impersonate::class, 'customer'],
|
||||
'callback' => [Impersonate::class, 'customer'],
|
||||
],
|
||||
'a.loginname' => [
|
||||
'label' => $lng['admin']['admin'],
|
||||
'field' => 'admin.loginname',
|
||||
'format_callback' => [Impersonate::class, 'admin'],
|
||||
'callback' => [Impersonate::class, 'admin'],
|
||||
],
|
||||
'c.email' => [
|
||||
'label' => $lng['customer']['email'],
|
||||
@@ -49,12 +49,12 @@ return [
|
||||
'c.diskspace' => [
|
||||
'label' => $lng['customer']['diskspace'],
|
||||
'field' => 'diskspace',
|
||||
'format_callback' => [ProgressBar::class, 'diskspace'],
|
||||
'callback' => [ProgressBar::class, 'diskspace'],
|
||||
],
|
||||
'c.traffic' => [
|
||||
'label' => $lng['customer']['traffic'],
|
||||
'field' => 'traffic',
|
||||
'format_callback' => [ProgressBar::class, 'traffic'],
|
||||
'callback' => [ProgressBar::class, 'traffic'],
|
||||
],
|
||||
],
|
||||
'visible_columns' => Listing::getVisibleColumnsForListing('customer_list', [
|
||||
|
||||
@@ -34,12 +34,12 @@ return [
|
||||
'c.name' => [
|
||||
'label' => $lng['customer']['name'],
|
||||
'field' => 'customer.name',
|
||||
'format_callback' => [Text::class, 'customerfullname'],
|
||||
'callback' => [Text::class, 'customerfullname'],
|
||||
],
|
||||
'c.loginname' => [
|
||||
'label' => $lng['login']['username'],
|
||||
'field' => 'customer.loginname',
|
||||
'format_callback' => [Impersonate::class, 'customer'],
|
||||
'callback' => [Impersonate::class, 'customer'],
|
||||
],
|
||||
'd.aliasdomain' => [
|
||||
'label' => $lng['domains']['aliasdomain'],
|
||||
|
||||
@@ -30,8 +30,7 @@ return [
|
||||
],
|
||||
'configs' => [
|
||||
'label' => $lng['admin']['phpsettings']['activephpconfigs'],
|
||||
'field' => 'configs',
|
||||
'text' => [PHPConf::class, 'configsList']
|
||||
'callback' => [PHPConf::class, 'configsList']
|
||||
],
|
||||
'reload_cmd' => [
|
||||
'label' => $lng['serversettings']['phpfpm_settings']['reload'],
|
||||
|
||||
@@ -38,40 +38,40 @@ return [
|
||||
'label' => 'Listen',
|
||||
'field' => 'listen_statement',
|
||||
'class' => 'text-center',
|
||||
'format_callback' => [Text::class, 'boolean'],
|
||||
'callback' => [Text::class, 'boolean'],
|
||||
'visible' => Settings::Get('system.webserver') != 'nginx'
|
||||
],
|
||||
'namevirtualhost' => [
|
||||
'label' => 'NameVirtualHost',
|
||||
'field' => 'namevirtualhost_statement',
|
||||
'class' => 'text-center',
|
||||
'format_callback' => [Text::class, 'boolean'],
|
||||
'callback' => [Text::class, 'boolean'],
|
||||
'visible' => Settings::Get('system.webserver') == 'apache2' && (int)Settings::Get('system.apache24') == 0
|
||||
],
|
||||
'vhostcontainer' => [
|
||||
'label' => 'vHost-Container',
|
||||
'field' => 'vhostcontainer',
|
||||
'class' => 'text-center',
|
||||
'format_callback' => [Text::class, 'boolean']
|
||||
'callback' => [Text::class, 'boolean']
|
||||
],
|
||||
'specialsettings' => [
|
||||
'label' => 'Specialsettings',
|
||||
'field' => 'specialsettings',
|
||||
'class' => 'text-center',
|
||||
'format_callback' => [Text::class, 'boolean']
|
||||
'callback' => [Text::class, 'boolean']
|
||||
],
|
||||
'servername' => [
|
||||
'label' => 'ServerName',
|
||||
'field' => 'vhostcontainer_servername_statement',
|
||||
'class' => 'text-center',
|
||||
'format_callback' => [Text::class, 'boolean'],
|
||||
'callback' => [Text::class, 'boolean'],
|
||||
'visible' => Settings::Get('system.webserver') == 'apache2'
|
||||
],
|
||||
'ssl' => [
|
||||
'label' => 'SSL',
|
||||
'field' => 'ssl',
|
||||
'class' => 'text-center',
|
||||
'format_callback' => [Text::class, 'boolean']
|
||||
'callback' => [Text::class, 'boolean']
|
||||
],
|
||||
],
|
||||
'visible_columns' => Listing::getVisibleColumnsForListing('ipsandports_list', [
|
||||
|
||||
@@ -32,13 +32,13 @@ return [
|
||||
'domains' => [
|
||||
'label' => $lng['admin']['phpsettings']['activedomains'],
|
||||
'field' => 'domains',
|
||||
'text' => [PHPConf::class, 'domainList']
|
||||
'callback' => [PHPConf::class, 'domainList']
|
||||
],
|
||||
'fpmdesc' => [
|
||||
'label' => $lng['admin']['phpsettings']['fpmdesc'],
|
||||
'field' => 'fpmdesc',
|
||||
'visible' => (bool) Settings::Get('phpfpm.enabled'),
|
||||
'format_callback' => [PHPConf::class, 'fpmConfLink']
|
||||
'callback' => [PHPConf::class, 'fpmConfLink']
|
||||
],
|
||||
'c.binary' => [
|
||||
'label' => $lng['admin']['phpsettings']['binary'],
|
||||
|
||||
@@ -39,7 +39,7 @@ return [
|
||||
'p.ts' => [
|
||||
'label' => $lng['admin']['plans']['last_update'],
|
||||
'field' => 'ts',
|
||||
'format_callback' => [Text::class, 'timestamp'],
|
||||
'callback' => [Text::class, 'timestamp'],
|
||||
],
|
||||
],
|
||||
'visible_columns' => Listing::getVisibleColumnsForListing('plan_list', [
|
||||
|
||||
@@ -33,7 +33,7 @@ return [
|
||||
'c.domain' => [
|
||||
'label' => $lng['ssl_certificates']['certificate_for'],
|
||||
'field' => 'domain',
|
||||
'format_callback' => [SSLCertificate::class, 'domainWithSan'],
|
||||
'callback' => [SSLCertificate::class, 'domainWithSan'],
|
||||
],
|
||||
'c.issuer' => [
|
||||
'label' => $lng['ssl_certificates']['issuer'],
|
||||
@@ -51,7 +51,7 @@ return [
|
||||
'label' => $lng['panel']['letsencrypt'],
|
||||
'field' => 'letsencrypt',
|
||||
'class' => 'text-center',
|
||||
'format_callback' => [Text::class, 'boolean'],
|
||||
'callback' => [Text::class, 'boolean'],
|
||||
'visible' => Settings::Get('system.le_froxlor_enabled'),
|
||||
],
|
||||
],
|
||||
|
||||
@@ -31,7 +31,7 @@ return [
|
||||
'd.documentroot' => [
|
||||
'label' => $lng['panel']['path'],
|
||||
'field' => 'documentroot',
|
||||
'format_callback' => [Domain::class, 'domainTarget'],
|
||||
'callback' => [Domain::class, 'domainTarget'],
|
||||
]
|
||||
],
|
||||
'visible_columns' => Listing::getVisibleColumnsForListing('domain_list', [
|
||||
|
||||
@@ -38,12 +38,12 @@ return [
|
||||
'm.popaccountid' => [
|
||||
'label' => $lng['emails']['account'],
|
||||
'field' => 'popaccountid',
|
||||
'format_callback' => [Email::class, 'account'],
|
||||
'callback' => [Email::class, 'account'],
|
||||
],
|
||||
'm.iscatchall' => [
|
||||
'label' => $lng['emails']['catchall'],
|
||||
'field' => 'iscatchall',
|
||||
'format_callback' => [Text::class, 'boolean'],
|
||||
'callback' => [Text::class, 'boolean'],
|
||||
'visible' => Settings::Get('catchall.catchall_enabled') == '1'
|
||||
],
|
||||
'm.quota' => [
|
||||
|
||||
@@ -36,7 +36,7 @@ return [
|
||||
'homedir' => [
|
||||
'label' => $lng['panel']['path'],
|
||||
'field' => 'homedir',
|
||||
'format_callback' => [Ftp::class, 'pathRelative']
|
||||
'callback' => [Ftp::class, 'pathRelative']
|
||||
],
|
||||
'shell' => [
|
||||
'label' => $lng['panel']['shell'],
|
||||
|
||||
@@ -28,12 +28,12 @@ return [
|
||||
'path' => [
|
||||
'label' => $lng['panel']['path'],
|
||||
'field' => 'path',
|
||||
'format_callback' => [Ftp::class, 'pathRelative']
|
||||
'callback' => [Ftp::class, 'pathRelative']
|
||||
],
|
||||
'option_indexes' => [
|
||||
'label' => $lng['extras']['view_directory'],
|
||||
'field' => 'option_indexes',
|
||||
'format_callback' => [Text::class, 'boolean']
|
||||
'callback' => [Text::class, 'boolean']
|
||||
],
|
||||
'error404path' => [
|
||||
'label' => $lng['extras']['error404path'],
|
||||
@@ -50,7 +50,7 @@ return [
|
||||
'options_cgi' => [
|
||||
'label' => $lng['extras']['execute_perl'],
|
||||
'field' => 'options_cgi',
|
||||
'format_callback' => [Text::class, 'boolean'],
|
||||
'callback' => [Text::class, 'boolean'],
|
||||
'visible' => $cperlenabled
|
||||
]
|
||||
],
|
||||
|
||||
@@ -31,7 +31,7 @@ return [
|
||||
'path' => [
|
||||
'label' => $lng['panel']['path'],
|
||||
'field' => 'path',
|
||||
'format_callback' => [Ftp::class, 'pathRelative']
|
||||
'callback' => [Ftp::class, 'pathRelative']
|
||||
]
|
||||
],
|
||||
'visible_columns' => Listing::getVisibleColumnsForListing('htpasswd_list', [
|
||||
|
||||
@@ -36,12 +36,12 @@ return [
|
||||
'size' => [
|
||||
'label' => $lng['mysql']['size'],
|
||||
'field' => 'size',
|
||||
'format_callback' => [Text::class, 'size']
|
||||
'callback' => [Text::class, 'size']
|
||||
],
|
||||
'dbserver' => [
|
||||
'label' => $lng['mysql']['mysql_server'],
|
||||
'field' => 'dbserver',
|
||||
'format_callback' => [Mysql::class, 'dbserver'],
|
||||
'callback' => [Mysql::class, 'dbserver'],
|
||||
'visible' => $count_mysqlservers > 1
|
||||
]
|
||||
],
|
||||
|
||||
@@ -45,8 +45,10 @@
|
||||
{% macro domainWithSan(data) %}
|
||||
{{ data.domain }}
|
||||
{% if data.san is not empty %}
|
||||
<br/><span class="small">SAN:
|
||||
{{ data.san }}</span>
|
||||
<br/>
|
||||
<span class="small">
|
||||
SAN: {{ data.san }}
|
||||
</span>
|
||||
{% endif %}
|
||||
{% endmacro %}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{% macro table(listing) %}
|
||||
|
||||
{% import "Froxlor/table/callbacks.html.twig" as callbacks %}
|
||||
{% import "Froxlor/table/macros.html.twig" as macros %}
|
||||
{% import "Froxlor/table/pagination.html.twig" as pagination %}
|
||||
|
||||
<form action="{{ action|default("") }}" method="post" enctype="application/x-www-form-urlencoded" class="form">
|
||||
@@ -34,20 +34,21 @@
|
||||
{% for td in tr.td %}
|
||||
<td class="px-3{% if td.class is defined %} {{ td.class }}{% endif %}">
|
||||
{% if td.data is iterable %}
|
||||
{% if td.data.type == 'progressbar' %}
|
||||
{{ callbacks.progressbar(td.data.data) }}
|
||||
{% elseif td.data.type == 'boolean' %}
|
||||
{{ callbacks.boolean(td.data.data) }}
|
||||
{% elseif td.data.type == 'booleanWithInfo' %}
|
||||
{{ callbacks.booleanWithInfo(td.data.data) }}
|
||||
{% elseif td.data.type == 'link' %}
|
||||
{{ callbacks.link(td.data.data) }}
|
||||
{% elseif td.data.type == 'domainWithSan' %}
|
||||
{{ callbacks.domainWithSan(td.data.data) }}
|
||||
{% elseif td.data.type == 'actions' %}
|
||||
{{ callbacks.actions(td.data.data) }}
|
||||
{% if td.data.macro == 'progressbar' %}
|
||||
{{ macros.progressbar(td.data.data) }}
|
||||
{% elseif td.data.macro == 'boolean' %}
|
||||
{{ macros.boolean(td.data.data) }}
|
||||
{% elseif td.data.macro == 'booleanWithInfo' %}
|
||||
{{ macros.booleanWithInfo(td.data.data) }}
|
||||
{% elseif td.data.macro == 'link' %}
|
||||
{{ macros.link(td.data.data) }}
|
||||
{% elseif td.data.macro == 'domainWithSan' %}
|
||||
{{ macros.domainWithSan(td.data.data) }}
|
||||
{% elseif td.data.macro == 'actions' %}
|
||||
{{ macros.actions(td.data.data) }}
|
||||
{% else %}
|
||||
Callback '{{ td|json_encode }}' is not implemented!
|
||||
Table macro '{{ td.data.macro|json_encode }}' is not implemented!
|
||||
Unable to handle this data: {{ td.data|json_encode }}
|
||||
{% endif %}
|
||||
{% else %}
|
||||
{{ td.data|raw }}
|
||||
|
||||
Reference in New Issue
Block a user