From 52911841ff1e1cc646a1996c3cbfdbdc4382c313 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Thu, 25 Jan 2018 11:42:58 +0200 Subject: [PATCH] Show tooltip for long texts in datatable --- app/Ninja/Datatables/EntityDatatable.php | 10 ++++++++++ app/Ninja/Datatables/ExpenseDatatable.php | 2 +- app/Ninja/Datatables/RecurringExpenseDatatable.php | 2 +- app/Ninja/Datatables/RecurringInvoiceDatatable.php | 2 +- app/Ninja/Datatables/SubscriptionDatatable.php | 2 +- app/Ninja/Datatables/TaskDatatable.php | 2 +- 6 files changed, 15 insertions(+), 5 deletions(-) diff --git a/app/Ninja/Datatables/EntityDatatable.php b/app/Ninja/Datatables/EntityDatatable.php index 02fd808457..08e55549e9 100644 --- a/app/Ninja/Datatables/EntityDatatable.php +++ b/app/Ninja/Datatables/EntityDatatable.php @@ -98,4 +98,14 @@ class EntityDatatable return $str . '  '; } + + public function showWithTooltip($str, $max = 60) { + $str = e($str); + + if (strlen($str) > $max) { + return '' . trim(substr($str, 0, $max)) . '...' . ''; + } else { + return $str; + } + } } diff --git a/app/Ninja/Datatables/ExpenseDatatable.php b/app/Ninja/Datatables/ExpenseDatatable.php index 45e277e154..800bc56f7e 100644 --- a/app/Ninja/Datatables/ExpenseDatatable.php +++ b/app/Ninja/Datatables/ExpenseDatatable.php @@ -85,7 +85,7 @@ class ExpenseDatatable extends EntityDatatable [ 'public_notes', function ($model) { - return $model->public_notes != null ? e(substr($model->public_notes, 0, 100)) : ''; + return $this->showWithTooltip($model->public_notes); }, ], [ diff --git a/app/Ninja/Datatables/RecurringExpenseDatatable.php b/app/Ninja/Datatables/RecurringExpenseDatatable.php index 3117e1cec5..78a6fdb7df 100644 --- a/app/Ninja/Datatables/RecurringExpenseDatatable.php +++ b/app/Ninja/Datatables/RecurringExpenseDatatable.php @@ -98,7 +98,7 @@ class RecurringExpenseDatatable extends EntityDatatable [ 'public_notes', function ($model) { - return $model->public_notes != null ? substr($model->public_notes, 0, 100) : ''; + return $this->showWithTooltip($model->public_notes, 100); }, ], ]; diff --git a/app/Ninja/Datatables/RecurringInvoiceDatatable.php b/app/Ninja/Datatables/RecurringInvoiceDatatable.php index df434b1190..2f4555da7e 100644 --- a/app/Ninja/Datatables/RecurringInvoiceDatatable.php +++ b/app/Ninja/Datatables/RecurringInvoiceDatatable.php @@ -64,7 +64,7 @@ class RecurringInvoiceDatatable extends EntityDatatable [ 'private_notes', function ($model) { - return e($model->private_notes); + return $this->showWithTooltip($model->private_notes); }, ], [ diff --git a/app/Ninja/Datatables/SubscriptionDatatable.php b/app/Ninja/Datatables/SubscriptionDatatable.php index d83d9a501f..c07cac0123 100644 --- a/app/Ninja/Datatables/SubscriptionDatatable.php +++ b/app/Ninja/Datatables/SubscriptionDatatable.php @@ -20,7 +20,7 @@ class SubscriptionDatatable extends EntityDatatable [ 'target', function ($model) { - return e(substr($model->target, 0, 40) . (strlen($model->target) > 40 ? '...' : '')); + return $this->showWithTooltip($model->target, 40); }, ], ]; diff --git a/app/Ninja/Datatables/TaskDatatable.php b/app/Ninja/Datatables/TaskDatatable.php index e019c899b1..c4a5814afd 100644 --- a/app/Ninja/Datatables/TaskDatatable.php +++ b/app/Ninja/Datatables/TaskDatatable.php @@ -59,7 +59,7 @@ class TaskDatatable extends EntityDatatable [ 'description', function ($model) { - return e(substr($model->description, 0, 80) . (strlen($model->description) > 80 ? '...' : '')); + return $this->showWithTooltip($model->description); }, ], [