make tables more customizable
This commit is contained in:
@@ -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">
|
||||
|
||||
40
templates/Froxlor/table/tablemacros.html.twig
Normal file
40
templates/Froxlor/table/tablemacros.html.twig
Normal 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 %}
|
||||
Reference in New Issue
Block a user