Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v3.2.6 Release #1729

Merged
merged 13 commits into from
Jun 5, 2024
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@

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

## [v3.2.5] - 2024-04-30
### New Features
- Add setConfigurableArea by @lrljoe in https://github.com/rappasoft/laravel-livewire-tables/pull/1706
- Add User prompt for missing inputs by @achyutkneupane in https://github.com/rappasoft/laravel-livewire-tables/pull/1681

### Bug Fixes
- UI patch: toolbar fix for reordering by @itsLeonB in https://github.com/rappasoft/laravel-livewire-tables/pull/1690

### Tweaks
- Adjust Workflow behaviour for PCOV by @lrljoe in https://github.com/rappasoft/laravel-livewire-tables/pull/1706
- Updated nl language by @Jerimu in https://github.com/rappasoft/laravel-livewire-tables/pull/1695
- Updated nl language by @Jerimu in https://github.com/rappasoft/laravel-livewire-tables/pull/1694

## [v3.2.4] - 2024-03-01
### Bug Fixes
- Collapsing Columns fix when multiple tables are displayed on a page by @lrljoe
Expand Down
9 changes: 9 additions & 0 deletions docs/columns/available-methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,15 @@ Column::make('Name')
->html(),
```

And this method is also available for the [LinkColumn](./other-column-types#content-link-columns)

```php
LinkColumn::make('Name', 'name')
->title(fn ($row) => 'Title')
->location(fn ($row) => "#$row->id")
->html(),
```

### Using a view

If you would like to render a view for the cell:
Expand Down
60 changes: 60 additions & 0 deletions docs/filters/available-methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -398,3 +398,63 @@ If the filter takes any config options, you can set them with the `config` metho
'max' => '2021-12-31',
])
```

### Customising Wireable Behaviour

For the following Filters, you may customise how the input is wire:model into the Table Component:

- DateFilter (Defaults to Live)
- DateTimeFilter (Defaults to Live)
- MultiSelectDropdownFilter (Defaults to live.debounce.250ms)
- MultiSelectFilter (Defaults to live.debounce.250ms)
- NumberFilter (Defaults to Blur)
- SelectFilter (Defaults to Live)
- TextFilter (Defaults to Blur)

You may override this using the following methods, on any of the above Filter types:

#### setWireBlur()
Forces the filter to use a wire:model.blur approach
```
TextFilter::make('Name')
->config([
'placeholder' => 'Search Name',
'maxlength' => '25',
])
->setWireBlur()
```

#### setWireDefer()
Forces the filter to use a wire:model approach
```
TextFilter::make('Name')
->config([
'placeholder' => 'Search Name',
'maxlength' => '25',
])
->setWireDefer()
```

#### setWireLive()
Forces the fitler to use a wire:model.live approach
```
TextFilter::make('Name')
->config([
'placeholder' => 'Search Name',
'maxlength' => '25',
])
->setWireLive()
```

#### setWireDebounce(int $debounceDelay)
Allows you to pass a string to use a wire:model.live.debounce.Xms approach
```
```
TextFilter::make('Name')
->config([
'placeholder' => 'Search Name',
'maxlength' => '25',
])
->setWireDebounce(50)
```
```
3 changes: 1 addition & 2 deletions resources/views/components/tools/filters/date.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
"rounded-md shadow-sm" => $isTailwind,
"mb-3 mb-md-0 input-group" => $isBootstrap,
])>
<input
wire:model.live="filterComponents.{{ $filter->getKey() }}"
<input {{ $filter->getWireMethod("filterComponents.".$filter->getKey()) }}
wire:key="{{ $filter->generateWireKey($tableName, 'date') }}"
id="{{ $tableName }}-filter-{{ $filter->getKey() }}@if($filter->hasCustomPosition())-{{ $filter->getCustomPosition() }}@endif"
type="date"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"mb-3 mb-md-0 input-group" => $isBootstrap,
])>
<input
wire:model.live="filterComponents.{{ $filter->getKey() }}"
wire:key="{{ $filter->generateWireKey($tableName, 'datetime') }}"
id="{{ $tableName }}-filter-{{ $filter->getKey() }}@if($filter->hasCustomPosition())-{{ $filter->getCustomPosition() }}@endif"
type="datetime-local"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
@if ($isTailwind)
<div class="rounded-md shadow-sm">
<select multiple
wire:model.live.debounce.250ms="filterComponents.{{ $filter->getKey() }}"
{{ $filter->getWireMethod("filterComponents.".$filter->getKey()) }}
wire:key="{{ $filter->generateWireKey($tableName, 'multiselectdropdown') }}"
id="{{ $tableName }}-filter-{{ $filter->getKey() }}@if($filter->hasCustomPosition())-{{ $filter->getCustomPosition() }}@endif"
class="block w-full transition duration-150 ease-in-out border-gray-300 rounded-md shadow-sm focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50 dark:bg-gray-800 dark:text-white dark:border-gray-600"
Expand All @@ -28,7 +28,7 @@ class="block w-full transition duration-150 ease-in-out border-gray-300 rounded-
</div>
@elseif ($isBootstrap)
<select multiple
wire:model.live.debounce.250ms="filterComponents.{{ $filter->getKey() }}"
{{ $filter->getWireMethod("filterComponents.".$filter->getKey()) }}
wire:key="{{ $filter->generateWireKey($tableName, 'multiselectdropdown') }}"
id="{{ $tableName }}-filter-{{ $filter->getKey() }}@if($filter->hasCustomPosition())-{{ $filter->getCustomPosition() }}@endif"
class="{{ $isBootstrap4 ? 'form-control' : 'form-select' }}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class="text-indigo-600 rounded border-gray-300 shadow-sm transition duration-150
id="{{ $tableName }}-filter-{{ $filter->getKey() }}-{{ $loop->index }}-@if($filter->hasCustomPosition()){{ $filter->getCustomPosition() }}@endif"
value="{{ $key }}"
wire:key="{{ $tableName }}-filter-{{ $filter->getKey() }}-{{ $loop->index }}-@if($filter->hasCustomPosition()){{ $filter->getCustomPosition() }}@endif"
wire:model.live.debounce.250ms="filterComponents.{{ $filter->getKey() }}"
{{ $filter->getWireMethod("filterComponents.".$filter->getKey()) }}
class="text-indigo-600 rounded border-gray-300 shadow-sm transition duration-150 ease-in-out focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50 dark:bg-gray-900 dark:text-white dark:border-gray-600 dark:hover:bg-gray-600 dark:focus:bg-gray-600 disabled:opacity-50 disabled:cursor-wait"
>
<label for="{{ $tableName }}-filter-{{ $filter->getKey() }}-{{ $loop->index }}-@if($filter->hasCustomPosition()){{ $filter->getCustomPosition() }}@endif" class="dark:text-white">{{ $value }}</label>
Expand All @@ -53,7 +53,8 @@ class="form-check-input"
id="{{ $tableName }}-filter-{{ $filter->getKey() }}-{{ $loop->index }}-@if($filter->hasCustomPosition()){{ $filter->getCustomPosition() }}@endif"
value="{{ $key }}"
wire:key="{{ $tableName }}-filter-{{ $filter->getKey() }}-{{ $loop->index }}-@if($filter->hasCustomPosition()){{ $filter->getCustomPosition() }}@endif"
wire:model.live.debounce.250ms="filterComponents.{{ $filter->getKey() }}"
{{ $filter->getWireMethod("filterComponents.".$filter->getKey()) }}

>
<label class="form-check-label" for="{{ $tableName }}-filter-{{ $filter->getKey() }}-{{ $loop->index }}-@if($filter->hasCustomPosition()){{ $filter->getCustomPosition() }}@endif">{{ $value }}</label>
</div>
Expand Down
3 changes: 1 addition & 2 deletions resources/views/components/tools/filters/number.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
"rounded-md shadow-sm" => $isTailwind,
"mb-3 mb-md-0 input-group" => $isBootstrap,
])>
<input
wire:model.blur="filterComponents.{{ $filter->getKey() }}"
<input {{ $filter->getWireMethod("filterComponents.".$filter->getKey()) }}
wire:key="{{ $filter->generateWireKey($tableName, 'number') }}"
id="{{ $tableName }}-filter-{{ $filter->getKey() }}@if($filter->hasCustomPosition())-{{ $filter->getCustomPosition() }}@endif"
type="number"
Expand Down
3 changes: 1 addition & 2 deletions resources/views/components/tools/filters/select.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
'rounded-md shadow-sm' => $isTailwind,
'inline' => $isBootstrap,
])>
<select
wire:model.live="filterComponents.{{ $filter->getKey() }}"
<select {{ $filter->getWireMethod("filterComponents.".$filter->getKey()) }}
wire:key="{{ $filter->generateWireKey($tableName, 'select') }}"
id="{{ $tableName }}-filter-{{ $filter->getKey() }}@if($filter->hasCustomPosition())-{{ $filter->getCustomPosition() }}@endif"
@class([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
"rounded-md shadow-sm" => $isTailwind,
"mb-3 mb-md-0 input-group" => $isBootstrap,
])>
<input
wire:model.blur="filterComponents.{{ $filter->getKey() }}"
<input {{ $filter->getWireMethod("filterComponents.".$filter->getKey()) }}
wire:key="{{ $filter->generateWireKey($tableName, 'text') }}"
id="{{ $tableName }}-filter-{{ $filter->getKey() }}@if($filter->hasCustomPosition())-{{ $filter->getCustomPosition() }}@endif"
type="text"
Expand Down
8 changes: 7 additions & 1 deletion resources/views/includes/columns/link.blade.php
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
<a href="{{ $path }}" {!! count($attributes) ? $column->arrayToAttributes($attributes) : '' !!}>{{ $title }}</a>
<a href="{{ $path }}" {!! count($attributes) ? $column->arrayToAttributes($attributes) : '' !!}>
@if($column->isHtml())
{!! $title !!}
@else
{{ $title }}
@endif
</a>
49 changes: 46 additions & 3 deletions src/Commands/MakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,15 @@ public function getModelImport(): string
}

if (isset($this->modelPath)) {
if (File::exists(rtrim($this->modelPath, '/').'/'.$this->model.'.php')) {

return Str::studly(str_replace('/', '\\', $this->modelPath)).$this->model;
$filename = rtrim($this->modelPath, '/').'/'.$this->model.'.php';
if (File::exists($filename)) {
//In case the file has more than one class which is highly unlikely but still possible
$classes = array_filter($this->getClassesList($filename), function ($class) {
return substr($class, strrpos($class, '\\') + 1) == $this->model;
});
if (count($classes) == 1) {
return $classes[0];
}
}
}

Expand All @@ -138,6 +144,43 @@ public function getModelImport(): string
return 'App\Models\\'.$this->model;
}

/*
* Credits to Harm Smits: https://stackoverflow.com/a/67099502/2263114
*/
private function getClassesList($file): array
{
$classes = [];
$namespace = '';
$tokens = \PhpToken::tokenize(file_get_contents($file));

for ($i = 0; $i < count($tokens); $i++) {
if ($tokens[$i]->getTokenName() === 'T_NAMESPACE') {
for ($j = $i + 1; $j < count($tokens); $j++) {
if ($tokens[$j]->getTokenName() === 'T_NAME_QUALIFIED') {
$namespace = $tokens[$j]->text;
break;
}
}
}

if ($tokens[$i]->getTokenName() === 'T_CLASS') {
for ($j = $i + 1; $j < count($tokens); $j++) {
if ($tokens[$j]->getTokenName() === 'T_WHITESPACE') {
continue;
}

if ($tokens[$j]->getTokenName() === 'T_STRING') {
$classes[] = $namespace.'\\'.$tokens[$j]->text;
} else {
break;
}
}
}
}

return $classes;
}

/**
* @throws \Exception
*/
Expand Down
2 changes: 1 addition & 1 deletion src/LaravelLivewireTablesServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class LaravelLivewireTablesServiceProvider extends ServiceProvider
public function boot(): void
{

AboutCommand::add('Rappasoft Laravel Livewire Tables', fn () => ['Version' => '3.2.4']);
AboutCommand::add('Rappasoft Laravel Livewire Tables', fn () => ['Version' => '3.2.5']);

$this->mergeConfigFrom(
__DIR__.'/../config/livewire-tables.php', 'livewire-tables'
Expand Down
33 changes: 18 additions & 15 deletions src/Views/Columns/DateColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Rappasoft\LaravelLivewireTables\Views\Columns;

use Carbon\Carbon;
use DateTime;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\HtmlString;
use Rappasoft\LaravelLivewireTables\Exceptions\DataTableConfigurationException;
Expand All @@ -28,25 +30,26 @@ public function getContents(Model $row): null|string|\BackedEnum|HtmlString|Data
{

$dateTime = $this->getValue($row);
if (! ($dateTime instanceof \DateTime)) {
try {
// Check if format matches what is expected
if (! \Carbon\Carbon::hasFormatWithModifiers($dateTime, $this->getInputFormat())) {
throw new \Exception('DateColumn Received Invalid Format');
}

// Create DateTime Object
$dateTime = \DateTime::createFromFormat($this->getInputFormat(), $dateTime);
} catch (\Exception $exception) {
report($exception);
if ($dateTime != '' && $dateTime != null) {
if ($dateTime instanceof DateTime) {
return $dateTime->format($this->getOutputFormat());
} else {
try {
// Check if format matches what is expected
if (Carbon::canBeCreatedFromFormat($dateTime, $this->getInputFormat())) {
return Carbon::createFromFormat($this->getInputFormat(), $dateTime)->format($this->getOutputFormat());
}
} catch (\Exception $exception) {
report($exception);

// Return Null
return $this->getEmptyValue();
}

// Return Null
return $this->getEmptyValue();
}
}

// Return
return $dateTime->format($this->getOutputFormat());

return $this->getEmptyValue();
}
}
4 changes: 4 additions & 0 deletions src/Views/Filters/DateFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@

use DateTime;
use Rappasoft\LaravelLivewireTables\Views\Filter;
use Rappasoft\LaravelLivewireTables\Views\Traits\Core\HasWireables;
use Rappasoft\LaravelLivewireTables\Views\Traits\Filters\{HasConfig, IsStringFilter};

class DateFilter extends Filter
{
use HasConfig,
IsStringFilter;
use HasWireables;

public string $wireMethod = 'live';

protected string $view = 'livewire-tables::components.tools.filters.date';

Expand Down
4 changes: 4 additions & 0 deletions src/Views/Filters/DateRangeFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@
namespace Rappasoft\LaravelLivewireTables\Views\Filters;

use Rappasoft\LaravelLivewireTables\Views\Filter;
use Rappasoft\LaravelLivewireTables\Views\Traits\Core\HasWireables;
use Rappasoft\LaravelLivewireTables\Views\Traits\Filters\{HasConfig,HasOptions};

class DateRangeFilter extends Filter
{
use HasOptions,
HasConfig;
use HasWireables;

public string $wireMethod = 'blur';

protected string $view = 'livewire-tables::components.tools.filters.date-range';

Expand Down
4 changes: 4 additions & 0 deletions src/Views/Filters/DateTimeFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@

use DateTime;
use Rappasoft\LaravelLivewireTables\Views\Filter;
use Rappasoft\LaravelLivewireTables\Views\Traits\Core\HasWireables;
use Rappasoft\LaravelLivewireTables\Views\Traits\Filters\{HasConfig, IsStringFilter};

class DateTimeFilter extends Filter
{
use HasConfig,
IsStringFilter;
use HasWireables;

public string $wireMethod = 'live';

protected string $view = 'livewire-tables::components.tools.filters.datetime';

Expand Down
5 changes: 5 additions & 0 deletions src/Views/Filters/LivewireComponentFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@

use Rappasoft\LaravelLivewireTables\Exceptions\DataTableConfigurationException;
use Rappasoft\LaravelLivewireTables\Views\Filter;
use Rappasoft\LaravelLivewireTables\Views\Traits\Core\HasWireables;

class LivewireComponentFilter extends Filter
{
use HasWireables;

public string $wireMethod = 'blur';

protected string $view = 'livewire-tables::components.tools.filters.livewire-component-filter';

public string $livewireComponent = '';
Expand Down
Loading
Loading