Phase 0: Fundament für Inhaus
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 1m14s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 1m12s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 1m7s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 1m19s
CI / PHP 8.3 / mysql:8.0 (pull_request) Successful in 1m32s
CI / PHP 8.4 / mysql:8.0 (pull_request) Successful in 1m22s
CI / PHP 8.4 / mysql:8.4 (pull_request) Successful in 1m32s
CI / PHP 8.3 / mysql:8.4 (pull_request) Successful in 1m35s
CI / Build-Artefakte aktuell (pull_request) Failing after 1m7s
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 1m14s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 1m12s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 1m7s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 1m19s
CI / PHP 8.3 / mysql:8.0 (pull_request) Successful in 1m32s
CI / PHP 8.4 / mysql:8.0 (pull_request) Successful in 1m22s
CI / PHP 8.4 / mysql:8.4 (pull_request) Successful in 1m32s
CI / PHP 8.3 / mysql:8.4 (pull_request) Successful in 1m35s
CI / Build-Artefakte aktuell (pull_request) Failing after 1m7s
- Laravel 13 mit Filament 5 (Admin), Inertia 3 + Vue 3 + Vuetify 4 (Material 3) - Anmeldung über Fortify (Login, Passwort vergessen/ändern), keine Selbstregistrierung - Profil mit Profilbild (WebP in festen Größen), Personenseiten, Header mit Avatar-Menü - Material-3-Farbschema aus der Primärfarbe, hell/dunkel/System pro Person - Basis-Branding (Portalname, Logo, Primärfarbe) im Admin unter „Erscheinungsbild“ - Benutzerverwaltung im Admin, Zugang vorläufig über is_admin - vendor/ (ohne Dev-Pakete) und Frontend-Build mitversioniert, Dev-Pakete in vendor-dev/ - PHPUnit-Tests gegen MySQL/MariaDB, Forgejo-CI-Matrix, Docker-Entwicklungsumgebung - VERSION, CHANGELOG.md und CONTRIBUTING.md mit Release-Ablauf Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
7197eaebf2
commit
9c0f8de791
15771 changed files with 1564103 additions and 5 deletions
22
vendor/filament/tables/src/Table/Concerns/BelongsToLivewire.php
vendored
Normal file
22
vendor/filament/tables/src/Table/Concerns/BelongsToLivewire.php
vendored
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Tables\Table\Concerns;
|
||||
|
||||
use Filament\Tables\Contracts\HasTable;
|
||||
|
||||
trait BelongsToLivewire
|
||||
{
|
||||
protected HasTable $livewire;
|
||||
|
||||
public function livewire(HasTable $livewire): static
|
||||
{
|
||||
$this->livewire = $livewire;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getLivewire(): HasTable
|
||||
{
|
||||
return $this->livewire;
|
||||
}
|
||||
}
|
||||
22
vendor/filament/tables/src/Table/Concerns/CanBeStackedOnMobile.php
vendored
Normal file
22
vendor/filament/tables/src/Table/Concerns/CanBeStackedOnMobile.php
vendored
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Tables\Table\Concerns;
|
||||
|
||||
use Closure;
|
||||
|
||||
trait CanBeStackedOnMobile
|
||||
{
|
||||
protected bool | Closure $isStackedOnMobile = false;
|
||||
|
||||
public function stackedOnMobile(bool | Closure $condition = true): static
|
||||
{
|
||||
$this->isStackedOnMobile = $condition;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function isStackedOnMobile(): bool
|
||||
{
|
||||
return (bool) $this->evaluate($this->isStackedOnMobile);
|
||||
}
|
||||
}
|
||||
22
vendor/filament/tables/src/Table/Concerns/CanBeStriped.php
vendored
Normal file
22
vendor/filament/tables/src/Table/Concerns/CanBeStriped.php
vendored
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Tables\Table\Concerns;
|
||||
|
||||
use Closure;
|
||||
|
||||
trait CanBeStriped
|
||||
{
|
||||
protected bool | Closure $isStriped = false;
|
||||
|
||||
public function striped(bool | Closure $condition = true): static
|
||||
{
|
||||
$this->isStriped = $condition;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function isStriped(): bool
|
||||
{
|
||||
return (bool) $this->evaluate($this->isStriped);
|
||||
}
|
||||
}
|
||||
27
vendor/filament/tables/src/Table/Concerns/CanDeferLoading.php
vendored
Normal file
27
vendor/filament/tables/src/Table/Concerns/CanDeferLoading.php
vendored
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Tables\Table\Concerns;
|
||||
|
||||
use Closure;
|
||||
|
||||
trait CanDeferLoading
|
||||
{
|
||||
protected bool | Closure $isLoadingDeferred = false;
|
||||
|
||||
public function deferLoading(bool | Closure $condition = true): static
|
||||
{
|
||||
$this->isLoadingDeferred = $condition;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function isLoadingDeferred(): bool
|
||||
{
|
||||
return (bool) $this->evaluate($this->isLoadingDeferred);
|
||||
}
|
||||
|
||||
public function isLoaded(): bool
|
||||
{
|
||||
return $this->getLivewire()->isTableLoaded();
|
||||
}
|
||||
}
|
||||
239
vendor/filament/tables/src/Table/Concerns/CanGroupRecords.php
vendored
Normal file
239
vendor/filament/tables/src/Table/Concerns/CanGroupRecords.php
vendored
Normal file
|
|
@ -0,0 +1,239 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Tables\Table\Concerns;
|
||||
|
||||
use Closure;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Support\Facades\FilamentIcon;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use Filament\Tables\Grouping\Group;
|
||||
use Filament\Tables\View\TablesIconAlias;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
trait CanGroupRecords
|
||||
{
|
||||
protected string | Group | Closure | null $defaultGroup = null;
|
||||
|
||||
protected string | Closure | null $defaultGroupDirection = null;
|
||||
|
||||
/**
|
||||
* @var array<string, Group>
|
||||
*/
|
||||
protected ?array $cachedGroups;
|
||||
|
||||
/**
|
||||
* @var array<string | Group> | Closure
|
||||
*/
|
||||
protected array | Closure $groups = [];
|
||||
|
||||
protected bool | Closure $isGroupsOnly = false;
|
||||
|
||||
protected bool | Closure | null $persistsGroupInSession = false;
|
||||
|
||||
protected bool | Closure $areGroupingSettingsInDropdownOnDesktop = false;
|
||||
|
||||
protected bool | Closure $areGroupingSettingsHidden = false;
|
||||
|
||||
protected bool | Closure $isGroupingDirectionSettingHidden = false;
|
||||
|
||||
protected bool | Closure $areGroupsCollapsedByDefault = false;
|
||||
|
||||
protected ?Closure $modifyGroupRecordsTriggerActionUsing = null;
|
||||
|
||||
public function groupRecordsTriggerAction(?Closure $callback): static
|
||||
{
|
||||
$this->modifyGroupRecordsTriggerActionUsing = $callback;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function groupingSettingsInDropdownOnDesktop(bool | Closure $condition = true): static
|
||||
{
|
||||
$this->areGroupingSettingsInDropdownOnDesktop = $condition;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use the `groupingSettingsInDropdownOnDesktop()` method instead.
|
||||
*/
|
||||
public function groupsInDropdownOnDesktop(bool | Closure $condition = true): static
|
||||
{
|
||||
$this->groupingSettingsInDropdownOnDesktop($condition);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function groupingSettingsHidden(bool | Closure $condition = true): static
|
||||
{
|
||||
$this->areGroupingSettingsHidden = $condition;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function groupingDirectionSettingHidden(bool | Closure $condition = true): static
|
||||
{
|
||||
$this->isGroupingDirectionSettingHidden = $condition;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function collapsedGroupsByDefault(bool | Closure $condition = true): static
|
||||
{
|
||||
$this->areGroupsCollapsedByDefault = $condition;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function defaultGroup(string | Group | Closure | null $group, string | Closure | null $direction = 'asc'): static
|
||||
{
|
||||
$this->defaultGroup = $group;
|
||||
$this->defaultGroupDirection = $direction;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string | Group> | Closure $groups
|
||||
*/
|
||||
public function groups(array | Closure $groups): static
|
||||
{
|
||||
$this->groups = $groups;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function groupsOnly(bool | Closure $condition = true): static
|
||||
{
|
||||
$this->isGroupsOnly = $condition;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function persistGroupInSession(bool | Closure $condition = true): static
|
||||
{
|
||||
$this->persistsGroupInSession = $condition;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getGroupRecordsTriggerAction(): Action
|
||||
{
|
||||
$action = Action::make('groupRecords')
|
||||
->label(__('filament-tables::table.actions.group.label'))
|
||||
->iconButton()
|
||||
->icon(FilamentIcon::resolve(TablesIconAlias::ACTIONS_GROUP) ?? Heroicon::RectangleStack)
|
||||
->color('gray')
|
||||
->livewireClickHandlerEnabled(false)
|
||||
->table($this)
|
||||
->authorize(true);
|
||||
|
||||
if ($this->modifyGroupRecordsTriggerActionUsing) {
|
||||
$action = $this->evaluate($this->modifyGroupRecordsTriggerActionUsing, [
|
||||
'action' => $action,
|
||||
]) ?? $action;
|
||||
}
|
||||
|
||||
$action->extraAttributes(['class' => 'fi-force-enabled'], merge: true);
|
||||
|
||||
return $action;
|
||||
}
|
||||
|
||||
public function isDefaultGroupSelectable(): bool
|
||||
{
|
||||
$defaultGroup = $this->getDefaultGroup();
|
||||
|
||||
if (! $defaultGroup) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->getGroup($defaultGroup->getId()) !== null;
|
||||
}
|
||||
|
||||
public function areGroupingSettingsInDropdownOnDesktop(): bool
|
||||
{
|
||||
return (bool) $this->evaluate($this->areGroupingSettingsInDropdownOnDesktop);
|
||||
}
|
||||
|
||||
public function areGroupingSettingsHidden(): bool
|
||||
{
|
||||
return (bool) $this->evaluate($this->areGroupingSettingsHidden);
|
||||
}
|
||||
|
||||
public function isGroupingDirectionSettingHidden(): bool
|
||||
{
|
||||
return (bool) $this->evaluate($this->isGroupingDirectionSettingHidden);
|
||||
}
|
||||
|
||||
public function areGroupsCollapsedByDefault(): bool
|
||||
{
|
||||
return (bool) $this->evaluate($this->areGroupsCollapsedByDefault);
|
||||
}
|
||||
|
||||
public function getDefaultGroup(): ?Group
|
||||
{
|
||||
$defaultGroup = $this->evaluate($this->defaultGroup);
|
||||
|
||||
if ($defaultGroup === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($defaultGroup instanceof Group) {
|
||||
return $defaultGroup->table($this);
|
||||
}
|
||||
|
||||
$group = $this->getGroup($defaultGroup);
|
||||
|
||||
if ($group) {
|
||||
return $group;
|
||||
}
|
||||
|
||||
return Group::make($defaultGroup)
|
||||
->table($this);
|
||||
}
|
||||
|
||||
public function getDefaultGroupDirection(): string
|
||||
{
|
||||
return Str::lower($this->evaluate($this->defaultGroupDirection) ?? 'asc');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, Group>
|
||||
*/
|
||||
public function getGroups(): array
|
||||
{
|
||||
return $this->cachedGroups ??= array_reduce(
|
||||
$this->evaluate($this->groups),
|
||||
function (array $carry, $group): array {
|
||||
if (! $group instanceof Group) {
|
||||
$group = Group::make($group);
|
||||
}
|
||||
|
||||
$carry[$group->getId()] = $group->table($this);
|
||||
|
||||
return $carry;
|
||||
},
|
||||
initial: [],
|
||||
);
|
||||
}
|
||||
|
||||
public function getGroup(string $id): ?Group
|
||||
{
|
||||
return $this->getGroups()[$id] ?? null;
|
||||
}
|
||||
|
||||
public function getGrouping(): ?Group
|
||||
{
|
||||
return $this->getLivewire()->getTableGrouping();
|
||||
}
|
||||
|
||||
public function isGroupsOnly(): bool
|
||||
{
|
||||
return (bool) $this->evaluate($this->isGroupsOnly);
|
||||
}
|
||||
|
||||
public function persistsGroupInSession(): bool
|
||||
{
|
||||
return (bool) $this->evaluate($this->persistsGroupInSession);
|
||||
}
|
||||
}
|
||||
151
vendor/filament/tables/src/Table/Concerns/CanPaginateRecords.php
vendored
Normal file
151
vendor/filament/tables/src/Table/Concerns/CanPaginateRecords.php
vendored
Normal file
|
|
@ -0,0 +1,151 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Tables\Table\Concerns;
|
||||
|
||||
use Closure;
|
||||
use Filament\Tables\Enums\PaginationMode;
|
||||
use Illuminate\Support\Arr;
|
||||
|
||||
trait CanPaginateRecords
|
||||
{
|
||||
protected int | string | Closure | null $defaultPaginationPageOption = null;
|
||||
|
||||
protected bool | Closure $isPaginated = true;
|
||||
|
||||
protected bool | Closure $isPaginatedWhileReordering = false;
|
||||
|
||||
protected bool | Closure $persistsRecordsPerPageInSession = true;
|
||||
|
||||
/**
|
||||
* @var array<int | string> | Closure | null
|
||||
*/
|
||||
protected array | Closure | null $paginationPageOptions = null;
|
||||
|
||||
protected bool | Closure $hasExtremePaginationLinks = false;
|
||||
|
||||
protected PaginationMode | Closure | null $paginationMode = null;
|
||||
|
||||
protected bool | Closure $shouldScrollToTopOnPageChange = false;
|
||||
|
||||
public function scrollToTopOnPageChange(bool | Closure $condition = true): static
|
||||
{
|
||||
$this->shouldScrollToTopOnPageChange = $condition;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function shouldScrollToTopOnPageChange(): bool
|
||||
{
|
||||
return (bool) $this->evaluate($this->shouldScrollToTopOnPageChange);
|
||||
}
|
||||
|
||||
public function paginationMode(PaginationMode | Closure | null $mode): static
|
||||
{
|
||||
$this->paginationMode = $mode;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getPaginationMode(): ?PaginationMode
|
||||
{
|
||||
return $this->evaluate($this->paginationMode) ?? PaginationMode::Default;
|
||||
}
|
||||
|
||||
public function defaultPaginationPageOption(int | string | Closure | null $option): static
|
||||
{
|
||||
$this->defaultPaginationPageOption = $option;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool | array<int | string> | Closure $condition
|
||||
*/
|
||||
public function paginated(bool | array | Closure $condition = true): static
|
||||
{
|
||||
if (is_array($condition)) {
|
||||
$this->paginationPageOptions($condition);
|
||||
$condition = true;
|
||||
}
|
||||
|
||||
$this->isPaginated = $condition;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function paginatedWhileReordering(bool | Closure $condition = true): static
|
||||
{
|
||||
$this->isPaginatedWhileReordering = $condition;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function persistRecordsPerPageInSession(bool | Closure $condition = true): static
|
||||
{
|
||||
$this->persistsRecordsPerPageInSession = $condition;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<int | string> | Closure | null $options
|
||||
*/
|
||||
public function paginationPageOptions(array | Closure | null $options): static
|
||||
{
|
||||
$this->paginationPageOptions = $options;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function extremePaginationLinks(bool | Closure $condition = true): static
|
||||
{
|
||||
$this->hasExtremePaginationLinks = $condition;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getDefaultPaginationPageOption(): int | string | null
|
||||
{
|
||||
$option = $this->evaluate($this->defaultPaginationPageOption);
|
||||
|
||||
if ($option) {
|
||||
return $option;
|
||||
}
|
||||
|
||||
$options = $this->getPaginationPageOptions();
|
||||
|
||||
if (in_array(10, $options)) {
|
||||
return 10;
|
||||
}
|
||||
|
||||
return Arr::first($options);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int | string>
|
||||
*/
|
||||
public function getPaginationPageOptions(): array
|
||||
{
|
||||
return $this->evaluate($this->paginationPageOptions) ?? [5, 10, 25, 50];
|
||||
}
|
||||
|
||||
public function isPaginated(): bool
|
||||
{
|
||||
return $this->evaluate($this->isPaginated) && (! $this->isGroupsOnly());
|
||||
}
|
||||
|
||||
public function isPaginatedWhileReordering(): bool
|
||||
{
|
||||
return (bool) $this->evaluate($this->isPaginatedWhileReordering);
|
||||
}
|
||||
|
||||
public function persistsRecordsPerPageInSession(): bool
|
||||
{
|
||||
return (bool) $this->evaluate($this->persistsRecordsPerPageInSession);
|
||||
}
|
||||
|
||||
public function hasExtremePaginationLinks(): bool
|
||||
{
|
||||
return (bool) $this->evaluate($this->hasExtremePaginationLinks);
|
||||
}
|
||||
}
|
||||
21
vendor/filament/tables/src/Table/Concerns/CanPersistInSession.php
vendored
Normal file
21
vendor/filament/tables/src/Table/Concerns/CanPersistInSession.php
vendored
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Tables\Table\Concerns;
|
||||
|
||||
use Closure;
|
||||
|
||||
trait CanPersistInSession
|
||||
{
|
||||
public function persistInSession(bool | Closure $condition = true): static
|
||||
{
|
||||
$this->persistFiltersInSession($condition);
|
||||
$this->persistSearchInSession($condition);
|
||||
$this->persistColumnSearchesInSession($condition);
|
||||
$this->persistSortInSession($condition);
|
||||
$this->persistGroupInSession($condition);
|
||||
$this->persistColumnsInSession($condition);
|
||||
$this->persistRecordsPerPageInSession($condition);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
22
vendor/filament/tables/src/Table/Concerns/CanPollRecords.php
vendored
Normal file
22
vendor/filament/tables/src/Table/Concerns/CanPollRecords.php
vendored
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Tables\Table\Concerns;
|
||||
|
||||
use Closure;
|
||||
|
||||
trait CanPollRecords
|
||||
{
|
||||
protected string | Closure | null $pollingInterval = null;
|
||||
|
||||
public function poll(string | Closure | null $interval = '10s'): static
|
||||
{
|
||||
$this->pollingInterval = $interval;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getPollingInterval(): ?string
|
||||
{
|
||||
return $this->evaluate($this->pollingInterval);
|
||||
}
|
||||
}
|
||||
134
vendor/filament/tables/src/Table/Concerns/CanReorderRecords.php
vendored
Normal file
134
vendor/filament/tables/src/Table/Concerns/CanReorderRecords.php
vendored
Normal file
|
|
@ -0,0 +1,134 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Tables\Table\Concerns;
|
||||
|
||||
use Closure;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Support\Concerns\HasReorderAnimationDuration;
|
||||
use Filament\Support\Facades\FilamentIcon;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use Filament\Tables\View\TablesIconAlias;
|
||||
|
||||
trait CanReorderRecords
|
||||
{
|
||||
use HasReorderAnimationDuration;
|
||||
|
||||
protected bool | Closure $isReorderable = true;
|
||||
|
||||
protected bool | Closure $isReorderAuthorized = true;
|
||||
|
||||
protected string | Closure | null $reorderColumn = null;
|
||||
|
||||
protected string | Closure | null $reorderDirection = null;
|
||||
|
||||
protected ?Closure $modifyReorderRecordsTriggerActionUsing = null;
|
||||
|
||||
protected ?Closure $beforeReorderingCallback = null;
|
||||
|
||||
protected ?Closure $afterReorderingCallback = null;
|
||||
|
||||
public function reorderRecordsTriggerAction(?Closure $callback): static
|
||||
{
|
||||
$this->modifyReorderRecordsTriggerActionUsing = $callback;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function reorderable(string | Closure | null $column = null, bool | Closure | null $condition = null, string | Closure | null $direction = null): static
|
||||
{
|
||||
$this->reorderColumn = $column;
|
||||
|
||||
if ($condition !== null) {
|
||||
$this->isReorderable = $condition;
|
||||
}
|
||||
|
||||
$this->reorderDirection = $direction;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function beforeReordering(?Closure $callback): static
|
||||
{
|
||||
$this->beforeReorderingCallback = $callback;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function afterReordering(?Closure $callback): static
|
||||
{
|
||||
$this->afterReorderingCallback = $callback;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function authorizeReorder(bool | Closure $condition = true): static
|
||||
{
|
||||
$this->isReorderAuthorized = $condition;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getReorderRecordsTriggerAction(bool $isReordering): Action
|
||||
{
|
||||
$action = Action::make('reorderRecords')
|
||||
->label($isReordering ? __('filament-tables::table.actions.disable_reordering.label') : __('filament-tables::table.actions.enable_reordering.label'))
|
||||
->iconButton()
|
||||
->icon($isReordering ? (FilamentIcon::resolve(TablesIconAlias::ACTIONS_DISABLE_REORDERING) ?? Heroicon::Check) : (FilamentIcon::resolve(TablesIconAlias::ACTIONS_ENABLE_REORDERING) ?? Heroicon::ArrowsUpDown))
|
||||
->color('gray')
|
||||
->action('toggleTableReordering')
|
||||
->table($this)
|
||||
->authorize(true);
|
||||
|
||||
if ($this->modifyReorderRecordsTriggerActionUsing) {
|
||||
$action = $this->evaluate($this->modifyReorderRecordsTriggerActionUsing, [
|
||||
'action' => $action,
|
||||
'isReordering' => $isReordering,
|
||||
]) ?? $action;
|
||||
}
|
||||
|
||||
$action->extraAttributes(['class' => 'fi-force-enabled'], merge: true);
|
||||
|
||||
return $action;
|
||||
}
|
||||
|
||||
public function getReorderColumn(): ?string
|
||||
{
|
||||
return $this->evaluate($this->reorderColumn);
|
||||
}
|
||||
|
||||
public function getReorderDirection(): string
|
||||
{
|
||||
return $this->evaluate($this->reorderDirection) ?? 'asc';
|
||||
}
|
||||
|
||||
public function isReorderable(): bool
|
||||
{
|
||||
return filled($this->getReorderColumn()) && $this->evaluate($this->isReorderable) && $this->isReorderAuthorized();
|
||||
}
|
||||
|
||||
public function isReordering(): bool
|
||||
{
|
||||
return $this->getLivewire()->isTableReordering();
|
||||
}
|
||||
|
||||
public function isReorderAuthorized(): bool
|
||||
{
|
||||
return (bool) $this->evaluate($this->isReorderAuthorized);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<int | string> $order
|
||||
*/
|
||||
public function callBeforeReordering(array $order): void
|
||||
{
|
||||
$this->evaluate($this->beforeReorderingCallback, ['order' => $order]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<int | string> $order
|
||||
*/
|
||||
public function callAfterReordering(array $order): void
|
||||
{
|
||||
$this->evaluate($this->afterReorderingCallback, ['order' => $order]);
|
||||
}
|
||||
}
|
||||
301
vendor/filament/tables/src/Table/Concerns/CanSearchRecords.php
vendored
Normal file
301
vendor/filament/tables/src/Table/Concerns/CanSearchRecords.php
vendored
Normal file
|
|
@ -0,0 +1,301 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Tables\Table\Concerns;
|
||||
|
||||
use Closure;
|
||||
use Filament\Tables\Filters\Indicator;
|
||||
use Illuminate\Database\Connection;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\Relation;
|
||||
|
||||
use function Filament\Support\generate_search_column_expression;
|
||||
use function Filament\Support\generate_search_term_expression;
|
||||
|
||||
trait CanSearchRecords
|
||||
{
|
||||
protected ?bool $isSearchable = null;
|
||||
|
||||
/**
|
||||
* @var array<string | Closure>
|
||||
*/
|
||||
protected array $extraSearchableColumns = [];
|
||||
|
||||
protected bool | Closure | null $persistsSearchInSession = false;
|
||||
|
||||
protected bool | Closure | null $persistsColumnSearchesInSession = false;
|
||||
|
||||
protected string | Closure | null $searchPlaceholder = null;
|
||||
|
||||
protected ?string $searchDebounce = null;
|
||||
|
||||
protected bool | Closure $isSearchOnBlur = false;
|
||||
|
||||
protected bool | Closure $shouldSplitSearchTerms = true;
|
||||
|
||||
protected ?Closure $searchUsing = null;
|
||||
|
||||
public function persistSearchInSession(bool | Closure $condition = true): static
|
||||
{
|
||||
$this->persistsSearchInSession = $condition;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function persistColumnSearchesInSession(bool | Closure $condition = true): static
|
||||
{
|
||||
$this->persistsColumnSearchesInSession = $condition;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool | array<string | Closure> $condition
|
||||
*/
|
||||
public function searchable(bool | array $condition = true): static
|
||||
{
|
||||
if ($condition === true) {
|
||||
$this->isSearchable = true;
|
||||
} elseif (! $condition) {
|
||||
$this->isSearchable = false;
|
||||
$this->extraSearchableColumns = [];
|
||||
} else {
|
||||
$this->isSearchable = true;
|
||||
$this->extraSearchableColumns = $condition;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function searchDebounce(?string $debounce): static
|
||||
{
|
||||
$this->searchDebounce = $debounce;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function isSearchable(): bool
|
||||
{
|
||||
if (is_bool($this->isSearchable)) {
|
||||
return $this->isSearchable;
|
||||
}
|
||||
|
||||
if ($this->getExtraSearchableColumns()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
foreach ($this->getColumns() as $column) {
|
||||
if (! $column->isGloballySearchable()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function isSearchableByColumn(): bool
|
||||
{
|
||||
foreach ($this->getColumns() as $column) {
|
||||
if (! $column->isIndividuallySearchable()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($column->isHidden()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function persistsSearchInSession(): bool
|
||||
{
|
||||
return (bool) $this->evaluate($this->persistsSearchInSession);
|
||||
}
|
||||
|
||||
public function persistsColumnSearchesInSession(): bool
|
||||
{
|
||||
return (bool) $this->evaluate($this->persistsColumnSearchesInSession);
|
||||
}
|
||||
|
||||
public function searchPlaceholder(string | Closure | null $searchPlaceholder): static
|
||||
{
|
||||
$this->searchPlaceholder = $searchPlaceholder;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getSearchPlaceholder(): ?string
|
||||
{
|
||||
return $this->evaluate($this->searchPlaceholder);
|
||||
}
|
||||
|
||||
public function hasSearch(): bool
|
||||
{
|
||||
return $this->getLivewire()->hasTableSearch();
|
||||
}
|
||||
|
||||
public function getSearchIndicator(): Indicator
|
||||
{
|
||||
return $this->getLivewire()->getTableSearchIndicator();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<Indicator> | array<string, string>
|
||||
*/
|
||||
public function getColumnSearchIndicators(): array
|
||||
{
|
||||
return $this->getLivewire()->getTableColumnSearchIndicators();
|
||||
}
|
||||
|
||||
public function getSearchDebounce(): string
|
||||
{
|
||||
return $this->searchDebounce ?? '500ms';
|
||||
}
|
||||
|
||||
public function searchOnBlur(bool | Closure $condition = true): static
|
||||
{
|
||||
$this->isSearchOnBlur = $condition;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function isSearchOnBlur(): bool
|
||||
{
|
||||
return (bool) $this->evaluate($this->isSearchOnBlur);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string | Closure>
|
||||
*/
|
||||
public function getExtraSearchableColumns(): array
|
||||
{
|
||||
return $this->extraSearchableColumns;
|
||||
}
|
||||
|
||||
public function applyExtraSearchConstraints(Builder $query, string $search, bool &$isFirst): void
|
||||
{
|
||||
foreach ($this->getExtraSearchableColumns() as $column) {
|
||||
if (blank($column)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$whereClause = $isFirst ? 'where' : 'orWhere';
|
||||
|
||||
if ($column instanceof Closure) {
|
||||
$query->{$whereClause}(
|
||||
fn ($query) => $this->evaluate($column, [
|
||||
'query' => $query,
|
||||
'search' => $search,
|
||||
'searchQuery' => $search,
|
||||
]),
|
||||
);
|
||||
|
||||
$isFirst = false;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
/** @var Connection $databaseConnection */
|
||||
$databaseConnection = $query->getConnection();
|
||||
|
||||
$model = $query->getModel();
|
||||
|
||||
$nonTranslatableSearch = generate_search_term_expression($search, isSearchForcedCaseInsensitive: null, databaseConnection: $databaseConnection);
|
||||
|
||||
$translatableContentDriver = $this->getLivewire()->makeFilamentTranslatableContentDriver();
|
||||
|
||||
$query->when(
|
||||
$translatableContentDriver?->isAttributeTranslatable($model::class, attribute: $column),
|
||||
fn (Builder $query): Builder => $translatableContentDriver->applySearchConstraintToQuery($query, $column, $search, $whereClause),
|
||||
fn (Builder $query) => $query->when(
|
||||
$this->getExtraSearchableColumnRelationship($column, $query->getModel()),
|
||||
fn (Builder $query): Builder => $query->{"{$whereClause}Relation"}(
|
||||
(string) str($column)->beforeLast('.'),
|
||||
generate_search_column_expression((string) str($column)->afterLast('.'), isSearchForcedCaseInsensitive: null, databaseConnection: $databaseConnection),
|
||||
'like',
|
||||
"%{$nonTranslatableSearch}%",
|
||||
),
|
||||
function (Builder $query) use ($databaseConnection, $nonTranslatableSearch, $column, $whereClause): Builder {
|
||||
// Treat the missing "relationship" as a JSON column if dot notation is used in the column name.
|
||||
if (str($column)->contains('.')) {
|
||||
$column = (string) str($column)->replace('.', '->');
|
||||
}
|
||||
|
||||
return $query->{$whereClause}(
|
||||
generate_search_column_expression($column, isSearchForcedCaseInsensitive: null, databaseConnection: $databaseConnection),
|
||||
'like',
|
||||
"%{$nonTranslatableSearch}%",
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
$isFirst = false;
|
||||
}
|
||||
}
|
||||
|
||||
public function getExtraSearchableColumnRelationship(string $name, Model $record): ?Relation
|
||||
{
|
||||
if (blank($name) || (! str($name)->contains('.'))) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$relationship = null;
|
||||
|
||||
foreach (str($name)->beforeLast('.')->explode('.')->all() as $nestedRelationshipName) {
|
||||
if ($record->hasAttribute($nestedRelationshipName)) {
|
||||
$relationship = null;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if (! $record->isRelation($nestedRelationshipName)) {
|
||||
$relationship = null;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
$relationship = $record->{$nestedRelationshipName}();
|
||||
$record = $relationship->getRelated();
|
||||
}
|
||||
|
||||
return $relationship;
|
||||
}
|
||||
|
||||
public function splitSearchTerms(bool | Closure $condition = true): static
|
||||
{
|
||||
$this->shouldSplitSearchTerms = $condition;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function shouldSplitSearchTerms(): bool
|
||||
{
|
||||
return (bool) $this->evaluate($this->shouldSplitSearchTerms);
|
||||
}
|
||||
|
||||
public function searchUsing(?Closure $searchUsing): static
|
||||
{
|
||||
$this->searchUsing = $searchUsing;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function hasSearchUsingCallback(): bool
|
||||
{
|
||||
return filled($this->searchUsing);
|
||||
}
|
||||
|
||||
public function callSearchUsing(Builder $query, string $search): void
|
||||
{
|
||||
$this->evaluate($this->searchUsing, [
|
||||
'query' => $query,
|
||||
'search' => $search,
|
||||
]);
|
||||
}
|
||||
}
|
||||
138
vendor/filament/tables/src/Table/Concerns/CanSortRecords.php
vendored
Normal file
138
vendor/filament/tables/src/Table/Concerns/CanSortRecords.php
vendored
Normal file
|
|
@ -0,0 +1,138 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Tables\Table\Concerns;
|
||||
|
||||
use Closure;
|
||||
use Filament\Tables\Columns\Column;
|
||||
use Illuminate\Contracts\Support\Htmlable;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
trait CanSortRecords
|
||||
{
|
||||
protected string | Closure | null $defaultSort = null;
|
||||
|
||||
protected string | Closure | null $defaultSortDirection = null;
|
||||
|
||||
protected bool | Closure | null $persistsSortInSession = false;
|
||||
|
||||
protected string | Htmlable | Closure | null $defaultSortOptionLabel = null;
|
||||
|
||||
protected bool | Closure $hasDefaultKeySort = true;
|
||||
|
||||
public function defaultSort(string | Closure | null $column, string | Closure | null $direction = 'asc'): static
|
||||
{
|
||||
$this->defaultSort = $column;
|
||||
$this->defaultSortDirection = $direction;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function persistSortInSession(bool | Closure $condition = true): static
|
||||
{
|
||||
$this->persistsSortInSession = $condition;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function defaultSortOptionLabel(string | Htmlable | Closure | null $label): static
|
||||
{
|
||||
$this->defaultSortOptionLabel = $label;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function defaultKeySort(bool | Closure $condition = true): static
|
||||
{
|
||||
$this->hasDefaultKeySort = $condition;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getSortableVisibleColumn(string $name): ?Column
|
||||
{
|
||||
$column = $this->getColumn($name);
|
||||
|
||||
if (! $column) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($column->isHidden()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (! $column->isSortable()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $column;
|
||||
}
|
||||
|
||||
public function getDefaultSort(Builder $query, string $direction): string | Builder | null
|
||||
{
|
||||
return $this->evaluate($this->defaultSort, [
|
||||
'direction' => $direction,
|
||||
'query' => $query,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use `getDefaultSort()` instead.
|
||||
*/
|
||||
public function getDefaultSortColumn(): ?string
|
||||
{
|
||||
if (! is_string($this->defaultSort)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->defaultSort;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use `getDefaultSort()` instead.
|
||||
*/
|
||||
public function getDefaultSortQuery(): ?Closure
|
||||
{
|
||||
if (! ($this->defaultSort instanceof Closure)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->defaultSort;
|
||||
}
|
||||
|
||||
public function getDefaultSortDirection(): ?string
|
||||
{
|
||||
$direction = $this->evaluate($this->defaultSortDirection);
|
||||
|
||||
if ($direction !== null) {
|
||||
$direction = Str::lower($direction);
|
||||
}
|
||||
|
||||
return $direction;
|
||||
}
|
||||
|
||||
public function getSortColumn(): ?string
|
||||
{
|
||||
return $this->getLivewire()->getTableSortColumn();
|
||||
}
|
||||
|
||||
public function getSortDirection(): ?string
|
||||
{
|
||||
return $this->getLivewire()->getTableSortDirection();
|
||||
}
|
||||
|
||||
public function persistsSortInSession(): bool
|
||||
{
|
||||
return (bool) $this->evaluate($this->persistsSortInSession);
|
||||
}
|
||||
|
||||
public function getDefaultSortOptionLabel(): string | Htmlable | null
|
||||
{
|
||||
return $this->evaluate($this->defaultSortOptionLabel) ?? '-';
|
||||
}
|
||||
|
||||
public function hasDefaultKeySort(): bool
|
||||
{
|
||||
return (bool) $this->evaluate($this->hasDefaultKeySort);
|
||||
}
|
||||
}
|
||||
42
vendor/filament/tables/src/Table/Concerns/CanSummarizeRecords.php
vendored
Normal file
42
vendor/filament/tables/src/Table/Concerns/CanSummarizeRecords.php
vendored
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Tables\Table\Concerns;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
trait CanSummarizeRecords
|
||||
{
|
||||
protected bool | Closure $hasPageSummary = true;
|
||||
|
||||
protected bool | Closure $hasAllTableSummary = true;
|
||||
|
||||
public function summaries(bool | Closure $pageCondition = true, bool | Closure $allTableCondition = true): static
|
||||
{
|
||||
$this->hasPageSummary = $pageCondition;
|
||||
$this->hasAllTableSummary = $allTableCondition;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function hasPageSummary(): bool
|
||||
{
|
||||
return (bool) $this->evaluate($this->hasPageSummary);
|
||||
}
|
||||
|
||||
public function hasAllTableSummary(): bool
|
||||
{
|
||||
return (bool) $this->evaluate($this->hasAllTableSummary);
|
||||
}
|
||||
|
||||
public function hasSummary(Builder | Closure | null $query): bool
|
||||
{
|
||||
foreach ($this->getColumns() as $column) {
|
||||
if ($column->hasSummary($query)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
102
vendor/filament/tables/src/Table/Concerns/HasActions.php
vendored
Normal file
102
vendor/filament/tables/src/Table/Concerns/HasActions.php
vendored
Normal file
|
|
@ -0,0 +1,102 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Tables\Table\Concerns;
|
||||
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Actions\BulkAction;
|
||||
|
||||
trait HasActions
|
||||
{
|
||||
/**
|
||||
* @var array<string, Action>
|
||||
*/
|
||||
protected array $flatActions = [];
|
||||
|
||||
/**
|
||||
* @var array<string, BulkAction>
|
||||
*/
|
||||
protected array $flatBulkActions = [];
|
||||
|
||||
public function getAction(string $name): ?Action
|
||||
{
|
||||
return $this->getFlatActions()[$name] ?? null;
|
||||
}
|
||||
|
||||
public function getBulkAction(string $name): ?BulkAction
|
||||
{
|
||||
return $this->getFlatBulkActions()[$name] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, Action>
|
||||
*/
|
||||
public function getFlatActions(): array
|
||||
{
|
||||
return $this->flatActions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, BulkAction>
|
||||
*/
|
||||
public function getFlatBulkActions(): array
|
||||
{
|
||||
return $this->flatBulkActions;
|
||||
}
|
||||
|
||||
public function hasAction(string $name): bool
|
||||
{
|
||||
return array_key_exists($name, $this->getFlatActions());
|
||||
}
|
||||
|
||||
public function hasBulkAction(string $name): bool
|
||||
{
|
||||
return array_key_exists($name, $this->getFlatBulkActions());
|
||||
}
|
||||
|
||||
protected function cacheAction(Action $action, bool $shouldOverwriteExistingAction = true): void
|
||||
{
|
||||
if (! $shouldOverwriteExistingAction) {
|
||||
if ($action instanceof BulkAction) {
|
||||
$this->flatBulkActions[$action->getName()] ??= $action;
|
||||
} else {
|
||||
$this->flatActions[$action->getName()] ??= $action;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ($action instanceof BulkAction) {
|
||||
$this->flatBulkActions[$action->getName()] = $action;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->flatActions[$action->getName()] = $action;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, Action> $actions
|
||||
*/
|
||||
protected function mergeCachedFlatActions(array $actions, bool $shouldOverwriteExistingActions = true): void
|
||||
{
|
||||
foreach ($actions as $action) {
|
||||
$this->cacheAction($action, $shouldOverwriteExistingActions);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<Action> $actions
|
||||
*/
|
||||
protected function removeCachedActions(array $actions): void
|
||||
{
|
||||
$this->flatActions = array_filter(
|
||||
$this->flatActions,
|
||||
fn (Action $existingAction): bool => ! in_array($existingAction, $actions, true),
|
||||
);
|
||||
|
||||
$this->flatBulkActions = array_filter(
|
||||
$this->flatBulkActions,
|
||||
fn (Action $existingAction): bool => ! in_array($existingAction, $actions, true),
|
||||
);
|
||||
}
|
||||
}
|
||||
31
vendor/filament/tables/src/Table/Concerns/HasArguments.php
vendored
Normal file
31
vendor/filament/tables/src/Table/Concerns/HasArguments.php
vendored
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Tables\Table\Concerns;
|
||||
|
||||
use Closure;
|
||||
|
||||
trait HasArguments
|
||||
{
|
||||
/**
|
||||
* @var array<mixed> | Closure
|
||||
*/
|
||||
protected array | Closure $arguments = [];
|
||||
|
||||
/**
|
||||
* @param array<mixed> | Closure $arguments
|
||||
*/
|
||||
public function arguments(array | Closure $arguments): static
|
||||
{
|
||||
$this->arguments = $arguments;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<mixed>
|
||||
*/
|
||||
public function getArguments(): array
|
||||
{
|
||||
return $this->evaluate($this->arguments) ?? [];
|
||||
}
|
||||
}
|
||||
219
vendor/filament/tables/src/Table/Concerns/HasBulkActions.php
vendored
Normal file
219
vendor/filament/tables/src/Table/Concerns/HasBulkActions.php
vendored
Normal file
|
|
@ -0,0 +1,219 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Tables\Table\Concerns;
|
||||
|
||||
use Closure;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Actions\ActionGroup;
|
||||
use Filament\Actions\BulkActionGroup;
|
||||
use Filament\Tables\Enums\RecordCheckboxPosition;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
trait HasBulkActions
|
||||
{
|
||||
protected ?Closure $checkIfRecordIsSelectableUsing = null;
|
||||
|
||||
protected bool | Closure | null $selectsCurrentPageOnly = false;
|
||||
|
||||
protected bool | Closure | null $selectsGroupsOnly = false;
|
||||
|
||||
protected RecordCheckboxPosition | Closure | null $recordCheckboxPosition = null;
|
||||
|
||||
protected bool | Closure | null $isSelectable = null;
|
||||
|
||||
protected bool | Closure $canTrackDeselectedRecords = true;
|
||||
|
||||
protected string | Closure | null $currentSelectionLivewireProperty = null;
|
||||
|
||||
protected int | Closure | null $maxSelectableRecords = null;
|
||||
|
||||
protected bool | Closure $isSelectionDisabled = false;
|
||||
|
||||
/**
|
||||
* @deprecated Use `toolbarActions()` instead.
|
||||
*
|
||||
* @param array<Action | ActionGroup> | ActionGroup $actions
|
||||
*/
|
||||
public function bulkActions(array | ActionGroup $actions): static
|
||||
{
|
||||
$this->toolbarActions($actions);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use `pushToolbarActions()` instead.
|
||||
*
|
||||
* @param array<Action | ActionGroup> | ActionGroup $actions
|
||||
*/
|
||||
public function pushBulkActions(array | ActionGroup $actions): static
|
||||
{
|
||||
$this->pushToolbarActions($actions);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<Action | ActionGroup> $actions
|
||||
*/
|
||||
public function groupedBulkActions(array $actions): static
|
||||
{
|
||||
$this->toolbarActions([BulkActionGroup::make($actions)]);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function checkIfRecordIsSelectableUsing(?Closure $callback): static
|
||||
{
|
||||
$this->checkIfRecordIsSelectableUsing = $callback;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function selectCurrentPageOnly(bool | Closure $condition = true): static
|
||||
{
|
||||
$this->selectsCurrentPageOnly = $condition;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function selectGroupsOnly(bool | Closure $condition = true): static
|
||||
{
|
||||
$this->selectsGroupsOnly = $condition;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Model | array<string, mixed> $record
|
||||
*/
|
||||
public function isRecordSelectable(Model | array $record): bool
|
||||
{
|
||||
return (bool) ($this->evaluate(
|
||||
$this->checkIfRecordIsSelectableUsing,
|
||||
namedInjections: [
|
||||
'record' => $record,
|
||||
],
|
||||
typedInjections: ($record instanceof Model) ? [
|
||||
Model::class => $record,
|
||||
$record::class => $record,
|
||||
] : [],
|
||||
) ?? true);
|
||||
}
|
||||
|
||||
public function getAllSelectableRecordsCount(): int
|
||||
{
|
||||
return $this->getLivewire()->getAllSelectableTableRecordsCount();
|
||||
}
|
||||
|
||||
public function selectable(bool | Closure | null $condition = true): static
|
||||
{
|
||||
$this->isSelectable = $condition;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function isSelectionEnabled(): bool
|
||||
{
|
||||
if (is_bool($isSelectable = $this->evaluate($this->isSelectable))) {
|
||||
return $isSelectable;
|
||||
}
|
||||
|
||||
foreach ($this->getFlatBulkActions() as $action) {
|
||||
if ($action->isVisible()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function selectsCurrentPageOnly(): bool
|
||||
{
|
||||
return $this->evaluate($this->selectsCurrentPageOnly) || (! $this->hasQuery());
|
||||
}
|
||||
|
||||
public function selectsGroupsOnly(): bool
|
||||
{
|
||||
return (bool) $this->evaluate($this->selectsGroupsOnly);
|
||||
}
|
||||
|
||||
public function checksIfRecordIsSelectable(): bool
|
||||
{
|
||||
return $this->checkIfRecordIsSelectableUsing !== null;
|
||||
}
|
||||
|
||||
public function recordCheckboxPosition(RecordCheckboxPosition | Closure | null $position = null): static
|
||||
{
|
||||
$this->recordCheckboxPosition = $position;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getRecordCheckboxPosition(): RecordCheckboxPosition
|
||||
{
|
||||
return $this->evaluate($this->recordCheckboxPosition) ?? RecordCheckboxPosition::BeforeCells;
|
||||
}
|
||||
|
||||
public function trackDeselectedRecords(bool | Closure $condition = true): static
|
||||
{
|
||||
$this->canTrackDeselectedRecords = $condition;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function canTrackDeselectedRecords(): bool
|
||||
{
|
||||
if (! $this->shouldDeselectAllRecordsWhenFiltered()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return (bool) $this->evaluate($this->canTrackDeselectedRecords);
|
||||
}
|
||||
|
||||
public function currentSelectionLivewireProperty(string | Closure | null $property): static
|
||||
{
|
||||
$this->currentSelectionLivewireProperty = $property;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getCurrentSelectionLivewireProperty(): ?string
|
||||
{
|
||||
return $this->evaluate($this->currentSelectionLivewireProperty);
|
||||
}
|
||||
|
||||
public function maxSelectableRecords(int | Closure | null $count): static
|
||||
{
|
||||
$this->maxSelectableRecords = $count;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getMaxSelectableRecords(): ?int
|
||||
{
|
||||
return $this->evaluate($this->maxSelectableRecords);
|
||||
}
|
||||
|
||||
public function disabledSelection(bool | Closure $condition = true): static
|
||||
{
|
||||
$this->isSelectionDisabled = $condition;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function isSelectionDisabled(): bool
|
||||
{
|
||||
return (bool) $this->evaluate($this->isSelectionDisabled);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use `getToolbarActions()` instead.
|
||||
*
|
||||
* @return array<Action | ActionGroup>
|
||||
*/
|
||||
public function getBulkActions(): array
|
||||
{
|
||||
return $this->getToolbarActions();
|
||||
}
|
||||
}
|
||||
312
vendor/filament/tables/src/Table/Concerns/HasColumnManager.php
vendored
Normal file
312
vendor/filament/tables/src/Table/Concerns/HasColumnManager.php
vendored
Normal file
|
|
@ -0,0 +1,312 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Tables\Table\Concerns;
|
||||
|
||||
use Closure;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Support\Enums\Width;
|
||||
use Filament\Support\Facades\FilamentIcon;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use Filament\Tables\Enums\ColumnManagerLayout;
|
||||
use Filament\Tables\Enums\ColumnManagerResetActionPosition;
|
||||
use Filament\Tables\View\TablesIconAlias;
|
||||
|
||||
trait HasColumnManager
|
||||
{
|
||||
protected ColumnManagerResetActionPosition | Closure | null $columnManagerResetActionPosition = null;
|
||||
|
||||
protected bool | Closure | null $hasColumnManager = null;
|
||||
|
||||
protected bool | Closure $hasReorderableColumns = false;
|
||||
|
||||
/**
|
||||
* @var int | array<string, int | null> | Closure
|
||||
*/
|
||||
protected int | array | Closure $columnManagerColumns = 1;
|
||||
|
||||
protected string | Closure | null $columnManagerMaxHeight = null;
|
||||
|
||||
protected Width | string | Closure | null $columnManagerWidth = null;
|
||||
|
||||
protected ?Closure $modifyColumnManagerTriggerActionUsing = null;
|
||||
|
||||
protected ColumnManagerLayout | Closure | null $columnManagerLayout = null;
|
||||
|
||||
protected bool | Closure $hasDeferredColumnManager = true;
|
||||
|
||||
protected ?Closure $modifyColumnManagerApplyActionUsing = null;
|
||||
|
||||
protected bool | Closure $persistsColumnsInSession = true;
|
||||
|
||||
public function columnManager(bool | Closure | null $condition = true): static
|
||||
{
|
||||
$this->hasColumnManager = $condition;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function deferColumnManager(bool | Closure $condition = true): static
|
||||
{
|
||||
$this->hasDeferredColumnManager = $condition;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function reorderableColumns(bool | Closure $condition = true): static
|
||||
{
|
||||
$this->hasReorderableColumns = $condition;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function hasColumnManager(): bool
|
||||
{
|
||||
return (bool) (
|
||||
$this->evaluate($this->hasColumnManager) ?? (
|
||||
($hasReorderableColumns = $this->hasReorderableColumns())
|
||||
? $hasReorderableColumns
|
||||
: $this->hasToggleableColumns()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function hasReorderableColumns(): bool
|
||||
{
|
||||
return (bool) $this->evaluate($this->hasReorderableColumns);
|
||||
}
|
||||
|
||||
public function hasDeferredColumnManager(): bool
|
||||
{
|
||||
return (bool) $this->evaluate($this->hasDeferredColumnManager);
|
||||
}
|
||||
|
||||
public function columnManagerApplyAction(?Closure $callback): static
|
||||
{
|
||||
$this->modifyColumnManagerApplyActionUsing = $callback;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function persistColumnsInSession(bool | Closure $condition = true): static
|
||||
{
|
||||
$this->persistsColumnsInSession = $condition;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function columnManagerLayout(ColumnManagerLayout | Closure | null $layout): static
|
||||
{
|
||||
$this->columnManagerLayout = $layout;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getColumnManagerLayout(): ColumnManagerLayout
|
||||
{
|
||||
return $this->evaluate($this->columnManagerLayout) ?? ColumnManagerLayout::Dropdown;
|
||||
}
|
||||
|
||||
public function columnManagerResetActionPosition(ColumnManagerResetActionPosition | Closure | null $position): static
|
||||
{
|
||||
$this->columnManagerResetActionPosition = $position;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function persistsColumnsInSession(): bool
|
||||
{
|
||||
return (bool) $this->evaluate($this->persistsColumnsInSession);
|
||||
}
|
||||
|
||||
public function getColumnManagerResetActionPosition(): ColumnManagerResetActionPosition
|
||||
{
|
||||
return $this->evaluate($this->columnManagerResetActionPosition) ?? ColumnManagerResetActionPosition::Header;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use `columnManagerTriggerAction()` instead.
|
||||
*/
|
||||
public function toggleColumnsTriggerAction(?Closure $callback): static
|
||||
{
|
||||
return $this->columnManagerTriggerAction($callback);
|
||||
}
|
||||
|
||||
public function columnManagerTriggerAction(?Closure $callback): static
|
||||
{
|
||||
$this->modifyColumnManagerTriggerActionUsing = $callback;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use `columnManagerColumns()` instead.
|
||||
*
|
||||
* @param int | array<string, int | null> | Closure $columns
|
||||
*/
|
||||
public function columnToggleFormColumns(int | array | Closure $columns): static
|
||||
{
|
||||
return $this->columnManagerColumns($columns);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int | array<string, int | null> | Closure $columns
|
||||
*/
|
||||
public function columnManagerColumns(int | array | Closure $columns): static
|
||||
{
|
||||
$this->columnManagerColumns = $columns;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use `columnManagerMaxHeight()` instead.
|
||||
*/
|
||||
public function columnToggleFormMaxHeight(string | Closure | null $height): static
|
||||
{
|
||||
return $this->columnManagerMaxHeight($height);
|
||||
}
|
||||
|
||||
public function columnManagerMaxHeight(string | Closure | null $height): static
|
||||
{
|
||||
$this->columnManagerMaxHeight = $height;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use `columnManagerWidth()` instead.
|
||||
*/
|
||||
public function columnToggleFormWidth(Width | string | Closure | null $width): static
|
||||
{
|
||||
return $this->columnManagerWidth($width);
|
||||
}
|
||||
|
||||
public function columnManagerWidth(Width | string | Closure | null $width): static
|
||||
{
|
||||
$this->columnManagerWidth = $width;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use `getColumnManagerColumns()` instead.
|
||||
*
|
||||
* @return int | array<string, int | null>
|
||||
*/
|
||||
public function getColumnToggleFormColumns(): int | array
|
||||
{
|
||||
return $this->getColumnManagerColumns();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int | array<string, int | null>
|
||||
*/
|
||||
public function getColumnManagerColumns(): int | array
|
||||
{
|
||||
return $this->evaluate($this->columnManagerColumns) ?? 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use `getColumnManagerMaxHeight()` instead.
|
||||
*/
|
||||
public function getColumnToggleFormMaxHeight(): ?string
|
||||
{
|
||||
return $this->getColumnManagerMaxHeight();
|
||||
}
|
||||
|
||||
public function getColumnManagerMaxHeight(): ?string
|
||||
{
|
||||
return $this->evaluate($this->columnManagerMaxHeight);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use `getColumnManagerWidth()` instead.
|
||||
*/
|
||||
public function getColumnToggleFormWidth(): ?string
|
||||
{
|
||||
return $this->getColumnManagerWidth();
|
||||
}
|
||||
|
||||
public function getColumnManagerWidth(): Width | string | null
|
||||
{
|
||||
return $this->evaluate($this->columnManagerWidth) ?? match ($this->getColumnManagerColumns()) {
|
||||
2 => Width::TwoExtraLarge,
|
||||
3 => Width::FourExtraLarge,
|
||||
4 => Width::SixExtraLarge,
|
||||
default => Width::ExtraSmall,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use `getColumnManagerTriggerAction()` instead.
|
||||
*/
|
||||
public function getToggleColumnsTriggerAction(): Action
|
||||
{
|
||||
return $this->getColumnManagerTriggerAction();
|
||||
}
|
||||
|
||||
public function getColumnManagerTriggerAction(): Action
|
||||
{
|
||||
$action = Action::make('openColumnManager')
|
||||
->label(__('filament-tables::table.actions.column_manager.label'))
|
||||
->iconButton()
|
||||
->icon(FilamentIcon::resolve(TablesIconAlias::ACTIONS_COLUMN_MANAGER) ?? Heroicon::ViewColumns)
|
||||
->color('gray')
|
||||
->livewireClickHandlerEnabled(false)
|
||||
->modalSubmitAction(false)
|
||||
->extraModalFooterActions([
|
||||
$this->getColumnManagerApplyAction()
|
||||
->alpineClickHandler("\$dispatch('apply-table-column-manager'); close()"),
|
||||
Action::make('resetColumnManager')
|
||||
->label(__('filament-tables::table.column_manager.actions.reset.label'))
|
||||
->color('danger')
|
||||
->alpineClickHandler("\$dispatch('reset-table-column-manager'); \$wire.resetTableColumnManager()")
|
||||
->button(),
|
||||
])
|
||||
->modalCancelActionLabel(__('filament::components/modal.actions.close.label'))
|
||||
->table($this)
|
||||
->authorize(true);
|
||||
|
||||
if ($this->modifyColumnManagerTriggerActionUsing) {
|
||||
$action = $this->evaluate($this->modifyColumnManagerTriggerActionUsing, [
|
||||
'action' => $action,
|
||||
]) ?? $action;
|
||||
}
|
||||
|
||||
$action->extraAttributes(['class' => 'fi-force-enabled'], merge: true);
|
||||
|
||||
return $action;
|
||||
}
|
||||
|
||||
public function getColumnManagerApplyAction(): Action
|
||||
{
|
||||
$action = Action::make('applyTableColumnManager')
|
||||
->label(__('filament-tables::table.column_manager.actions.apply.label'))
|
||||
->button()
|
||||
->visible($this->hasDeferredColumnManager())
|
||||
->alpineClickHandler('applyTableColumnManager')
|
||||
->table($this)
|
||||
->authorize(true);
|
||||
|
||||
if ($this->modifyColumnManagerApplyActionUsing) {
|
||||
$action = $this->evaluate($this->modifyColumnManagerApplyActionUsing, [
|
||||
'action' => $action,
|
||||
]) ?? $action;
|
||||
}
|
||||
|
||||
return $action;
|
||||
}
|
||||
|
||||
public function hasToggleableColumns(): bool
|
||||
{
|
||||
foreach ($this->getColumns() as $column) {
|
||||
if (! $column->isToggleable()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
191
vendor/filament/tables/src/Table/Concerns/HasColumns.php
vendored
Normal file
191
vendor/filament/tables/src/Table/Concerns/HasColumns.php
vendored
Normal file
|
|
@ -0,0 +1,191 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Tables\Table\Concerns;
|
||||
|
||||
use Closure;
|
||||
use Filament\Tables\Columns\Column;
|
||||
use Filament\Tables\Columns\ColumnGroup;
|
||||
use Filament\Tables\Columns\Layout\Component as ColumnLayoutComponent;
|
||||
|
||||
trait HasColumns
|
||||
{
|
||||
/**
|
||||
* @var array<string, Column>
|
||||
*/
|
||||
protected array $columns = [];
|
||||
|
||||
/**
|
||||
* @var array<string, Column> | null
|
||||
*/
|
||||
protected ?array $cachedVisibleColumns = null;
|
||||
|
||||
/**
|
||||
* @var array<string, ColumnGroup>
|
||||
*/
|
||||
protected array $columnGroups = [];
|
||||
|
||||
/**
|
||||
* @var array<Column | ColumnLayoutComponent | ColumnGroup>
|
||||
*/
|
||||
protected array $columnsLayout = [];
|
||||
|
||||
protected ?ColumnLayoutComponent $collapsibleColumnsLayout = null;
|
||||
|
||||
protected bool $hasColumnGroups = false;
|
||||
|
||||
protected bool $hasColumnsLayout = false;
|
||||
|
||||
/**
|
||||
* @param array<Column | ColumnLayoutComponent | ColumnGroup> $components
|
||||
*/
|
||||
public function columns(array $components): static
|
||||
{
|
||||
$this->columns = [];
|
||||
$this->columnGroups = [];
|
||||
$this->columnsLayout = [];
|
||||
$this->collapsibleColumnsLayout = null;
|
||||
$this->hasColumnsLayout = false;
|
||||
$this->pushColumns($components);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<Column | ColumnLayoutComponent | ColumnGroup> $components
|
||||
*/
|
||||
public function pushColumns(array $components): static
|
||||
{
|
||||
$this->cachedVisibleColumns = null;
|
||||
|
||||
foreach ($components as $component) {
|
||||
$component->table($this);
|
||||
|
||||
if ($component instanceof ColumnLayoutComponent && $component->isCollapsible()) {
|
||||
$this->collapsibleColumnsLayout = $component;
|
||||
} else {
|
||||
$this->columnsLayout[] = $component;
|
||||
}
|
||||
|
||||
if ($component instanceof ColumnGroup) {
|
||||
$this->hasColumnGroups = true;
|
||||
|
||||
$this->columnGroups[e($component->getLabel())] = $component;
|
||||
|
||||
$this->columns = [
|
||||
...$this->columns,
|
||||
...$component->getColumns(),
|
||||
];
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($component instanceof ColumnLayoutComponent) {
|
||||
$this->hasColumnsLayout = true;
|
||||
|
||||
$this->columns = [
|
||||
...$this->columns,
|
||||
...$component->getColumns(),
|
||||
];
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->columns[$component->getName()] = $component;
|
||||
}
|
||||
|
||||
foreach ($this->columns as $column) {
|
||||
$action = $column->getAction();
|
||||
|
||||
if (($action === null) || ($action instanceof Closure)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->cacheAction($action->table($this));
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, Column>
|
||||
*/
|
||||
public function getColumns(): array
|
||||
{
|
||||
return $this->columns;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, ColumnGroup>
|
||||
*/
|
||||
public function getColumnGroups(): array
|
||||
{
|
||||
return $this->columnGroups;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, Column>
|
||||
*/
|
||||
public function getVisibleColumns(): array
|
||||
{
|
||||
return $this->cachedVisibleColumns ??= array_filter(
|
||||
$this->getColumns(),
|
||||
fn (Column $column): bool => $column->isVisible() && (! $column->isToggledHidden()),
|
||||
);
|
||||
}
|
||||
|
||||
public function flushCachedVisibleColumns(): void
|
||||
{
|
||||
$this->cachedVisibleColumns = null;
|
||||
}
|
||||
|
||||
public function getColumn(string $name): ?Column
|
||||
{
|
||||
return $this->getColumns()[$name] ?? null;
|
||||
}
|
||||
|
||||
public function getColumnGroup(string $name): ?ColumnGroup
|
||||
{
|
||||
return $this->getColumnGroups()[$name] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<Column | ColumnLayoutComponent | ColumnGroup>
|
||||
*/
|
||||
public function getColumnsLayout(): array
|
||||
{
|
||||
return $this->columnsLayout;
|
||||
}
|
||||
|
||||
public function getCollapsibleColumnsLayout(): ?ColumnLayoutComponent
|
||||
{
|
||||
return $this->collapsibleColumnsLayout;
|
||||
}
|
||||
|
||||
public function hasColumnGroups(): bool
|
||||
{
|
||||
if (! $this->hasColumnGroups) {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ($this->getVisibleColumns() as $column) {
|
||||
$columnGroup = $column->getGroup();
|
||||
|
||||
if (! $columnGroup) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (empty($columnGroup->getVisibleColumns())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function hasColumnsLayout(): bool
|
||||
{
|
||||
return $this->hasColumnsLayout;
|
||||
}
|
||||
}
|
||||
61
vendor/filament/tables/src/Table/Concerns/HasContent.php
vendored
Normal file
61
vendor/filament/tables/src/Table/Concerns/HasContent.php
vendored
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Tables\Table\Concerns;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Contracts\Support\Htmlable;
|
||||
use Illuminate\Contracts\View\View;
|
||||
|
||||
trait HasContent
|
||||
{
|
||||
protected View | Htmlable | Closure | null $content = null;
|
||||
|
||||
protected View | Htmlable | Closure | null $contentFooter = null;
|
||||
|
||||
/**
|
||||
* @var array<string, int | null> | Closure | null
|
||||
*/
|
||||
protected array | Closure | null $contentGrid = null;
|
||||
|
||||
public function content(View | Htmlable | Closure | null $content): static
|
||||
{
|
||||
$this->content = $content;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function contentFooter(View | Htmlable | Closure | null $footer): static
|
||||
{
|
||||
$this->contentFooter = $footer;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, int | null> | Closure | null $grid
|
||||
*/
|
||||
public function contentGrid(array | Closure | null $grid): static
|
||||
{
|
||||
$this->contentGrid = $grid;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getContent(): View | Htmlable | null
|
||||
{
|
||||
return $this->evaluate($this->content);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, int | null> | null
|
||||
*/
|
||||
public function getContentGrid(): ?array
|
||||
{
|
||||
return $this->evaluate($this->contentGrid);
|
||||
}
|
||||
|
||||
public function getContentFooter(): View | Htmlable | null
|
||||
{
|
||||
return $this->evaluate($this->contentFooter);
|
||||
}
|
||||
}
|
||||
127
vendor/filament/tables/src/Table/Concerns/HasEmptyState.php
vendored
Normal file
127
vendor/filament/tables/src/Table/Concerns/HasEmptyState.php
vendored
Normal file
|
|
@ -0,0 +1,127 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Tables\Table\Concerns;
|
||||
|
||||
use BackedEnum;
|
||||
use Closure;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Actions\ActionGroup;
|
||||
use Filament\Support\Facades\FilamentIcon;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use Filament\Tables\View\TablesIconAlias;
|
||||
use Illuminate\Contracts\Support\Htmlable;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Support\Arr;
|
||||
use InvalidArgumentException;
|
||||
|
||||
trait HasEmptyState
|
||||
{
|
||||
protected View | Htmlable | Closure | null $emptyState = null;
|
||||
|
||||
protected string | Htmlable | Closure | null $emptyStateDescription = null;
|
||||
|
||||
protected string | Htmlable | Closure | null $emptyStateHeading = null;
|
||||
|
||||
protected string | BackedEnum | Htmlable | Closure | null $emptyStateIcon = null;
|
||||
|
||||
/**
|
||||
* @var array<Action | ActionGroup>
|
||||
*/
|
||||
protected array $emptyStateActions = [];
|
||||
|
||||
public function emptyStateDescription(string | Htmlable | Closure | null $description): static
|
||||
{
|
||||
$this->emptyStateDescription = $description;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function emptyState(View | Htmlable | Closure | null $emptyState): static
|
||||
{
|
||||
$this->emptyState = $emptyState;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<Action | ActionGroup> | ActionGroup $actions
|
||||
*/
|
||||
public function emptyStateActions(array | ActionGroup $actions, bool $shouldOverwriteExistingActions = false): static
|
||||
{
|
||||
$this->emptyStateActions = [];
|
||||
$this->pushEmptyStateActions($actions, $shouldOverwriteExistingActions);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<Action | ActionGroup> | ActionGroup $actions
|
||||
*/
|
||||
public function pushEmptyStateActions(array | ActionGroup $actions, bool $shouldOverwriteExistingActions = false): static
|
||||
{
|
||||
foreach (Arr::wrap($actions) as $action) {
|
||||
$action->table($this);
|
||||
|
||||
if ($action instanceof ActionGroup) {
|
||||
/** @var array<string, Action> $flatActions */
|
||||
$flatActions = $action->getFlatActions();
|
||||
|
||||
$this->mergeCachedFlatActions($flatActions, $shouldOverwriteExistingActions);
|
||||
} elseif ($action instanceof Action) {
|
||||
$this->cacheAction($action, $shouldOverwriteExistingActions);
|
||||
} else {
|
||||
throw new InvalidArgumentException('Table empty state actions must be an instance of [' . Action::class . '] or [' . ActionGroup::class . '].');
|
||||
}
|
||||
|
||||
$this->emptyStateActions[] = $action;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function emptyStateHeading(string | Htmlable | Closure | null $heading): static
|
||||
{
|
||||
$this->emptyStateHeading = $heading;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function emptyStateIcon(string | BackedEnum | Htmlable | Closure | null $icon): static
|
||||
{
|
||||
$this->emptyStateIcon = $icon;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getEmptyState(): View | Htmlable | null
|
||||
{
|
||||
return $this->evaluate($this->emptyState);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<Action | ActionGroup>
|
||||
*/
|
||||
public function getEmptyStateActions(): array
|
||||
{
|
||||
return $this->emptyStateActions;
|
||||
}
|
||||
|
||||
public function getEmptyStateDescription(): string | Htmlable | null
|
||||
{
|
||||
return $this->evaluate($this->emptyStateDescription);
|
||||
}
|
||||
|
||||
public function getEmptyStateHeading(): string | Htmlable
|
||||
{
|
||||
return $this->evaluate($this->emptyStateHeading) ?? __('filament-tables::table.empty.heading', [
|
||||
'model' => $this->getPluralModelLabel(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function getEmptyStateIcon(): string | BackedEnum
|
||||
{
|
||||
return $this->evaluate($this->emptyStateIcon)
|
||||
?? FilamentIcon::resolve(TablesIconAlias::EMPTY_STATE)
|
||||
?? Heroicon::OutlinedXMark;
|
||||
}
|
||||
}
|
||||
48
vendor/filament/tables/src/Table/Concerns/HasFilterIndicators.php
vendored
Normal file
48
vendor/filament/tables/src/Table/Concerns/HasFilterIndicators.php
vendored
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Tables\Table\Concerns;
|
||||
|
||||
use Closure;
|
||||
use Filament\Tables\Filters\BaseFilter;
|
||||
use Filament\Tables\Filters\Indicator;
|
||||
|
||||
trait HasFilterIndicators
|
||||
{
|
||||
protected bool | Closure $areFilterIndicatorsHidden = false;
|
||||
|
||||
/**
|
||||
* @return array<Indicator>
|
||||
*/
|
||||
public function getFilterIndicators(): array
|
||||
{
|
||||
if ($this->evaluate($this->areFilterIndicatorsHidden)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return [
|
||||
...($this->hasSearch() ? [$this->getSearchIndicator()] : []),
|
||||
...$this->getColumnSearchIndicators(),
|
||||
...array_reduce(
|
||||
$this->getFilters(),
|
||||
fn (array $carry, BaseFilter $filter): array => [
|
||||
...$carry,
|
||||
...collect($filter->getIndicators())
|
||||
->map(function (Indicator $indicator) use ($filter): Indicator {
|
||||
$removeField = $indicator->getRemoveField();
|
||||
|
||||
return $indicator->removeLivewireClickHandler("removeTableFilter('{$filter->getName()}'" . (filled($removeField) ? ', \'' . $removeField . '\'' : null) . ')');
|
||||
})
|
||||
->all(),
|
||||
],
|
||||
[],
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
public function hiddenFilterIndicators(bool | Closure $condition = true): static
|
||||
{
|
||||
$this->areFilterIndicatorsHidden = $condition;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
393
vendor/filament/tables/src/Table/Concerns/HasFilters.php
vendored
Normal file
393
vendor/filament/tables/src/Table/Concerns/HasFilters.php
vendored
Normal file
|
|
@ -0,0 +1,393 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Tables\Table\Concerns;
|
||||
|
||||
use Closure;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Schemas\Components\Group;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Support\Enums\Size;
|
||||
use Filament\Support\Enums\Width;
|
||||
use Filament\Support\Facades\FilamentIcon;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use Filament\Tables\Enums\FiltersLayout;
|
||||
use Filament\Tables\Enums\FiltersResetActionPosition;
|
||||
use Filament\Tables\Filters\BaseFilter;
|
||||
use Filament\Tables\View\TablesIconAlias;
|
||||
|
||||
trait HasFilters
|
||||
{
|
||||
/**
|
||||
* @var array<string, BaseFilter>
|
||||
*/
|
||||
protected array $filters = [];
|
||||
|
||||
protected ?Closure $filtersFormSchema = null;
|
||||
|
||||
/**
|
||||
* @var int | array<string, int | null> | Closure
|
||||
*/
|
||||
protected int | array | Closure | null $filtersFormColumns = null;
|
||||
|
||||
protected string | Closure | null $filtersFormMaxHeight = null;
|
||||
|
||||
protected Width | string | Closure | null $filtersFormWidth = null;
|
||||
|
||||
protected FiltersLayout | Closure | null $filtersLayout = null;
|
||||
|
||||
protected ?Closure $modifyFiltersTriggerActionUsing = null;
|
||||
|
||||
protected bool | Closure | null $persistsFiltersInSession = false;
|
||||
|
||||
protected bool | Closure $shouldDeselectAllRecordsWhenFiltered = true;
|
||||
|
||||
protected bool | Closure $hasDeferredFilters = true;
|
||||
|
||||
protected ?Closure $modifyFiltersApplyActionUsing = null;
|
||||
|
||||
protected ?Closure $modifyFiltersRemoveAllActionUsing = null;
|
||||
|
||||
protected FiltersResetActionPosition | Closure | null $filtersResetActionPosition = null;
|
||||
|
||||
public function deferFilters(bool | Closure $condition = true): static
|
||||
{
|
||||
$this->hasDeferredFilters = $condition;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function hasDeferredFilters(): bool
|
||||
{
|
||||
return (bool) $this->evaluate($this->hasDeferredFilters);
|
||||
}
|
||||
|
||||
public function filtersApplyAction(?Closure $callback): static
|
||||
{
|
||||
$this->modifyFiltersApplyActionUsing = $callback;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function filtersRemoveAllAction(?Closure $callback): static
|
||||
{
|
||||
$this->modifyFiltersRemoveAllActionUsing = $callback;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function deselectAllRecordsWhenFiltered(bool | Closure $condition = true): static
|
||||
{
|
||||
$this->shouldDeselectAllRecordsWhenFiltered = $condition;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<BaseFilter> $filters
|
||||
*/
|
||||
public function filters(array $filters, FiltersLayout | string | Closure | null $layout = null): static
|
||||
{
|
||||
$this->filters = [];
|
||||
$this->pushFilters($filters);
|
||||
|
||||
if ($layout) {
|
||||
$this->filtersLayout($layout);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<BaseFilter> $filters
|
||||
*/
|
||||
public function pushFilters(array $filters): static
|
||||
{
|
||||
foreach ($filters as $filter) {
|
||||
$filter->table($this);
|
||||
|
||||
$this->filters[$filter->getName()] = $filter;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int | array<string, int | null> | Closure $columns
|
||||
*/
|
||||
public function filtersFormColumns(int | array | Closure | null $columns): static
|
||||
{
|
||||
$this->filtersFormColumns = $columns;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function filtersFormMaxHeight(string | Closure | null $height): static
|
||||
{
|
||||
$this->filtersFormMaxHeight = $height;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function filtersFormWidth(Width | string | Closure | null $width): static
|
||||
{
|
||||
$this->filtersFormWidth = $width;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function filtersResetActionPosition(FiltersResetActionPosition | Closure | null $position): static
|
||||
{
|
||||
$this->filtersResetActionPosition = $position;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getFiltersResetActionPosition(): FiltersResetActionPosition
|
||||
{
|
||||
return $this->evaluate($this->filtersResetActionPosition) ?? FiltersResetActionPosition::Header;
|
||||
}
|
||||
|
||||
public function filtersLayout(FiltersLayout | Closure | null $filtersLayout): static
|
||||
{
|
||||
$this->filtersLayout = $filtersLayout;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function filtersTriggerAction(?Closure $callback): static
|
||||
{
|
||||
$this->modifyFiltersTriggerActionUsing = $callback;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function persistFiltersInSession(bool | Closure $condition = true): static
|
||||
{
|
||||
$this->persistsFiltersInSession = $condition;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, BaseFilter>
|
||||
*/
|
||||
public function getFilters(bool $withHidden = false): array
|
||||
{
|
||||
if ($withHidden) {
|
||||
return $this->filters;
|
||||
}
|
||||
|
||||
return array_filter(
|
||||
$this->filters,
|
||||
fn (BaseFilter $filter): bool => $filter->isVisible(),
|
||||
);
|
||||
}
|
||||
|
||||
public function getFilter(string $name, bool $withHidden = false): ?BaseFilter
|
||||
{
|
||||
return $this->getFilters($withHidden)[$name] ?? null;
|
||||
}
|
||||
|
||||
public function getFiltersForm(): Schema
|
||||
{
|
||||
return $this->getLivewire()->getTableFiltersForm();
|
||||
}
|
||||
|
||||
/**
|
||||
* @template TReturn
|
||||
*
|
||||
* @param Closure(): TReturn $callback
|
||||
* @return TReturn
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
public function withAppliedFiltersFormState(Closure $callback): mixed
|
||||
{
|
||||
if (! $this->hasDeferredFilters()) {
|
||||
return $callback();
|
||||
}
|
||||
|
||||
$this->setFiltersFormStatePath('tableFilters');
|
||||
|
||||
try {
|
||||
return $callback();
|
||||
} finally {
|
||||
$this->setFiltersFormStatePath('tableDeferredFilters');
|
||||
}
|
||||
}
|
||||
|
||||
protected function setFiltersFormStatePath(string $statePath): void
|
||||
{
|
||||
$filtersForm = $this->getFiltersForm()->statePath($statePath);
|
||||
|
||||
$filtersForm->flushCachedAbsoluteStatePaths();
|
||||
$filtersForm->clearCachedChildSchemas();
|
||||
}
|
||||
|
||||
public function filtersFormSchema(?Closure $schema): static
|
||||
{
|
||||
$this->filtersFormSchema = $schema;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, Group>
|
||||
*/
|
||||
public function getFiltersFormSchema(): array
|
||||
{
|
||||
$filters = [];
|
||||
|
||||
foreach ($this->getFilters() as $filterName => $filter) {
|
||||
$filters[$filterName] = Group::make()
|
||||
->schema($filter->getSchemaComponents())
|
||||
->statePath($filterName)
|
||||
->key($filterName)
|
||||
->columnSpan($filter->getColumnSpan())
|
||||
->columnStart($filter->getColumnStart())
|
||||
->columns($filter->getColumns());
|
||||
}
|
||||
|
||||
return $this->evaluate($this->filtersFormSchema, ['filters' => $filters]) ?? array_values($filters);
|
||||
}
|
||||
|
||||
public function getFiltersTriggerAction(): Action
|
||||
{
|
||||
$action = Action::make('openFilters')
|
||||
->label(__('filament-tables::table.actions.filter.label'))
|
||||
->iconButton()
|
||||
->icon(FilamentIcon::resolve(TablesIconAlias::ACTIONS_FILTER) ?? Heroicon::Funnel)
|
||||
->color('gray')
|
||||
->livewireClickHandlerEnabled(false)
|
||||
->modalSubmitAction(false)
|
||||
->extraModalFooterActions([
|
||||
$this->getFiltersApplyAction()
|
||||
->close(),
|
||||
Action::make('resetFilters')
|
||||
->label(__('filament-tables::table.filters.actions.reset.label'))
|
||||
->color('danger')
|
||||
->action('resetTableFiltersForm')
|
||||
->button(),
|
||||
])
|
||||
->modalCancelActionLabel(__('filament::components/modal.actions.close.label'))
|
||||
->table($this)
|
||||
->authorize(true);
|
||||
|
||||
if ($this->modifyFiltersTriggerActionUsing) {
|
||||
$action = $this->evaluate($this->modifyFiltersTriggerActionUsing, [
|
||||
'action' => $action,
|
||||
]) ?? $action;
|
||||
}
|
||||
|
||||
$action->extraAttributes(['class' => 'fi-force-enabled'], merge: true);
|
||||
|
||||
return $action;
|
||||
}
|
||||
|
||||
public function getFiltersApplyAction(): Action
|
||||
{
|
||||
$action = Action::make('applyFilters')
|
||||
->label(__('filament-tables::table.filters.actions.apply.label'))
|
||||
->action('applyTableFilters')
|
||||
->table($this)
|
||||
->visible($this->hasDeferredFilters())
|
||||
->authorize(true)
|
||||
->button();
|
||||
|
||||
if ($this->modifyFiltersApplyActionUsing) {
|
||||
$action = $this->evaluate($this->modifyFiltersApplyActionUsing, [
|
||||
'action' => $action,
|
||||
]) ?? $action;
|
||||
}
|
||||
|
||||
return $action;
|
||||
}
|
||||
|
||||
public function getFiltersRemoveAllAction(): Action
|
||||
{
|
||||
$action = Action::make('removeAllFilters')
|
||||
->label(__('filament-tables::table.filters.actions.remove_all.label'))
|
||||
->tooltip(__('filament-tables::table.filters.actions.remove_all.tooltip'))
|
||||
->action('removeTableFilters')
|
||||
->livewireTarget('removeTableFilters,removeTableFilter')
|
||||
->iconButton()
|
||||
->icon(FilamentIcon::resolve(TablesIconAlias::FILTERS_REMOVE_ALL_BUTTON) ?? Heroicon::XMark)
|
||||
->color('gray')
|
||||
->defaultSize(Size::Small)
|
||||
->table($this)
|
||||
->authorize(true);
|
||||
|
||||
if ($this->modifyFiltersRemoveAllActionUsing) {
|
||||
$action = $this->evaluate($this->modifyFiltersRemoveAllActionUsing, [
|
||||
'action' => $action,
|
||||
]) ?? $action;
|
||||
}
|
||||
|
||||
return $action;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int | array<string, int | null>
|
||||
*/
|
||||
public function getFiltersFormColumns(): int | array
|
||||
{
|
||||
return $this->evaluate($this->filtersFormColumns) ?? match ($this->getFiltersLayout()) {
|
||||
FiltersLayout::AboveContent, FiltersLayout::AboveContentCollapsible, FiltersLayout::BelowContent => [
|
||||
'sm' => 2,
|
||||
'lg' => 3,
|
||||
'xl' => 4,
|
||||
'2xl' => 5,
|
||||
],
|
||||
default => 1,
|
||||
};
|
||||
}
|
||||
|
||||
public function getFiltersFormMaxHeight(): ?string
|
||||
{
|
||||
return $this->evaluate($this->filtersFormMaxHeight);
|
||||
}
|
||||
|
||||
public function getFiltersFormWidth(): Width | string | null
|
||||
{
|
||||
return $this->evaluate($this->filtersFormWidth) ?? match ($this->getFiltersFormColumns()) {
|
||||
2 => Width::TwoExtraLarge,
|
||||
3 => Width::FourExtraLarge,
|
||||
4 => Width::SixExtraLarge,
|
||||
default => null,
|
||||
};
|
||||
}
|
||||
|
||||
public function getFiltersLayout(): FiltersLayout
|
||||
{
|
||||
return $this->evaluate($this->filtersLayout) ?? FiltersLayout::Dropdown;
|
||||
}
|
||||
|
||||
public function isFilterable(): bool
|
||||
{
|
||||
return (bool) count($this->getFilters());
|
||||
}
|
||||
|
||||
public function persistsFiltersInSession(): bool
|
||||
{
|
||||
return (bool) $this->evaluate($this->persistsFiltersInSession);
|
||||
}
|
||||
|
||||
public function shouldDeselectAllRecordsWhenFiltered(): bool
|
||||
{
|
||||
return (bool) $this->evaluate($this->shouldDeselectAllRecordsWhenFiltered);
|
||||
}
|
||||
|
||||
public function getActiveFiltersCount(): int
|
||||
{
|
||||
return array_reduce(
|
||||
$this->getFilters(),
|
||||
fn (int $carry, BaseFilter $filter): int => $carry + $filter->getActiveCount(),
|
||||
0,
|
||||
);
|
||||
}
|
||||
|
||||
public function isFiltered(): bool
|
||||
{
|
||||
return $this->getActiveFiltersCount() > 0;
|
||||
}
|
||||
}
|
||||
52
vendor/filament/tables/src/Table/Concerns/HasHeader.php
vendored
Normal file
52
vendor/filament/tables/src/Table/Concerns/HasHeader.php
vendored
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Tables\Table\Concerns;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Contracts\Support\Htmlable;
|
||||
use Illuminate\Contracts\View\View;
|
||||
|
||||
trait HasHeader
|
||||
{
|
||||
protected string | Htmlable | Closure | null $heading = null;
|
||||
|
||||
protected View | Htmlable | Closure | null $header = null;
|
||||
|
||||
protected string | Htmlable | Closure | null $description = null;
|
||||
|
||||
public function description(string | Htmlable | Closure | null $description): static
|
||||
{
|
||||
$this->description = $description;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function header(View | Htmlable | Closure | null $header): static
|
||||
{
|
||||
$this->header = $header;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function heading(string | Htmlable | Closure | null $heading): static
|
||||
{
|
||||
$this->heading = $heading;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getHeader(): View | Htmlable | null
|
||||
{
|
||||
return $this->evaluate($this->header);
|
||||
}
|
||||
|
||||
public function getHeading(): string | Htmlable | null
|
||||
{
|
||||
return $this->evaluate($this->heading);
|
||||
}
|
||||
|
||||
public function getDescription(): string | Htmlable | null
|
||||
{
|
||||
return $this->evaluate($this->description);
|
||||
}
|
||||
}
|
||||
104
vendor/filament/tables/src/Table/Concerns/HasHeaderActions.php
vendored
Normal file
104
vendor/filament/tables/src/Table/Concerns/HasHeaderActions.php
vendored
Normal file
|
|
@ -0,0 +1,104 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Tables\Table\Concerns;
|
||||
|
||||
use Closure;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Actions\ActionGroup;
|
||||
use Filament\Actions\BulkAction;
|
||||
use Filament\Tables\Actions\HeaderActionsPosition;
|
||||
use Illuminate\Support\Arr;
|
||||
use InvalidArgumentException;
|
||||
|
||||
trait HasHeaderActions
|
||||
{
|
||||
/**
|
||||
* @var array<string, Action | BulkAction | ActionGroup>
|
||||
*/
|
||||
protected array $headerActions = [];
|
||||
|
||||
protected HeaderActionsPosition | Closure | null $headerActionsPosition = null;
|
||||
|
||||
public function headerActionsPosition(HeaderActionsPosition | Closure | null $position = null): static
|
||||
{
|
||||
$this->headerActionsPosition = $position;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<Action | BulkAction | ActionGroup> | ActionGroup $actions
|
||||
*/
|
||||
public function headerActions(array | ActionGroup $actions, HeaderActionsPosition | Closure | null $position = null): static
|
||||
{
|
||||
// We must remove the existing cached header actions before setting the new ones, as
|
||||
// the visibility of the checkboxes is determined by which bulk actions are visible.
|
||||
// The `$this->flatActions` array is used to determine if any bulk actions are
|
||||
// visible. We cannot simply clear it, as the bulk actions defined in the header
|
||||
// of the table are also stored in this array, and we do not want to remove them,
|
||||
// only the bulk actions that are stored in the `$this->headerActions` array.
|
||||
foreach ($this->headerActions as $existingAction) {
|
||||
if ($existingAction instanceof ActionGroup) {
|
||||
/** @var array<Action> $flatExistingActions */
|
||||
$flatExistingActions = $existingAction->getFlatActions();
|
||||
|
||||
$this->removeCachedActions($flatExistingActions);
|
||||
} elseif ($existingAction instanceof Action) {
|
||||
$this->removeCachedActions([$existingAction]);
|
||||
}
|
||||
}
|
||||
|
||||
$this->headerActions = [];
|
||||
|
||||
$this->pushHeaderActions($actions);
|
||||
|
||||
if ($position) {
|
||||
$this->headerActionsPosition($position);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<Action | BulkAction | ActionGroup> | ActionGroup $actions
|
||||
*/
|
||||
public function pushHeaderActions(array | ActionGroup $actions): static
|
||||
{
|
||||
foreach (Arr::wrap($actions) as $action) {
|
||||
$action->table($this);
|
||||
|
||||
if ($action instanceof ActionGroup) {
|
||||
foreach ($action->getFlatActions() as $flatAction) {
|
||||
$this->cacheAction($flatAction);
|
||||
}
|
||||
} elseif ($action instanceof Action) {
|
||||
$this->cacheAction($action);
|
||||
} else {
|
||||
throw new InvalidArgumentException('Table header actions must be an instance of [' . Action::class . '], [' . BulkAction::class . '] or [' . ActionGroup::class . '].');
|
||||
}
|
||||
|
||||
$this->headerActions[] = $action;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getHeaderActionsPosition(): HeaderActionsPosition
|
||||
{
|
||||
$position = $this->evaluate($this->headerActionsPosition);
|
||||
|
||||
if (filled($position)) {
|
||||
return $position;
|
||||
}
|
||||
|
||||
return HeaderActionsPosition::Adaptive;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, Action | BulkAction | ActionGroup>
|
||||
*/
|
||||
public function getHeaderActions(): array
|
||||
{
|
||||
return $this->headerActions;
|
||||
}
|
||||
}
|
||||
36
vendor/filament/tables/src/Table/Concerns/HasHeadings.php
vendored
Normal file
36
vendor/filament/tables/src/Table/Concerns/HasHeadings.php
vendored
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Tables\Table\Concerns;
|
||||
|
||||
trait HasHeadings
|
||||
{
|
||||
protected int $rootHeadingLevel = 2;
|
||||
|
||||
public function rootHeadingLevel(int $level): static
|
||||
{
|
||||
$this->rootHeadingLevel = $level;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getRootHeadingLevel(): int
|
||||
{
|
||||
return $this->rootHeadingLevel;
|
||||
}
|
||||
|
||||
public function getHeadingLevel(int $index = 0): int
|
||||
{
|
||||
return $this->getRootHeadingLevel() + $index;
|
||||
}
|
||||
|
||||
public function getHeadingTag(int $index = 0): string
|
||||
{
|
||||
$level = $this->getHeadingLevel($index);
|
||||
|
||||
if ($level > 6) {
|
||||
return 'p';
|
||||
}
|
||||
|
||||
return "h{$level}";
|
||||
}
|
||||
}
|
||||
176
vendor/filament/tables/src/Table/Concerns/HasQuery.php
vendored
Normal file
176
vendor/filament/tables/src/Table/Concerns/HasQuery.php
vendored
Normal file
|
|
@ -0,0 +1,176 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Tables\Table\Concerns;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOneOrMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOneOrManyThrough;
|
||||
use Illuminate\Database\Eloquent\Relations\Relation;
|
||||
|
||||
use function Livewire\invade;
|
||||
|
||||
trait HasQuery
|
||||
{
|
||||
protected Builder | Closure | null $query = null;
|
||||
|
||||
protected string | Closure | null $inverseRelationship = null;
|
||||
|
||||
protected ?Closure $getRelationshipUsing = null;
|
||||
|
||||
/**
|
||||
* @var array<Closure>
|
||||
*/
|
||||
protected array $queryScopes = [];
|
||||
|
||||
public function query(Builder | Closure | null $query): static
|
||||
{
|
||||
$this->query = $query;
|
||||
$this->hasCachedModel = false;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function modifyQueryUsing(Closure $callback): static
|
||||
{
|
||||
$this->queryScopes[] = $callback;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function relationship(?Closure $relationship): static
|
||||
{
|
||||
$this->getRelationshipUsing = $relationship;
|
||||
$this->hasCachedModel = false;
|
||||
$this->cachedHasPivotRecordKeys = null;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function inverseRelationship(string | Closure | null $name): static
|
||||
{
|
||||
$this->inverseRelationship = $name;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function applyQueryScopes(Builder $query, bool $isResolvingRecord = false): Builder
|
||||
{
|
||||
foreach ($this->queryScopes as $scope) {
|
||||
$query = $this->evaluate($scope, [
|
||||
'query' => $query,
|
||||
'isResolvingRecord' => $isResolvingRecord,
|
||||
]) ?? $query;
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
public function getQuery(bool $isResolvingRecord = false): Builder | Relation | null
|
||||
{
|
||||
if ($query = $this->evaluate($this->query)) {
|
||||
return $this->applyQueryScopes($query->clone(), $isResolvingRecord);
|
||||
}
|
||||
|
||||
if ($query = $this->getRelationshipQuery()) {
|
||||
return $this->applyQueryScopes($query->clone(), $isResolvingRecord);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getRelationshipQuery(): ?Builder
|
||||
{
|
||||
$relationship = $this->getRelationship();
|
||||
|
||||
if (! $relationship) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$query = $relationship->getQuery();
|
||||
|
||||
if ($relationship instanceof HasOneOrManyThrough) {
|
||||
// https://github.com/laravel/framework/issues/4962
|
||||
$query->select($query->getModel()->getTable() . '.*');
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
if ($relationship instanceof BelongsToMany) {
|
||||
// https://github.com/laravel/framework/issues/4962
|
||||
if (! $this->allowsDuplicates()) {
|
||||
$this->selectPivotDataInQuery($query);
|
||||
}
|
||||
|
||||
// https://github.com/filamentphp/filament/issues/2079
|
||||
$query->withCasts(
|
||||
app($relationship->getPivotClass())->getCasts(),
|
||||
);
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
public function selectPivotDataInQuery(Builder | Relation $query): Builder | Relation
|
||||
{
|
||||
/** @var BelongsToMany $relationship */
|
||||
$relationship = $this->getRelationship();
|
||||
|
||||
$columns = [
|
||||
$relationship->getTable() . '.*',
|
||||
$query->getModel()->getTable() . '.*',
|
||||
];
|
||||
|
||||
if (! $this->allowsDuplicates()) {
|
||||
$columns = [
|
||||
...invade($relationship)->aliasedPivotColumns(),
|
||||
...$columns,
|
||||
];
|
||||
}
|
||||
|
||||
$baseQuery = $query instanceof Relation ? $query->getQuery()->getQuery() : $query->getQuery();
|
||||
$baseQuery->columns = array_values(array_filter(
|
||||
$baseQuery->columns ?? [],
|
||||
fn ($column): bool => ! in_array($column, $columns, true),
|
||||
));
|
||||
|
||||
$query->addSelect($columns);
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
public function getRelationship(): Relation | Builder | null
|
||||
{
|
||||
return $this->evaluate($this->getRelationshipUsing);
|
||||
}
|
||||
|
||||
public function getInverseRelationship(): ?string
|
||||
{
|
||||
$relationship = $this->getRelationship();
|
||||
|
||||
if (! $relationship) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$inverseRelationship = $this->evaluate($this->inverseRelationship);
|
||||
|
||||
if ($inverseRelationship) {
|
||||
return $inverseRelationship;
|
||||
}
|
||||
|
||||
$parentModelClass = str(class_basename($relationship->getParent()::class));
|
||||
|
||||
if ($relationship instanceof HasOneOrMany) {
|
||||
return (string) $parentModelClass->singular()->camel();
|
||||
}
|
||||
|
||||
return (string) $parentModelClass->plural()->camel();
|
||||
}
|
||||
|
||||
public function getInverseRelationshipFor(Model $record): Relation | Builder
|
||||
{
|
||||
return $record->{$this->getInverseRelationship()}();
|
||||
}
|
||||
}
|
||||
22
vendor/filament/tables/src/Table/Concerns/HasQueryStringIdentifier.php
vendored
Normal file
22
vendor/filament/tables/src/Table/Concerns/HasQueryStringIdentifier.php
vendored
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Tables\Table\Concerns;
|
||||
|
||||
use Closure;
|
||||
|
||||
trait HasQueryStringIdentifier
|
||||
{
|
||||
protected string | Closure | null $queryStringIdentifier = null;
|
||||
|
||||
public function queryStringIdentifier(string | Closure | null $identifier): static
|
||||
{
|
||||
$this->queryStringIdentifier = $identifier;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getQueryStringIdentifier(): ?string
|
||||
{
|
||||
return $this->evaluate($this->queryStringIdentifier);
|
||||
}
|
||||
}
|
||||
50
vendor/filament/tables/src/Table/Concerns/HasRecordAction.php
vendored
Normal file
50
vendor/filament/tables/src/Table/Concerns/HasRecordAction.php
vendored
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Tables\Table\Concerns;
|
||||
|
||||
use Closure;
|
||||
use Filament\Actions\Action;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
trait HasRecordAction
|
||||
{
|
||||
protected string | Closure | null $recordAction = null;
|
||||
|
||||
public function recordAction(string | Closure | null $action): static
|
||||
{
|
||||
$this->recordAction = $action;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Model | array<string, mixed> $record
|
||||
*/
|
||||
public function getRecordAction(Model | array $record): ?string
|
||||
{
|
||||
$action = $this->evaluate(
|
||||
$this->recordAction,
|
||||
namedInjections: [
|
||||
'record' => $record,
|
||||
],
|
||||
typedInjections: $record instanceof Model ? [
|
||||
Model::class => $record,
|
||||
$record::class => $record,
|
||||
] : [],
|
||||
);
|
||||
|
||||
if (! $action) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (! class_exists($action)) {
|
||||
return $action;
|
||||
}
|
||||
|
||||
if (! is_subclass_of($action, Action::class)) {
|
||||
return $action;
|
||||
}
|
||||
|
||||
return $action::getDefaultName() ?? $action;
|
||||
}
|
||||
}
|
||||
249
vendor/filament/tables/src/Table/Concerns/HasRecordActions.php
vendored
Normal file
249
vendor/filament/tables/src/Table/Concerns/HasRecordActions.php
vendored
Normal file
|
|
@ -0,0 +1,249 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Tables\Table\Concerns;
|
||||
|
||||
use Closure;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Actions\ActionGroup;
|
||||
use Filament\Support\Enums\Size;
|
||||
use Filament\Tables\Enums\RecordActionsPosition;
|
||||
use Illuminate\Contracts\Support\Htmlable;
|
||||
use Illuminate\Support\Arr;
|
||||
use PHPUnit\Event\InvalidArgumentException;
|
||||
|
||||
trait HasRecordActions
|
||||
{
|
||||
/**
|
||||
* @var array<Action | ActionGroup>
|
||||
*/
|
||||
protected array $recordActions = [];
|
||||
|
||||
protected string | Htmlable | Closure | null $recordActionsColumnLabel = null;
|
||||
|
||||
protected string | Closure | null $recordActionsAlignment = null;
|
||||
|
||||
protected RecordActionsPosition | Closure | null $recordActionsPosition = null;
|
||||
|
||||
protected ?Closure $modifyUngroupedRecordActionsUsing = null;
|
||||
|
||||
/**
|
||||
* @param array<Action | ActionGroup> | ActionGroup $actions
|
||||
*/
|
||||
public function recordActions(array | ActionGroup $actions, RecordActionsPosition | string | Closure | null $position = null): static
|
||||
{
|
||||
$this->recordActions = [];
|
||||
$this->pushRecordActions($actions);
|
||||
|
||||
if ($position) {
|
||||
$this->recordActionsPosition($position);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<Action | ActionGroup> | ActionGroup $actions
|
||||
*/
|
||||
public function pushRecordActions(array | ActionGroup $actions): static
|
||||
{
|
||||
foreach (Arr::wrap($actions) as $action) {
|
||||
$action->table($this);
|
||||
|
||||
if ($action instanceof ActionGroup) {
|
||||
/** @var array<string, Action> $flatActions */
|
||||
$flatActions = $action->getFlatActions();
|
||||
|
||||
$this->mergeCachedFlatActions($flatActions);
|
||||
} elseif ($action instanceof Action) {
|
||||
$action->defaultSize(Size::Small);
|
||||
$action->defaultView($action::LINK_VIEW);
|
||||
|
||||
if ($this->modifyUngroupedRecordActionsUsing) {
|
||||
$this->evaluate($this->modifyUngroupedRecordActionsUsing, ['action' => $action]);
|
||||
}
|
||||
|
||||
$this->cacheAction($action);
|
||||
} else {
|
||||
throw new InvalidArgumentException('Table actions must be an instance of [' . Action::class . '] or [' . ActionGroup::class . '].');
|
||||
}
|
||||
|
||||
$this->recordActions[] = $action;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function recordActionsColumnLabel(string | Htmlable | Closure | null $label): static
|
||||
{
|
||||
$this->recordActionsColumnLabel = $label;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function recordActionsAlignment(string | Closure | null $alignment = null): static
|
||||
{
|
||||
$this->recordActionsAlignment = $alignment;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function recordActionsPosition(RecordActionsPosition | Closure | null $position = null): static
|
||||
{
|
||||
$this->recordActionsPosition = $position;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<Action | ActionGroup>
|
||||
*/
|
||||
public function getRecordActions(): array
|
||||
{
|
||||
$defaultGroupDropdownPlacement = in_array($this->getRecordActionsPosition(), [RecordActionsPosition::BeforeCells, RecordActionsPosition::BeforeColumns])
|
||||
? 'bottom-start'
|
||||
: 'bottom-end';
|
||||
|
||||
return array_map(
|
||||
fn (Action | ActionGroup $action) => $action instanceof ActionGroup ? $action->defaultDropdownPlacement($defaultGroupDropdownPlacement)->defaultDropdownTeleport(true) : $action,
|
||||
$this->recordActions,
|
||||
);
|
||||
}
|
||||
|
||||
public function getRecordActionsPosition(): RecordActionsPosition
|
||||
{
|
||||
$position = $this->evaluate($this->recordActionsPosition);
|
||||
|
||||
if ($position) {
|
||||
return $position;
|
||||
}
|
||||
|
||||
if (! ($this->getContentGrid() || $this->hasColumnsLayout())) {
|
||||
return RecordActionsPosition::AfterColumns;
|
||||
}
|
||||
|
||||
return RecordActionsPosition::AfterContent;
|
||||
}
|
||||
|
||||
public function getRecordActionsAlignment(): ?string
|
||||
{
|
||||
return $this->evaluate($this->recordActionsAlignment);
|
||||
}
|
||||
|
||||
public function getRecordActionsColumnLabel(): string | Htmlable | null
|
||||
{
|
||||
return $this->evaluate($this->recordActionsColumnLabel);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use `recordActions()` instead.
|
||||
*
|
||||
* @param array<Action | ActionGroup> | ActionGroup $actions
|
||||
*/
|
||||
public function actions(array | ActionGroup $actions, RecordActionsPosition | string | Closure | null $position = null): static
|
||||
{
|
||||
$this->recordActions($actions, $position);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use `pushRecordActions()` instead.
|
||||
*
|
||||
* @param array<Action | ActionGroup> | ActionGroup $actions
|
||||
*/
|
||||
public function pushActions(array | ActionGroup $actions): static
|
||||
{
|
||||
$this->pushRecordActions($actions);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use `recordActionsColumnLabel()` instead.
|
||||
*/
|
||||
public function actionsColumnLabel(string | Htmlable | Closure | null $label): static
|
||||
{
|
||||
$this->recordActionsColumnLabel($label);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use `recordActionsAlignment()` instead.
|
||||
*/
|
||||
public function actionsAlignment(string | Closure | null $alignment = null): static
|
||||
{
|
||||
$this->recordActionsAlignment($alignment);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use `recordActionsPosition()` instead.
|
||||
*/
|
||||
public function actionsPosition(RecordActionsPosition | Closure | null $position = null): static
|
||||
{
|
||||
$this->recordActionsPosition($position);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use `getRecordActions()` instead.
|
||||
*
|
||||
* @return array<Action | ActionGroup>
|
||||
*/
|
||||
public function getActions(): array
|
||||
{
|
||||
return $this->getRecordActions();
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use `getRecordActionsPosition()` instead.
|
||||
*/
|
||||
public function getActionsPosition(): RecordActionsPosition
|
||||
{
|
||||
return $this->getRecordActionsPosition();
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use `getRecordActionsAlignment()` instead.
|
||||
*/
|
||||
public function getActionsAlignment(): ?string
|
||||
{
|
||||
return $this->getRecordActionsAlignment();
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use `getRecordActionsColumnLabel()` instead.
|
||||
*/
|
||||
public function getActionsColumnLabel(): string | Htmlable | null
|
||||
{
|
||||
return $this->getRecordActionsColumnLabel();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, Action>
|
||||
*/
|
||||
public function getFlatRecordActions(): array
|
||||
{
|
||||
$flatActions = [];
|
||||
|
||||
foreach ($this->getRecordActions() as $action) {
|
||||
if ($action instanceof ActionGroup) {
|
||||
$flatActions = array_merge($flatActions, $action->getFlatActions());
|
||||
} else {
|
||||
$flatActions[$action->getName()] = $action;
|
||||
}
|
||||
}
|
||||
|
||||
return $flatActions;
|
||||
}
|
||||
|
||||
public function modifyUngroupedRecordActionsUsing(?Closure $callback = null): static
|
||||
{
|
||||
$this->modifyUngroupedRecordActionsUsing = $callback;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
43
vendor/filament/tables/src/Table/Concerns/HasRecordClasses.php
vendored
Normal file
43
vendor/filament/tables/src/Table/Concerns/HasRecordClasses.php
vendored
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Tables\Table\Concerns;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Arr;
|
||||
|
||||
trait HasRecordClasses
|
||||
{
|
||||
/**
|
||||
* @var array<string | int, bool | string> | string | Closure | null
|
||||
*/
|
||||
protected array | string | Closure | null $recordClasses = null;
|
||||
|
||||
/**
|
||||
* @param array<string | int, bool | string> | string | Closure | null $classes
|
||||
*/
|
||||
public function recordClasses(array | string | Closure | null $classes): static
|
||||
{
|
||||
$this->recordClasses = $classes;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Model | array<string, mixed> $record
|
||||
* @return array<string | int, bool | string>
|
||||
*/
|
||||
public function getRecordClasses(Model | array $record): array
|
||||
{
|
||||
return Arr::wrap($this->evaluate(
|
||||
$this->recordClasses,
|
||||
namedInjections: [
|
||||
'record' => $record,
|
||||
],
|
||||
typedInjections: ($record instanceof Model) ? [
|
||||
Model::class => $record,
|
||||
$record::class => $record,
|
||||
] : [],
|
||||
) ?? []);
|
||||
}
|
||||
}
|
||||
140
vendor/filament/tables/src/Table/Concerns/HasRecordUrl.php
vendored
Normal file
140
vendor/filament/tables/src/Table/Concerns/HasRecordUrl.php
vendored
Normal file
|
|
@ -0,0 +1,140 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Tables\Table\Concerns;
|
||||
|
||||
use Closure;
|
||||
use Filament\Support\View\ComponentAttributeBag as FilamentComponentAttributeBag;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\View\ComponentAttributeBag;
|
||||
|
||||
trait HasRecordUrl
|
||||
{
|
||||
protected bool | Closure $shouldOpenRecordUrlInNewTab = false;
|
||||
|
||||
protected string | Closure | null $recordUrl = null;
|
||||
|
||||
protected bool $hasCustomRecordUrl = false;
|
||||
|
||||
/**
|
||||
* @var array<array<mixed> | Closure>
|
||||
*/
|
||||
protected array $extraRecordLinkAttributes = [];
|
||||
|
||||
public function openRecordUrlInNewTab(bool | Closure $condition = true): static
|
||||
{
|
||||
$this->shouldOpenRecordUrlInNewTab = $condition;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function recordUrl(string | Closure | null $url, bool | Closure | null $shouldOpenInNewTab = null): static
|
||||
{
|
||||
// Security: If this URL is derived from user input, validate it
|
||||
// to prevent XSS via `javascript:` protocol URLs rendered
|
||||
// in `href` attributes.
|
||||
|
||||
if ($shouldOpenInNewTab !== null) {
|
||||
$this->openRecordUrlInNewTab($shouldOpenInNewTab);
|
||||
}
|
||||
|
||||
$this->recordUrl = $url;
|
||||
$this->hasCustomRecordUrl = true;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function hasCustomRecordUrl(): bool
|
||||
{
|
||||
return $this->hasCustomRecordUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Model | array<string, mixed> $record
|
||||
*/
|
||||
public function getRecordUrl(Model | array $record): ?string
|
||||
{
|
||||
return $this->evaluate(
|
||||
$this->recordUrl,
|
||||
namedInjections: [
|
||||
'record' => $record,
|
||||
],
|
||||
typedInjections: ($record instanceof Model) ? [
|
||||
Model::class => $record,
|
||||
$record::class => $record,
|
||||
] : [],
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Model | array<string, mixed> $record
|
||||
*/
|
||||
public function shouldOpenRecordUrlInNewTab(Model | array $record): bool
|
||||
{
|
||||
return (bool) $this->evaluate(
|
||||
$this->shouldOpenRecordUrlInNewTab,
|
||||
namedInjections: [
|
||||
'record' => $record,
|
||||
],
|
||||
typedInjections: ($record instanceof Model) ? [
|
||||
Model::class => $record,
|
||||
$record::class => $record,
|
||||
] : [],
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<mixed> | Closure $attributes
|
||||
*/
|
||||
public function extraRecordLinkAttributes(array | Closure $attributes, bool $merge = false): static
|
||||
{
|
||||
// Security: Attribute values are not escaped when rendered. Never
|
||||
// pass unsanitized user input as attribute names or values.
|
||||
|
||||
if ($merge) {
|
||||
if (($attributes instanceof Closure) && in_array($attributes, $this->extraRecordLinkAttributes, strict: true)) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
$this->extraRecordLinkAttributes[] = $attributes;
|
||||
} else {
|
||||
$this->extraRecordLinkAttributes = [$attributes];
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Model | array<string, mixed> $record
|
||||
* @return array<mixed>
|
||||
*/
|
||||
public function getExtraRecordLinkAttributes(Model | array $record): array
|
||||
{
|
||||
$temporaryAttributeBag = new FilamentComponentAttributeBag;
|
||||
|
||||
foreach ($this->extraRecordLinkAttributes as $extraAttributes) {
|
||||
$temporaryAttributeBag = $temporaryAttributeBag->merge(
|
||||
$this->evaluate(
|
||||
$extraAttributes,
|
||||
namedInjections: [
|
||||
'record' => $record,
|
||||
],
|
||||
typedInjections: ($record instanceof Model) ? [
|
||||
Model::class => $record,
|
||||
$record::class => $record,
|
||||
] : [],
|
||||
),
|
||||
escape: false,
|
||||
);
|
||||
}
|
||||
|
||||
return $temporaryAttributeBag->getAttributes();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Model | array<string, mixed> $record
|
||||
*/
|
||||
public function getExtraRecordLinkAttributeBag(Model | array $record): ComponentAttributeBag
|
||||
{
|
||||
return new FilamentComponentAttributeBag($this->getExtraRecordLinkAttributes($record));
|
||||
}
|
||||
}
|
||||
225
vendor/filament/tables/src/Table/Concerns/HasRecords.php
vendored
Normal file
225
vendor/filament/tables/src/Table/Concerns/HasRecords.php
vendored
Normal file
|
|
@ -0,0 +1,225 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Tables\Table\Concerns;
|
||||
|
||||
use BackedEnum;
|
||||
use Closure;
|
||||
use Filament\Support\Contracts\HasLabel;
|
||||
use Illuminate\Contracts\Pagination\CursorPaginator;
|
||||
use Illuminate\Contracts\Pagination\Paginator;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
use function Filament\Support\get_model_label;
|
||||
use function Filament\Support\locale_has_pluralization;
|
||||
|
||||
trait HasRecords
|
||||
{
|
||||
protected bool | Closure $allowsDuplicates = false;
|
||||
|
||||
protected string | Closure | null $modelLabel = null;
|
||||
|
||||
protected string | Closure | null $pluralModelLabel = null;
|
||||
|
||||
protected string | Closure | null $recordTitle = null;
|
||||
|
||||
protected string | Closure | null $recordTitleAttribute = null;
|
||||
|
||||
protected ?Closure $dataSource = null;
|
||||
|
||||
protected ?string $cachedModel = null;
|
||||
|
||||
protected bool $hasCachedModel = false;
|
||||
|
||||
protected ?bool $cachedHasPivotRecordKeys = null;
|
||||
|
||||
protected ?Closure $resolveSelectedRecordsUsing = null;
|
||||
|
||||
public function records(?Closure $dataSource): static
|
||||
{
|
||||
$this->dataSource = $dataSource;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function resolveSelectedRecordsUsing(?Closure $callback): static
|
||||
{
|
||||
$this->resolveSelectedRecordsUsing = $callback;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function allowDuplicates(bool | Closure $condition = true): static
|
||||
{
|
||||
$this->allowsDuplicates = $condition;
|
||||
$this->cachedHasPivotRecordKeys = null;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function modelLabel(string | Closure | null $label): static
|
||||
{
|
||||
$this->modelLabel = $label;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function pluralModelLabel(string | Closure | null $label): static
|
||||
{
|
||||
$this->pluralModelLabel = $label;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function recordTitle(string | Closure | null $title): static
|
||||
{
|
||||
$this->recordTitle = $title;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function recordTitleAttribute(string | Closure | null $attribute): static
|
||||
{
|
||||
$this->recordTitleAttribute = $attribute;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getRecords(): Collection | Paginator | CursorPaginator
|
||||
{
|
||||
return $this->getLivewire()->getTableRecords();
|
||||
}
|
||||
|
||||
public function hasQuery(): bool
|
||||
{
|
||||
return ! $this->dataSource;
|
||||
}
|
||||
|
||||
public function getDataSource(): ?Closure
|
||||
{
|
||||
return $this->dataSource;
|
||||
}
|
||||
|
||||
public function getResolveSelectedRecordsCallback(): ?Closure
|
||||
{
|
||||
return $this->resolveSelectedRecordsUsing;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Model | array<string, mixed> $record
|
||||
*/
|
||||
public function getRecordKey(Model | array $record): string
|
||||
{
|
||||
return $this->getLivewire()->getTableRecordKey($record);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return class-string<Model>|null
|
||||
*/
|
||||
public function getModel(): ?string
|
||||
{
|
||||
if ($this->hasCachedModel) {
|
||||
return $this->cachedModel;
|
||||
}
|
||||
|
||||
$this->hasCachedModel = true;
|
||||
|
||||
if ($baseQuery = $this->evaluate($this->query)) {
|
||||
return $this->cachedModel = $baseQuery->getModel()::class;
|
||||
}
|
||||
|
||||
if ($relationshipQuery = $this->getRelationshipQuery()) {
|
||||
return $this->cachedModel = $relationshipQuery->getModel()::class;
|
||||
}
|
||||
|
||||
return $this->cachedModel = null;
|
||||
}
|
||||
|
||||
public function allowsDuplicates(): bool
|
||||
{
|
||||
return (bool) $this->evaluate($this->allowsDuplicates);
|
||||
}
|
||||
|
||||
/** Cached because both underlying calls evaluate Closures and this is hit per row. */
|
||||
public function hasPivotRecordKeys(): bool
|
||||
{
|
||||
return $this->cachedHasPivotRecordKeys ??= (
|
||||
($this->getRelationship() instanceof BelongsToMany)
|
||||
&& $this->allowsDuplicates()
|
||||
);
|
||||
}
|
||||
|
||||
public function getModelLabel(): string
|
||||
{
|
||||
$label = $this->evaluate($this->modelLabel);
|
||||
|
||||
if (filled($label)) {
|
||||
return $label;
|
||||
}
|
||||
|
||||
$model = $this->getModel();
|
||||
|
||||
if (filled($model)) {
|
||||
return get_model_label($model);
|
||||
}
|
||||
|
||||
return __('filament-tables::table.default_model_label');
|
||||
}
|
||||
|
||||
public function getPluralModelLabel(): string
|
||||
{
|
||||
$label = $this->evaluate($this->pluralModelLabel);
|
||||
|
||||
if (filled($label)) {
|
||||
return $label;
|
||||
}
|
||||
|
||||
if (locale_has_pluralization()) {
|
||||
return Str::plural($this->getModelLabel());
|
||||
}
|
||||
|
||||
return $this->getModelLabel();
|
||||
}
|
||||
|
||||
public function getRecordTitle(Model $record): string
|
||||
{
|
||||
$title = $this->evaluate(
|
||||
$this->recordTitle,
|
||||
namedInjections: [
|
||||
'record' => $record,
|
||||
],
|
||||
typedInjections: [
|
||||
Model::class => $record,
|
||||
$record::class => $record,
|
||||
],
|
||||
);
|
||||
|
||||
if (filled($titleAttribute = $this->getRecordTitleAttribute())) {
|
||||
$title ??= $record->getAttributeValue($titleAttribute);
|
||||
}
|
||||
|
||||
$title ??= $this->getModelLabel();
|
||||
|
||||
if ($title instanceof HasLabel) {
|
||||
return $title->getLabel();
|
||||
}
|
||||
|
||||
if ($title instanceof BackedEnum) {
|
||||
return $title->value;
|
||||
}
|
||||
|
||||
return $title;
|
||||
}
|
||||
|
||||
public function hasCustomRecordTitle(): bool
|
||||
{
|
||||
return $this->recordTitle !== null;
|
||||
}
|
||||
|
||||
public function getRecordTitleAttribute(): ?string
|
||||
{
|
||||
return $this->evaluate($this->recordTitleAttribute);
|
||||
}
|
||||
}
|
||||
78
vendor/filament/tables/src/Table/Concerns/HasToolbarActions.php
vendored
Normal file
78
vendor/filament/tables/src/Table/Concerns/HasToolbarActions.php
vendored
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
<?php
|
||||
|
||||
namespace Filament\Tables\Table\Concerns;
|
||||
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Actions\ActionGroup;
|
||||
use Illuminate\Support\Arr;
|
||||
use InvalidArgumentException;
|
||||
|
||||
trait HasToolbarActions
|
||||
{
|
||||
/**
|
||||
* @var array<Action | ActionGroup>
|
||||
*/
|
||||
protected array $toolbarActions = [];
|
||||
|
||||
/**
|
||||
* @param array<Action | ActionGroup> | ActionGroup $actions
|
||||
*/
|
||||
public function toolbarActions(array | ActionGroup $actions): static
|
||||
{
|
||||
// We must remove the existing cached toolbar actions before setting the new ones, as
|
||||
// the visibility of the checkboxes is determined by which bulk actions are visible.
|
||||
// The `$this->flatActions` array is used to determine if any bulk actions are
|
||||
// visible. We cannot simply clear it, as the bulk actions defined in the toolbar
|
||||
// of the table are also stored in this array, and we do not want to remove them,
|
||||
// only the bulk actions that are stored in the `$this->toolbarActions` array.
|
||||
foreach ($this->toolbarActions as $existingAction) {
|
||||
if ($existingAction instanceof ActionGroup) {
|
||||
/** @var array<Action> $flatExistingActions */
|
||||
$flatExistingActions = $existingAction->getFlatActions();
|
||||
|
||||
$this->removeCachedActions($flatExistingActions);
|
||||
} elseif ($existingAction instanceof Action) {
|
||||
$this->removeCachedActions([$existingAction]);
|
||||
}
|
||||
}
|
||||
|
||||
$this->toolbarActions = [];
|
||||
|
||||
$this->pushToolbarActions($actions);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<Action | ActionGroup> | ActionGroup $actions
|
||||
*/
|
||||
public function pushToolbarActions(array | ActionGroup $actions): static
|
||||
{
|
||||
foreach (Arr::wrap($actions) as $action) {
|
||||
$action->table($this);
|
||||
|
||||
if ($action instanceof ActionGroup) {
|
||||
/** @var array<string, Action> $flatActions */
|
||||
$flatActions = $action->getFlatActions();
|
||||
|
||||
$this->mergeCachedFlatActions($flatActions);
|
||||
} elseif ($action instanceof Action) {
|
||||
$this->cacheAction($action);
|
||||
} else {
|
||||
throw new InvalidArgumentException('Table actions must be an instance of [' . Action::class . '] or [' . ActionGroup::class . '].');
|
||||
}
|
||||
|
||||
$this->toolbarActions[] = $action;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<Action | ActionGroup>
|
||||
*/
|
||||
public function getToolbarActions(): array
|
||||
{
|
||||
return $this->toolbarActions;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue