From 18d442d0d8c963351eb1b43f58149b276aa149a2 Mon Sep 17 00:00:00 2001 From: Luan Freitas Date: Fri, 18 Feb 2022 20:33:23 -0300 Subject: [PATCH] rollback formatAvg sum and count --- .../views/components/table-footer.blade.php | 31 ++-------- .../views/components/table-header.blade.php | 31 ++-------- src/Column.php | 58 ++----------------- 3 files changed, 16 insertions(+), 104 deletions(-) diff --git a/resources/views/components/table-footer.blade.php b/resources/views/components/table-footer.blade.php index 2a9a09d5..4fd92b3b 100644 --- a/resources/views/components/table-footer.blade.php +++ b/resources/views/components/table-footer.blade.php @@ -26,39 +26,18 @@ @if ($column->count['footer']) - @php - $count = $withoutPaginatedData->collect() - ->reject(function($data) use($field) { return empty($data->$field); }) - ->count($field); - - if (is_callable($column->count['formatter'])) { - $count = call_user_func($column->count['formatter'], $count); - } - @endphp - {{ $column->count['label'] }}: {{ $count }} + {{ $column->count['label'] }}: {{ $withoutPaginatedData->collect() + ->reject(function($data) use($field) { return empty($data->{$field}); }) + ->count($field) }}
@endif @if ($column->sum['footer'] && is_numeric($withoutPaginatedData[0][$field])) - @php - $sum = $withoutPaginatedData->collect()->sum($field); - - if (is_callable($column->sum['formatter'])) { - $sum = call_user_func($column->sum['formatter'], $sum); - } - @endphp - {{ $column->sum['label'] }}: {{ $sum }} + {{ $column->sum['label'] }}: {{ $withoutPaginatedData->collect()->sum($field) }}
@endif @if ($column->avg['footer'] && is_numeric($withoutPaginatedData[0][$column->dataField])) - @php - $avg = round($withoutPaginatedData->collect()->avg($field), $column->avg['rounded']); - - if (is_callable($column->avg['formatter'])) { - $avg = call_user_func($column->avg['formatter'], $avg); - } - @endphp - {{ $column->avg['label'] }}: {{ $avg }} + {{ $column->avg['label'] }}: {{ $withoutPaginatedData->collect()->avg($field) }}
@endif diff --git a/resources/views/components/table-header.blade.php b/resources/views/components/table-header.blade.php index 478a0345..1bb05445 100644 --- a/resources/views/components/table-header.blade.php +++ b/resources/views/components/table-header.blade.php @@ -26,39 +26,18 @@ @if ($column->count['header']) - @php - $count = $withoutPaginatedData->collect() - ->reject(function($data) use($field) { return empty($data->$field); }) - ->count($field); - - if (is_callable($column->count['formatter'])) { - $count = call_user_func($column->count['formatter'], $count); - } - @endphp - {{ $column->count['label'] }}: {{ $count }} + {{ $column->count['label'] }}: {{ $withoutPaginatedData->collect() + ->reject(function($data) use($field) { return empty($data->$field); }) + ->count($field) }}
@endif @if ($column->sum['header'] && is_numeric($withoutPaginatedData[0][$field])) - @php - $sum = $withoutPaginatedData->collect()->sum($field); - - if (is_callable($column->sum['formatter'])) { - $sum = call_user_func($column->sum['formatter'], $sum); - } - @endphp - {{ $column->sum['label'] }}: {{ $sum }} + {{ $column->sum['label'] }}: {{ $withoutPaginatedData->collect()->sum($field) }}
@endif @if ($column->avg['header'] && is_numeric($withoutPaginatedData[0][$field])) - @php - $avg = round($withoutPaginatedData->collect()->avg($field), $column->avg['rounded']); - - if (is_callable($column->avg['formatter'])) { - $avg = call_user_func($column->avg['formatter'], $avg); - } - @endphp - {{ $column->avg['label'] }}: {{ $avg }} + {{ $column->avg['label'] }}: {{ round($withoutPaginatedData->collect()->avg($field), $column->avg['rounded']) }}
@endif diff --git a/src/Column.php b/src/Column.php index 5f4bc577..16f64186 100644 --- a/src/Column.php +++ b/src/Column.php @@ -35,22 +35,18 @@ final class Column public bool $sortable = false; public array $sum = [ - 'header' => false, - 'footer' => false, - 'formatter' => null, + 'header' => false, + 'footer' => false, ]; public array $count = [ - 'header' => false, - 'footer' => false, - 'formatter' => null, + 'header' => false, + 'footer' => false, ]; public array $avg = [ - 'header' => false, - 'footer' => false, - 'formatter' => null, - 'rounded' => 0, + 'header' => false, + 'footer' => false, ]; public array $inputs = []; @@ -137,20 +133,6 @@ public function withSum(string $label = 'Sum', bool $header = true, bool $footer return $this; } - /** - * Format SUM output - * - * @param callable $formatFunction - * - * @return $this - */ - public function formatSum(callable $formatFunction): Column - { - $this->sum['formatter'] = $formatFunction; - - return $this; - } - /** * Will enable the column for total count * @@ -161,20 +143,6 @@ public function withCount(string $label = 'Count', bool $header = true, bool $fo $this->count['label'] = $label; $this->count['header'] = $header; $this->count['footer'] = $footer; - - return $this; - } - - /** - * Format Count output - * - * @param callable $formatFunction - * - * @return $this - */ - public function formatCount(callable $formatFunction): Column - { - $this->count['formatter'] = $formatFunction; return $this; } @@ -193,20 +161,6 @@ public function withAvg(string $label = 'Avg', bool $header = true, bool $footer return $this; } - - /** - * Format Avg output - * - * @param callable $formatFunction - * - * @return $this - */ - public function formatAvg(callable $formatFunction): Column - { - $this->avg['formatter'] = $formatFunction; - - return $this; - } /** * Field in the database