Skip to content

Commit

Permalink
v3.4.15 (#1893)
Browse files Browse the repository at this point in the history
## [v3.4.15] - 2024-08-25
### New Features
- BooleanColumn - Toggleable Callback by @lrljoe in #1892

### Tweaks
- Doc Type Fixes by @lrljoe in #1891
  • Loading branch information
lrljoe authored Aug 25, 2024
1 parent ecf1fee commit d140f39
Show file tree
Hide file tree
Showing 26 changed files with 221 additions and 97 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

All notable changes to `laravel-livewire-tables` will be documented in this file

## [v3.4.15] - 2024-08-25
### New Features
- BooleanColumn - Toggleable Callback by @lrljoe in https://github.com/rappasoft/laravel-livewire-tables/pull/1892

### Tweaks
- Doc Type Fixes by @lrljoe in https://github.com/rappasoft/laravel-livewire-tables/pull/1891

## [v3.4.14] - 2024-08-25
### New Features
- Set Action Position (Left/Center/Right) and Set Actions in Toolbar by @lrljoe in https://github.com/rappasoft/laravel-livewire-tables/pull/1889
Expand Down
40 changes: 40 additions & 0 deletions docs/column-types/boolean_columns.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,46 @@ BooleanColumn::make('Active')
->yesNo()
```

### Toggleable

You may call a defined public function, which should live within your Table Component, to allow "toggling" against your database:

```php
BooleanColumn::make('Active', 'status')
->toggleable('changeStatus'),
```

Then your "changeStatus" method may look like
```php
public function changeStatus(int $id)
{
$item = $this->model::find($id);
$item->status = !$item->status;
$item->save();
}
```

### Toggleable Confirmation Message

You may define a confirmation message prior to executing your toggleable() method. The method will only be executed upon confirming.
```php
BooleanColumn::make('Active', 'status')
->confirmMessage('Are you sure that you want to change the status?')
->toggleable('changeStatus'),
```

Then your "changeStatus" method may look like
```php
public function changeStatus(int $id)
{
$item = $this->model::find($id);
$item->status = !$item->status;
$item->save();
}
```


### Additional Methods
Please also see the following for other available methods:
<ul>
<li>
Expand Down
75 changes: 38 additions & 37 deletions resources/views/includes/columns/boolean.blade.php
Original file line number Diff line number Diff line change
@@ -1,40 +1,27 @@
@if ($isTailwind)
@if ($status)
@if ($type === 'icons')
@if ($successValue === true)
<x-heroicon-o-check-circle class="inline-block h-5 w-5 text-green-500" />
@else
<x-heroicon-o-check-circle class="inline-block h-5 w-5 text-red-500" />
@endif
@elseif ($type === 'yes-no')
@if ($successValue === true)
<span>Yes</span>
@else
<span>No</span>
@endif
@endif
@else
@if ($type === 'icons')
@if ($successValue === false)
<x-heroicon-o-x-circle class="inline-block h-5 w-5 text-green-500" />
@else
<x-heroicon-o-x-circle class="inline-block h-5 w-5 text-red-500" />
@endif
@elseif ($type === 'yes-no')
@if ($successValue === false)
<span>Yes</span>
@else
<span>No</span>
@endif
@endif
@endif
@elseif ($isBootstrap)
@if($isToggleable && $toggleMethod != '')
<button wire:click="{{ $toggleMethod }}('{{ $rowPrimaryKey }}')"
@if($hasConfirmMessage) wire:confirm="{{ $confirmMessage }}" @endif
>
@endif
@if ($status)
@if ($type === 'icons')
@if ($successValue === true)
<x-heroicon-o-check-circle class="d-inline-block text-success laravel-livewire-tables-btn-small" />
@else
<x-heroicon-o-check-circle class="d-inline-block text-danger laravel-livewire-tables-btn-small" />
<x-heroicon-o-check-circle
@class(
[
"inline-block h-5 w-5 text-green-500" => $isTailwind,
"d-inline-block text-success laravel-livewire-tables-btn-small" => $isBootstrap
]
)
/>
@else
<x-heroicon-o-check-circle @class(
[
"inline-block h-5 w-5 text-red-500" => $isTailwind,
"d-inline-block text-danger laravel-livewire-tables-btn-small" => $isBootstrap
]
)
/>
@endif
@elseif ($type === 'yes-no')
@if ($successValue === true)
Expand All @@ -46,9 +33,21 @@
@else
@if ($type === 'icons')
@if ($successValue === false)
<x-heroicon-o-x-circle class="d-inline-block text-success laravel-livewire-tables-btn-small" />
@else
<x-heroicon-o-x-circle class="d-inline-block text-danger laravel-livewire-tables-btn-small" />
<x-heroicon-o-x-circle @class(
[
"inline-block h-5 w-5 text-green-500" => $isTailwind,
"d-inline-block text-success laravel-livewire-tables-btn-small" => $isBootstrap
]
)
/>
@else
<x-heroicon-o-x-circle @class(
[
"inline-block h-5 w-5 text-red-500" => $isTailwind,
"d-inline-block text-danger laravel-livewire-tables-btn-small" => $isBootstrap
]
)
/>
@endif
@elseif ($type === 'yes-no')
@if ($successValue === false)
Expand All @@ -58,4 +57,6 @@
@endif
@endif
@endif
@if($isToggleable && $toggleMethod != '')
</button>
@endif
4 changes: 2 additions & 2 deletions src/Traits/Configuration/FooterConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ public function setUseHeaderAsFooterDisabled(): self
return $this;
}

public function setFooterTrAttributes(callable $callback): self
public function setFooterTrAttributes(\Closure $callback): self
{
$this->footerTrAttributesCallback = $callback;

return $this;
}

public function setFooterTdAttributes(callable $callback): self
public function setFooterTdAttributes(\Closure $callback): self
{
$this->footerTdAttributesCallback = $callback;

Expand Down
4 changes: 2 additions & 2 deletions src/Traits/Configuration/SecondaryHeaderConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ public function setSecondaryHeaderDisabled(): self
return $this;
}

public function setSecondaryHeaderTrAttributes(callable $callback): self
public function setSecondaryHeaderTrAttributes(\Closure $callback): self
{
$this->secondaryHeaderTrAttributesCallback = $callback;

return $this;
}

public function setSecondaryHeaderTdAttributes(callable $callback): self
public function setSecondaryHeaderTdAttributes(\Closure $callback): self
{
$this->secondaryHeaderTdAttributesCallback = $callback;

Expand Down
12 changes: 6 additions & 6 deletions src/Traits/Configuration/TableAttributeConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function setTbodyAttributes(array $attributes = []): self
/**
* Set a list of attributes to override on the th elements
*/
public function setThAttributes(callable $callback): self
public function setThAttributes(\Closure $callback): self
{
$this->thAttributesCallback = $callback;

Expand All @@ -78,7 +78,7 @@ public function setThAttributes(callable $callback): self
/**
* Set a list of attributes to override on the th sort button elements
*/
public function setThSortButtonAttributes(callable $callback): self
public function setThSortButtonAttributes(\Closure $callback): self
{
$this->thSortButtonAttributesCallback = $callback;

Expand All @@ -88,7 +88,7 @@ public function setThSortButtonAttributes(callable $callback): self
/**
* Set a list of attributes to override on the td elements
*/
public function setTrAttributes(callable $callback): self
public function setTrAttributes(\Closure $callback): self
{
$this->trAttributesCallback = $callback;

Expand All @@ -98,21 +98,21 @@ public function setTrAttributes(callable $callback): self
/**
* Set a list of attributes to override on the td elements
*/
public function setTdAttributes(callable $callback): self
public function setTdAttributes(\Closure $callback): self
{
$this->tdAttributesCallback = $callback;

return $this;
}

public function setTableRowUrl(callable $callback): self
public function setTableRowUrl(\Closure $callback): self
{
$this->trUrlCallback = $callback;

return $this;
}

public function setTableRowUrlTarget(callable $callback): self
public function setTableRowUrlTarget(\Closure $callback): self
{
$this->trUrlTargetCallback = $callback;

Expand Down
15 changes: 4 additions & 11 deletions src/Traits/Helpers/ConfigurableAreasHelpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,9 @@ public function hasConfigurableAreaFor(string $area): bool
return isset($this->configurableAreas[$area]) && $this->getConfigurableAreaFor($area) !== null;
}

/**
* @param string|array<mixed> $area
*/
public function getConfigurableAreaFor($area): ?string
public function getConfigurableAreaFor(string $area): ?string
{
$area = $this->configurableAreas[$area] ?? null;
$area = array_key_exists($area, $this->configurableAreas) ? $this->configurableAreas[$area] : null;

if (is_array($area)) {
return $area[0];
Expand All @@ -35,13 +32,9 @@ public function getConfigurableAreaFor($area): ?string
return $area;
}

/**
* @param string|array<mixed> $area
* @return array<mixed>
*/
public function getParametersForConfigurableArea($area): array
public function getParametersForConfigurableArea(string $area): array
{
$area = $this->configurableAreas[$area] ?? null;
$area = array_key_exists($area, $this->configurableAreas) ? $this->configurableAreas[$area] : null;

if (is_array($area) && isset($area[1]) && is_array($area[1])) {
return $area[1];
Expand Down
6 changes: 5 additions & 1 deletion src/Traits/Helpers/SearchHelpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,11 @@ public function getSearchOptions(): string

public function getSearchPlaceholder(): string
{
return $this->hasSearchPlaceholder() ? $this->searchPlaceholder : __('Search');
if ($this->hasSearchPlaceholder()) {
return $this->searchPlaceholder;
}

return __('Search');
}

public function hasSearchPlaceholder(): bool
Expand Down
4 changes: 2 additions & 2 deletions src/Traits/WithFooter.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ trait WithFooter

protected bool $columnsWithFooter = false;

protected ?object $footerTrAttributesCallback;
protected ?\Closure $footerTrAttributesCallback;

protected ?object $footerTdAttributesCallback;
protected ?\Closure $footerTdAttributesCallback;

public function setupFooter(): void
{
Expand Down
4 changes: 2 additions & 2 deletions src/Traits/WithSecondaryHeader.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ trait WithSecondaryHeader

protected bool $columnsWithSecondaryHeader = false;

protected ?object $secondaryHeaderTrAttributesCallback;
protected ?\Closure $secondaryHeaderTrAttributesCallback;

protected ?object $secondaryHeaderTdAttributesCallback;
protected ?\Closure $secondaryHeaderTdAttributesCallback;

public function bootedWithSecondaryHeader(): void
{
Expand Down
12 changes: 6 additions & 6 deletions src/Traits/WithTableAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ trait WithTableAttributes

protected array $tbodyAttributes = [];

protected ?object $thAttributesCallback;
protected ?\Closure $thAttributesCallback;

protected ?object $thSortButtonAttributesCallback;
protected ?\Closure $thSortButtonAttributesCallback;

protected ?object $trAttributesCallback;
protected ?\Closure $trAttributesCallback;

protected ?object $tdAttributesCallback;
protected ?\Closure $tdAttributesCallback;

protected ?object $trUrlCallback;
protected ?\Closure $trUrlCallback;

protected ?object $trUrlTargetCallback;
protected ?\Closure $trUrlTargetCallback;
}
11 changes: 11 additions & 0 deletions src/Views/Columns/BooleanColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
use Rappasoft\LaravelLivewireTables\Views\Column;
use Rappasoft\LaravelLivewireTables\Views\Traits\Configuration\BooleanColumnConfiguration;
use Rappasoft\LaravelLivewireTables\Views\Traits\Core\HasCallback;
use Rappasoft\LaravelLivewireTables\Views\Traits\Core\HasConfirmation;
use Rappasoft\LaravelLivewireTables\Views\Traits\Helpers\BooleanColumnHelpers;

class BooleanColumn extends Column
{
use BooleanColumnConfiguration,
BooleanColumnHelpers,
HasConfirmation,
HasCallback;

protected string $type = 'icons';
Expand All @@ -21,6 +23,10 @@ class BooleanColumn extends Column

protected string $view = 'livewire-tables::includes.columns.boolean';

protected bool $isToggleable = false;

protected ?string $toggleMethod;

public function getContents(Model $row): null|string|\Illuminate\Support\HtmlString|DataTableConfigurationException|\Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
{
if ($this->isLabel()) {
Expand All @@ -30,6 +36,11 @@ public function getContents(Model $row): null|string|\Illuminate\Support\HtmlStr
$value = $this->getValue($row);

return view($this->getView())
->withRowPrimaryKey($row->{$row->getKeyName()})
->withIsToggleable($this->getIsToggleable())
->withToggleMethod($this->getIsToggleable() ? $this->getToggleMethod() : '')
->withHasConfirmMessage($this->hasConfirmMessage())
->withConfirmMessage($this->hasConfirmMessage() ? $this->getConfirmMessage() : '')
->withIsTailwind($this->isTailwind())
->withIsBootstrap($this->isBootstrap())
->withSuccessValue($this->getSuccessValue())
Expand Down
2 changes: 1 addition & 1 deletion src/Views/Columns/ColorColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class ColorColumn extends Column
ColorColumnHelpers;
use HasDefaultStringValue;

public ?object $colorCallback = null;
public ?\Closure $colorCallback;

protected string $view = 'livewire-tables::includes.columns.color';

Expand Down
Loading

0 comments on commit d140f39

Please sign in to comment.