From 9cc8ce646a2e2a6a3a4f2adad7350d4223b39e82 Mon Sep 17 00:00:00 2001 From: marcogermani87 Date: Thu, 29 Aug 2024 22:57:16 +0000 Subject: [PATCH] Fix styling --- config/filament-email.php | 106 ++-- src/Filament/Resources/EmailResource.php | 697 +++++++++++------------ 2 files changed, 401 insertions(+), 402 deletions(-) diff --git a/config/filament-email.php b/config/filament-email.php index ed8cdcc..7081375 100644 --- a/config/filament-email.php +++ b/config/filament-email.php @@ -1,53 +1,53 @@ - [ - 'class' => EmailResource::class, - 'model' => Email::class, - 'group' => null, - 'sort' => null, - 'icon' => null, - 'default_sort_column' => 'created_at', - 'default_sort_direction' => 'desc', - 'datetime_format' => 'Y-m-d H:i:s', - 'filters' => [ - 'created_at' => [ - 'date_format' => 'Y-m-d', - ], - ], - 'table_search_fields' => [ - 'subject', - 'from', - 'to', - 'cc', - 'bcc', - ], - ], - - 'keep_email_for_days' => 60, - - 'label' => null, - - 'prune_enabled' => true, - - 'prune_crontab' => '0 0 * * *', - - 'can_access' => [ - 'role' => [], - ], - - 'pagination_page_options' => [ - 10, 25, 50, 'all', - ], - - 'attachments_disk' => 'local', - 'store_attachments' => true, - - //Use this option for customize tenant model class - //'tenant_model' => \App\Models\Team::class, - -]; + [ + 'class' => EmailResource::class, + 'model' => Email::class, + 'group' => null, + 'sort' => null, + 'icon' => null, + 'default_sort_column' => 'created_at', + 'default_sort_direction' => 'desc', + 'datetime_format' => 'Y-m-d H:i:s', + 'filters' => [ + 'created_at' => [ + 'date_format' => 'Y-m-d', + ], + ], + 'table_search_fields' => [ + 'subject', + 'from', + 'to', + 'cc', + 'bcc', + ], + ], + + 'keep_email_for_days' => 60, + + 'label' => null, + + 'prune_enabled' => true, + + 'prune_crontab' => '0 0 * * *', + + 'can_access' => [ + 'role' => [], + ], + + 'pagination_page_options' => [ + 10, 25, 50, 'all', + ], + + 'attachments_disk' => 'local', + 'store_attachments' => true, + + //Use this option for customize tenant model class + //'tenant_model' => \App\Models\Team::class, + +]; diff --git a/src/Filament/Resources/EmailResource.php b/src/Filament/Resources/EmailResource.php index 114910e..e9779fa 100644 --- a/src/Filament/Resources/EmailResource.php +++ b/src/Filament/Resources/EmailResource.php @@ -1,349 +1,348 @@ -schema([ - Fieldset::make('Envelope') - ->label('') - ->schema([ - TextInput::make('from') - ->label(__('filament-email::filament-email.from')) - ->columnSpan(2), - Textinput::make('to') - ->label(__('filament-email::filament-email.to')) - ->columnSpan(2), - TextInput::make('cc') - ->label(__('filament-email::filament-email.cc')) - ->columnSpan(2), - TextInput::make('bcc') - ->label(__('filament-email::filament-email.bcc')) - ->columnSpan(2), - TextInput::make('subject') - ->label(__('filament-email::filament-email.subject')) - ->columnSpan(3), - DateTimePicker::make('created_at') - ->format(config('filament-email.resource.datetime_format')) - ->label(__('filament-email::filament-email.created_at')), - ])->columns(4), - Fieldset::make('attachments') - ->hidden(fn(): bool => !config('filament-email.store_attachments')) - ->label(__('filament-email::filament-email.attachments')) - ->schema([ - View::make('filament-email::attachments') - ->columnSpanFull(), - ]), - Tabs::make('Content')->tabs([ - Tabs\Tab::make(__('filament-email::filament-email.html')) - ->schema([ - ViewField::make('html_body') - ->label('') - ->view('filament-email::html_view'), - ]), - Tabs\Tab::make(__('filament-email::filament-email.text')) - ->schema([ - Textarea::make('text_body') - ->label('') - ->rows(20), - ]), - Tabs\Tab::make(__('filament-email::filament-email.raw')) - ->schema([ - ViewField::make('raw_body') - ->label('') - ->view('filament-email::raw_body'), - ]), - Tabs\Tab::make(__('filament-email::filament-email.debug_info')) - ->schema([ - Textarea::make('sent_debug_info') - ->label('') - ->rows(20), - ]), - ])->columnSpan(2), - ]); - } - - public static function table(Table $table): Table - { - return $table - ->defaultSort(config('filament-email.resource.default_sort_column'), config('filament-email.resource.default_sort_direction')) - ->actions([ - Action::make('preview') - ->label(false) - ->icon('heroicon-o-eye') - ->iconSize(IconSize::Medium) - ->modalFooterActions( - fn($action): array => [ - $action->getModalCancelAction(), - ]) - ->fillForm(function ($record) { - $body = $record->html_body; - - return [ - 'html_body' => $body, - ]; - }) - ->form([ - ViewField::make('html_body') - ->hiddenLabel() - ->view('filament-email::html_view'), - ]), - Action::make('resend') - ->label(false) - ->icon('heroicon-o-arrow-path') - ->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') - ->action(function ($record) { - try { - 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(); - } - }), - Action::make('resend-mod') - ->label(false) - ->icon('heroicon-o-envelope-open') - ->iconSize(IconSize::Medium) - ->tooltip(__('filament-email::filament-email.update_and_resend_email_heading')) - ->modalHeading(__('filament-email::filament-email.update_and_resend_email_heading')) - ->form([ - TagsInput::make('to') - ->label(__('filament-email::filament-email.to')) - ->placeholder(__('filament-email::filament-email.insert_multiple_email_placelholder')) - ->nestedRecursiveRules([ - 'email', - ]) - ->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) : []), - 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) : []), - 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)) - ->required(), - ]) - ->action(function (Email $record, array $data) { - try { - Mail::to($data['to']) - ->cc($data['cc']) - ->bcc($data['bcc']) - ->send(new ResendMail($record, $data['attachments'] ?? false)); - 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(); - } - }) - ->modalWidth('2xl'), - ]) - ->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)) . ')' : '') - ->label(__('filament-email::filament-email.header')) - ->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')) - ->limit(50), - TextColumn::make('created_at') - ->label(__('filament-email::filament-email.sent_at')) - ->dateTime(config('filament-email.resource.datetime_format')) - ->sortable(), - - ]) - ->groupedBulkActions([ - DeleteBulkAction::make() - ->requiresConfirmation(), - ]) - ->persistFiltersInSession() - ->filters([ - Filter::make('headers-filter') - ->form([ - TextInput::make('to') - ->label(__('filament-email::filament-email.to')) - ->email(), - TextInput::make('cc') - ->label(__('filament-email::filament-email.cc')) - ->email(), - TextInput::make('bcc') - ->label(__('filament-email::filament-email.bcc')) - ->email(), - DateRangePicker::make('created_at') - ->label(__('filament-email::filament-email.sent_at')), - ]) - ->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"; - } - } - return $indicators; - }) - ->query(function (Builder $query, array $data): Builder { - return $query - ->when( - $data['to'], - fn(Builder $query, $value): Builder => $query->where('to', 'like', "%$value%"), - ) - ->when( - $data['cc'], - fn(Builder $query, $value): Builder => $query->where('cc', 'like', "%$value%"), - ) - ->when( - $data['bcc'], - fn(Builder $query, $value): Builder => $query->where('bcc', 'like', "%$value%"), - )->when( - $data['created_at'], - function (Builder $query, $value): Builder { - $format = config('filament-email.resource.filters.created_at.date_format'); - list($start, $end) = explode(' - ', $value); - return $query->whereBetween('created_at', [ - Carbon::createFromFormat($format, $start) - ->format('Y-m-d'), - Carbon::createFromFormat($format, $end) - ->format('Y-m-d') - ]); - } - ); - }), - ]) - ->filtersFormWidth(MaxWidth::ExtraLarge) - ->paginationPageOptions(function (Table $table) { - $options = config('filament-email.pagination_page_options'); - - return !empty($options) && is_array($options) ? $options : $table->getPaginationPageOptions(); - }); - } - - public static function getPages(): array - { - return [ - 'index' => ListEmails::route('/'), - 'view' => ViewEmail::route('/{record}'), - ]; - } - - public static function canAccess(): bool - { - $roles = config('filament-email.can_access.role', []); - - if (method_exists(auth()->user(), 'hasRole') && !empty($roles)) { - return auth()->user()->hasRole($roles); - } - - return true; - } -} +schema([ + Fieldset::make('Envelope') + ->label('') + ->schema([ + TextInput::make('from') + ->label(__('filament-email::filament-email.from')) + ->columnSpan(2), + Textinput::make('to') + ->label(__('filament-email::filament-email.to')) + ->columnSpan(2), + TextInput::make('cc') + ->label(__('filament-email::filament-email.cc')) + ->columnSpan(2), + TextInput::make('bcc') + ->label(__('filament-email::filament-email.bcc')) + ->columnSpan(2), + TextInput::make('subject') + ->label(__('filament-email::filament-email.subject')) + ->columnSpan(3), + DateTimePicker::make('created_at') + ->format(config('filament-email.resource.datetime_format')) + ->label(__('filament-email::filament-email.created_at')), + ])->columns(4), + Fieldset::make('attachments') + ->hidden(fn (): bool => ! config('filament-email.store_attachments')) + ->label(__('filament-email::filament-email.attachments')) + ->schema([ + View::make('filament-email::attachments') + ->columnSpanFull(), + ]), + Tabs::make('Content')->tabs([ + Tabs\Tab::make(__('filament-email::filament-email.html')) + ->schema([ + ViewField::make('html_body') + ->label('') + ->view('filament-email::html_view'), + ]), + Tabs\Tab::make(__('filament-email::filament-email.text')) + ->schema([ + Textarea::make('text_body') + ->label('') + ->rows(20), + ]), + Tabs\Tab::make(__('filament-email::filament-email.raw')) + ->schema([ + ViewField::make('raw_body') + ->label('') + ->view('filament-email::raw_body'), + ]), + Tabs\Tab::make(__('filament-email::filament-email.debug_info')) + ->schema([ + Textarea::make('sent_debug_info') + ->label('') + ->rows(20), + ]), + ])->columnSpan(2), + ]); + } + + public static function table(Table $table): Table + { + return $table + ->defaultSort(config('filament-email.resource.default_sort_column'), config('filament-email.resource.default_sort_direction')) + ->actions([ + Action::make('preview') + ->label(false) + ->icon('heroicon-o-eye') + ->iconSize(IconSize::Medium) + ->modalFooterActions( + fn ($action): array => [ + $action->getModalCancelAction(), + ]) + ->fillForm(function ($record) { + $body = $record->html_body; + + return [ + 'html_body' => $body, + ]; + }) + ->form([ + ViewField::make('html_body') + ->hiddenLabel() + ->view('filament-email::html_view'), + ]), + Action::make('resend') + ->label(false) + ->icon('heroicon-o-arrow-path') + ->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') + ->action(function ($record) { + try { + 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(); + } + }), + Action::make('resend-mod') + ->label(false) + ->icon('heroicon-o-envelope-open') + ->iconSize(IconSize::Medium) + ->tooltip(__('filament-email::filament-email.update_and_resend_email_heading')) + ->modalHeading(__('filament-email::filament-email.update_and_resend_email_heading')) + ->form([ + TagsInput::make('to') + ->label(__('filament-email::filament-email.to')) + ->placeholder(__('filament-email::filament-email.insert_multiple_email_placelholder')) + ->nestedRecursiveRules([ + 'email', + ]) + ->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) : []), + 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) : []), + 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)) + ->required(), + ]) + ->action(function (Email $record, array $data) { + try { + Mail::to($data['to']) + ->cc($data['cc']) + ->bcc($data['bcc']) + ->send(new ResendMail($record, $data['attachments'] ?? false)); + 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(); + } + }) + ->modalWidth('2xl'), + ]) + ->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)).')' : '') + ->label(__('filament-email::filament-email.header')) + ->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')) + ->limit(50), + TextColumn::make('created_at') + ->label(__('filament-email::filament-email.sent_at')) + ->dateTime(config('filament-email.resource.datetime_format')) + ->sortable(), + + ]) + ->groupedBulkActions([ + DeleteBulkAction::make() + ->requiresConfirmation(), + ]) + ->persistFiltersInSession() + ->filters([ + Filter::make('headers-filter') + ->form([ + TextInput::make('to') + ->label(__('filament-email::filament-email.to')) + ->email(), + TextInput::make('cc') + ->label(__('filament-email::filament-email.cc')) + ->email(), + TextInput::make('bcc') + ->label(__('filament-email::filament-email.bcc')) + ->email(), + DateRangePicker::make('created_at') + ->label(__('filament-email::filament-email.sent_at')), + ]) + ->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"; + } + } + + return $indicators; + }) + ->query(function (Builder $query, array $data): Builder { + return $query + ->when( + $data['to'], + fn (Builder $query, $value): Builder => $query->where('to', 'like', "%$value%"), + ) + ->when( + $data['cc'], + fn (Builder $query, $value): Builder => $query->where('cc', 'like', "%$value%"), + ) + ->when( + $data['bcc'], + fn (Builder $query, $value): Builder => $query->where('bcc', 'like', "%$value%"), + )->when( + $data['created_at'], + function (Builder $query, $value): Builder { + $format = config('filament-email.resource.filters.created_at.date_format'); + [$start, $end] = explode(' - ', $value); + + return $query->whereBetween('created_at', [ + Carbon::createFromFormat($format, $start) + ->format('Y-m-d'), + Carbon::createFromFormat($format, $end) + ->format('Y-m-d'), + ]); + } + ); + }), + ]) + ->filtersFormWidth(MaxWidth::ExtraLarge) + ->paginationPageOptions(function (Table $table) { + $options = config('filament-email.pagination_page_options'); + + return ! empty($options) && is_array($options) ? $options : $table->getPaginationPageOptions(); + }); + } + + public static function getPages(): array + { + return [ + 'index' => ListEmails::route('/'), + 'view' => ViewEmail::route('/{record}'), + ]; + } + + public static function canAccess(): bool + { + $roles = config('filament-email.can_access.role', []); + + if (method_exists(auth()->user(), 'hasRole') && ! empty($roles)) { + return auth()->user()->hasRole($roles); + } + + return true; + } +}