Display meta-fields in datatables (#1116)

This commit is contained in:
Kevin Papst
2019-09-19 20:28:31 +02:00
committed by GitHub
parent 24cbe3d281
commit 5aa422dde1
71 changed files with 1461 additions and 212 deletions

View File

@@ -9,9 +9,16 @@
'customer': 'hidden-xs',
'project': 'hidden-xs',
'comment': 'hidden-xs',
} %}
{% for field in metaColumns %}
{% set columns = columns|merge({
(field.name): {'title': field.label, 'class': 'hidden-xs hidden-sm', 'orderBy': false}
}) %}
{% endfor %}
{% set columns = columns|merge({
'visible': {'class': '', 'orderBy': false},
'actions': 'actions alwaysVisible',
} %}
}) %}
{% set tableName = 'activity_admin' %}
@@ -46,6 +53,11 @@
{% endif %}
</td>
<td class="{{ tables.data_table_column_class(tableName, columns, 'comment') }}">{{ entry.comment|comment2html }}</td>
{% for field in metaColumns %}
<td class="text-nowrap {{ tables.data_table_column_class(tableName, columns, field.name) }}">
{{ tables.datatable_meta_column(entry, field) }}
</td>
{% endfor %}
<td class="{{ tables.data_table_column_class(tableName, columns, 'visible') }}">{{ widgets.label_visible(entry.visible) }}</td>
<td class="actions">
{{ actions.activity(entry, 'index') }}

View File

@@ -9,10 +9,17 @@
'comment': 'hidden-xs',
'country': 'hidden-xs hidden-sm',
'number': 'hidden-xs',
} %}
{% for field in metaColumns %}
{% set columns = columns|merge({
(field.name): {'title': field.label, 'class': 'hidden-xs hidden-sm', 'orderBy': false}
}) %}
{% endfor %}
{% set columns = columns|merge({
'team': {'class': '', 'orderBy': false},
'visible': {'class': 'hidden-xs', 'orderBy': false},
'actions': 'actions alwaysVisible',
} %}
}) %}
{% set tableName = 'customer_admin' %}
@@ -37,6 +44,11 @@
<td class="{{ tables.data_table_column_class(tableName, columns, 'comment') }}">{{ entry.comment|comment2html }}</td>
<td class="{{ tables.data_table_column_class(tableName, columns, 'country') }}">{{ entry.country|country }}</td>
<td class="{{ tables.data_table_column_class(tableName, columns, 'number') }}">{{ entry.number }}</td>
{% for field in metaColumns %}
<td class="text-nowrap {{ tables.data_table_column_class(tableName, columns, field.name) }}">
{{ tables.datatable_meta_column(entry, field) }}
</td>
{% endfor %}
<td class="{{ tables.data_table_column_class(tableName, columns, 'team') }}">
{% if entry.teams|length > 0 %}
{{ widgets.badge_counter(entry.teams|length) }}

View File

@@ -1,4 +1,5 @@
{% import "macros/widgets.html.twig" as widgets %}
{% import "macros/datatables.html.twig" as tables %}
{% extends 'export/layout.html.twig' %}
{% set columnTitles = {} %}
@@ -13,9 +14,25 @@
'tags': false,
} %}
{% for id, metaField in metaFields %}
{% set columns = columns|merge({ (metaField): true}) %}
{% set columnTitles = columnTitles|merge({ (metaField): (metaField)}) %}
{% for id, field in timesheetMetaFields %}
{% set columns = columns|merge({ ('t_' ~ field.name): true}) %}
{% set columnTitles = columnTitles|merge({ ('t_' ~ field.name): (field.label)}) %}
{% endfor %}
{% for id, field in customerMetaFields %}
{% set columns = columns|merge({ ('c_' ~ field.name): true}) %}
{% set columnTitles = columnTitles|merge({ ('c_' ~ field.name): (field.label)}) %}
{% endfor %}
{% for id, field in projectMetaFields %}
{% set columns = columns|merge({ ('p_' ~ field.name): true}) %}
{% set columnTitles = columnTitles|merge({ ('p_' ~ field.name): (field.label)}) %}
{% endfor %}
{% for id, field in activityMetaFields %}
{% set columns = columns|merge({ ('a_' ~ field.name): true}) %}
{% set columnTitles = columnTitles|merge({ ('a_' ~ field.name): (field.label)}) %}
{% endfor %}
{% for id, field in userPreferences %}
{% set columns = columns|merge({ ('u_' ~ field.name): true}) %}
{% set columnTitles = columnTitles|merge({ ('u_' ~ field.name): (field.label)}) %}
{% endfor %}
{% set columns = columns|merge({
@@ -293,11 +310,31 @@
{{ entry.tagsAsArray|join(', ') }}
{% endif %}
</td>
{% for id, metaFieldName in metaFields %}
<td class="column-{{ metaFieldName }} text-nowrap" {% if not columns[metaFieldName] %}style="display: none"{% endif %}>
{% set metaField = entry.metaField(metaFieldName) %}
{% if not metaField is null and metaField.visible %}
{{ metaField.value }}
{% for id, field in timesheetMetaFields %}
<td class="column-{{ 't_' ~ field.name }} text-nowrap" {% if not columns['t_' ~ field.name] %}style="display: none"{% endif %}>
{{ tables.datatable_meta_column(entry, field) }}
</td>
{% endfor %}
{% for id, field in customerMetaFields %}
<td class="column-{{ 'c_' ~ field.name }} text-nowrap" {% if not columns['c_' ~ field.name] %}style="display: none"{% endif %}>
{{ tables.datatable_meta_column(entry.project.customer, field) }}
</td>
{% endfor %}
{% for id, field in projectMetaFields %}
<td class="column-{{ 'p_' ~ field.name }} text-nowrap" {% if not columns['p_' ~ field.name] %}style="display: none"{% endif %}>
{{ tables.datatable_meta_column(entry.project, field) }}
</td>
{% endfor %}
{% for id, field in activityMetaFields %}
<td class="column-{{ 'a_' ~ field.name }} text-nowrap" {% if not columns['a_' ~ field.name] %}style="display: none"{% endif %}>
{{ tables.datatable_meta_column(entry.activity, field) }}
</td>
{% endfor %}
{% for id, field in userPreferences %}
<td class="column-{{ 'u_' ~ field.name }} text-nowrap" {% if not columns['u_' ~ field.name] %}style="display: none"{% endif %}>
{% set metaField = entry.user.preference(field.name) %}
{% if not metaField is null and metaField.value is not null and metaField.value is not empty %}
{{ widgets.form_type_value(field.type, metaField.value, entry.user) }}
{% endif %}
</td>
{% endfor %}

View File

@@ -9,11 +9,18 @@
</div>
<div class="modal-body">
<form name="{{ name }}_visibility">
{% for title, class in columns %}
{% if 'alwaysVisible' not in class %}
{%- for title, headerOptions in columns -%}
{% if not headerOptions is iterable %}
{% set headerOptions = {'class': headerOptions} %}
{% endif %}
{% set headerTitle = ('label.' ~ title)|trans %}
{% if headerOptions.title is defined %}
{% set headerTitle = headerOptions.title %}
{% endif %}
{% if 'alwaysVisible' not in headerOptions.class %}
<div class="form-group">
<input type="checkbox" id="column_{{ title }}" name="{{ title }}"{% if is_visible_column(name, title) %} checked="checked"{% endif %}>
<label class="control-label" for="column_{{ title }}">{{ ('label.' ~ title)|trans }}</label>
<label class="control-label" for="column_{{ title }}">{{ headerTitle }}</label>
</div>
{% endif %}
{% endfor %}
@@ -66,7 +73,9 @@
{% endif %}
{% endif %}
{% set headerTitle = '' %}
{% if title is not empty and title != 'actions' %}
{% if headerOptions.title is defined %}
{% set headerTitle = headerOptions.title %}
{% elseif 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>
@@ -168,3 +177,12 @@
</div>
{% endif %}
{% endmacro %}
{% macro datatable_meta_column(entry, field) %}
{% import "macros/widgets.html.twig" as widgets %}
{% set metaField = entry.metaField(field.name) %}
{% if not metaField is null and metaField.value is not null and metaField.value is not empty %}
{% set metaField = metaField.merge(field) %}
{{ widgets.form_type_value(metaField.type, metaField.value, entry) }}
{% endif %}
{% endmacro %}

View File

@@ -102,6 +102,12 @@
</span>
{% endmacro %}
{% macro color_dot(color, tooltip) %}
<span class="label-color" data-toggle="tooltip" data-placement="top" title="{{ tooltip }}">
<span class="dot" style="background-color:{{ color }}"></span>
</span>
{% endmacro %}
{% macro badge_counter(count, url) %}
{% if url %}
<a href="{{ url }}"><span class="badge bg-blue">{{ count }}</span></a>
@@ -294,3 +300,40 @@
{{ macro.badge(tag.name , 'green') }}
{% endfor %}
{% endmacro %}
{% macro form_type_value(type, value, entity) %}
{% import _self as widgets %}
{% if '\\ColorPickerType' in type %}
{{ widgets.color_dot(value, value) }}
{% elseif '\\DurationType' in type %}
{{ value|duration }}
{% elseif '\\YesNoType' in type or '\\CheckBoxType' in type %}
{{ widgets.label_boolean(value) }}
{% elseif '\\DatePickerType' in type %}
{{ value|date_short }}
{% elseif '\\DateTimePickerType' in type %}
{{ value|date_full }}
{% elseif '\\CountryType' in type %}
{{ value|country }}
{% elseif '\\CurrencyType' in type %}
{{ value|currency }}
{% elseif '\\LanguageType' in type %}
{{ value|language }}
{% elseif '\\MoneyType' in type %}
{% if entity is null %}
{{ value }}
{% elseif class_name(entity) == 'App\\Entity\\Timesheet' %}
{{ value|money(entity.project.customer.currency) }}
{% elseif class_name(entity) == 'App\\Entity\\Customer' %}
{{ value|money(entity.currency) }}
{% elseif class_name(entity) == 'App\\Entity\\Project' %}
{{ value|money(entity.customer.currency) }}
{% elseif class_name(entity) == 'App\\Entity\\Activity' and entity.project is not null %}
{{ value|money(entity.project.customer.currency) }}
{% else %}
{{ value }}
{% endif %}
{% else %}
{{ value }}
{% endif %}
{% endmacro %}

View File

@@ -9,10 +9,17 @@
'customer': 'hidden-xs',
'comment': 'hidden-xs hidden-sm',
'orderNumber': 'hidden-xs hidden-sm',
} %}
{% for field in metaColumns %}
{% set columns = columns|merge({
(field.name): {'title': field.label, 'class': 'hidden-xs hidden-sm', 'orderBy': false}
}) %}
{% endfor %}
{% set columns = columns|merge({
'team': {'class': '', 'orderBy': false},
'visible': {'class': '', 'orderBy': false},
'actions': 'actions alwaysVisible',
} %}
}) %}
{% set tableName = 'project_admin' %}
@@ -39,6 +46,11 @@
</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>
{% for field in metaColumns %}
<td class="text-nowrap {{ tables.data_table_column_class(tableName, columns, field.name) }}">
{{ tables.datatable_meta_column(entry, field) }}
</td>
{% endfor %}
<td class="{{ tables.data_table_column_class(tableName, columns, 'team') }}">
{% if entry.teams|length > 0 %}
{{ widgets.badge_counter(entry.teams|length) }}

View File

@@ -1,4 +1,5 @@
{% import "macros/widgets.html.twig" as widgets %}
{% import "macros/datatables.html.twig" as tables %}
{% extends 'invoice/layout.html.twig' %}
{% block invoice %}
@@ -34,6 +35,9 @@
<th>{{ 'label.username'|trans }}</th>
{% endif %}
<th>{{ 'label.description'|trans }}</th>
{% for field in metaColumns %}
<th>{{ field.label|trans }}</th>
{% endfor %}
<th>{{ 'label.hours'|trans }}</th>
</tr>
</thead>
@@ -58,6 +62,9 @@
{{ 'label.customer'|trans }}: {{ entry.project.customer.name }}
</span>
</td>
{% for field in metaColumns %}
<td>{{ tables.datatable_meta_column(entry, field) }}</td>
{% endfor %}
<td class="text-nowrap">{{ entry.duration|duration }}</td>
</tr>
{% endfor %}
@@ -65,6 +72,12 @@
<tfoot>
<tr>
<th></th>
{% if query.user is empty %}
<th></th>
{% endif %}
{% for field in metaColumns %}
<th></th>
{% endfor %}
<th>{{ 'invoice.total_working_time'|trans }}</th>
<th>{{ timeWorked|duration }}</th>
</tr>

View File

@@ -25,6 +25,13 @@
'description': 'hidden-xs hidden-sm',
'username': {'class': 'hidden-xs', 'orderBy': false},
'tags': {'class': 'hidden-xs hidden-sm', 'orderBy': false},
}) %}
{% for field in metaColumns %}
{% set columns = columns|merge({
(field.name): {'title': field.label, 'class': 'hidden-xs hidden-sm', 'orderBy': false}
}) %}
{% endfor %}
{% set columns = columns|merge({
'actions': 'actions alwaysVisible',
}) %}
@@ -87,6 +94,11 @@
{{ widgets.label_user(entry.user) }}
</td>
<td class="{{ tables.data_table_column_class(tableName, columns, 'tags') }}">{{ widgets.tag_list(entry.tags) }}</td>
{% for field in metaColumns %}
<td class="text-nowrap {{ tables.data_table_column_class(tableName, columns, field.name) }}">
{{ tables.datatable_meta_column(entry, field) }}
</td>
{% endfor %}
<td class="actions">
{{- actions.timesheet_team(entry, 'index') -}}
</td>

View File

@@ -1,4 +1,5 @@
{% import "macros/widgets.html.twig" as widgets %}
{% import "macros/datatables.html.twig" as tables %}
{% extends 'invoice/layout.html.twig' %}
{% block invoice %}
@@ -29,6 +30,9 @@
<tr>
<th>{{ 'label.date'|trans }}</th>
<th>{{ 'label.description'|trans }}</th>
{% for field in metaColumns %}
<th>{{ field.label|trans }}</th>
{% endfor %}
<th>{{ 'label.hours'|trans }}</th>
</tr>
</thead>
@@ -50,6 +54,9 @@
{{ 'label.customer'|trans }}: {{ entry.project.customer.name }}
</span>
</td>
{% for field in metaColumns %}
<td>{{ tables.datatable_meta_column(entry, field) }}</td>
{% endfor %}
<td class="text-nowrap">{{ entry.duration|duration }}</td>
</tr>
{% endfor %}
@@ -57,6 +64,9 @@
<tfoot>
<tr>
<th></th>
{% for field in metaColumns %}
<th></th>
{% endfor %}
<th>{{ 'invoice.total_working_time'|trans }}</th>
<th>{{ timeWorked|duration }}</th>
</tr>

View File

@@ -27,6 +27,13 @@
'activity': 'hidden-xs hidden-sm',
'description': 'hidden-xs hidden-sm',
'tags': {'class': 'hidden-xs hidden-sm', 'orderBy': false},
}) %}
{% for field in metaColumns %}
{% set columns = columns|merge({
(field.name): {'title': field.label, 'class': 'hidden-xs hidden-sm', 'orderBy': false}
}) %}
{% endfor %}
{% set columns = columns|merge({
'actions': 'actions alwaysVisible',
}) %}
@@ -54,7 +61,7 @@
{% set day = entry.begin|date_short %}
{% endif %}
{%- if showSummary and day is not same as(entry.begin|date_short) -%}
{{ timesheet.summary(day, dayDuration, dayRate, columns, canSeeRate, showStartEndTime, tableName) }}
{{ timesheet.summary(day, dayDuration, dayRate, columns, canSeeRate, showStartEndTime, tableName, metaColumns) }}
{% set day = entry.begin|date_short %}
{% set dayDuration = 0 %}
{% set dayRate = {} %}
@@ -96,6 +103,11 @@
<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') }} timesheet-description">{{ entry.description|escape|desc2html }}</td>
<td class="{{ tables.data_table_column_class(tableName, columns, 'tags') }}">{{ widgets.tag_list(entry.tags) }}</td>
{% for field in metaColumns %}
<td class="text-nowrap {{ tables.data_table_column_class(tableName, columns, field.name) }}">
{{ tables.datatable_meta_column(entry, field) }}
</td>
{% endfor %}
<td class="actions">
{{- actions.timesheet(entry, 'index') -}}
</td>
@@ -110,7 +122,7 @@
{% endfor %}
{% if showSummary %}
{{ timesheet.summary(day, dayDuration, dayRate, columns, canSeeRate, showStartEndTime, tableName) }}
{{ timesheet.summary(day, dayDuration, dayRate, columns, canSeeRate, showStartEndTime, tableName, metaColumns) }}
{% endif %}
{{ tables.data_table_footer(entries, 'timesheet_paginated') }}
@@ -118,7 +130,7 @@
{% endblock %}
{% macro summary(day, duration, dayRates, columns, canSeeRate, showStartEndTime, tableName) %}
{% macro summary(day, duration, dayRates, columns, canSeeRate, showStartEndTime, tableName, metaColumns) %}
{% import "macros/datatables.html.twig" as tables %}
<tr class="summary info">
<td class="text-nowrap">{{ day }}</td>
@@ -142,6 +154,9 @@
<td class="{{ tables.data_table_column_class(tableName, columns, 'activity') }}"></td>
<td class="{{ tables.data_table_column_class(tableName, columns, 'description') }}"></td>
<td class="{{ tables.data_table_column_class(tableName, columns, 'tags') }}"></td>
{% for field in metaColumns %}
<td class="{{ tables.data_table_column_class(tableName, columns, field.name) }}"></td>
{% endfor %}
<td class="actions"></td>
</tr>
{% endmacro %}

View File

@@ -9,10 +9,17 @@
'username': 'hidden-xs',
'email': 'hidden-xs hidden-sm',
'title': 'hidden-xs',
} %}
{% for pref in preferences %}
{% set columns = columns|merge({
(pref.name): {'title': pref.label, 'class': 'hidden-xs hidden-sm', 'orderBy': false}
}) %}
{% endfor %}
{% set columns = columns|merge({
'roles': {'class': 'hidden-xs', 'orderBy': false},
'active': {'class': '', 'orderBy': false},
'actions': 'actions alwaysVisible',
} %}
}) %}
{% set tableName = 'user_admin' %}
@@ -37,6 +44,14 @@
<td class="{{ tables.data_table_column_class(tableName, columns, 'username') }}">{{ entry.username }}</td>
<td class="{{ tables.data_table_column_class(tableName, columns, 'email') }}">{{ entry.email }}</td>
<td class="{{ tables.data_table_column_class(tableName, columns, 'title') }}">{{ entry.title }}</td>
{% for pref in preferences %}
<td class="text-nowrap {{ tables.data_table_column_class(tableName, columns, pref.name) }}">
{% set metaField = entry.preference(pref.name) %}
{% if not metaField is null and metaField.value is not null and metaField.value is not empty %}
{{ widgets.form_type_value(pref.type, metaField.value, entry) }}
{% endif %}
</td>
{% endfor %}
<td class="{{ tables.data_table_column_class(tableName, columns, 'roles') }}">
{% for role in entry.roles %}
{% if role != 'ROLE_USER' %}