make tables more customizable

This commit is contained in:
envoyr 2022-02-21 19:29:34 +01:00
parent 1e4da4850e
commit ffe536a57f
No known key found for this signature in database
GPG Key ID: 5A16F49AF96F462F
3 changed files with 81 additions and 6 deletions

View File

@ -34,24 +34,33 @@ return [
],
'diskspace' => [
'title' => $lng['customer']['diskspace'],
'type' => 'usage',
],
'diskspace_used' => [
'title' => $lng['customer']['diskspace'] . ' (' . $lng['panel']['used'] . ')',
'type' => 'usage',
],
'traffic' => [
'title' => $lng['customer']['traffic']
'title' => $lng['customer']['traffic'],
'type' => 'usage',
],
'traffic_used' => [
'title' => $lng['customer']['traffic'] . ' (' . $lng['panel']['used'] . ')'
'title' => $lng['customer']['traffic'] . ' (' . $lng['panel']['used'] . ')',
'type' => 'usage',
],
'deactivated' => [
'title' => $lng['admin']['deactivated']
'title' => $lng['admin']['deactivated'],
'type' => 'boolean',
],
],
'visible_columns' => getVisibleColumnsForListing('admin_list', [
'loginname',
'name',
'diskspace',
'diskspace_used',
'traffic',
'traffic_used',
'deactivated',
]),
'actions' => [
'delete' => [
@ -62,6 +71,22 @@ return [
'title' => 'Show',
'href' => '#',
]
],
'contextual_class' => [
'deactivated' => [
'value' => true,
'return' => 'bg-secondary'
],
'diskspace_used' => [
'column' => 'diskspace',
'operator' => '>=',
'return' => 'bg-danger'
],
'traffic_used' => [
'column' => 'traffic',
'operator' => '>=',
'return' => 'bg-danger'
],
]
]
];

View File

@ -1,5 +1,7 @@
{% macro table(table_options, api_response, action, title = "") %}
{% import "Froxlor/table/tablemacros.html.twig" as tablemacros %}
<form action="{{ action|default("") }}" method="post" enctype="application/x-www-form-urlencoded" class="form">
{% if title is not empty %}
<h3 class="page-header">
@ -23,10 +25,18 @@
</tr>
</thead>
<tbody>
{% for item in api_response.list %}
<tr>
{% for columns in api_response.list %}
<tr class="{{ tablemacros.contextual_class(table_options.contextual_class, columns)|trim }}">
{% for column in table_options.visible_columns %}
<td class="p-3">{{ item[column] }}</td>
<td class="p-3">
{% if table_options.columns[column].type is empty %}
{{ columns[column] }}
{% elseif table_options.columns[column].type == 'boolean' %}
{{ tablemacros.boolean(columns[column]) }}
{% elseif table_options.columns[column].type == 'usage' %}
{{ tablemacros.usage(columns[column]) }}
{% endif %}
</td>
{% endfor %}
{% if table_options.actions %}
<th class="p-3 text-end">

View File

@ -0,0 +1,40 @@
{% macro contextual_class(contextual_class, columns) %}
{% for i_key,i_column in columns %}
{% for c_key, c_column in contextual_class %}
{% if i_key == c_key %}
{% if c_column.value is not empty %}
{# check for values #}
{% if c_column.operator is empty and i_column == c_column.value %}
{{ c_column.return }}
{% elseif c_column.operator is not empty and c_column.operator == '>=' and i_column >= c_column.value %}
{{ c_column.return }}
{% elseif c_column.operator is not empty and c_column.operator == '<=' and i_column <= c_column.value %}
{{ c_column.return }}
{% endif %}
{% elseif c_column.column is not empty %}
check for {{ columns[c_column.column] }}
{# check for column #}
{% if c_column.operator is empty and columns[c_column.column] == i_column %}
{{ c_column.return }}
{% elseif c_column.operator is not empty and c_column.operator == '>=' and columns[c_column.column] >= i_column %}
{{ c_column.return }}
{% elseif c_column.operator is not empty and c_column.operator == '<=' and columns[c_column.column] <= i_column %}
{{ c_column.return }}
{% endif %}
{% endif %}
{% endif %}
{% endfor %}
{% endfor %}
{% endmacro %}
{% macro boolean(value) %}
{% if value %}
<i class="fa fa-check-circle"></i>
{% else %}
<i class="fa fa-times-circle"></i>
{% endif %}
{% endmacro %}
{% macro usage(value) %}
{{ value }}
{% endmacro %}