Skip to content

Commit

Permalink
column grid customization
Browse files Browse the repository at this point in the history
  • Loading branch information
bezhanSalleh committed Sep 24, 2023
1 parent 13c8b45 commit 007d15f
Show file tree
Hide file tree
Showing 3 changed files with 159 additions and 38 deletions.
116 changes: 116 additions & 0 deletions src/Concerns/CanCustomizeColumns.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
<?php

declare(strict_types=1);

namespace BezhanSalleh\FilamentShield\Concerns;


trait CanCustomizeColumns
{
protected int | string | array $checkboxListColumnSpan = 'full';

protected int | string | array $checkboxListColumns = [
'sm' => 2,
'lg' => 4,
];

protected int | string | array $gridColumns = 1;

protected int | string | array $resourceCheckboxListColumnSpan = 'full';

protected int | string | array $resourceCheckboxListColumns = [
'sm' => 2,
'lg' => 4,
];

protected int | string | array $sectionColumnSpan = 'full';

protected int | string | array $sectionColumns = [
'sm' => 2,
'lg' => 4,
];

public function checkboxListColumns(int | string | array $columns): static
{
$this->checkboxListColumns = $columns;

return $this;
}

public function checkboxListColumnSpan(int | string | array $columnSpan): static
{
$this->checkboxListColumnSpan = $columnSpan;

return $this;
}

public function gridColumns(int | string | array $columns): static
{
$this->gridColumns = $columns;

return $this;
}

public function resourceCheckboxListColumns(int | string | array $columns): static
{
$this->resourceCheckboxListColumns = $columns;

return $this;
}

public function resourceCheckboxListColumnSpan(int | string | array $columnSpan): static
{
$this->resourceCheckboxListColumnSpan = $columnSpan;

return $this;
}

public function sectionColumns(int | string | array $columns): static
{
$this->sectionColumns = $columns;

return $this;
}

public function sectionColumnSpan(int | string | array $columnSpan): static
{
$this->sectionColumnSpan = $columnSpan;

return $this;
}

public function getCheckboxListColumns(): int | string | array
{
return $this->checkboxListColumns;
}

public function getCheckboxListColumnSpan(): int | string | array
{
return $this->checkboxListColumnSpan;
}

public function getGridColumns(): int | string | array
{
return $this->gridColumns;
}

public function getResourceCheckboxListColumns(): int | string | array
{
return $this->resourceCheckboxListColumns;
}

public function getResourceCheckboxListColumnSpan(): int | string | array
{
return $this->resourceCheckboxListColumnSpan;
}

public function getSectionColumns(): int | string | array
{
return $this->sectionColumns;
}

public function getSectionColumnSpan(): int | string | array
{
return $this->sectionColumnSpan;
}
}
9 changes: 6 additions & 3 deletions src/FilamentShieldPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@

namespace BezhanSalleh\FilamentShield;

use BezhanSalleh\FilamentShield\Support\Utils;
use Filament\Contracts\Plugin;
use Filament\FilamentManager;
use Filament\Panel;
use Filament\FilamentManager;
use Filament\Contracts\Plugin;
use BezhanSalleh\FilamentShield\Support\Utils;
use BezhanSalleh\FilamentShield\Concerns;

class FilamentShieldPlugin implements Plugin
{
use Concerns\CanCustomizeColumns;

public static function make(): static
{
return app(static::class);
Expand Down
72 changes: 37 additions & 35 deletions src/Resources/RoleResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,22 @@

namespace BezhanSalleh\FilamentShield\Resources;

use BezhanSalleh\FilamentShield\Contracts\HasShieldPermissions;
use BezhanSalleh\FilamentShield\Facades\FilamentShield;
use BezhanSalleh\FilamentShield\Resources\RoleResource\Pages;
use BezhanSalleh\FilamentShield\Support\Utils;
use Filament\Forms;
use Filament\Forms\Components\Actions\Action as FormAction;
use Filament\Forms\Components\Component;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Forms\Form;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Str;
use Filament\Resources\Resource;
use Illuminate\Support\Collection;
use Illuminate\Support\HtmlString;
use Illuminate\Support\Str;
use Illuminate\Database\Eloquent\Model;
use Filament\Forms\Components\Component;
use BezhanSalleh\FilamentShield\Support\Utils;
use BezhanSalleh\FilamentShield\FilamentShieldPlugin;
use BezhanSalleh\FilamentShield\Facades\FilamentShield;
use Filament\Forms\Components\Actions\Action as FormAction;
use BezhanSalleh\FilamentShield\Resources\RoleResource\Pages;
use BezhanSalleh\FilamentShield\Contracts\HasShieldPermissions;

class RoleResource extends Resource implements HasShieldPermissions
{
Expand Down Expand Up @@ -78,10 +79,7 @@ public static function form(Form $form): Form
->schema([
Forms\Components\Grid::make()
->schema(static::getResourceEntitiesSchema())
->columns([
'sm' => 1,
'lg' => 1,
]),
->columns(FilamentShieldPlugin::get()->getGridColumns()),

Check failure on line 82 in src/Resources/RoleResource.php

View workflow job for this annotation

GitHub Actions / phpstan

Call to an undefined method Filament\Contracts\Plugin|Filament\FilamentManager::getGridColumns().
]),
Forms\Components\Tabs\Tab::make(__('filament-shield::filament-shield.pages'))
->visible(fn (): bool => (bool) Utils::isPageEntityEnabled() && (count(FilamentShield::getPages()) > 0 ? true : false))
Expand Down Expand Up @@ -118,11 +116,8 @@ public static function form(Form $form): Form
->dehydrated(fn ($state) => blank($state) ? false : true)
->bulkToggleable()
->gridDirection('row')
->columns([
'sm' => 2,
'lg' => 4,
])
->columnSpanFull(),
->columns(FilamentShieldPlugin::get()->getCheckboxListColumns())

Check failure on line 119 in src/Resources/RoleResource.php

View workflow job for this annotation

GitHub Actions / phpstan

Call to an undefined method Filament\Contracts\Plugin|Filament\FilamentManager::getCheckboxListColumns().
->columnSpan(FilamentShieldPlugin::get()->getCheckboxListColumnSpan()),

Check failure on line 120 in src/Resources/RoleResource.php

View workflow job for this annotation

GitHub Actions / phpstan

Call to an undefined method Filament\Contracts\Plugin|Filament\FilamentManager::getCheckboxListColumnSpan().
]),
Forms\Components\Tabs\Tab::make(__('filament-shield::filament-shield.widgets'))
->visible(fn (): bool => (bool) Utils::isWidgetEntityEnabled() && (count(FilamentShield::getWidgets()) > 0 ? true : false))
Expand Down Expand Up @@ -160,11 +155,8 @@ public static function form(Form $form): Form
->dehydrated(fn ($state) => blank($state) ? false : true)
->bulkToggleable()
->gridDirection('row')
->columns([
'sm' => 2,
'lg' => 4,
])
->columnSpanFull(),
->columns(FilamentShieldPlugin::get()->getCheckboxListColumns())

Check failure on line 158 in src/Resources/RoleResource.php

View workflow job for this annotation

GitHub Actions / phpstan

Call to an undefined method Filament\Contracts\Plugin|Filament\FilamentManager::getCheckboxListColumns().
->columnSpan(FilamentShieldPlugin::get()->getCheckboxListColumnSpan()),

Check failure on line 159 in src/Resources/RoleResource.php

View workflow job for this annotation

GitHub Actions / phpstan

Call to an undefined method Filament\Contracts\Plugin|Filament\FilamentManager::getCheckboxListColumnSpan().
]),
Forms\Components\Tabs\Tab::make(__('filament-shield::filament-shield.custom'))
->visible(fn (): bool => (bool) Utils::isCustomPermissionEntityEnabled() && (count(static::getCustomEntities()) > 0 ? true : false))
Expand Down Expand Up @@ -201,11 +193,8 @@ public static function form(Form $form): Form
->dehydrated(fn ($state) => blank($state) ? false : true)
->bulkToggleable()
->gridDirection('row')
->columns([
'sm' => 2,
'lg' => 4,
])
->columnSpanFull(),
->columns(FilamentShieldPlugin::get()->getCheckboxListColumns())

Check failure on line 196 in src/Resources/RoleResource.php

View workflow job for this annotation

GitHub Actions / phpstan

Call to an undefined method Filament\Contracts\Plugin|Filament\FilamentManager::getCheckboxListColumns().
->columnSpan(FilamentShieldPlugin::get()->getCheckboxListColumnSpan()),

Check failure on line 197 in src/Resources/RoleResource.php

View workflow job for this annotation

GitHub Actions / phpstan

Call to an undefined method Filament\Contracts\Plugin|Filament\FilamentManager::getCheckboxListColumnSpan().
]),
])
->columnSpan('full'),
Expand Down Expand Up @@ -237,6 +226,23 @@ public static function table(Table $table): Table
->filters([
//
])
->headerActions([
Tables\Actions\Action::make('new_permission')
->label('New Permission')
->form([
Forms\Components\TextInput::make('name')
->required()
->unique('permissions', 'name'),
Forms\Components\TextInput::make('guard_name')
->default(Utils::getFilamentAuthGuard()),
])
->modalHeading('Delete post')
->action(function (array $data): void {
Utils::getPermissionModel()::create($data);
})
->modalWidth('2xl')
->slideOver(),
])
->actions([
Tables\Actions\EditAction::make(),
Tables\Actions\DeleteAction::make(),
Expand Down Expand Up @@ -365,13 +371,9 @@ public static function getResourceEntitiesSchema(): ?array
->dehydrated(fn ($state) => blank($state) ? false : true)
->bulkToggleable()
->gridDirection('row')
->columns([
'default' => 2,
'sm' => 3,
'lg' => 4,
]),
->columns(FilamentShieldPlugin::get()->getResourceCheckboxListColumns()),

Check failure on line 374 in src/Resources/RoleResource.php

View workflow job for this annotation

GitHub Actions / phpstan

Call to an undefined method Filament\Contracts\Plugin|Filament\FilamentManager::getResourceCheckboxListColumns().
])
->columnSpanFull()
->columnSpan(FilamentShieldPlugin::get()->getSectionColumnSpan())

Check failure on line 376 in src/Resources/RoleResource.php

View workflow job for this annotation

GitHub Actions / phpstan

Call to an undefined method Filament\Contracts\Plugin|Filament\FilamentManager::getSectionColumnSpan().
->collapsible();

return $entities;
Expand Down

0 comments on commit 007d15f

Please sign in to comment.