diff --git a/lib/Froxlor/UI/Listing.php b/lib/Froxlor/UI/Listing.php index 45711656..60994037 100644 --- a/lib/Froxlor/UI/Listing.php +++ b/lib/Froxlor/UI/Listing.php @@ -1,6 +1,8 @@ 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; } -} \ No newline at end of file +} diff --git a/lib/tablelisting/admin/tablelisting.admin.php b/lib/tablelisting/admin/tablelisting.admin.php index 709fa713..2ca091ba 100644 --- a/lib/tablelisting/admin/tablelisting.admin.php +++ b/lib/tablelisting/admin/tablelisting.admin.php @@ -69,7 +69,7 @@ return [ 'href' => '#', ], 'edit' => [ - 'text' => 'fa fa-pen', + 'text' => 'Edit', 'href' => '#', ] ], diff --git a/lib/tablelisting/admin/tablelisting.domain.php b/lib/tablelisting/admin/tablelisting.domain.php index 0ba3d01b..eabbd9f1 100644 --- a/lib/tablelisting/admin/tablelisting.domain.php +++ b/lib/tablelisting/admin/tablelisting.domain.php @@ -54,5 +54,15 @@ return [ 'c.loginname', 'd.aliasdomain', ]), + 'actions' => [ + 'delete' => [ + 'icon' => 'fa fa-trash', + 'href' => '#', + ], + 'edit' => [ + 'icon' => 'fa fa-edit', + 'href' => '#', + ] + ] ] ]; diff --git a/lng/english.lng.php b/lng/english.lng.php index 09d44e87..0cac2f3f 100644 --- a/lng/english.lng.php +++ b/lng/english.lng.php @@ -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'; \ No newline at end of file diff --git a/templates/Froxlor/table/callbacks.html.twig b/templates/Froxlor/table/callbacks.html.twig index 1ffbe3c8..3b7fd1fa 100644 --- a/templates/Froxlor/table/callbacks.html.twig +++ b/templates/Froxlor/table/callbacks.html.twig @@ -16,4 +16,21 @@ {% else %} {% 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 %} + + {% if action.icon is defined %} + + {% endif %} + {% if action.text is defined %} + {{ action.text }} + {% endif %} + + {% endapply %} + {% endif %} + {% endfor %} {% endmacro %} \ No newline at end of file diff --git a/templates/Froxlor/table/table.html.twig b/templates/Froxlor/table/table.html.twig index bdf0776b..60df5418 100644 --- a/templates/Froxlor/table/table.html.twig +++ b/templates/Froxlor/table/table.html.twig @@ -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 %}