Skip to content

Commit

Permalink
rollback formatAvg sum and count
Browse files Browse the repository at this point in the history
  • Loading branch information
luanfreitasdev committed Feb 18, 2022
1 parent 7baf5cc commit 18d442d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 104 deletions.
31 changes: 5 additions & 26 deletions resources/views/components/table-footer.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,39 +26,18 @@
<td class="{{ $theme->table->tdBodyClassTotalColumns . ' '.$column->bodyClass ?? '' }}"
style="{{ $column->hidden === true ? 'display:none': '' }}; {{ $theme->table->tdBodyStyleTotalColumns .' '.$column->bodyStyle ?? '' }}">
@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
<span>{{ $column->count['label'] }}: {{ $count }}
<span>{{ $column->count['label'] }}: {{ $withoutPaginatedData->collect()
->reject(function($data) use($field) { return empty($data->{$field}); })
->count($field) }}
</span>
<br>
@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
<span>{{ $column->sum['label'] }}: {{ $sum }}</span>
<span>{{ $column->sum['label'] }}: {{ $withoutPaginatedData->collect()->sum($field) }}</span>
<br>
@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
<span>{{ $column->avg['label'] }}: {{ $avg }}</span>
<span>{{ $column->avg['label'] }}: {{ $withoutPaginatedData->collect()->avg($field) }}</span>
<br>
@endif
</td>
Expand Down
31 changes: 5 additions & 26 deletions resources/views/components/table-header.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,39 +26,18 @@
<td class="{{ $theme->table->tdBodyClassTotalColumns . ' '.$column->bodyClass ?? '' }}"
style="{{ $column->hidden === true ? 'display:none': '' }}; {{$theme->table->tdBodyStyleTotalColumns . ' '.$column->bodyStyle ?? '' }}">
@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
<span>{{ $column->count['label'] }}: {{ $count }}
<span>{{ $column->count['label'] }}: {{ $withoutPaginatedData->collect()
->reject(function($data) use($field) { return empty($data->$field); })
->count($field) }}
</span>
<br>
@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
<span>{{ $column->sum['label'] }}: {{ $sum }}</span>
<span>{{ $column->sum['label'] }}: {{ $withoutPaginatedData->collect()->sum($field) }}</span>
<br>
@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
<span>{{ $column->avg['label'] }}: {{ $avg }}</span>
<span>{{ $column->avg['label'] }}: {{ round($withoutPaginatedData->collect()->avg($field), $column->avg['rounded']) }}</span>
<br>
@endif
</td>
Expand Down
58 changes: 6 additions & 52 deletions src/Column.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand Down Expand Up @@ -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
*
Expand All @@ -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;
}
Expand All @@ -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
Expand Down

0 comments on commit 18d442d

Please sign in to comment.