Skip to content

Commit

Permalink
Merge pull request #13 from a21ns1g4ts/fix-filament-upgrade-v3-and-im…
Browse files Browse the repository at this point in the history
…provements

Fix filament upgrade v3 and improvements
  • Loading branch information
widiu7omo authored Sep 27, 2023
2 parents 263c835 + ae948b5 commit 59eef98
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 37 deletions.
4 changes: 4 additions & 0 deletions resources/lang/ar/translations.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
<?php

return [
'ban_model' => 'تم الحظر',
'unban_model' => 'تم الغاء الحظر',
'single-ban-success' => 'تم الحظر!',
'single-unban-success' => 'تم إلغاء الحظر!',
'bulk-ban' => 'تم الحظر',
'bulk-unban' => 'تم إلغاء الحظر',
'bulk-ban-success' => 'تم الحظر!',
'bulk-unban-success' => 'تم إلغاء الحظر!'
];
4 changes: 4 additions & 0 deletions resources/lang/en/translations.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
<?php

return [
'ban_model' => 'Ban Model',
'unban_model' => 'Unban Model',
'single-ban-success' => 'Model was banned!',
'single-unban-success' => 'Model was unbanned!',
'bulk-ban' => 'Ban Models',
'bulk-unban' => 'Unban Models',
'bulk-ban-success' => 'Models ware banned!',
'bulk-unban-success' => 'Models were unbanned!'
];
4 changes: 4 additions & 0 deletions resources/lang/id/translations.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
<?php

return [
'ban_model' => 'Blokir Model',
'unban_model' => 'Buka Model',
'single-ban-success' => 'Model berhasil diblokir aksesnya',
'single-unban-success' => 'Model berhasil dibuka aksesnya',
'bulk-ban' => 'Blokir Models',
'bulk-unban' => 'Buka Akses Models',
'bulk-ban-success' => 'Beberapa Model berhasil diblokir aksesnya',
'bulk-unban-success' => 'Beberapa Model berhasil dibuka aksesnya'
];
13 changes: 13 additions & 0 deletions resources/lang/pt_BR/translations.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

return [
'ban_model' => 'Banir Registros',
'unban_model' => 'Desbanir Registros',
'single-ban-success' => 'Registro banido com sucesso!',
'single-unban-success' => 'Registro desbanido com sucesso!',
'bulk-ban' => 'Banir Registros',
'bulk-unban' => 'Desbanir Registros',
'bulk-ban-success' => 'Registros banidos com sucesso!',
'bulk-unban-success' => 'Registros desbanidos com sucesso!'
];

2 changes: 1 addition & 1 deletion src/Actions/BanAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class BanAction extends Action

public static function getDefaultName(): ?string
{
return 'banned';
return 'ban';
}

protected function setUp(): void
Expand Down
58 changes: 35 additions & 23 deletions src/Actions/BanBulkAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,54 @@

namespace Widiu7omo\FilamentBandel\Actions;

use Closure;
use Filament\Forms\Components\Textarea;
use Filament\Notifications\Notification;
use Filament\Tables\Actions\BulkAction;
use Illuminate\Database\Eloquent\Collection;
use Filament\Forms\Components\DateTimePicker;
use Filament\Actions\Concerns\CanCustomizeProcess;

class BanBulkAction extends BulkAction
{
use CanCustomizeProcess;

protected bool|Closure $shouldDeselectRecordsAfterCompletion = true;

protected string|Closure|null $icon = 'heroicon-o-lock-closed';

protected function setUp(): void
public static function getDefaultName(): ?string
{
$this->modalWidth = 'sm';
$this->action($this->handle(...));
return 'ban_bulk';
}

protected function handle(Collection $records, array $data): void
protected function setUp(): void
{
$records->each->ban([
'comment' => $data['comment'],
'expired_at' => $data['expired_at'],
]);
Notification::make('unbanned_models')->success()->title(trans('filament-bandel::translations.bulk-ban-success'))->send();
}
parent::setUp();

public function getFormSchema(): array
{
return [
Textarea::make('comment')->rows(4),
DateTimePicker::make('expired_at')->label(__('Expires At')),
];
}
$this->label(__('filament-bandel::translations.bulk-ban'));

$this->successNotificationTitle(__('filament-bandel::translations.bulk-ban-success'));

$this->color('primary');

$this->icon('heroicon-o-lock-closed');

$this->form(fn () => $this->getFormSchema());

$this->action(function () {
$this->process(function (array $data, Collection $records) {
$records->filter(fn ($r) => !$r->banned_at)->each->ban([
'comment' => $data['comment'],
'expired_at' => $data['expired_at'],
]);
});

$this->success();
});

$this->deselectRecordsAfterCompletion();
}

public function getFormSchema(): array
{
return [
Textarea::make('comment')->rows(4),
DateTimePicker::make('expired_at')->label(__('Expires At')),
];
}
}
5 changes: 2 additions & 3 deletions src/Actions/UnbanAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@
use Filament\Tables\Actions\Action;
use Illuminate\Database\Eloquent\Model;
use Filament\Actions\Concerns\CanCustomizeProcess;
use Filament\Tables\Table;

class UnbanAction extends Action
{
use CanCustomizeProcess;

public static function getDefaultName(): ?string
{
return 'unbanned';
return 'unban';
}

protected function setUp(): void
Expand All @@ -27,7 +26,7 @@ protected function setUp(): void
$this->icon('heroicon-o-lock-open');

$this->action(function (): void {
$this->process(function (array $data, Model $record, Table $table) {
$this->process(function (Model $record) {
$record->unban();
});

Expand Down
34 changes: 24 additions & 10 deletions src/Actions/UnbanBulkAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,39 @@

namespace Widiu7omo\FilamentBandel\Actions;

use Filament\Notifications\Notification;
use Filament\Actions\Concerns\CanCustomizeProcess;
use Filament\Tables\Actions\BulkAction;
use Closure;
use Illuminate\Database\Eloquent\Collection;

class UnbanBulkAction extends BulkAction
{
protected bool|Closure $shouldDeselectRecordsAfterCompletion = true;
use CanCustomizeProcess;

protected string|Closure|null $icon = 'heroicon-o-lock-open';

protected function setUp(): void
public static function getDefaultName(): ?string
{
$this->action($this->handle(...));
return 'unban_bulk';
}

protected function handle(Collection $records, array $data): void
protected function setUp(): void
{
$records->each->unban();
Notification::make('unbanned_models')->success()->title(trans('filament-bandel::translations.bulk-unban-success'))->send();
parent::setUp();

$this->label(__('filament-bandel::translations.bulk-unban'));

$this->successNotificationTitle(__('filament-bandel::translations.bulk-unban-success'));

$this->color('primary');

$this->icon('heroicon-o-lock-closed');

$this->action(function () {
$this->process(function (Collection $records) {
$records->filter(fn ($r) => $r->banned_at)->each->unban();
});

$this->success();
});

$this->deselectRecordsAfterCompletion();
}
}

0 comments on commit 59eef98

Please sign in to comment.