add actions to the listing

This commit is contained in:
envoyr
2022-02-23 18:24:51 +01:00
parent 04263cb69f
commit c4940897a3
6 changed files with 77 additions and 14 deletions

View File

@@ -1,6 +1,8 @@
<?php
namespace Froxlor\UI;
use Froxlor\UI\Panel\UI;
/**
* This file is part of the Froxlor project.
* Copyright (c) 2010 the Froxlor Team (see authors).
@@ -20,18 +22,46 @@ class Listing
{
public static function format(Collection $collection, array $tabellisting): array
{
$items = $collection->getData()['list'];
$table = [];
return [
'title' => $tabellisting['title'],
'icon' => $tabellisting['icon'],
'table' => [
'th' => self::generateTableHeadings($tabellisting),
'tr' => self::generateTableRows($collection, $tabellisting),
],
'pagination' => null, // TODO: write some logic
];
}
foreach ($tabellisting['visible_columns'] as $key => $visible_column) {
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['th'][] = $tabellisting['columns'][$visible_column]['label'];
$heading[] = $tabellisting['columns'][$visible_column]['label'];
}
// Table headings for actions
if (isset($tabellisting['actions'])) {
$heading[] = UI::getLng('panel.actions');
}
return $heading;
}
private static function generateTableRows(Collection $collection, array $tabellisting): array
{
$rows = [];
$items = $collection->getData()['list'];
// Create new row from item
foreach ($items as $key => $item) {
// Generate columns from item
foreach ($tabellisting['visible_columns'] as $visible_column) {
if (isset($tabellisting['columns'][$visible_column]['visible']) && !$tabellisting['columns'][$visible_column]['visible']) {
continue;
@@ -44,19 +74,22 @@ class Listing
// TODO: contextual_class ...
if ($format_callback) {
$table['tr'][$key][] = call_user_func($format_callback, $data, $item);
$rows[$key][] = call_user_func($format_callback, $data, $item);
} else {
$table['tr'][$key][] = $data;
$rows[$key][] = $data;
}
}
// Set all actions for row
if (isset($tabellisting['actions'])) {
$rows[$key]['action'] = [
'type' => 'actions',
'data' => $tabellisting['actions'],
];
}
}
return [
'title' => $tabellisting['title'],
'icon' => $tabellisting['icon'],
'table' => $table,
'pagination' => null, // TODO: write some logic
];
return $rows;
}
public static function getVisibleColumnsForListing($listing, $default_columns)
@@ -79,4 +112,4 @@ class Listing
return $arr;
}
}
}

View File

@@ -69,7 +69,7 @@ return [
'href' => '#',
],
'edit' => [
'text' => 'fa fa-pen',
'text' => 'Edit',
'href' => '#',
]
],

View File

@@ -54,5 +54,15 @@ return [
'c.loginname',
'd.aliasdomain',
]),
'actions' => [
'delete' => [
'icon' => 'fa fa-trash',
'href' => '#',
],
'edit' => [
'icon' => 'fa fa-edit',
'href' => '#',
]
]
]
];

View File

@@ -2142,3 +2142,4 @@ $lng['serversettings']['acmeshpath']['description'] = 'Set this to where acme.sh
$lng['panel']['usage_statistics'] = 'Resource usage';
$lng['panel']['security_question'] = 'Security question';
$lng['panel']['actions'] = 'Actions';

View File

@@ -16,4 +16,21 @@
{% else %}
<i class="fa fa-times-circle"></i>
{% endif %}
{% endmacro %}
{% macro actions(data) %}
{% for action in data %}
{% if action.visible is not defined or action.visible is defined and action.visible %}
{% apply spaceless %}
<a href="{{ action.href }}" {% if action.target is defined %}target="{{ action.target }}"{% endif %}>
{% if action.icon is defined %}
<i class="{{ action.icon }}"></i>
{% endif %}
{% if action.text is defined %}
{{ action.text }}
{% endif %}
</a>
{% endapply %}
{% endif %}
{% endfor %}
{% endmacro %}

View File

@@ -31,6 +31,8 @@
{{ callbacks.progressbar(value.data) }}
{% elseif value.type == 'boolean' %}
{{ callbacks.boolean(value.data) }}
{% elseif value.type == 'actions' %}
{{ callbacks.actions(value.data) }}
{% else %}
Callback '{{ value|json_encode }}' is not implemented!
{% endif %}