From 949c59230f9871951f35f0d89e35d3e8e3995a8f Mon Sep 17 00:00:00 2001 From: Kevin Papst Date: Fri, 25 Oct 2019 16:21:30 +0200 Subject: [PATCH] improve list views (#1191) --- src/Twig/DatatableExtensions.php | 28 ++++++++++-- src/Twig/IconExtension.php | 63 ++++++++++++++------------- templates/activity/index.html.twig | 4 +- templates/customer/index.html.twig | 36 ++++++++++++++- templates/macros/datatables.html.twig | 6 ++- templates/project/index.html.twig | 10 ++++- 6 files changed, 106 insertions(+), 41 deletions(-) diff --git a/src/Twig/DatatableExtensions.php b/src/Twig/DatatableExtensions.php index 1af42e0b..2a2a29e8 100644 --- a/src/Twig/DatatableExtensions.php +++ b/src/Twig/DatatableExtensions.php @@ -69,9 +69,10 @@ class DatatableExtensions extends AbstractExtension * * @param string $dataTable * @param string $column + * @param array $columns * @return bool */ - public function isColumnVisible(string $dataTable, string $column) + public function isColumnVisible(string $dataTable, string $column, array $columns) { // name handling is spread between here and datatables.html.twig (data_table_column_modal) $cookie = $this->getVisibilityCookieName($dataTable); @@ -86,13 +87,34 @@ class DatatableExtensions extends AbstractExtension $values = $this->cookies[$cookie]; if (empty($values) || !is_array($values)) { - return true; + return $this->checkInColumDefinition($columns, $column); } - if (isset($values[$column]) && $values[$column] === false) { + if (!isset($values[$column])) { + return $this->checkInColumDefinition($columns, $column); + } + + if ($values[$column] === false) { return false; } return true; } + + private function checkInColumDefinition(array $columns, string $column) + { + if (array_key_exists($column, $columns)) { + $tmp = $columns[$column]; + if (is_array($tmp)) { + $tmp = $tmp['class']; + } + foreach (explode(' ', $tmp) as $class) { + if ($class === 'hidden') { + return false; + } + } + } + + return true; + } } diff --git a/src/Twig/IconExtension.php b/src/Twig/IconExtension.php index 91103ab7..87a970ee 100644 --- a/src/Twig/IconExtension.php +++ b/src/Twig/IconExtension.php @@ -18,65 +18,68 @@ final class IconExtension extends AbstractExtension * @var string[] */ private static $icons = [ + 'about' => 'fas fa-info-circle', 'activity' => 'fas fa-tasks', 'admin' => 'fas fa-wrench', + 'audit' => 'fas fa-history', + 'avatar' => 'fas fa-user', + 'back' => 'fas fa-long-arrow-alt-left', 'calendar' => 'far fa-calendar-alt', - 'customer' => 'fas fa-user-tie', + 'clock' => 'far fa-clock', + 'configuration' => 'fas fa-cogs', 'copy' => 'far fa-copy', 'create' => 'far fa-plus-square', + 'csv' => 'fas fa-table', + 'customer' => 'fas fa-user-tie', 'dashboard' => 'fas fa-tachometer-alt', + 'debug' => 'far fa-file-alt', 'delete' => 'far fa-trash-alt', + 'doctor' => 'fas fa-medkit', 'download' => 'fas fa-download', 'duration' => 'far fa-hourglass', 'edit' => 'far fa-edit', + 'export' => 'fas fa-file-export', 'filter' => 'fas fa-filter', 'help' => 'far fa-question-circle', + 'home' => 'fas fa-home', 'invoice' => 'fas fa-file-invoice', 'list' => 'fas fa-list', 'logout' => 'fas fa-sign-out-alt', + 'mail' => 'fas fa-envelope-open', + 'mail-sent' => 'fas fa-paper-plane', 'manual' => 'fas fa-book', + 'mobile' => 'fas fa-mobile', 'money' => 'far fa-money-bill-alt', + 'ods' => 'fas fa-table', + 'off' => 'fas fa-toggle-off', + 'on' => 'fas fa-toggle-on', + 'pdf' => 'fas fa-file-pdf', + 'permissions' => 'fas fa-user-lock', + 'phone' => 'fas fa-phone', + 'plugin' => 'fas fa-plug', 'print' => 'fas fa-print', + 'profile' => 'fas fa-user-edit', + 'profile-stats' => 'far fa-chart-bar', 'project' => 'fas fa-briefcase', 'repeat' => 'fas fa-redo-alt', 'search' => 'fas fa-search', + 'settings' => 'fas fa-cog', + 'shop' => 'fas fa-shopping-cart', 'start' => 'fas fa-play-circle', 'start-small' => 'far fa-play-circle', 'stop' => 'fas fa-stop', 'stop-small' => 'far fa-stop-circle', - 'timesheet' => 'fas fa-clock', - 'trash' => 'far fa-trash-alt', + 'success' => 'fas fa-check', + 'tag' => 'fas fa-tags', 'team' => 'fas fa-users', + 'timesheet' => 'fas fa-clock', + 'timesheet-team' => 'fas fa-user-clock', + 'trash' => 'far fa-trash-alt', + 'unlocked' => 'fas fa-unlock-alt', 'user' => 'fas fa-user-friends', 'visibility' => 'far fa-eye', - 'settings' => 'fas fa-cog', - 'export' => 'fas fa-file-export', - 'pdf' => 'fas fa-file-pdf', - 'csv' => 'fas fa-table', - 'ods' => 'fas fa-table', - 'xlsx' => 'fas fa-file-excel', - 'on' => 'fas fa-toggle-on', - 'off' => 'fas fa-toggle-off', - 'audit' => 'fas fa-history', - 'home' => 'fas fa-home', - 'shop' => 'fas fa-shopping-cart', - 'about' => 'fas fa-info-circle', - 'debug' => 'far fa-file-alt', - 'profile-stats' => 'far fa-chart-bar', - 'profile' => 'fas fa-user-edit', 'warning' => 'fas fa-exclamation-triangle', - 'permissions' => 'fas fa-user-lock', - 'unlocked' => 'fas fa-unlock-alt', - 'back' => 'fas fa-long-arrow-alt-left', - 'tag' => 'fas fa-tags', - 'avatar' => 'fas fa-user', - 'timesheet-team' => 'fas fa-user-clock', - 'plugin' => 'fas fa-plug', - 'configuration' => 'fas fa-cogs', - 'mail-sent' => 'fas fa-paper-plane', - 'mail' => 'fas fa-envelope-open', - 'doctor' => 'fas fa-medkit', - 'success' => 'fas fa-check', + 'xlsx' => 'fas fa-file-excel', ]; /** diff --git a/templates/activity/index.html.twig b/templates/activity/index.html.twig index 92c242af..959e6852 100644 --- a/templates/activity/index.html.twig +++ b/templates/activity/index.html.twig @@ -8,7 +8,7 @@ 'name': 'alwaysVisible', 'customer': 'hidden-xs', 'project': 'hidden-xs', - 'comment': 'hidden-xs', + 'comment': 'hidden-xs hidden-sm', } %} {% for field in metaColumns %} {% set columns = columns|merge({ @@ -16,7 +16,7 @@ }) %} {% endfor %} {% set columns = columns|merge({ - 'visible': {'class': '', 'orderBy': false}, + 'visible': {'class': 'text-center', 'orderBy': false}, 'actions': 'actions alwaysVisible', }) %} diff --git a/templates/customer/index.html.twig b/templates/customer/index.html.twig index b37770a0..8f93fd54 100644 --- a/templates/customer/index.html.twig +++ b/templates/customer/index.html.twig @@ -16,8 +16,12 @@ }) %} {% endfor %} {% set columns = columns|merge({ - 'team': {'class': '', 'orderBy': false}, - 'visible': {'class': 'hidden-xs', 'orderBy': false}, + 'email': {'class': 'text-center hidden hidden-xs', 'orderBy': false}, + 'homepage': {'class': 'text-center hidden hidden-xs', 'orderBy': false}, + 'mobile': {'class': 'text-center hidden hidden-xs', 'orderBy': false}, + 'phone': {'class': 'text-center hidden hidden-xs', 'orderBy': false}, + 'team': {'class': 'text-center', 'orderBy': false}, + 'visible': {'class': 'text-center', 'orderBy': false}, 'actions': 'actions alwaysVisible', }) %} @@ -49,6 +53,34 @@ {{ tables.datatable_meta_column(entry, field) }} {% endfor %} + + {% if entry.email is not empty %} + + {% else %} + – + {% endif %} + + + {% if entry.homepage is not empty %} + + {% else %} + – + {% endif %} + + + {% if entry.mobile is not empty %} + + {% else %} + – + {% endif %} + + + {% if entry.phone is not empty %} + + {% else %} + – + {% endif %} + {% if entry.teams|length > 0 %} {{ widgets.badge_counter(entry.teams|length) }} diff --git a/templates/macros/datatables.html.twig b/templates/macros/datatables.html.twig index 487027fb..8f2a23bc 100644 --- a/templates/macros/datatables.html.twig +++ b/templates/macros/datatables.html.twig @@ -20,7 +20,7 @@ {% endif %} {% if 'alwaysVisible' not in headerOptions.class %}
- +
{% endif %} @@ -105,15 +105,17 @@ {% endif %} {% endfor %} {% else %} - {% if not is_visible_column(name, column) %} + {% if not is_visible_column(name, column, columns) %} {% set classes = classes ~ ' hidden' %} {% elseif not is_datatable_configured(name) %} + {# needs to be a foreach, as classes like "hidden-xs" would match in: if 'hidden' in classes #} {% for tmp in classes|split(' ') %} {% if 'hidden' == tmp %} {% set classes = classes|replace({(tmp): ''}) %} {% endif %} {% endfor %} {% else %} + {# needs to be a foreach, as classes like "hidden-xs" would match in: if 'hidden' in classes #} {% for tmp in classes|split(' ') %} {% if 'hidden' in tmp %} {% set classes = classes|replace({(tmp): ''}) %} diff --git a/templates/project/index.html.twig b/templates/project/index.html.twig index ab48ac4d..51a7a409 100644 --- a/templates/project/index.html.twig +++ b/templates/project/index.html.twig @@ -9,6 +9,7 @@ 'customer': 'hidden-xs', 'comment': 'hidden-xs hidden-sm', 'orderNumber': 'hidden-xs hidden-sm', + 'orderDate': 'hidden-xs hidden-sm', } %} {% for field in metaColumns %} {% set columns = columns|merge({ @@ -16,8 +17,8 @@ }) %} {% endfor %} {% set columns = columns|merge({ - 'team': {'class': '', 'orderBy': false}, - 'visible': {'class': '', 'orderBy': false}, + 'team': {'class': 'text-center', 'orderBy': false}, + 'visible': {'class': 'text-center', 'orderBy': false}, 'actions': 'actions alwaysVisible', }) %} @@ -46,6 +47,11 @@ {{ entry.comment|comment2html }} {{ entry.orderNumber }} + + {% if entry.orderDate is not empty %} + {{ entry.orderDate|date_short }} + {% endif %} + {% for field in metaColumns %} {{ tables.datatable_meta_column(entry, field) }}