From a7858a8561f3c81d8fc6aa8a8d038e99c69dbe8c Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Sun, 25 Dec 2016 23:43:57 +0200 Subject: [PATCH] Right align number and center statuses in data tables --- app/Ninja/Datatables/EntityDatatable.php | 26 ++++++++++++++++++++ app/Ninja/Datatables/PaymentDatatable.php | 4 +-- app/Ninja/Repositories/PaymentRepository.php | 2 +- resources/lang/en/texts.php | 1 - resources/views/clients/show.blade.php | 1 + resources/views/datatable.blade.php | 6 ++--- resources/views/list.blade.php | 18 +++++++++++++- 7 files changed, 50 insertions(+), 8 deletions(-) diff --git a/app/Ninja/Datatables/EntityDatatable.php b/app/Ninja/Datatables/EntityDatatable.php index 99e2a414ad89..8d6249c1990c 100644 --- a/app/Ninja/Datatables/EntityDatatable.php +++ b/app/Ninja/Datatables/EntityDatatable.php @@ -64,4 +64,30 @@ class EntityDatatable return $data; } + + public function rightAlignIndices() + { + return $this->alignIndices(['amount', 'balance', 'cost']); + } + + public function centerAlignIndices() + { + return $this->alignIndices(['status']); + } + + public function alignIndices($fields) + { + $columns = $this->columnFields(); + $indices = []; + + foreach ($columns as $index => $column) { + if (in_array($column, $fields)) { + $indices[] = $index + 1; + } + } + + return $indices; + } + + } diff --git a/app/Ninja/Datatables/PaymentDatatable.php b/app/Ninja/Datatables/PaymentDatatable.php index fb7dc175d5c7..4524337919d9 100644 --- a/app/Ninja/Datatables/PaymentDatatable.php +++ b/app/Ninja/Datatables/PaymentDatatable.php @@ -98,7 +98,7 @@ class PaymentDatatable extends EntityDatatable } ], [ - 'payment_status_name', + 'status', function ($model) { return self::getStatusLabel($model); } @@ -140,7 +140,7 @@ class PaymentDatatable extends EntityDatatable private function getStatusLabel($model) { - $label = trans('texts.status_' . strtolower($model->payment_status_name)); + $label = trans('texts.status_' . strtolower($model->status)); $class = 'default'; switch ($model->payment_status_id) { case PAYMENT_STATUS_PENDING: diff --git a/app/Ninja/Repositories/PaymentRepository.php b/app/Ninja/Repositories/PaymentRepository.php index 0c99521368c9..b6f37de72420 100644 --- a/app/Ninja/Repositories/PaymentRepository.php +++ b/app/Ninja/Repositories/PaymentRepository.php @@ -62,7 +62,7 @@ class PaymentRepository extends BaseRepository 'invoices.is_deleted as invoice_is_deleted', 'gateways.name as gateway_name', 'gateways.id as gateway_id', - 'payment_statuses.name as payment_status_name' + 'payment_statuses.name as status' ); $this->applyFilters($query, ENTITY_PAYMENT); diff --git a/resources/lang/en/texts.php b/resources/lang/en/texts.php index a5156a50a9ad..90e5929f307a 100644 --- a/resources/lang/en/texts.php +++ b/resources/lang/en/texts.php @@ -2225,7 +2225,6 @@ $LANG = array( 'vendor_name' => 'Vendor', 'entity_state' => 'State', - 'payment_status_name' => 'Status', 'client_created_at' => 'Date Created', 'postmark_error' => 'There was a problem sending the email through Postmark: :link', 'project' => 'Project', diff --git a/resources/views/clients/show.blade.php b/resources/views/clients/show.blade.php index 23c60e272e87..aa88495df769 100644 --- a/resources/views/clients/show.blade.php +++ b/resources/views/clients/show.blade.php @@ -219,6 +219,7 @@ ->setUrl(url('api/activities/'. $client->public_id)) ->setCustomValues('entityType', 'activity') ->setCustomValues('clientId', $client->public_id) + ->setCustomValues('rightAlign', [2, 3]) ->setOptions('sPaginationType', 'bootstrap') ->setOptions('bFilter', false) ->setOptions('aaSorting', [['0', 'desc']]) diff --git a/resources/views/datatable.blade.php b/resources/views/datatable.blade.php index 4355282fa94e..fdc6aa682b56 100644 --- a/resources/views/datatable.blade.php +++ b/resources/views/datatable.blade.php @@ -59,19 +59,19 @@ } }, "bAutoWidth": false, - @if (isset($hasCheckboxes) && $hasCheckboxes) - // Disable sorting on the first column "aoColumnDefs": [ + @if (isset($hasCheckboxes) && $hasCheckboxes) + // Disable sorting on the first column { 'bSortable': false, 'aTargets': [ 0, {{ count($columns) - 1 }} ] }, + @endif { 'sClass': 'right', 'aTargets': {{ isset($values['rightAlign']) ? json_encode($values['rightAlign']) : '[]' }} } ], - @endif @foreach ($options as $k => $o) {!! json_encode($k) !!}: {!! json_encode($o) !!}, @endforeach diff --git a/resources/views/list.blade.php b/resources/views/list.blade.php index 4b1f94021194..b2019484d216 100644 --- a/resources/views/list.blade.php +++ b/resources/views/list.blade.php @@ -65,7 +65,6 @@ {!! Datatable::table() ->addColumn(Utils::trans($datatable->columnFields(), $datatable->entityType)) ->setUrl(url('api/' . Utils::pluralizeEntityType($entityType) . '/' . (isset($clientId) ? $clientId : (isset($vendorId) ? $vendorId : '')))) - ->setCustomValues('rightAlign', isset($rightAlign) ? $rightAlign : []) ->setCustomValues('entityType', Utils::pluralizeEntityType($entityType)) ->setCustomValues('clientId', isset($clientId) && $clientId) ->setOptions('sPaginationType', 'bootstrap') @@ -108,6 +107,23 @@ {!! Former::close() !!} + +