generated from spatie/package-skeleton-laravel
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added previous/next buttons for view page
- Loading branch information
1 parent
c00498a
commit 9fbb7a7
Showing
11 changed files
with
136 additions
and
1 deletion.
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
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
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,24 @@ | ||
<?php | ||
|
||
namespace RickDBCN\FilamentEmail\Filament\Resources\Actions; | ||
|
||
use Filament\Actions\Action; | ||
|
||
class NextAction extends Action | ||
{ | ||
public static function getDefaultName(): ?string | ||
{ | ||
return 'next'; | ||
} | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->hiddenLabel() | ||
->icon('heroicon-o-arrow-right') | ||
->outlined() | ||
->size('sm') | ||
->tooltip(__('filament-email::filament-email.next')); | ||
} | ||
} |
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,24 @@ | ||
<?php | ||
|
||
namespace RickDBCN\FilamentEmail\Filament\Resources\Actions; | ||
|
||
use Filament\Actions\Action; | ||
|
||
class PreviousAction extends Action | ||
{ | ||
public static function getDefaultName(): ?string | ||
{ | ||
return 'previous'; | ||
} | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->hiddenLabel() | ||
->icon('heroicon-o-arrow-left') | ||
->outlined() | ||
->size('sm') | ||
->tooltip(__('filament-email::filament-email.previous')); | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
src/Filament/Resources/Concernes/CanPaginateViewRecord.php
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,64 @@ | ||
<?php | ||
|
||
namespace RickDBCN\FilamentEmail\Filament\Resources\Concernes; | ||
|
||
use Filament\Actions\Action; | ||
use Illuminate\Database\Eloquent\Model; | ||
use RickDBCN\FilamentEmail\Filament\Resources\Actions\NextAction; | ||
use RickDBCN\FilamentEmail\Filament\Resources\Actions\PreviousAction; | ||
|
||
trait CanPaginateViewRecord | ||
{ | ||
protected function configureAction(Action $action): void | ||
{ | ||
$this->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(); | ||
} | ||
} |
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