-
-
Notifications
You must be signed in to change notification settings - Fork 344
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Use booted instead of boot for traits * Update Test Case * Add test for mount parameters * Update for NoColumns Test * Add null mount --------- Co-authored-by: lrljoe <[email protected]>
- Loading branch information
Showing
13 changed files
with
372 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
import './css/laravel-livewire-tables.min.css' | ||
import './js/laravel-livewire-tables.js' | ||
import './js/laravel-livewire-tables.min.js' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
<?php | ||
|
||
namespace Rappasoft\LaravelLivewireTables\Tests\Http\Livewire\FailingTables; | ||
|
||
use Illuminate\Database\Eloquent\Builder; | ||
use Rappasoft\LaravelLivewireTables\DataTableComponent; | ||
use Rappasoft\LaravelLivewireTables\Tests\Models\Breed; | ||
use Rappasoft\LaravelLivewireTables\Tests\Models\Pet; | ||
use Rappasoft\LaravelLivewireTables\Tests\Models\Species; | ||
use Rappasoft\LaravelLivewireTables\Views\Filters\DateFilter; | ||
use Rappasoft\LaravelLivewireTables\Views\Filters\DateTimeFilter; | ||
use Rappasoft\LaravelLivewireTables\Views\Filters\MultiSelectDropdownFilter; | ||
use Rappasoft\LaravelLivewireTables\Views\Filters\MultiSelectFilter; | ||
use Rappasoft\LaravelLivewireTables\Views\Filters\NumberFilter; | ||
use Rappasoft\LaravelLivewireTables\Views\Filters\SelectFilter; | ||
use Rappasoft\LaravelLivewireTables\Views\Filters\TextFilter; | ||
|
||
class NoColumnsTable extends DataTableComponent | ||
{ | ||
public $model = Pet::class; | ||
|
||
public function configure(): void | ||
{ | ||
$this->setPrimaryKey('id'); | ||
} | ||
|
||
public function columns(): array | ||
{ | ||
return [ | ||
]; | ||
} | ||
|
||
public function filters(): array | ||
{ | ||
return [ | ||
MultiSelectFilter::make('Breed') | ||
->options( | ||
Breed::query() | ||
->orderBy('name') | ||
->get() | ||
->keyBy('id') | ||
->map(fn ($breed) => $breed->name) | ||
->toArray() | ||
) | ||
->filter(function (Builder $builder, array $values) { | ||
return $builder->whereIn('breed_id', $values); | ||
}), | ||
MultiSelectDropdownFilter::make('Species') | ||
->options( | ||
Species::query() | ||
->orderBy('name') | ||
->get() | ||
->keyBy('id') | ||
->map(fn ($species) => $species->name) | ||
->toArray() | ||
) | ||
->filter(function (Builder $builder, array $values) { | ||
return $builder->whereIn('species_id', $values); | ||
}), | ||
NumberFilter::make('Breed ID', 'breed_id_filter') | ||
->filter(function (Builder $builder, string $value) { | ||
return $builder->where('breed_id', '=', $value); | ||
}), | ||
|
||
TextFilter::make('Pet Name', 'pet_name_filter') | ||
->filter(function (Builder $builder, string $value) { | ||
return $builder->where('pets.name', '=', $value); | ||
}), | ||
|
||
DateFilter::make('Last Visit After Date', 'last_visit_date_filter') | ||
->filter(function (Builder $builder, string $value) { | ||
return $builder->whereDate('pets.last_visit', '=>', $value); | ||
}), | ||
|
||
DateTimeFilter::make('Last Visit Before DateTime', 'last_visit_datetime_filter') | ||
->filter(function (Builder $builder, string $value) { | ||
return $builder->whereDate('pets.last_visit', '<=', $value); | ||
}), | ||
|
||
SelectFilter::make('Breed SelectFilter', 'breed_select_filter') | ||
->options( | ||
Breed::query() | ||
->orderBy('name') | ||
->get() | ||
->keyBy('id') | ||
->map(fn ($breed) => $breed->name) | ||
->toArray() | ||
) | ||
->filter(function (Builder $builder, string $value) { | ||
return $builder->where('breed_id', $value); | ||
}) | ||
->setCustomFilterLabel('livewire-tables::tests.testFilterLabel') | ||
->setFilterPillBlade('livewire-tables::tests.testFilterPills'), | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
<?php | ||
|
||
namespace Rappasoft\LaravelLivewireTables\Tests\Http\Livewire; | ||
|
||
use Illuminate\Database\Eloquent\Builder; | ||
use Rappasoft\LaravelLivewireTables\DataTableComponent; | ||
use Rappasoft\LaravelLivewireTables\Tests\Models\Breed; | ||
use Rappasoft\LaravelLivewireTables\Tests\Models\Pet; | ||
use Rappasoft\LaravelLivewireTables\Tests\Models\Species; | ||
use Rappasoft\LaravelLivewireTables\Views\Column; | ||
use Rappasoft\LaravelLivewireTables\Views\Columns\ImageColumn; | ||
use Rappasoft\LaravelLivewireTables\Views\Columns\LinkColumn; | ||
use Rappasoft\LaravelLivewireTables\Views\Filters\DateFilter; | ||
use Rappasoft\LaravelLivewireTables\Views\Filters\DateTimeFilter; | ||
use Rappasoft\LaravelLivewireTables\Views\Filters\MultiSelectDropdownFilter; | ||
use Rappasoft\LaravelLivewireTables\Views\Filters\MultiSelectFilter; | ||
use Rappasoft\LaravelLivewireTables\Views\Filters\NumberFilter; | ||
use Rappasoft\LaravelLivewireTables\Views\Filters\SelectFilter; | ||
use Rappasoft\LaravelLivewireTables\Views\Filters\TextFilter; | ||
|
||
class PetsTableMount extends DataTableComponent | ||
{ | ||
public $model = Pet::class; | ||
|
||
public ?int $mountBreed = null; | ||
|
||
public function mount(?int $mountBreed = null) | ||
{ | ||
if (isset($mountBreed)) { | ||
$this->mountBreed = $mountBreed; | ||
} | ||
} | ||
|
||
public function configure(): void | ||
{ | ||
$this->setPrimaryKey('id'); | ||
} | ||
|
||
public function columns(): array | ||
{ | ||
return [ | ||
Column::make('ID', 'id') | ||
->sortable() | ||
->setSortingPillTitle('Key') | ||
->setSortingPillDirections('0-9', '9-0'), | ||
Column::make('Sort') | ||
->sortable() | ||
->excludeFromColumnSelect(), | ||
Column::make('Name') | ||
->sortable() | ||
->secondaryHeader($this->getFilterByKey('pet_name_filter')) | ||
->footerFilter('pet_name_filter') | ||
->searchable(), | ||
|
||
Column::make('Age'), | ||
|
||
Column::make('Breed', 'breed.name') | ||
->secondaryHeaderFilter('breed') | ||
->footer($this->getFilterByKey('breed')) | ||
->sortable( | ||
fn (Builder $query, string $direction) => $query->orderBy('pets.id', $direction) | ||
) | ||
->searchable( | ||
fn (Builder $query, $searchTerm) => $query->orWhere('breed.name', $searchTerm) | ||
), | ||
|
||
Column::make('Other') | ||
->label(function ($row, Column $column) { | ||
return 'Other'; | ||
}) | ||
->footer(function ($rows) { | ||
return 'Count: '.$rows->count(); | ||
}), | ||
|
||
LinkColumn::make('Link') | ||
->title(fn ($row) => 'Edit') | ||
->location(fn ($row) => 'http://www.google.com') | ||
->attributes(fn ($row) => [ | ||
'class' => 'rounded-full', | ||
'alt' => $row->name.' Avatar', | ||
]), | ||
ImageColumn::make('RowImg') | ||
->location(fn ($row) => 'test'.$row->id) | ||
->attributes(fn ($row) => [ | ||
'class' => 'rounded-full', | ||
'alt' => $row->name.' Avatar', | ||
]), | ||
Column::make('Last Visit', 'last_visit') | ||
->sortable() | ||
->deselected(), | ||
]; | ||
} | ||
|
||
public function filters(): array | ||
{ | ||
return [ | ||
MultiSelectFilter::make('Breed') | ||
->options( | ||
Breed::query() | ||
->orderBy('name') | ||
->get() | ||
->keyBy('id') | ||
->map(fn ($breed) => $breed->name) | ||
->toArray() | ||
) | ||
->filter(function (Builder $builder, array $values) { | ||
return $builder->whereIn('breed_id', $values); | ||
}), | ||
MultiSelectDropdownFilter::make('Species') | ||
->options( | ||
Species::query() | ||
->orderBy('name') | ||
->get() | ||
->keyBy('id') | ||
->map(fn ($species) => $species->name) | ||
->toArray() | ||
) | ||
->filter(function (Builder $builder, array $values) { | ||
return $builder->whereIn('species_id', $values); | ||
}), | ||
NumberFilter::make('Breed ID', 'breed_id_filter') | ||
->filter(function (Builder $builder, string $value) { | ||
return $builder->where('breed_id', '=', $value); | ||
}), | ||
|
||
TextFilter::make('Pet Name', 'pet_name_filter') | ||
->filter(function (Builder $builder, string $value) { | ||
return $builder->where('pets.name', '=', $value); | ||
}), | ||
|
||
DateFilter::make('Last Visit After Date', 'last_visit_date_filter') | ||
->filter(function (Builder $builder, string $value) { | ||
return $builder->whereDate('pets.last_visit', '=>', $value); | ||
}), | ||
|
||
DateTimeFilter::make('Last Visit Before DateTime', 'last_visit_datetime_filter') | ||
->filter(function (Builder $builder, string $value) { | ||
return $builder->whereDate('pets.last_visit', '<=', $value); | ||
}), | ||
|
||
SelectFilter::make('Breed SelectFilter', 'breed_select_filter') | ||
->options( | ||
Breed::query() | ||
->orderBy('name') | ||
->get() | ||
->keyBy('id') | ||
->map(fn ($breed) => $breed->name) | ||
->toArray() | ||
) | ||
->filter(function (Builder $builder, string $value) { | ||
return $builder->where('breed_id', $value); | ||
}) | ||
->setCustomFilterLabel('livewire-tables::tests.testFilterLabel') | ||
->setFilterPillBlade('livewire-tables::tests.testFilterPills'), | ||
]; | ||
} | ||
|
||
public function builder(): Builder | ||
{ | ||
if (isset($this->mountBreed)) { | ||
return Pet::where('breed_id', $this->mountBreed); | ||
} | ||
|
||
return Pet::query(); | ||
} | ||
} |
Oops, something went wrong.