diff --git a/resources/lang/de/filament-email.php b/resources/lang/de/filament-email.php index 03e064e..d7ed384 100644 --- a/resources/lang/de/filament-email.php +++ b/resources/lang/de/filament-email.php @@ -29,4 +29,6 @@ 'download_attachment_error' => 'Anhang konnte nicht heruntergeladen werden!', 'add_attachments' => 'Anhänge hinzufügen', 'attachments_number' => ':count Anhang|:count Anhänge', + 'previous' => 'Vorherige', + 'next' => 'Nächste', ]; diff --git a/resources/lang/en/filament-email.php b/resources/lang/en/filament-email.php index c2b4bc4..70cfacd 100644 --- a/resources/lang/en/filament-email.php +++ b/resources/lang/en/filament-email.php @@ -29,4 +29,6 @@ 'download_attachment_error' => 'Unable to download attachment!', 'add_attachments' => 'Add attachments', 'attachments_number' => ':count attachment|:count attachments', + 'previous' => 'Previous', + 'next' => 'Next', ]; diff --git a/resources/lang/it/filament-email.php b/resources/lang/it/filament-email.php index 870fd1d..01b7e9a 100644 --- a/resources/lang/it/filament-email.php +++ b/resources/lang/it/filament-email.php @@ -29,4 +29,6 @@ 'download_attachment_error' => "Impossibile scaricare l'allegato!", 'add_attachments' => 'Aggiungi allegati', 'attachments_number' => ':count allegato|:count allegati', + 'previous' => 'Precedente', + 'next' => 'Prossimo', ]; diff --git a/resources/lang/nl/filament-email.php b/resources/lang/nl/filament-email.php index 9665829..6a67363 100644 --- a/resources/lang/nl/filament-email.php +++ b/resources/lang/nl/filament-email.php @@ -29,4 +29,6 @@ 'download_attachment_error' => 'Kan bijlage niet downloaden!', 'add_attachments' => 'Bijlagen toevoegen', 'attachments_number' => ':count bijlage|:count bijlagen', + 'previous' => 'Vorig', + 'next' => 'Volgende', ]; diff --git a/resources/lang/pt/filament-email.php b/resources/lang/pt/filament-email.php index a190967..f1e1931 100644 --- a/resources/lang/pt/filament-email.php +++ b/resources/lang/pt/filament-email.php @@ -29,4 +29,6 @@ 'download_attachment_error' => 'Não foi possível baixar o anexo!', 'add_attachments' => 'Adicionar anexos', 'attachments_number' => ':count anexo|:count anexos', + 'previous' => 'Próximo', + 'next' => 'Anterior', ]; diff --git a/resources/lang/tr/filament-email.php b/resources/lang/tr/filament-email.php index a50c41e..f773268 100644 --- a/resources/lang/tr/filament-email.php +++ b/resources/lang/tr/filament-email.php @@ -29,4 +29,6 @@ 'download_attachment_error' => 'Eki indirme başarısız!', 'add_attachments' => 'Dosya ekle', 'attachments_number' => ':count ek|:count ek', + 'previous' => 'Öncesi', + 'next' => 'Sonraki', ]; diff --git a/screenshots/view.png b/screenshots/view.png index 6157589..b4567b8 100644 Binary files a/screenshots/view.png and b/screenshots/view.png differ diff --git a/src/Filament/Resources/Actions/NextAction.php b/src/Filament/Resources/Actions/NextAction.php new file mode 100644 index 0000000..509a7a7 --- /dev/null +++ b/src/Filament/Resources/Actions/NextAction.php @@ -0,0 +1,24 @@ +hiddenLabel() + ->icon('heroicon-o-arrow-right') + ->outlined() + ->size('sm') + ->tooltip(__('filament-email::filament-email.next')); + } +} diff --git a/src/Filament/Resources/Actions/PreviousAction.php b/src/Filament/Resources/Actions/PreviousAction.php new file mode 100644 index 0000000..75f9fa6 --- /dev/null +++ b/src/Filament/Resources/Actions/PreviousAction.php @@ -0,0 +1,24 @@ +hiddenLabel() + ->icon('heroicon-o-arrow-left') + ->outlined() + ->size('sm') + ->tooltip(__('filament-email::filament-email.previous')); + } +} diff --git a/src/Filament/Resources/Concernes/CanPaginateViewRecord.php b/src/Filament/Resources/Concernes/CanPaginateViewRecord.php new file mode 100644 index 0000000..47e4261 --- /dev/null +++ b/src/Filament/Resources/Concernes/CanPaginateViewRecord.php @@ -0,0 +1,64 @@ +configureActionRecord($action); + + match (true) { + $action instanceof PreviousAction => $this->configurePreviousAction($action), + $action instanceof NextAction => $this->configureNextAction($action), + default => parent::configureAction($action), + }; + } + + protected function configurePreviousAction(Action $action): void + { + if ($this->getPreviousRecord()) { + $action->url(fn(): string => static::getResource()::getUrl('view', ['record' => $this->getPreviousRecord()])); + } else { + $action + ->disabled() + ->color('gray'); + } + } + + protected function configureNextAction(Action $action): void + { + if ($this->getNextRecord()) { + $action->url(fn(): string => static::getResource()::getUrl('view', ['record' => $this->getNextRecord()])); + } else { + $action + ->disabled() + ->color('gray'); + } + } + + protected function getPreviousRecord(): ?Model + { + return $this + ->getRecord() + ->where('created_at', '<', $this->getRecord()->created_at) + ->where('id', '<>', $this->getRecord()->id) + ->orderBy('created_at', 'desc') + ->first(); + } + + protected function getNextRecord(): ?Model + { + return $this + ->getRecord() + ->where('created_at', '>', $this->getRecord()->created_at) + ->where('id', '<>', $this->getRecord()->id) + ->orderBy('created_at', 'asc') + ->first(); + } +} diff --git a/src/Filament/Resources/EmailResource/Pages/ViewEmail.php b/src/Filament/Resources/EmailResource/Pages/ViewEmail.php index 2073155..4aeb0c5 100644 --- a/src/Filament/Resources/EmailResource/Pages/ViewEmail.php +++ b/src/Filament/Resources/EmailResource/Pages/ViewEmail.php @@ -10,10 +10,13 @@ use Illuminate\Support\Facades\Storage; use RickDBCN\FilamentEmail\Filament\Resources\EmailResource; use RickDBCN\FilamentEmail\Models\Email; +use RickDBCN\FilamentEmail\Filament\Resources\Actions\NextAction; +use RickDBCN\FilamentEmail\Filament\Resources\Actions\PreviousAction; +use RickDBCN\FilamentEmail\Filament\Resources\Concernes\CanPaginateViewRecord; class ViewEmail extends ViewRecord { - use InteractsWithActions; + use CanPaginateViewRecord; public Email $email; @@ -42,4 +45,12 @@ public function downloadAction(): Action } }); } + + protected function getHeaderActions(): array + { + return [ + PreviousAction::make(), + NextAction::make(), + ]; + } }