generated from spatie/package-skeleton-laravel
-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from okeonline/dev-page-actions
Add Archive and UnArchive page actions
- Loading branch information
Showing
8 changed files
with
441 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
|
||
return [ | ||
|
||
'archive' => [ | ||
|
||
'single' => [ | ||
|
||
'label' => 'Archive', | ||
|
||
'modal' => [ | ||
|
||
'heading' => 'Archive :label', | ||
|
||
'actions' => [ | ||
|
||
'archive' => [ | ||
|
||
'label' => 'Archive', | ||
], | ||
|
||
], | ||
|
||
], | ||
|
||
'notifications' => [ | ||
|
||
'archived' => [ | ||
|
||
'title' => 'Record archived', | ||
], | ||
], | ||
], | ||
], | ||
|
||
'unarchive' => [ | ||
|
||
'single' => [ | ||
|
||
'label' => 'Unarchive', | ||
|
||
'modal' => [ | ||
|
||
'heading' => 'Unarchive :label', | ||
|
||
'actions' => [ | ||
|
||
'unarchive' => [ | ||
|
||
'label' => 'Unarchive', | ||
], | ||
|
||
], | ||
], | ||
|
||
'notifications' => [ | ||
|
||
'unarchived' => [ | ||
|
||
'title' => 'Record unarchived', | ||
], | ||
], | ||
], | ||
], | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
|
||
return [ | ||
|
||
'archive' => [ | ||
|
||
'single' => [ | ||
|
||
'label' => 'Archiveer', | ||
|
||
'modal' => [ | ||
|
||
'heading' => 'Archiveer :label', | ||
|
||
'actions' => [ | ||
|
||
'archive' => [ | ||
|
||
'label' => 'Archiveren', | ||
], | ||
|
||
], | ||
|
||
], | ||
|
||
'notifications' => [ | ||
|
||
'archived' => [ | ||
|
||
'title' => 'Record gearchiveerd', | ||
], | ||
], | ||
], | ||
], | ||
|
||
'unarchive' => [ | ||
|
||
'single' => [ | ||
|
||
'label' => 'Herstellen', | ||
|
||
'modal' => [ | ||
|
||
'heading' => 'Herstel :label', | ||
|
||
'actions' => [ | ||
|
||
'unarchive' => [ | ||
|
||
'label' => 'Herstellen', | ||
], | ||
|
||
], | ||
], | ||
|
||
'notifications' => [ | ||
|
||
'unarchived' => [ | ||
|
||
'title' => 'Record hersteld', | ||
], | ||
], | ||
], | ||
], | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
|
||
namespace Okeonline\FilamentArchivable\Actions; | ||
|
||
use Filament\Actions\Action; | ||
use Filament\Actions\Concerns\CanCustomizeProcess; | ||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class ArchiveAction extends Action | ||
{ | ||
use CanCustomizeProcess; | ||
|
||
public static function getDefaultName(): ?string | ||
{ | ||
return 'archive'; | ||
} | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->label(__('filament-archivable::actions.archive.single.label')); | ||
|
||
$this->modalHeading(fn (): string => __('filament-archivable::actions.archive.single.modal.heading', ['label' => $this->getRecordTitle()])); | ||
|
||
$this->modalSubmitActionLabel(__('filament-archivable::actions.archive.single.modal.actions.archived.label')); | ||
|
||
$this->successNotificationTitle(__('filament-archivable::actions.archive.single.notifications.archived.title')); | ||
|
||
$this->color('warning'); | ||
|
||
$this->icon('heroicon-m-archive-box-arrow-down'); | ||
|
||
$this->requiresConfirmation(); | ||
|
||
$this->modalIcon('heroicon-m-archive-box-arrow-down'); | ||
|
||
$this->hidden(static function (Model $record): bool { | ||
if (! method_exists($record, 'isArchived')) { | ||
// @codeCoverageIgnoreStart | ||
return false; | ||
// @codeCoverageIgnoreEnd | ||
} | ||
|
||
return $record->isArchived(); | ||
}); | ||
|
||
$this->action(function (): void { | ||
$result = $this->process(static fn (Model $record) => $record->archive()); | ||
|
||
if (! $result) { | ||
// @codeCoverageIgnoreStart | ||
$this->failure(); | ||
|
||
return; | ||
// @codeCoverageIgnoreEnd | ||
} | ||
|
||
$this->success(); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
|
||
namespace Okeonline\FilamentArchivable\Actions; | ||
|
||
use Filament\Actions\Action; | ||
use Filament\Actions\Concerns\CanCustomizeProcess; | ||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class UnArchiveAction extends Action | ||
{ | ||
use CanCustomizeProcess; | ||
|
||
public static function getDefaultName(): ?string | ||
{ | ||
return 'unarchive'; | ||
} | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->label(__('filament-archivable::actions.unarchive.single.label')); | ||
|
||
$this->modalHeading(fn (): string => __('filament-archivable::actions.unarchive.single.modal.heading', ['label' => $this->getRecordTitle()])); | ||
|
||
$this->modalSubmitActionLabel(__('filament-archivable::actions.unarchive.single.modal.actions.unarchive.label')); | ||
|
||
$this->successNotificationTitle(__('filament-archivable::actions.unarchive.single.notifications.unarchived.title')); | ||
|
||
$this->color('gray'); | ||
|
||
$this->icon('heroicon-m-arrow-uturn-left'); | ||
|
||
$this->requiresConfirmation(); | ||
|
||
$this->modalIcon('heroicon-o-arrow-uturn-left'); | ||
|
||
$this->action(function (Model $record): void { | ||
if (! method_exists($record, 'unArchive')) { | ||
// @codeCoverageIgnoreStart | ||
$this->failure(); | ||
|
||
return; | ||
// @codeCoverageIgnoreEnd | ||
} | ||
|
||
$result = $this->process(static fn () => $record->unArchive()); | ||
|
||
if (! $result) { | ||
// @codeCoverageIgnoreStart | ||
$this->failure(); | ||
|
||
return; | ||
// @codeCoverageIgnoreEnd | ||
} | ||
|
||
$this->success(); | ||
}); | ||
|
||
$this->visible(static function (Model $record): bool { | ||
if (! method_exists($record, 'isArchived')) { | ||
// @codeCoverageIgnoreStart | ||
return false; | ||
// @codeCoverageIgnoreEnd | ||
} | ||
|
||
return $record->isArchived(); | ||
}); | ||
} | ||
} |
Oops, something went wrong.