Skip to content

Instantly share code, notes, and snippets.

@lam0819
Last active October 17, 2024 17:40
Show Gist options
  • Select an option

  • Save lam0819/2605aa6a17792fae2eb79cf0a6de985d to your computer and use it in GitHub Desktop.

Select an option

Save lam0819/2605aa6a17792fae2eb79cf0a6de985d to your computer and use it in GitHub Desktop.
A simple filamentphp Widget for pan package https://github.com/panphp/pan
<?php
namespace App\Livewire;
use Filament\Forms\Get;
use Filament\Tables\Table;
use Filament\Tables\Columns\TextColumn;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\TagsInput;
use Filament\Forms\Components\Checkbox;
use Filament\Widgets\TableWidget as BaseWidget;
use Illuminate\Database\Eloquent\Model;
use Filament\Tables\Actions\Action;
use Pan\PanConfiguration;
class PanOverview extends BaseWidget
{
public function table(Table $table): Table
{
$PanAnalytics = new class extends Model {
protected $table = 'pan_analytics';
};
$currentPanConfiguration = PanConfiguration::instance()->toArray();
return $table->query(fn() => $PanAnalytics::query())
->columns([
TextColumn::make('name')->searchable(),
TextColumn::make('impressions')->sortable(),
TextColumn::make('hovers')->sortable(),
TextColumn::make('clicks')->sortable()
])
->headerActions([
Action::make('Config')
->form([
Checkbox::make('unlimitedAnalytics')
->inline()
->live()
->default($currentPanConfiguration['max_analytics'] >= PHP_INT_MAX)
->hidden(fn (Get $get): bool => $currentPanConfiguration['max_analytics'] < PHP_INT_MAX),
TextInput::make('maxAnalytics')
->numeric()
->label('Max Analytics')
->default($currentPanConfiguration['max_analytics'])
->visible(fn (Get $get): bool => ! $get('unlimitedAnalytics')),
TagsInput::make('allowedAnalytics')
->label('Allowed Analytics')
->separator(',')
->default($currentPanConfiguration['allowed_analytics'])
])
->modalCancelAction(false)
->modalSubmitAction(false)
// Prepare for the future now.
// ->action(function (array $data): void {
// $unlimitedAnalytics = $data['unlimitedAnalytics'] ?? false;
// $maxAnalytics = $data['maxAnalytics'] ?? 50;
// $allowedAnalytics = $data['allowedAnalytics'] ?? [];
// if($unlimitedAnalytics){
// PanConfiguration::unlimitedAnalytics();
// }else{
// PanConfiguration::maxAnalytics($maxAnalytics);
// }
// PanConfiguration::allowedAnalytics(explode(",", $allowedAnalytics ));
// })
]);
}
}
@lam0819
Copy link
Author

lam0819 commented Oct 17, 2024

New update , showing your config in FilamentWidget
image
image

@lam0819
Copy link
Author

lam0819 commented Oct 17, 2024

Ok , we move this into a new package now.

Check it out.
https://github.com/solutionforest/filament-panphp

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment