diff --git a/resources/lang/de/filament-email.php b/resources/lang/de/filament-email.php index d7ed384..a48b97f 100644 --- a/resources/lang/de/filament-email.php +++ b/resources/lang/de/filament-email.php @@ -31,4 +31,7 @@ 'attachments_number' => ':count Anhang|:count Anhänge', 'previous' => 'Vorherige', 'next' => 'Nächste', + 'have_attachments' => 'Anhänge haben?', + 'yes' => 'ja', + 'no' => 'nein', ]; diff --git a/resources/lang/en/filament-email.php b/resources/lang/en/filament-email.php index 70cfacd..d1016c6 100644 --- a/resources/lang/en/filament-email.php +++ b/resources/lang/en/filament-email.php @@ -31,4 +31,7 @@ 'attachments_number' => ':count attachment|:count attachments', 'previous' => 'Previous', 'next' => 'Next', + 'have_attachments' => 'Have attachments?', + 'yes' => 'yes', + 'no' => 'no', ]; diff --git a/resources/lang/it/filament-email.php b/resources/lang/it/filament-email.php index 01b7e9a..39d2481 100644 --- a/resources/lang/it/filament-email.php +++ b/resources/lang/it/filament-email.php @@ -31,4 +31,7 @@ 'attachments_number' => ':count allegato|:count allegati', 'previous' => 'Precedente', 'next' => 'Prossimo', + 'have_attachments' => 'Contiene allegati?', + 'yes' => 'si', + 'no' => 'no', ]; diff --git a/resources/lang/nl/filament-email.php b/resources/lang/nl/filament-email.php index 6a67363..e130953 100644 --- a/resources/lang/nl/filament-email.php +++ b/resources/lang/nl/filament-email.php @@ -31,4 +31,7 @@ 'attachments_number' => ':count bijlage|:count bijlagen', 'previous' => 'Vorig', 'next' => 'Volgende', + 'have_attachments' => 'Heb bijlagen?', + 'yes' => 'ja', + 'no' => 'nee', ]; diff --git a/resources/lang/pt/filament-email.php b/resources/lang/pt/filament-email.php index f1e1931..382d370 100644 --- a/resources/lang/pt/filament-email.php +++ b/resources/lang/pt/filament-email.php @@ -31,4 +31,7 @@ 'attachments_number' => ':count anexo|:count anexos', 'previous' => 'Próximo', 'next' => 'Anterior', + 'have_attachments' => 'Tem anexos?', + 'yes' => 'sim', + 'no' => 'não', ]; diff --git a/resources/lang/tr/filament-email.php b/resources/lang/tr/filament-email.php index f773268..7873efc 100644 --- a/resources/lang/tr/filament-email.php +++ b/resources/lang/tr/filament-email.php @@ -31,4 +31,7 @@ 'attachments_number' => ':count ek|:count ek', 'previous' => 'Öncesi', 'next' => 'Sonraki', + 'have_attachments' => 'Ekleri var?', + 'yes' => 'evet', + 'no' => 'hayir', ]; diff --git a/resources/views/attachments.blade.php b/resources/views/attachments.blade.php index 329f26c..d420661 100644 --- a/resources/views/attachments.blade.php +++ b/resources/views/attachments.blade.php @@ -3,18 +3,12 @@ @if(!empty($attachments))
@foreach($attachments as $attachment) -
-
-
-

- {{ $attachment['name'] }} -

-
-
- {{ ($this->downloadAction)(['path' => $attachment['path'], 'name' => $attachment['name'] , 'type' => $attachment['contentType']]) }} -
-
-
+ + + {{ $attachment['name'] }} + + {{ ($this->downloadAction)(['path' => $attachment['path'], 'name' => $attachment['name'] , 'type' => $attachment['contentType']]) }} + @endforeach
@endif diff --git a/screenshots/filters.png b/screenshots/filters.png index 6dd7431..b245606 100644 Binary files a/screenshots/filters.png and b/screenshots/filters.png differ diff --git a/screenshots/view.png b/screenshots/view.png index 6a9c6cb..8196d21 100644 Binary files a/screenshots/view.png and b/screenshots/view.png differ diff --git a/src/Filament/Resources/EmailResource.php b/src/Filament/Resources/EmailResource.php index fcc8e7c..8872781 100644 --- a/src/Filament/Resources/EmailResource.php +++ b/src/Filament/Resources/EmailResource.php @@ -4,6 +4,7 @@ use Filament\Forms\Components\DateTimePicker; use Filament\Forms\Components\Fieldset; +use Filament\Forms\Components\Select; use Filament\Forms\Components\Tabs; use Filament\Forms\Components\TagsInput; use Filament\Forms\Components\Textarea; @@ -17,13 +18,16 @@ use Filament\Support\Enums\IconSize; use Filament\Support\Enums\MaxWidth; use Filament\Tables\Actions\Action; +use Filament\Tables\Actions\BulkAction; use Filament\Tables\Actions\DeleteBulkAction; use Filament\Tables\Columns\TextColumn; use Filament\Tables\Filters\Filter; use Filament\Tables\Table; use Illuminate\Contracts\Support\Htmlable; use Illuminate\Database\Eloquent\Builder; +use Illuminate\Database\Eloquent\Collection; use Illuminate\Support\Carbon; +use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Mail; use Illuminate\Support\Str; @@ -102,7 +106,7 @@ public static function form(Form $form): Form ->label(__('filament-email::filament-email.created_at')), ])->columns(4), Fieldset::make('attachments') - ->hidden(fn (): bool => ! config('filament-email.store_attachments')) + ->hidden(fn(): bool => !config('filament-email.store_attachments')) ->label(__('filament-email::filament-email.attachments')) ->schema([ View::make('filament-email::attachments') @@ -147,7 +151,7 @@ public static function table(Table $table): Table ->icon('heroicon-o-eye') ->iconSize(IconSize::Medium) ->modalFooterActions( - fn ($action): array => [ + fn($action): array => [ $action->getModalCancelAction(), ]) ->fillForm(function ($record) { @@ -204,7 +208,7 @@ public static function table(Table $table): Table ->nestedRecursiveRules([ 'email', ]) - ->default(fn ($record): array => ! empty($record->to) ? explode(',', $record->to) : []) + ->default(fn($record): array => !empty($record->to) ? explode(',', $record->to) : []) ->required(), TagsInput::make('cc') ->label(__('filament-email::filament-email.cc')) @@ -212,21 +216,21 @@ public static function table(Table $table): Table ->nestedRecursiveRules([ 'email', ]) - ->default(fn ($record): array => ! empty($record->cc) ? explode(',', $record->cc) : []), + ->default(fn($record): array => !empty($record->cc) ? explode(',', $record->cc) : []), TagsInput::make('bcc') ->label(__('filament-email::filament-email.bcc')) ->placeholder(__('filament-email::filament-email.insert_multiple_email_placelholder')) ->nestedRecursiveRules([ 'email', ]) - ->default(fn ($record): array => ! empty($record->bcc) ? explode(',', $record->bcc) : []), + ->default(fn($record): array => !empty($record->bcc) ? explode(',', $record->bcc) : []), Toggle::make('attachments') ->label(__('filament-email::filament-email.add_attachments')) ->onColor('success') ->offColor('danger') ->inline(false) - ->disabled(fn ($record): bool => empty($record->attachments)) - ->default(fn ($record): bool => ! empty($record->attachments)) + ->disabled(fn($record): bool => empty($record->attachments)) + ->default(fn($record): bool => !empty($record->attachments)) ->required(), ]) ->action(function (Email $record, array $data) { @@ -253,10 +257,10 @@ public static function table(Table $table): Table ]) ->columns([ TextColumn::make('from') - ->prefix(__('filament-email::filament-email.from').': ') - ->suffix(fn (Email $record): string => ! empty($record->attachments) ? ' ('.trans_choice('filament-email::filament-email.attachments_number', count($record->attachments)).')' : '') + ->prefix(__('filament-email::filament-email.from') . ': ') + ->suffix(fn(Email $record): string => !empty($record->attachments) ? ' (' . trans_choice('filament-email::filament-email.attachments_number', count($record->attachments)) . ')' : '') ->label(__('filament-email::filament-email.header')) - ->description(fn (Email $record): string => Str::limit(__('filament-email::filament-email.to').': '.$record->to, 40)) + ->description(fn(Email $record): string => Str::limit(__('filament-email::filament-email.to') . ': ' . $record->to, 40)) ->searchable(), TextColumn::make('subject') ->label(__('filament-email::filament-email.subject')) @@ -268,6 +272,39 @@ public static function table(Table $table): Table ]) ->groupedBulkActions([ + BulkAction::make('bulk-resend') + ->label(__('filament-email::filament-email.resend_email_heading')) + ->icon('heroicon-o-arrow-path') + ->color('primary') + ->iconSize(IconSize::Medium) + ->tooltip(__('filament-email::filament-email.resend_email_heading')) + ->requiresConfirmation() + ->modalHeading(__('filament-email::filament-email.resend_email_heading')) + ->modalDescription(__('filament-email::filament-email.resend_email_description')) + ->modalIconColor('warning') + ->deselectRecordsAfterCompletion() + ->action(function (Collection $records) { + try { + foreach ($records as $record) { + Mail::to($record->to) + ->cc($record->cc) + ->bcc($record->bcc) + ->send(new ResendMail($record)); + } + Notification::make() + ->title(__('filament-email::filament-email.resend_email_success')) + ->success() + ->duration(5000) + ->send(); + } catch (\Exception $e) { + Log::error($e->getMessage()); + Notification::make() + ->title(__('filament-email::filament-email.resend_email_error')) + ->danger() + ->duration(5000) + ->send(); + } + }), DeleteBulkAction::make() ->requiresConfirmation(), ]) @@ -275,6 +312,9 @@ public static function table(Table $table): Table ->filters([ Filter::make('headers-filter') ->form([ + TextInput::make('from') + ->label(__('filament-email::filament-email.from')) + ->email(), TextInput::make('to') ->label(__('filament-email::filament-email.to')) ->email(), @@ -286,13 +326,23 @@ public static function table(Table $table): Table ->email(), DateRangePicker::make('created_at') ->label(__('filament-email::filament-email.sent_at')), + Select::make('attachments') + ->label(__('filament-email::filament-email.have_attachments')) + ->options([ + 'no' => ucfirst(__('filament-email::filament-email.no')), + 'yes' => ucfirst(__('filament-email::filament-email.yes')), + ]), ]) ->columns(2) ->indicateUsing(function (array $data): array { $indicators = []; foreach ($data as $field => $value) { if ($data[$field] ?? null) { - $indicators[$field] = __('filament-email::filament-email.'.$field).": $value"; + if ($field === 'attachments') { + $indicators[$field] = __('filament-email::filament-email.' . $field) . ": " . ($value === 'yes' ? __('filament-email::filament-email.yes') : __('filament-email::filament-email.no')); + } else { + $indicators[$field] = __('filament-email::filament-email.' . $field) . ": $value"; + } } } @@ -300,17 +350,26 @@ public static function table(Table $table): Table }) ->query(function (Builder $query, array $data): Builder { return $query + ->when( + $data['from'], + fn(Builder $query, $value): Builder => $query->where('from', 'like', "%$value%"), + ) ->when( $data['to'], - fn (Builder $query, $value): Builder => $query->where('to', 'like', "%$value%"), + fn(Builder $query, $value): Builder => $query->where('to', 'like', "%$value%"), ) ->when( $data['cc'], - fn (Builder $query, $value): Builder => $query->where('cc', 'like', "%$value%"), + fn(Builder $query, $value): Builder => $query->where('cc', 'like', "%$value%"), ) ->when( $data['bcc'], - fn (Builder $query, $value): Builder => $query->where('bcc', 'like', "%$value%"), + fn(Builder $query, $value): Builder => $query->where('bcc', 'like', "%$value%"), + ) + ->when( + $data['attachments'], + //JSON_LENGTH + fn(Builder $query, $value): Builder => $query->where(DB::raw('JSON_LENGTH(attachments)'), $value === 'yes' ? '>' : '=', 0), ) ->when( $data['created_at'], @@ -333,7 +392,7 @@ function (Builder $query, $value): Builder { ->paginationPageOptions(function (Table $table) { $options = config('filament-email.pagination_page_options'); - return ! empty($options) && is_array($options) ? $options : $table->getPaginationPageOptions(); + return !empty($options) && is_array($options) ? $options : $table->getPaginationPageOptions(); }); } @@ -349,7 +408,7 @@ public static function canAccess(): bool { $roles = config('filament-email.can_access.role', []); - if (method_exists(filament()->auth()->user(), 'hasRole') && ! empty($roles)) { + if (method_exists(filament()->auth()->user(), 'hasRole') && !empty($roles)) { return filament()->auth()->user()->hasRole($roles); } diff --git a/src/Providers/EmailMessageServiceProvider.php b/src/Providers/EmailMessageServiceProvider.php index 9875fa7..a12bd7a 100644 --- a/src/Providers/EmailMessageServiceProvider.php +++ b/src/Providers/EmailMessageServiceProvider.php @@ -6,7 +6,6 @@ use Illuminate\Support\Facades\Event; use Illuminate\Support\ServiceProvider; use RickDBCN\FilamentEmail\Listeners\FilamentEmailLogger; - class EmailMessageServiceProvider extends ServiceProvider { public function boot(): void @@ -16,10 +15,4 @@ public function boot(): void [FilamentEmailLogger::class, 'handle'] ); } - // protected $listen = [ - // MessageSent::class => [ - // FilamentEmailLogger::class, - // ], - // ]; - }