show note if no entries exist for a listing
Signed-off-by: Michael Kaufmann <d00p@froxlor.org>
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace Froxlor\UI;
|
||||
|
||||
use Froxlor\UI\Panel\UI;
|
||||
@@ -20,142 +21,143 @@ use Froxlor\UI\Panel\UI;
|
||||
*/
|
||||
class Listing
|
||||
{
|
||||
public static function format(Collection $collection, array $tabellisting): array
|
||||
{
|
||||
$collection = $collection->get();
|
||||
public static function format(Collection $collection, array $tabellisting): array
|
||||
{
|
||||
$collection = $collection->get();
|
||||
|
||||
return [
|
||||
'title' => $tabellisting['title'],
|
||||
'icon' => $tabellisting['icon'],
|
||||
'table' => [
|
||||
'th' => self::generateTableHeadings($tabellisting),
|
||||
'tr' => self::generateTableRows($collection['data']['list'], $tabellisting),
|
||||
],
|
||||
'pagination' => $collection['pagination'],
|
||||
];
|
||||
}
|
||||
return [
|
||||
'title' => $tabellisting['title'],
|
||||
'icon' => $tabellisting['icon'],
|
||||
'table' => [
|
||||
'th' => self::generateTableHeadings($tabellisting),
|
||||
'tr' => self::generateTableRows($collection['data']['list'], $tabellisting),
|
||||
],
|
||||
'pagination' => $collection['pagination'],
|
||||
'empty_msg' => $tabellisting['empty_msg'] ?? null
|
||||
];
|
||||
}
|
||||
|
||||
private static function generateTableHeadings(array $tabellisting): array
|
||||
{
|
||||
$heading = [];
|
||||
private static function generateTableHeadings(array $tabellisting): array
|
||||
{
|
||||
$heading = [];
|
||||
|
||||
// Table headings for columns
|
||||
foreach ($tabellisting['visible_columns'] as $visible_column) {
|
||||
if (isset($tabellisting['columns'][$visible_column]['visible']) && !$tabellisting['columns'][$visible_column]['visible']) {
|
||||
continue;
|
||||
}
|
||||
// Table headings for columns
|
||||
foreach ($tabellisting['visible_columns'] as $visible_column) {
|
||||
if (isset($tabellisting['columns'][$visible_column]['visible']) && !$tabellisting['columns'][$visible_column]['visible']) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$heading[$visible_column] = [
|
||||
'text' => $tabellisting['columns'][$visible_column]['label'],
|
||||
'class' => $tabellisting['columns'][$visible_column]['class'] ?? null,
|
||||
];
|
||||
}
|
||||
$heading[$visible_column] = [
|
||||
'text' => $tabellisting['columns'][$visible_column]['label'],
|
||||
'class' => $tabellisting['columns'][$visible_column]['class'] ?? null,
|
||||
];
|
||||
}
|
||||
|
||||
// Table headings for actions
|
||||
if (isset($tabellisting['actions'])) {
|
||||
$heading['actions'] = [
|
||||
'text' => UI::getLng('panel.options'),
|
||||
'class' => 'text-end',
|
||||
];
|
||||
}
|
||||
// Table headings for actions
|
||||
if (isset($tabellisting['actions'])) {
|
||||
$heading['actions'] = [
|
||||
'text' => UI::getLng('panel.options'),
|
||||
'class' => 'text-end',
|
||||
];
|
||||
}
|
||||
|
||||
return $heading;
|
||||
}
|
||||
return $heading;
|
||||
}
|
||||
|
||||
private static function generateTableRows(array $list, array $tabellisting): array
|
||||
{
|
||||
$rows = [];
|
||||
private static function generateTableRows(array $list, array $tabellisting): array
|
||||
{
|
||||
$rows = [];
|
||||
|
||||
// Create new row from item
|
||||
foreach ($list as $row => $item) {
|
||||
// Generate columns from item
|
||||
foreach ($tabellisting['visible_columns'] as $col => $visible_column) {
|
||||
if (isset($tabellisting['columns'][$visible_column]['visible']) && !$tabellisting['columns'][$visible_column]['visible']) {
|
||||
continue;
|
||||
}
|
||||
// Create new row from item
|
||||
foreach ($list as $row => $item) {
|
||||
// Generate columns from item
|
||||
foreach ($tabellisting['visible_columns'] as $col => $visible_column) {
|
||||
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'];
|
||||
$data = self::getMultiArrayFromString($item, $column);
|
||||
$format_callback = $tabellisting['columns'][$visible_column]['format_callback'] ?? null;
|
||||
$column = $tabellisting['columns'][$visible_column]['field'];
|
||||
$data = self::getMultiArrayFromString($item, $column);
|
||||
|
||||
if ($format_callback) {
|
||||
$rows[$row]['td'][$col]['data'] = call_user_func($format_callback, ['data' => $data, 'fields' => $item]);
|
||||
} else {
|
||||
$rows[$row]['td'][$col]['data'] = $data;
|
||||
}
|
||||
if ($format_callback) {
|
||||
$rows[$row]['td'][$col]['data'] = call_user_func($format_callback, ['data' => $data, 'fields' => $item]);
|
||||
} else {
|
||||
$rows[$row]['td'][$col]['data'] = $data;
|
||||
}
|
||||
|
||||
$rows[$row]['td'][$col]['class'] = $tabellisting['columns'][$visible_column]['class'] ?? null;
|
||||
}
|
||||
$rows[$row]['td'][$col]['class'] = $tabellisting['columns'][$visible_column]['class'] ?? null;
|
||||
}
|
||||
|
||||
// Set row classes from format_callback
|
||||
if (isset($tabellisting['format_callback'])) {
|
||||
// Set row classes from format_callback
|
||||
if (isset($tabellisting['format_callback'])) {
|
||||
$class = [];
|
||||
foreach ($tabellisting['format_callback'] as $format_callback) {
|
||||
$class[] = call_user_func($format_callback, ['fields' => $item]);
|
||||
}
|
||||
$rows[$row]['class'] = implode(' ', $class);
|
||||
}
|
||||
$rows[$row]['class'] = implode(' ', $class);
|
||||
}
|
||||
|
||||
// Set all actions for row
|
||||
if (isset($tabellisting['actions'])) {
|
||||
$actions = self::setLinks($tabellisting['actions'], $item);
|
||||
// Set all actions for row
|
||||
if (isset($tabellisting['actions'])) {
|
||||
$actions = self::setLinks($tabellisting['actions'], $item);
|
||||
|
||||
$rows[$row]['td'][] = [
|
||||
'class' => 'text-end',
|
||||
'data' => [
|
||||
'type' => 'actions',
|
||||
'data' => $actions
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
||||
$rows[$row]['td'][] = [
|
||||
'class' => 'text-end',
|
||||
'data' => [
|
||||
'type' => 'actions',
|
||||
'data' => $actions
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return $rows;
|
||||
}
|
||||
return $rows;
|
||||
}
|
||||
|
||||
private static function setLinks(array $actions, array $item): array
|
||||
{
|
||||
$linker = UI::getLinker();
|
||||
private static function setLinks(array $actions, array $item): array
|
||||
{
|
||||
$linker = UI::getLinker();
|
||||
|
||||
// Check each action for a href
|
||||
foreach ($actions as $key => $action) {
|
||||
// Set link if href is an array
|
||||
if (isset($action['href']) && is_array($action['href'])) {
|
||||
// Search for "columns" in our href array
|
||||
foreach ($action['href'] as $href_key => $href_value) {
|
||||
$length = strlen(':');
|
||||
if (substr($href_value, 0, $length) === ':') {
|
||||
$column = ltrim($href_value, ':');
|
||||
$action['href'][$href_key] = $item[$column];
|
||||
}
|
||||
}
|
||||
// Check each action for a href
|
||||
foreach ($actions as $key => $action) {
|
||||
// Set link if href is an array
|
||||
if (isset($action['href']) && is_array($action['href'])) {
|
||||
// Search for "columns" in our href array
|
||||
foreach ($action['href'] as $href_key => $href_value) {
|
||||
$length = strlen(':');
|
||||
if (substr($href_value, 0, $length) === ':') {
|
||||
$column = ltrim($href_value, ':');
|
||||
$action['href'][$href_key] = $item[$column];
|
||||
}
|
||||
}
|
||||
|
||||
// Set actual link from linker
|
||||
$actions[$key]['href'] = $linker->getLink($action['href']);
|
||||
}
|
||||
}
|
||||
// Set actual link from linker
|
||||
$actions[$key]['href'] = $linker->getLink($action['href']);
|
||||
}
|
||||
}
|
||||
|
||||
return $actions;
|
||||
}
|
||||
return $actions;
|
||||
}
|
||||
|
||||
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
|
||||
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
|
||||
|
||||
return $default_columns;
|
||||
}
|
||||
return $default_columns;
|
||||
}
|
||||
|
||||
public static function getMultiArrayFromString(array $arr, string $str)
|
||||
{
|
||||
foreach (explode('.', $str) as $key) {
|
||||
if (!array_key_exists($key, $arr)) {
|
||||
return null;
|
||||
}
|
||||
$arr = $arr[$key];
|
||||
}
|
||||
public static function getMultiArrayFromString(array $arr, string $str)
|
||||
{
|
||||
foreach (explode('.', $str) as $key) {
|
||||
if (!array_key_exists($key, $arr)) {
|
||||
return null;
|
||||
}
|
||||
$arr = $arr[$key];
|
||||
}
|
||||
|
||||
return $arr;
|
||||
}
|
||||
return $arr;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ return [
|
||||
'domain_list' => [
|
||||
'title' => $lng['admin']['domains'],
|
||||
'icon' => 'fa-solid fa-user',
|
||||
'empty_msg' => $lng['admin']['domain_nocustomeraddingavailable'],
|
||||
'columns' => [
|
||||
'd.domain_ace' => [
|
||||
'label' => $lng['domains']['domainname'],
|
||||
|
||||
@@ -24,22 +24,22 @@ return [
|
||||
'title' => $lng['admin']['plans']['plans'],
|
||||
'icon' => 'fa-solid fa-user',
|
||||
'columns' => [
|
||||
'p.name' => [
|
||||
'label' => $lng['admin']['plans']['name'],
|
||||
'field' => 'name',
|
||||
],
|
||||
'p.description' => [
|
||||
'label' => $lng['admin']['plans']['description'],
|
||||
'field' => 'description',
|
||||
],
|
||||
'p.adminname' => [
|
||||
'label' => $lng['admin']['admin'],
|
||||
'field' => 'adminname',
|
||||
],
|
||||
'p.ts' => [
|
||||
'label' => $lng['admin']['plans']['last_update'],
|
||||
'field' => 'ts',
|
||||
],
|
||||
'p.name' => [
|
||||
'label' => $lng['admin']['plans']['name'],
|
||||
'field' => 'name',
|
||||
],
|
||||
'p.description' => [
|
||||
'label' => $lng['admin']['plans']['description'],
|
||||
'field' => 'description',
|
||||
],
|
||||
'p.adminname' => [
|
||||
'label' => $lng['admin']['admin'],
|
||||
'field' => 'adminname',
|
||||
],
|
||||
'p.ts' => [
|
||||
'label' => $lng['admin']['plans']['last_update'],
|
||||
'field' => 'ts',
|
||||
],
|
||||
],
|
||||
'visible_columns' => Listing::getVisibleColumnsForListing('sslcertificates_list', [
|
||||
'p.name',
|
||||
@@ -47,26 +47,26 @@ return [
|
||||
'p.adminname',
|
||||
'p.ts',
|
||||
]),
|
||||
'actions' => [
|
||||
'edit' => [
|
||||
'icon' => 'fa fa-edit',
|
||||
'href' => [
|
||||
'section' => 'plans',
|
||||
'page' => 'overview',
|
||||
'action' => 'edit',
|
||||
'id' => ':id'
|
||||
],
|
||||
],
|
||||
'delete' => [
|
||||
'icon' => 'fa fa-trash',
|
||||
'class' => 'text-danger',
|
||||
'href' => [
|
||||
'section' => 'plans',
|
||||
'page' => 'overview',
|
||||
'action' => 'delete',
|
||||
'id' => ':id'
|
||||
],
|
||||
],
|
||||
]
|
||||
'actions' => [
|
||||
'edit' => [
|
||||
'icon' => 'fa fa-edit',
|
||||
'href' => [
|
||||
'section' => 'plans',
|
||||
'page' => 'overview',
|
||||
'action' => 'edit',
|
||||
'id' => ':id'
|
||||
],
|
||||
],
|
||||
'delete' => [
|
||||
'icon' => 'fa fa-trash',
|
||||
'class' => 'text-danger',
|
||||
'href' => [
|
||||
'section' => 'plans',
|
||||
'page' => 'overview',
|
||||
'action' => 'delete',
|
||||
'id' => ':id'
|
||||
],
|
||||
],
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user