added table-column ordering (#1086)

This commit is contained in:
Kevin Papst
2019-09-09 23:47:42 +02:00
committed by GitHub
parent d041a3f4f9
commit a651e55dc9
82 changed files with 932 additions and 516 deletions

View File

@@ -9,7 +9,7 @@
'customer': 'hidden-xs',
'project': 'hidden-xs',
'comment': 'hidden-xs',
'visible': '',
'visible': {'class': '', 'orderBy': false},
'actions': 'actions alwaysVisible',
} %}
@@ -28,8 +28,7 @@
{% if entries.count == 0 %}
{{ widgets.callout('warning', 'error.no_entries_found') }}
{% else %}
{{ tables.data_table_header(tableName, columns, false, 'kimai.activityUpdate') }}
{{ tables.datatable_header(tableName, columns, query, {'reload': 'kimai.activityUpdate'}) }}
{% for entry in entries %}
<tr{% if is_granted('edit', entry) %} class="modal-ajax-form open-edit" data-href="{{ path('admin_activity_edit', {'id': entry.id}) }}"{% endif %}>

View File

@@ -9,8 +9,8 @@
'comment': 'hidden-xs',
'country': 'hidden-xs hidden-sm',
'number': 'hidden-xs',
'team': '',
'visible': 'hidden-xs',
'team': {'class': '', 'orderBy': false},
'visible': {'class': 'hidden-xs', 'orderBy': false},
'actions': 'actions alwaysVisible',
} %}
@@ -29,7 +29,7 @@
{% if entries.count == 0 %}
{{ widgets.callout('warning', 'error.no_entries_found') }}
{% else %}
{{ tables.data_table_header(tableName, columns, false, 'kimai.customerUpdate') }}
{{ tables.datatable_header(tableName, columns, query, {'reload': 'kimai.customerUpdate'}) }}
{% for entry in entries %}
<tr{% if is_granted('edit', entry) %} class="modal-ajax-form open-edit" data-href="{{ path('admin_customer_edit', {'id': entry.id}) }}"{% endif %}>

View File

@@ -30,6 +30,52 @@
</div>
{% endmacro %}
{% macro datatable_header(tableName, columns, query, options) %}
{% set orderBy = options.orderBy|default(query.orderBy) %}
{% set striped = options.striped|default(true) %}
{% set reloadEvent = options.reload|default('') %}
{% set translationDomain = options.translationDomain|default('messages') %}
{# |default does not work here, as the prefix might be an empty string #}
{% set translationPrefix = 'label.' %}
{% if options.translationPrefix is defined %}
{% set translationPrefix = options.translationPrefix %}
{% endif %}
{% import _self as macro %}
<div class="box box-{{ admin_lte_context.widget.type }} data_table" id="datatable_{{ tableName }}">
<div class="box-body no-padding">
<div class="dataTables_wrapper form-inline dt-bootstrap">
<div class="row">
<div class="col-sm-12">
<table class="table {% if striped %}table-striped {% endif %}table-hover dataTable" role="grid" data-reload-event="{{ reloadEvent }}" id="dt_{{ tableName }}">
<thead>
<tr>
{%- for title, headerOptions in columns -%}
{% if not headerOptions is iterable %}
{% set headerOptions = {'class': headerOptions} %}
{% endif %}
{% if not headerOptions.orderBy is defined %}
{% set headerOptions = headerOptions|merge({'orderBy': title}) %}
{% endif %}
{% set headerClass = macro.data_table_column_class(tableName, columns, title) %}
{% if title != 'actions' and not headerOptions.orderBy is same as(false) %}
{% if orderBy == headerOptions.orderBy %}
{% set headerClass = headerClass ~ ' sortable sorting_' ~ (query.order|lower) %}
{% else %}
{% set headerClass = headerClass ~ ' sortable sorting' %}
{% endif %}
{% endif %}
{% set headerTitle = '' %}
{% if title is not empty and title != 'actions' %}
{% set headerTitle = (translationPrefix ~ title)|trans({}, translationDomain) %}
{% endif %}
<th data-field="{{ title }}" {% if not headerOptions.orderBy is same as(false) %}data-order="{{ headerOptions.orderBy }}" {% endif %}class="{{ headerClass }}">{{ headerTitle }}</th>
{%- endfor -%}
</tr>
</thead>
<tbody>
{% endmacro %}
{% macro data_table_column_class(name, columns, column) %}
{% apply spaceless %}
{% set class = '' %}
@@ -37,6 +83,10 @@
{% if columns[column] is defined %}
{% set classes = columns[column] %}
{# change the next if, once data_table_header_options() will be deleted #}
{% if classes is iterable %}
{% set classes = classes.class %}
{% endif %}
{% if 'alwaysVisible' in classes %}
{# as this column should always be visible, we remove every class that includes hidden #}
{% for tmp in classes|split(' ') %}
@@ -71,6 +121,7 @@
{% endmacro %}
{% macro data_table_header_options(name, columns, options) %}
{% deprecated 'The macro "data_table_header_options()" is deprecated since 1.3 and will be removed with 2.0, use "datatable_header()" instead' %}
{% set skipStripped = options.skipStripped|default(false) %}
{% set reloadEvent = options.reloadEvent|default('') %}
{% set translationDomain = options.translationDomain|default('messages') %}
@@ -98,6 +149,7 @@
{% endmacro %}
{% macro data_table_header(name, columns, skipStripped, reloadEvent) %}
{% deprecated 'The macro "data_table_header()" is deprecated since 1.3 and will be removed with 2.0, use "datatable_header()" instead' %}
{% import _self as macro %}
{{ macro.data_table_header_options(name, columns, {'skipStripped': skipStripped, 'reloadEvent': reloadEvent}) }}
{% endmacro %}

View File

@@ -8,8 +8,9 @@
'name': 'alwaysVisible',
'customer': 'hidden-xs',
'comment': 'hidden-xs hidden-sm',
'team': '',
'visible': '',
'orderNumber': 'hidden-xs hidden-sm',
'team': {'class': '', 'orderBy': false},
'visible': {'class': '', 'orderBy': false},
'actions': 'actions alwaysVisible',
} %}
@@ -28,7 +29,7 @@
{% if entries.count == 0 %}
{{ widgets.callout('warning', 'error.no_entries_found') }}
{% else %}
{{ tables.data_table_header(tableName, columns, false, 'kimai.projectUpdate') }}
{{ tables.datatable_header(tableName, columns, query, {'reload': 'kimai.projectUpdate'}) }}
{% for entry in entries %}
<tr{% if is_granted('edit', entry) %} class="modal-ajax-form open-edit" data-href="{{ path('admin_project_edit', {'id': entry.id}) }}"{% endif %}>
@@ -37,6 +38,7 @@
{{ widgets.label_customer(entry.customer) }}
</td>
<td class="{{ tables.data_table_column_class(tableName, columns, 'comment') }}">{{ entry.comment|comment2html }}</td>
<td class="{{ tables.data_table_column_class(tableName, columns, 'orderNumber') }}">{{ entry.orderNumber }}</td>
<td class="{{ tables.data_table_column_class(tableName, columns, 'team') }}">
{% if entry.teams|length > 0 %}
{{ widgets.badge_counter(entry.teams|length) }}

View File

@@ -23,7 +23,7 @@
{% set tableName = 'admin_tags' %}
{% set manageAllowed = is_granted('manage_tag') %}
{{ tables.data_table_header(tableName, columns, false, 'kimai.tagUpdate') }}
{{ tables.datatable_header(tableName, columns, query, {'reload': 'kimai.tagUpdate'}) }}
{% for tag in tags %}
{% set type = 'primary' %}
{% if tag.amount == 0 %}

View File

@@ -17,13 +17,13 @@
{% set columns = {
'name': '',
'teamlead': '',
'user': '',
'user': {'class': '', 'orderBy': false},
'actions': 'actions alwaysVisible',
} %}
{% set tableName = 'admin_teams' %}
{{ tables.data_table_header(tableName, columns, false, 'kimai.teamUpdate') }}
{{ tables.datatable_header(tableName, columns, query, {'reload': 'kimai.teamUpdate'}) }}
{% for team in teams %}
<tr{% if is_granted('edit', team) %} class="open-edit alternative-link" data-href="{{ path('admin_team_edit', {'id': team.id}) }}"{% endif %}>
<td>{{ team.name }}</td>

View File

@@ -6,13 +6,13 @@
{% set tableName = 'timesheet_admin' %}
{% set columns = {
'date': 'alwaysVisible',
'date': {'class': 'alwaysVisible', 'orderBy': 'begin'},
} %}
{% if showStartEndTime %}
{% set columns = columns|merge({
'starttime': 'hidden-xs',
'endtime': 'hidden-xs'
'starttime': {'class': 'hidden-xs', 'orderBy': 'begin'},
'endtime': {'class': 'hidden-xs', 'orderBy': 'end'}
}) %}
{% endif %}
@@ -22,9 +22,9 @@
'customer': 'hidden-xs hidden-sm hidden-md',
'project': 'hidden-xs hidden-sm hidden-md',
'activity': 'hidden-xs hidden-sm',
'username': 'hidden-xs',
'description': 'hidden-xs hidden-sm',
'tags': 'hidden-xs hidden-sm',
'username': {'class': 'hidden-xs', 'orderBy': false},
'tags': {'class': 'hidden-xs hidden-sm', 'orderBy': false},
'actions': 'actions alwaysVisible',
}) %}
@@ -41,7 +41,7 @@
{% if entries.count == 0 %}
{{ widgets.callout('warning', 'error.no_entries_found') }}
{% else %}
{{ tables.data_table_header(tableName, columns, false, 'kimai.timesheetUpdate') }}
{{ tables.datatable_header(tableName, columns, query, {'reload': 'kimai.timesheetUpdate'}) }}
{% for entry in entries %}
<tr{% if is_granted('edit', entry) %} class="modal-ajax-form open-edit{% if not entry.end %} recording{% endif %}" data-href="{{ path('admin_timesheet_edit', {'id': entry.id}) }}"{% endif %}>
@@ -82,10 +82,10 @@
<td class="{{ tables.data_table_column_class(tableName, columns, 'activity') }}">
{{ widgets.label_activity(entry.activity) }}
</td>
<td class="{{ tables.data_table_column_class(tableName, columns, 'description') }}">{{ entry.description|nl2br }}</td>
<td class="{{ tables.data_table_column_class(tableName, columns, 'username') }}">
{{ widgets.label_user(entry.user) }}
</td>
<td class="{{ tables.data_table_column_class(tableName, columns, 'description') }}">{{ entry.description|nl2br }}</td>
<td class="{{ tables.data_table_column_class(tableName, columns, 'tags') }}">{{ widgets.tag_list(entry.tags) }}</td>
<td class="actions">
{{- actions.timesheet_team(entry, 'index') -}}

View File

@@ -8,13 +8,13 @@
{% set tableName = 'timesheet' %}
{% set canSeeRate = is_granted('view_rate_own_timesheet') %}
{% set columns = {
'date': 'alwaysVisible',
'date': {'class': 'alwaysVisible', 'orderBy': 'begin'},
} %}
{% if showStartEndTime %}
{% set columns = columns|merge({
'starttime': '',
'endtime': 'hidden-xs'
'starttime': {'class': '', 'orderBy': 'begin'},
'endtime': {'class': 'hidden-xs', 'orderBy': 'end'}
}) %}
{% endif %}
{% set columns = columns|merge({'duration': ''}) %}
@@ -26,7 +26,7 @@
'project': 'hidden-xs hidden-sm hidden-md',
'activity': 'hidden-xs hidden-sm',
'description': 'hidden-xs hidden-sm',
'tags': 'hidden-xs hidden-sm',
'tags': {'class': 'hidden-xs hidden-sm', 'orderBy': false},
'actions': 'actions alwaysVisible',
}) %}
@@ -43,7 +43,7 @@
{% if entries.count == 0 %}
{{ widgets.callout('warning', 'error.no_entries_found') }}
{% else %}
{{ tables.data_table_header(tableName, columns, showSummary, 'kimai.timesheetUpdate') }}
{{ tables.datatable_header(tableName, columns, query, {'striped': not showSummary, 'reload': 'kimai.timesheetUpdate'}) }}
{% set day = null %}
{% set dayDuration = 0 %}

View File

@@ -9,8 +9,8 @@
'username': 'hidden-xs',
'email': 'hidden-xs hidden-sm',
'title': 'hidden-xs',
'roles': 'hidden-xs',
'active': '',
'roles': {'class': 'hidden-xs', 'orderBy': false},
'active': {'class': '', 'orderBy': false},
'actions': 'actions alwaysVisible',
} %}
@@ -29,7 +29,7 @@
{% if entries.count == 0 %}
{{ widgets.callout('warning', 'error.no_entries_found') }}
{% else %}
{{ tables.data_table_header(tableName, columns, false, 'kimai.userUpdate') }}
{{ tables.datatable_header(tableName, columns, query, {'reload': 'kimai.userUpdate'}) }}
{% for entry in entries %}
<tr{% if is_granted('edit', entry) %} class="open-edit alternative-link" data-href="{{ path('user_profile_edit', {'username': entry.username}) }}"{% endif %}>