Skip to content

Commit

Permalink
Merge branch 'main' of github.com:vormkracht10/filament-mails into fi…
Browse files Browse the repository at this point in the history
…x-phpstan-issues
  • Loading branch information
Baspa committed Dec 27, 2024
2 parents e02b1f9 + d78ad3d commit 92920e4
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 51 deletions.
7 changes: 5 additions & 2 deletions src/Resources/MailResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@

class MailResource extends Resource
{
protected static ?string $model = Mail::class;

protected static ?string $slug = 'mails';

protected static ?string $recordTitleAttribute = 'subject';
Expand All @@ -40,6 +38,11 @@ class MailResource extends Resource

protected static bool $shouldRegisterNavigation = true;

public static function getModel(): string
{
return config('mails.models.mail');
}

public static function getNavigationGroup(): ?string
{
return __('Mails');
Expand Down
70 changes: 27 additions & 43 deletions src/Resources/MailResource/Pages/ListMails.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

namespace Vormkracht10\FilamentMails\Resources\MailResource\Pages;

use Vormkracht10\Mails\Models\Mail;
use Filament\Resources\Components\Tab;
use Filament\Resources\Pages\ListRecords;
use Illuminate\Database\Eloquent\Builder;
use Vormkracht10\FilamentMails\Resources\MailResource;
use Vormkracht10\FilamentMails\Resources\MailResource\Widgets\MailStatsWidget;
use Vormkracht10\Mails\Models\Mail;

class ListMails extends ListRecords
{
Expand All @@ -25,87 +25,71 @@ protected function getActions(): array

public function getTabs(): array
{
/** @var Mail $class */
$class = config('mails.models.mail');

return [
'all' => Tab::make()
->label(__('All'))
->badgeColor('primary')
->icon('heroicon-o-inbox')
->badge(Mail::count()),
->badge($class::count()),

'sent' => Tab::make()
->label(__('Sent'))
->badgeColor('info')
->icon('heroicon-o-paper-airplane')
->badge(Mail::sent()->count())
->modifyQueryUsing(function (Builder $query): Builder {
/** @var Mail $model */
$model = $query->getModel();

return $model->sent();
->badge($class::sent()->count())
->modifyQueryUsing(function (Builder $query) use ($class): Builder {
return $class->sent();
}),

'delivered' => Tab::make()
->label(__('Delivered'))
->badgeColor('success')
->icon('heroicon-o-check-circle')
->badge(Mail::delivered()->count())
->modifyQueryUsing(function (Builder $query): Builder {
/** @var Mail $model */
$model = $query->getModel();

return $model->delivered();
->badge($class::delivered()->count())
->modifyQueryUsing(function (Builder $query) use ($class): Builder {
return $class->delivered();
}),

'opened' => Tab::make()
->label(__('Opened'))
->badgeColor('info')
->icon('heroicon-o-eye')
->badge(Mail::opened()->count())
->modifyQueryUsing(function (Builder $query): Builder {
/** @var Mail $model */
$model = $query->getModel();

return $model->opened();
->badge($class::opened()->count())
->modifyQueryUsing(function (Builder $query) use ($class): Builder {
return $class->opened();
}),

'clicked' => Tab::make()
->label(__('Clicked'))
->badgeColor('clicked')
->icon('heroicon-o-cursor-arrow-rays')
->badge(Mail::clicked()->count())
->modifyQueryUsing(function (Builder $query): Builder {
/** @var Mail $model */
$model = $query->getModel();

return $model->clicked();
->badge($class::clicked()->count())
->modifyQueryUsing(function (Builder $query) use ($class): Builder {
return $class->clicked();
}),

'bounced' => Tab::make()
->label(__('Bounced'))
->badgeColor('danger')
->icon('heroicon-o-x-circle')
->badge(fn () => Mail::softBounced()->count() + Mail::hardBounced()->count())
->modifyQueryUsing(fn (Builder $query) => $query->where(function ($query) {
/** @var Mail $model */
$model = $query->getModel();

return $model->where(function (Builder $query): void {
$query->softBounced()->orWhere(function (Builder $query): void {
$query->hardBounced();
});
->badge(fn() => $class::softBounced()->count() + $class::hardBounced()->count())
->modifyQueryUsing(function (Builder $query) use ($class): Builder {
return $query->where(function (Builder $subQuery) use ($class) {
return $subQuery->whereIn('id', $class::softBounced()->select('id'))
->orWhereIn('id', $class::hardBounced()->select('id'));
});
})),
}),

'unsent' => Tab::make()
->label(__('Unsent'))
->badgeColor('gray')
->icon('heroicon-o-x-circle')
->badge(Mail::unsent()->count())
->modifyQueryUsing(function (Builder $query): Builder {
/** @var Mail $model */
$model = $query->getModel();

return $model->unsent();
->badge($class::unsent()->count())
->modifyQueryUsing(function (Builder $query) use ($class): Builder {
return $class->unsent();
}),
];
}
Expand All @@ -116,4 +100,4 @@ protected function getHeaderWidgets(): array
MailStatsWidget::class,
];
}
}
}
13 changes: 7 additions & 6 deletions src/Resources/MailResource/Widgets/MailStatsWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Filament\Facades\Filament;
use Filament\Widgets\StatsOverviewWidget as BaseWidget;
use Filament\Widgets\StatsOverviewWidget\Stat;
use Vormkracht10\Mails\Models\Mail;

class MailStatsWidget extends BaseWidget
{
Expand All @@ -15,12 +14,14 @@ class MailStatsWidget extends BaseWidget

protected function getStats(): array
{
$bouncedMails = Mail::where(fn ($query) => $query->softBounced()->orWhere(fn ($query) => $query->hardBounced()))->count();
$openedMails = Mail::opened()->count();
$deliveredMails = Mail::delivered()->count();
$clickedMails = Mail::clicked()->count();
$class = config('mails.models.mail');

$mailCount = Mail::count();
$bouncedMails = $class::where(fn ($query) => $query->softBounced()->orWhere(fn ($query) => $query->hardBounced()))->count();
$openedMails = $class::opened()->count();
$deliveredMails = $class::delivered()->count();
$clickedMails = $class::clicked()->count();

$mailCount = $class::count();

if ($mailCount === 0) {
return [];
Expand Down

0 comments on commit 92920e4

Please sign in to comment.