Skip to content

Commit

Permalink
New from and attachments table filter. New resend e-mail bulk action.…
Browse files Browse the repository at this point in the history
… Enhanched attachments section into view. Updated translations.
  • Loading branch information
Marco Germani committed Nov 3, 2024
1 parent 55a1334 commit 3d183d4
Show file tree
Hide file tree
Showing 11 changed files with 99 additions and 35 deletions.
3 changes: 3 additions & 0 deletions resources/lang/de/filament-email.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
];
3 changes: 3 additions & 0 deletions resources/lang/en/filament-email.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,7 @@
'attachments_number' => ':count attachment|:count attachments',
'previous' => 'Previous',
'next' => 'Next',
'have_attachments' => 'Have attachments?',
'yes' => 'yes',
'no' => 'no',
];
3 changes: 3 additions & 0 deletions resources/lang/it/filament-email.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,7 @@
'attachments_number' => ':count allegato|:count allegati',
'previous' => 'Precedente',
'next' => 'Prossimo',
'have_attachments' => 'Contiene allegati?',
'yes' => 'si',
'no' => 'no',
];
3 changes: 3 additions & 0 deletions resources/lang/nl/filament-email.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,7 @@
'attachments_number' => ':count bijlage|:count bijlagen',
'previous' => 'Vorig',
'next' => 'Volgende',
'have_attachments' => 'Heb bijlagen?',
'yes' => 'ja',
'no' => 'nee',
];
3 changes: 3 additions & 0 deletions resources/lang/pt/filament-email.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,7 @@
'attachments_number' => ':count anexo|:count anexos',
'previous' => 'Próximo',
'next' => 'Anterior',
'have_attachments' => 'Tem anexos?',
'yes' => 'sim',
'no' => 'não',
];
3 changes: 3 additions & 0 deletions resources/lang/tr/filament-email.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,7 @@
'attachments_number' => ':count ek|:count ek',
'previous' => 'Öncesi',
'next' => 'Sonraki',
'have_attachments' => 'Ekleri var?',
'yes' => 'evet',
'no' => 'hayir',
];
18 changes: 6 additions & 12 deletions resources/views/attachments.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,12 @@
@if(!empty($attachments))
<div class="flex flex-wrap gap-8">
@foreach($attachments as $attachment)
<div class="basis-1/4 me-3">
<div class="flex items-center space-x-6 rtl:space-x-reverse">
<div class="flex-initial min-w-0 pe-4">
<p class="text-sm font-medium text-gray-900 truncate dark:text-white">
<strong>{{ $attachment['name'] }}</strong>
</p>
</div>
<div class="inline-flex items-center text-base font-semibold text-gray-900 dark:text-white">
{{ ($this->downloadAction)(['path' => $attachment['path'], 'name' => $attachment['name'] , 'type' => $attachment['contentType']]) }}
</div>
</div>
</div>
<x-filament::section class="text-center grow">
<x-slot name="heading">
<strong>{{ $attachment['name'] }}</strong>
</x-slot>
{{ ($this->downloadAction)(['path' => $attachment['path'], 'name' => $attachment['name'] , 'type' => $attachment['contentType']]) }}
</x-filament::section>
@endforeach
</div>
@endif
Expand Down
Binary file modified screenshots/filters.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified screenshots/view.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
91 changes: 75 additions & 16 deletions src/Filament/Resources/EmailResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -204,29 +208,29 @@ 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'))
->placeholder(__('filament-email::filament-email.insert_multiple_email_placelholder'))
->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) {
Expand All @@ -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'))
Expand All @@ -268,13 +272,49 @@ 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(),
])
->persistFiltersInSession()
->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(),
Expand All @@ -286,31 +326,50 @@ 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";
}
}
}

return $indicators;
})
->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'],
Expand All @@ -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();
});
}

Expand All @@ -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);
}

Expand Down
7 changes: 0 additions & 7 deletions src/Providers/EmailMessageServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -16,10 +15,4 @@ public function boot(): void
[FilamentEmailLogger::class, 'handle']
);
}
// protected $listen = [
// MessageSent::class => [
// FilamentEmailLogger::class,
// ],
// ];

}

0 comments on commit 3d183d4

Please sign in to comment.