Skip to content

Commit

Permalink
Fix styling
Browse files Browse the repository at this point in the history
  • Loading branch information
marcogermani87 authored and github-actions[bot] committed Apr 25, 2024
1 parent f433571 commit 47e3ba0
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 42 deletions.
4 changes: 2 additions & 2 deletions resources/lang/en/filament-email.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
'update_and_resend_email_heading' => 'Update and resend e-mail',
'attachments' => 'Attachments',
'download' => 'Download',
'download_attachment_error' => "Unable to download attachment!" ,
'add_attachments' => "Add attachments",
'download_attachment_error' => 'Unable to download attachment!',
'add_attachments' => 'Add attachments',
'attachments_number' => ':count attachment|:count attachments',
];
4 changes: 2 additions & 2 deletions resources/lang/it/filament-email.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
'update_and_resend_email_heading' => 'Modifica and re-invia e-mail',
'attachments' => 'Allegati',
'download' => 'Scarica',
'download_attachment_error' => "Impossibile scaricare l'allegato!" ,
'add_attachments' => "Aggiungi allegati",
'download_attachment_error' => "Impossibile scaricare l'allegato!",
'add_attachments' => 'Aggiungi allegati',
'attachments_number' => ':count allegato|:count allegati',
];
4 changes: 2 additions & 2 deletions resources/lang/nl/filament-email.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
'update_and_resend_email_heading' => 'Bijwerken en e-mail opnieuw versturen',
'attachments' => 'Bijlagen',
'download' => 'Downloaden',
'download_attachment_error' => "Kan bijlage niet downloaden!",
'add_attachments' => "Bijlagen toevoegen",
'download_attachment_error' => 'Kan bijlage niet downloaden!',
'add_attachments' => 'Bijlagen toevoegen',
'attachments_number' => ':count bijlage|:count bijlagen',
];
42 changes: 20 additions & 22 deletions src/Filament/Resources/EmailResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

use Filament\Forms\Components\DateTimePicker;
use Filament\Forms\Components\Fieldset;
use Filament\Forms\Components\Repeater;
use Filament\Forms\Components\Section;
use Filament\Forms\Components\Tabs;
use Filament\Forms\Components\TagsInput;
use Filament\Forms\Components\Textarea;
Expand Down Expand Up @@ -94,7 +92,7 @@ public static function form(Form $form): Form
->label(__('filament-email::filament-email.attachments'))
->schema([
View::make('filament-email::attachments')
->columnSpanFull()
->columnSpanFull(),
]),
Tabs::make('Content')->tabs([
Tabs\Tab::make(__('filament-email::filament-email.html'))
Expand Down Expand Up @@ -135,7 +133,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 @@ -192,28 +190,28 @@ 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)
->default(fn($record): bool => !empty($record->attachments))
->default(fn ($record): bool => ! empty($record->attachments))
->required(),
])
->action(function (Email $record, array $data) {
Expand All @@ -240,10 +238,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 Down Expand Up @@ -290,16 +288,16 @@ public static function table(Table $table): Table
$indicators = [];
$format = config('filament-email.resource.filter_date_format');

if (!empty($data['created_from'])) {
if (! empty($data['created_from'])) {
$from = Carbon::parse($data['created_from'])->format($format);
$indicators['created'] = __('filament-email::filament-email.from_filter') . " $from";
$indicators['created'] = __('filament-email::filament-email.from_filter')." $from";
}

if (!empty($data['created_until'])) {
if (! empty($data['created_until'])) {
$to = Carbon::parse($data['created_until'])->format($format);
$toText = __('filament-email::filament-email.to_filter');
if (!empty($indicators['created'])) {
$indicators['created'] .= ' ' . strtolower($toText) . " $to";
if (! empty($indicators['created'])) {
$indicators['created'] .= ' '.strtolower($toText)." $to";
} else {
$indicators['created'] = "$toText $to";
}
Expand All @@ -321,23 +319,23 @@ public static function table(Table $table): Table
return $query
->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['created_from'],
fn(Builder $query, $value): Builder => $query->where('created_at', '>=', $value),
fn (Builder $query, $value): Builder => $query->where('created_at', '>=', $value),
)
->when(
$data['created_until'],
fn(Builder $query, $value): Builder => $query->where('created_at', '<=', $value),
fn (Builder $query, $value): Builder => $query->where('created_at', '<=', $value),
);
}),
]);
Expand All @@ -355,7 +353,7 @@ public static function canAccess(): bool
{
$roles = config('filament-email.can_access.role') ?? [];

if (method_exists(auth()->user(), 'hasRole') && !empty($roles)) {
if (method_exists(auth()->user(), 'hasRole') && ! empty($roles)) {
return auth()->user()->hasRole($roles);
}

Expand Down
11 changes: 5 additions & 6 deletions src/Listeners/FilamentEmailLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace RickDBCN\FilamentEmail\Listeners;

use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;
use RickDBCN\FilamentEmail\Models\Email;
Expand Down Expand Up @@ -31,10 +30,10 @@ public function handle(object $event): void
$model = Config::get('filament-email.resource.model') ?? Email::class;

$attachments = [];
$savePath = 'filament-email-log' . DIRECTORY_SEPARATOR . date('YmdHis') . '_' . Str::random(5) . DIRECTORY_SEPARATOR;
$savePath = 'filament-email-log'.DIRECTORY_SEPARATOR.date('YmdHis').'_'.Str::random(5).DIRECTORY_SEPARATOR;

foreach ($event->message->getAttachments() as $attachment) {
$filePath = $savePath . Str::random(5) . '_' . $attachment->getFilename();
$filePath = $savePath.Str::random(5).'_'.$attachment->getFilename();
Storage::disk('local')
->put($filePath, $attachment->getBody());
$attachments[] = [
Expand All @@ -44,7 +43,7 @@ public function handle(object $event): void
];
}

$savePathRaw = $savePath . $rawMessage->getMessageId() . '.eml';
$savePathRaw = $savePath.$rawMessage->getMessageId().'.eml';

Storage::disk('local')
->put($savePathRaw, $rawMessage->getMessage()->toString());
Expand All @@ -59,7 +58,7 @@ public function handle(object $event): void
'text_body' => $email->getTextBody(),
'raw_body' => $savePathRaw,
'sent_debug_info' => $rawMessage->getDebug(),
'attachments' => !empty($attachments) ? $attachments : null,
'attachments' => ! empty($attachments) ? $attachments : null,
]);

}
Expand All @@ -69,7 +68,7 @@ private function recipientsToString(array $recipients): string
return implode(
',',
array_map(function ($email) {
return "{$email->getAddress()}" . ($email->getName() ? " <{$email->getName()}>" : '');
return "{$email->getAddress()}".($email->getName() ? " <{$email->getName()}>" : '');
}, $recipients)
);
}
Expand Down
6 changes: 3 additions & 3 deletions src/Mail/ResendMail.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Attachment;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;
use Illuminate\Mail\Mailables\Attachment;
use Illuminate\Queue\SerializesModels;

class ResendMail extends Mailable
Expand Down Expand Up @@ -43,9 +43,9 @@ public function attachments(): array

if ($this->addAttachments) {
$modelAttachments = $this->email->attachments;
if (!empty($modelAttachments)) {
if (! empty($modelAttachments)) {
foreach ($modelAttachments as $attachment) {
$attachments[] = Attachment::fromPath(storage_path('app' . DIRECTORY_SEPARATOR . $attachment['path']))
$attachments[] = Attachment::fromPath(storage_path('app'.DIRECTORY_SEPARATOR.$attachment['path']))
->as($attachment['name']);
}
}
Expand Down
8 changes: 3 additions & 5 deletions src/Models/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
use Illuminate\Support\Arr;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Storage;

/**
* Email
Expand Down Expand Up @@ -50,9 +48,9 @@ public static function boot()

self::deleting(function ($record) {
$folderPath = null;
if (!empty($record->attachments)) {
if (! empty($record->attachments)) {
foreach ($record->attachments as $attachment) {
$filePath = storage_path('app' . DIRECTORY_SEPARATOR . $attachment['path']);
$filePath = storage_path('app'.DIRECTORY_SEPARATOR.$attachment['path']);
if (empty($folderPath)) {
$parts = explode(DIRECTORY_SEPARATOR, $filePath);
array_pop($parts);
Expand All @@ -63,7 +61,7 @@ public static function boot()
}
}
}
$savePathRaw = storage_path('app' . DIRECTORY_SEPARATOR . $record->raw_body);
$savePathRaw = storage_path('app'.DIRECTORY_SEPARATOR.$record->raw_body);
if (file_exists($savePathRaw)) {
if (empty($folderPath)) {
$parts = explode(DIRECTORY_SEPARATOR, $savePathRaw);
Expand Down

0 comments on commit 47e3ba0

Please sign in to comment.