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

Dev bleed #26

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -7,6 +7,9 @@ APP_URL=http://localhost
LOG_CHANNEL=stack
LOG_LEVEL=debug

DEBUGBAR_ENABLED=false
DEBUGBAR_STORAGE=false

BROADCAST_DRIVER=log
CACHE_DRIVER=file
FILESYSTEM_DRIVER=local
220 changes: 141 additions & 79 deletions app/Http/Livewire/UsersTable.php
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@
use App\Exports\UsersExport;
use App\Models\Tag;
use App\Models\User;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Str;
use Maatwebsite\Excel\Facades\Excel;
@@ -13,7 +14,6 @@
use Rappasoft\LaravelLivewireTables\Views\Columns\BooleanColumn;
use Rappasoft\LaravelLivewireTables\Views\Columns\ButtonGroupColumn;
use Rappasoft\LaravelLivewireTables\Views\Columns\ComponentColumn;
use Rappasoft\LaravelLivewireTables\Views\Columns\ImageColumn;
use Rappasoft\LaravelLivewireTables\Views\Columns\LinkColumn;
use Rappasoft\LaravelLivewireTables\Views\Filters\DateFilter;
use Rappasoft\LaravelLivewireTables\Views\Filters\MultiSelectFilter;
@@ -24,19 +24,23 @@ class UsersTable extends DataTableComponent
{
public $myParam = 'Default';

public string $tableName = 'users1';
public string $tableName = 'users2';

public array $users1 = [];

public array $allTags = [];

public string $filterLayout = 'popover';

public function configure(): void
{
$this->setPrimaryKey('id')
->setDebugEnabled()
->setAdditionalSelects(['users.id as id'])
->setFilterLayout($this->filterLayout)
->setConfigurableAreas([
'toolbar-left-start' => ['includes.areas.toolbar-left-start', ['param1' => $this->myParam, 'param2' => ['param2' => 2]]],
])
// ->setPaginationMethod('simple')
->setReorderEnabled()
->setHideReorderColumnUnlessReorderingEnabled()
->setSecondaryHeaderTrAttributes(function ($rows) {
@@ -46,7 +50,11 @@ public function configure(): void
if ($column->isField('id')) {
return ['class' => 'text-red-500'];
}

if ($column->isHidden())
{
return ['class' => 'invisible',
'default' => false];
}
return ['default' => true];
})
->setFooterTrAttributes(function ($rows) {
@@ -65,69 +73,82 @@ public function configure(): void
})
->setTableRowUrlTarget(function ($row) {
return '_blank';
});
})->setEagerLoadAllRelationsDisabled();

if (empty($this->allTags))
{
$this->allTags = Tag::select('id', 'name', 'created_at')
->orderBy('name')
->get()
->pluck('name','id')->toArray();
}
}

public function columns(): array
{
return [
// ImageColumn::make('Avatar')
// ->location(function($row) {
// return asset('img/logo-'.$row->id.'.png');
// })
// ->attributes(function($row) {
// return [
// 'class' => 'w-8 h-8 rounded-full',
// ];
// }),
Column::make('Order', 'sort')
return [Column::make('Order', 'sort')
->sortable()
->collapseOnMobile()
->excludeFromColumnSelect(),

Column::make('Name')
->sortable(function (Builder $query, string $direction) {
return $query->orderBy('name', $direction); // Example, ->sortable() would work too.
})
->searchable()
->secondaryHeader($this->getFilterByKey('name'))
->footer($this->getFilterByKey('name')),
ComponentColumn::make('E-mail', 'email')
->sortable()
->searchable()
->component('email')
->attributes(fn ($value, $row, Column $column) => [
'type' => Str::endsWith($value, 'example.org') ? 'success' : 'danger',
'dismissible' => true,
])
->secondaryHeader($this->getFilterByKey('e-mail'))
->footer($this->getFilterByKey('e-mail')),

Column::make('E-Mail', 'email')
->sortable(function (Builder $query, string $direction) {
return $query->orderBy('email', $direction); // Example, ->sortable() would work too.
})
->searchable()
->secondaryHeader($this->getFilterByKey('email'))
->footer($this->getFilterByKey('email')),

Column::make('Verified At', 'email_verified_at')
->sortable()
->searchable()
->collapseOnTablet()
->format(
fn ($value, $row, Column $column) => Carbon::parse($value)->format('d M Y')
),

Column::make('parent_id', 'parent_id')
->sortable()
->collapseOnMobile()
->excludeFromColumnSelect(),

Column::make('Address', 'address.address')
->sortable()
->searchable()
->collapseOnTablet(),
->sortable()
->searchable()
->collapseOnTablet(),

Column::make('Address Group', 'address.group.name')
->sortable()
->searchable()
->collapseOnTablet(),

Column::make('Group City', 'address.group.city.name')
->sortable()
->searchable()
->collapseOnTablet(),

BooleanColumn::make('Active')
->sortable()
->collapseOnMobile()
->secondaryHeaderFilter('active')
->footerFilter('active'),
Column::make('Verified', 'email_verified_at')

Column::make('Group City', 'address.group.city.name')
->sortable()
->searchable()
->collapseOnTablet(),

Column::make('Tags')
->label(fn ($row) => $row->tags->pluck('name')->implode(', ')),
// Column::make('Actions')
// ->label(
// fn($row, Column $column) => view('tables.cells.actions')->withUser($row)
// )
// ->unclickable(),

ButtonGroupColumn::make('Actions')
->unclickable()
->attributes(function ($row) {
@@ -177,31 +198,51 @@ public function filters(): array
$builder->where('users.name', 'like', '%'.$value.'%');
})
->hiddenFromMenus(),
TextFilter::make('E-mail')

TextFilter::make('Email')
->config([
'maxlength' => 10,
'placeholder' => 'Search E-mail',
'placeholder' => 'Search Email',
])
->filter(function (Builder $builder, string $value) {
$builder->where('users.email', 'like', '%'.$value.'%');
})
->hiddenFromMenus(),
MultiSelectFilter::make('Tags')
->options(
Tag::query()
->orderBy('name')
->get()
->keyBy('id')
->map(fn ($tag) => $tag->name)
->toArray()
)->filter(function (Builder $builder, array $values) {
$builder->whereHas('tags', fn ($query) => $query->whereIn('tags.id', $values));

TextFilter::make('Name2')
->config([
'maxlength' => 10,
'placeholder' => 'Search Name',
])
->filter(function (Builder $builder, string $value) {
$builder->where('users.name', 'like', '%'.$value.'%');
})
->setFilterPillValues([
'3' => 'Tag 1',
]),
->hiddenFromMenus(),

TextFilter::make('Email2')
->config([
'maxlength' => 10,
'placeholder' => 'Search Email',
])
->filter(function (Builder $builder, string $value) {
$builder->where('users.email', 'like', '%'.$value.'%');
})
->hiddenFromMenus(),

MultiSelectFilter::make('Tags')
->options(
$this->allTags
)->filter(function (Builder $builder, array $values) {
$builder->whereHas('tags', fn ($query) => $query->whereIn('tags.id', $values));
})
->setFilterPillValues([
'3' => 'Tag 1',
]),

SelectFilter::make('E-mail Verified', 'email_verified_at')
->setFilterPillTitle('Verified')
->setCustomFilterLabel('includes.customFilterLabel')
->setFilterPillBlade('includes.customFilterPills')
->options([
'' => 'Any',
'yes' => 'Yes',
@@ -214,43 +255,64 @@ public function filters(): array
$builder->whereNull('email_verified_at');
}
}),
SelectFilter::make('Active')
->setFilterPillTitle('User Status')
->setFilterPillValues([
'1' => 'Active',
'0' => 'Inactive',
])
->options([
'' => 'All',
'1' => 'Yes',
'0' => 'No',
])
->filter(function (Builder $builder, string $value) {
if ($value === '1') {
$builder->where('active', true);
} elseif ($value === '0') {
$builder->where('active', false);
}
})
->hiddenFromAll(),
DateFilter::make('Verified From')

SelectFilter::make('Active')
->setFilterSlidedownRow(2)
->setFilterSlidedownColspan(2)
->setFilterPillTitle('User Status')
->setFilterPillValues([
'1' => 'Active',
'0' => 'Inactive',
])
->options([
'' => 'All',
'1' => 'Yes',
'0' => 'No',
])
->filter(function (Builder $builder, string $value) {
if ($value === '1') {
$builder->where('active', true);
} elseif ($value === '0') {
$builder->where('active', false);
}
})
->hiddenFromAll(),

DateFilter::make('Verified From')
->config([
'min' => '2020-01-01',
'max' => '2021-12-31',
])
->filter(function (Builder $builder, string $value) {
$builder->whereDate('email_verified_at', '>=', $value);
})
->setFilterSlidedownRow(2)
->setFilterSlidedownColspan("2"),

DateFilter::make('Verified To')
->filter(function (Builder $builder, string $value) {
$builder->where('email_verified_at', '<=', $value);
})->setFilterSlidedownRow(3)
->setFilterSlidedownColspan(2)
->setFilterPillBlade('includes.customFilterPillBlade')
,

TextFilter::make('Email5')
->setFilterPillTitle('User Email')
->setCustomFilterLabel('includes.customFilterLabel2')
->config([
'min' => '2020-01-01',
'max' => '2021-12-31',
'maxlength' => 10,
'placeholder' => 'Search Email',
])
->filter(function (Builder $builder, string $value) {
$builder->where('email_verified_at', '>=', $value);
}),
DateFilter::make('Verified To')
->filter(function (Builder $builder, string $value) {
$builder->where('email_verified_at', '<=', $value);
}),
$builder->where('users.email', 'like', '%'.$value.'%');
})->setFilterSlidedownRow("2"),
];
}

public function builder(): Builder
{
return User::query();
return User::query()->with(['tags', 'parent']);
}

public function bulkActions(): array
7 changes: 5 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -2,15 +2,18 @@
"name": "laravel/laravel",
"type": "project",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"keywords": [
"framework",
"laravel"
],
"license": "MIT",
"require": {
"php": "^8.1",
"guzzlehttp/guzzle": "^7.0.1",
"laravel/framework": "^10.0",
"laravel/pint": "^1.6",
"maatwebsite/excel": "^3.1",
"rappasoft/laravel-livewire-tables": "^2.0"
"rappasoft/laravel-livewire-tables": "^2.0|dev-develop"
},
"require-dev": {
"barryvdh/laravel-debugbar": "^3.6",
Loading