add actions to the listing
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace Froxlor\UI;
|
namespace Froxlor\UI;
|
||||||
|
|
||||||
|
use Froxlor\UI\Panel\UI;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This file is part of the Froxlor project.
|
* This file is part of the Froxlor project.
|
||||||
* Copyright (c) 2010 the Froxlor Team (see authors).
|
* Copyright (c) 2010 the Froxlor Team (see authors).
|
||||||
@@ -20,18 +22,46 @@ class Listing
|
|||||||
{
|
{
|
||||||
public static function format(Collection $collection, array $tabellisting): array
|
public static function format(Collection $collection, array $tabellisting): array
|
||||||
{
|
{
|
||||||
$items = $collection->getData()['list'];
|
return [
|
||||||
$table = [];
|
'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']) {
|
if (isset($tabellisting['columns'][$visible_column]['visible']) && !$tabellisting['columns'][$visible_column]['visible']) {
|
||||||
continue;
|
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) {
|
foreach ($items as $key => $item) {
|
||||||
|
// Generate columns from item
|
||||||
foreach ($tabellisting['visible_columns'] as $visible_column) {
|
foreach ($tabellisting['visible_columns'] as $visible_column) {
|
||||||
if (isset($tabellisting['columns'][$visible_column]['visible']) && !$tabellisting['columns'][$visible_column]['visible']) {
|
if (isset($tabellisting['columns'][$visible_column]['visible']) && !$tabellisting['columns'][$visible_column]['visible']) {
|
||||||
continue;
|
continue;
|
||||||
@@ -44,19 +74,22 @@ class Listing
|
|||||||
// TODO: contextual_class ...
|
// TODO: contextual_class ...
|
||||||
|
|
||||||
if ($format_callback) {
|
if ($format_callback) {
|
||||||
$table['tr'][$key][] = call_user_func($format_callback, $data, $item);
|
$rows[$key][] = call_user_func($format_callback, $data, $item);
|
||||||
} else {
|
} 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 [
|
return $rows;
|
||||||
'title' => $tabellisting['title'],
|
|
||||||
'icon' => $tabellisting['icon'],
|
|
||||||
'table' => $table,
|
|
||||||
'pagination' => null, // TODO: write some logic
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getVisibleColumnsForListing($listing, $default_columns)
|
public static function getVisibleColumnsForListing($listing, $default_columns)
|
||||||
@@ -79,4 +112,4 @@ class Listing
|
|||||||
|
|
||||||
return $arr;
|
return $arr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ return [
|
|||||||
'href' => '#',
|
'href' => '#',
|
||||||
],
|
],
|
||||||
'edit' => [
|
'edit' => [
|
||||||
'text' => 'fa fa-pen',
|
'text' => 'Edit',
|
||||||
'href' => '#',
|
'href' => '#',
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -54,5 +54,15 @@ return [
|
|||||||
'c.loginname',
|
'c.loginname',
|
||||||
'd.aliasdomain',
|
'd.aliasdomain',
|
||||||
]),
|
]),
|
||||||
|
'actions' => [
|
||||||
|
'delete' => [
|
||||||
|
'icon' => 'fa fa-trash',
|
||||||
|
'href' => '#',
|
||||||
|
],
|
||||||
|
'edit' => [
|
||||||
|
'icon' => 'fa fa-edit',
|
||||||
|
'href' => '#',
|
||||||
|
]
|
||||||
|
]
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -2142,3 +2142,4 @@ $lng['serversettings']['acmeshpath']['description'] = 'Set this to where acme.sh
|
|||||||
|
|
||||||
$lng['panel']['usage_statistics'] = 'Resource usage';
|
$lng['panel']['usage_statistics'] = 'Resource usage';
|
||||||
$lng['panel']['security_question'] = 'Security question';
|
$lng['panel']['security_question'] = 'Security question';
|
||||||
|
$lng['panel']['actions'] = 'Actions';
|
||||||
@@ -16,4 +16,21 @@
|
|||||||
{% else %}
|
{% else %}
|
||||||
<i class="fa fa-times-circle"></i>
|
<i class="fa fa-times-circle"></i>
|
||||||
{% endif %}
|
{% 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 %}
|
{% endmacro %}
|
||||||
@@ -31,6 +31,8 @@
|
|||||||
{{ callbacks.progressbar(value.data) }}
|
{{ callbacks.progressbar(value.data) }}
|
||||||
{% elseif value.type == 'boolean' %}
|
{% elseif value.type == 'boolean' %}
|
||||||
{{ callbacks.boolean(value.data) }}
|
{{ callbacks.boolean(value.data) }}
|
||||||
|
{% elseif value.type == 'actions' %}
|
||||||
|
{{ callbacks.actions(value.data) }}
|
||||||
{% else %}
|
{% else %}
|
||||||
Callback '{{ value|json_encode }}' is not implemented!
|
Callback '{{ value|json_encode }}' is not implemented!
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|||||||
Reference in New Issue
Block a user