Skip to content

Commit

Permalink
v3.2.6 Release (#1729)
Browse files Browse the repository at this point in the history
* Fix ChangeLog, SP

* Filters - Set wire:model Method per-filter (#1699)


* Add wireableMethod tests 
---------

Co-authored-by: lrljoe <lrljoe@users.noreply.github.com>

* Removing broken test (#1719)

* Scan provided path for all available FQCNs in paths within and outside app folder (#1714)

* Updated the make command to scan paths provided and check whether class of the model provided exists in the file.

This works with paths that are both within the app folder and outside such as vendor directory

---------

Co-authored-by: Marvin Ochieng <marvin@technologic-software.com>

* Add fix for DateColumn when empty (#1726)

* Add fix for DateColumn when empty


---------

Co-authored-by: lrljoe <lrljoe@users.noreply.github.com>

* PHPUnit - Migrate from Doc Comment Configuration (#1727)

* Migrate from Doc Comments to Attributes for PHPUnit

---------

Co-authored-by: lrljoe <lrljoe@users.noreply.github.com>

* Add HTML render support for LinkColumn (#1728)

* Add the html render support for the LinkColumn

---------

Co-authored-by: lrljoe <lrljoe@users.noreply.github.com>

* Remove ChangeLog & SP Fixes

---------

Co-authored-by: lrljoe <lrljoe@users.noreply.github.com>

---------

Co-authored-by: lrljoe <lrljoe@users.noreply.github.com>
Co-authored-by: marvoh <marvoh@protonmail.com>
Co-authored-by: Marvin Ochieng <marvin@technologic-software.com>
Co-authored-by: Abdul Haseeb Khan <abdulhaseebkhan407@gmail.com>
  • Loading branch information
5 people committed Jun 5, 2024
1 parent 2bd477e commit 9123480
Show file tree
Hide file tree
Showing 98 changed files with 1,368 additions and 1,809 deletions.
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
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
4 changes: 4 additions & 0 deletions src/Views/Filters/MultiSelectDropdownFilter.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\{HasOptions,IsArrayFilter};

class MultiSelectDropdownFilter extends Filter
{
use HasOptions,
IsArrayFilter;
use HasWireables;

public string $wireMethod = 'live.debounce.250ms';

protected string $view = 'livewire-tables::components.tools.filters.multi-select-dropdown';

Expand Down
4 changes: 4 additions & 0 deletions src/Views/Filters/MultiSelectFilter.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\{HasOptions,IsArrayFilter};

class MultiSelectFilter extends Filter
{
use HasOptions,
IsArrayFilter;
use HasWireables;

public string $wireMethod = 'live.debounce.250ms';

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

Expand Down
Loading

0 comments on commit 9123480

Please sign in to comment.