update table listing and add callbacks

This commit is contained in:
envoyr
2022-02-22 19:07:04 +01:00
parent 855e220d14
commit 8f7876b850
13 changed files with 189 additions and 192 deletions

View File

@@ -1,6 +1,4 @@
{% macro table(table_options, collection, action, title = "") %}
{% import "Froxlor/table/tablemacros.html.twig" as tablemacros %}
{% macro table(listing, action, title = "") %}
<form action="{{ action|default("") }}" method="post" enctype="application/x-www-form-urlencoded" class="form">
{% if title is not empty %}
@@ -16,39 +14,19 @@
<table class="table table-borderless table-striped mb-0">
<thead>
<tr>
{% for column in table_options.visible_columns %}
<th class="p-3">{{ table_options.columns[column].label }}</th>
{% for column in listing.table.th %}
<th class="p-3">{{ column }}</th>
{% endfor %}
{% if table_options.actions %}
<th class="p-3 text-end">Actions</th>
{% endif %}
</tr>
</thead>
<tbody>
{% for columns in collection.list %}
<tr class="{{ tablemacros.contextual_class(table_options.contextual_class, columns)|trim }}">
{% for column in table_options.visible_columns %}
{% for td in listing.table.tr %}
<tr>
{% for value in td %}
<td class="p-3">
{% if table_options.columns[column].type is empty %}
{{ tablemacros.column(columns, table_options.columns[column].column)|trim }}
{% elseif table_options.columns[column].type == 'boolean' %}
{{ tablemacros.boolean(tablemacros.column(columns, table_options.columns[column].column)|trim) }}
{% elseif table_options.columns[column].type == 'usage' %}
{{ tablemacros.usage(tablemacros.column(columns, table_options.columns[column].column)|trim) }}
{% endif %}
{{ value|raw }}
</td>
{% endfor %}
{% if table_options.actions %}
<th class="p-3 text-end">
{% for action in table_options.actions %}
{% if action.href is not empty %}
<a href="{{ action.href }}">{% if action.icon is not empty %}<i class="{{ action.icon }}"></i>{% endif %}{{ action.title }}</a>
{% else %}
{% if action.icon is not empty %}<i class="{{ action.icon }}"></i>{% endif %}{{ action.title }}
{% endif %}
{% endfor %}
</th>
{% endif %}
</tr>
{% endfor %}
</tbody>

View File

@@ -1,53 +0,0 @@
{% macro contextual_class(contextual_class, columns) %}
{# this could be refactored as filter #}
{% 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 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 %}
{% macro column(arr, str) %}
{# this could be refactored as filter #}
{% set strarr = str|split('.') %}
{% if strarr|length == 1 %}
{{ arr[strarr[0]] }}
{% elseif strarr|length == 2 %}
{{ arr[strarr[0]][strarr[1]] }}
{% else %}
column depth not supported
{% endif %}
{% endmacro %}