This commit is contained in:
Bozhidar 2024-09-19 15:20:33 +03:00
parent b46e238c20
commit 9d79bbec67
13 changed files with 286 additions and 2 deletions

View file

@ -0,0 +1,89 @@
<?php
namespace Modules\Email\App\Filament\Resources;
use App\Models\Domain;
use Modules\Email\App\Filament\Resources\EmailAliasDomainResource\Pages;
use Modules\Email\App\Filament\Resources\EmailAliasDomainResource\RelationManagers;
use Modules\Email\App\Models\EmailAliasDomain;
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;
class EmailAliasDomainResource extends Resource
{
protected static ?string $model = EmailAliasDomain::class;
protected static ?string $navigationIcon = 'heroicon-o-arrow-trending-up';
protected static ?string $navigationGroup = 'Email';
protected static ?string $label = 'Alias Domains';
protected static ?int $navigationSort = 3;
public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\Select::make('alias_domain')
->options(Domain::get()->pluck('domain', 'domain')->toArray())
->helperText('The domain that mails come in for.')
->columnSpanFull(),
Forms\Components\Select::make('target_domain')
->options(Domain::get()->pluck('domain', 'domain')->toArray())
->helperText('The domain where mails should go to.')
->columnSpanFull(),
]);
}
public static function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\TextColumn::make('alias_domain')
->searchable()
->sortable(),
Tables\Columns\TextColumn::make('target_domain')
->searchable()
->sortable(),
])
->filters([
//
])
->actions([
Tables\Actions\EditAction::make(),
Tables\Actions\DeleteAction::make(),
])
->bulkActions([
// Tables\Actions\BulkActionGroup::make([
// Tables\Actions\DeleteBulkAction::make(),
// ]),
]);
}
public static function getRelations(): array
{
return [
//
];
}
public static function getPages(): array
{
return [
'index' => Pages\ListEmailAliasDomains::route('/'),
// 'create' => Pages\CreateEmailAliasDomain::route('/create'),
// 'edit' => Pages\EditEmailAliasDomain::route('/{record}/edit'),
];
}
}

View file

@ -0,0 +1,12 @@
<?php
namespace Modules\Email\App\Filament\Resources\EmailAliasDomainResource\Pages;
use Modules\Email\App\Filament\Resources\EmailAliasDomainResource;
use Filament\Actions;
use Filament\Resources\Pages\CreateRecord;
class CreateEmailAliasDomain extends CreateRecord
{
protected static string $resource = EmailAliasDomainResource::class;
}

View file

@ -0,0 +1,19 @@
<?php
namespace Modules\Email\App\Filament\Resources\EmailAliasDomainResource\Pages;
use Modules\Email\App\Filament\Resources\EmailAliasDomainResource;
use Filament\Actions;
use Filament\Resources\Pages\EditRecord;
class EditEmailAliasDomain extends EditRecord
{
protected static string $resource = EmailAliasDomainResource::class;
protected function getHeaderActions(): array
{
return [
Actions\DeleteAction::make(),
];
}
}

View file

@ -0,0 +1,19 @@
<?php
namespace Modules\Email\App\Filament\Resources\EmailAliasDomainResource\Pages;
use Modules\Email\App\Filament\Resources\EmailAliasDomainResource;
use Filament\Actions;
use Filament\Resources\Pages\ListRecords;
class ListEmailAliasDomains extends ListRecords
{
protected static string $resource = EmailAliasDomainResource::class;
protected function getHeaderActions(): array
{
return [
Actions\CreateAction::make(),
];
}
}

View file

@ -0,0 +1,83 @@
<?php
namespace Modules\Email\App\Filament\Resources;
use App\Models\Domain;
use Modules\Email\App\Filament\Resources\EmailAliasResource\Pages;
use Modules\Email\App\Filament\Resources\EmailAliasResource\RelationManagers;
use Modules\Email\App\Models\EmailAlias;
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;
class EmailAliasResource extends Resource
{
protected static ?string $model = EmailAlias::class;
protected static ?string $navigationIcon = 'heroicon-o-arrow-trending-up';
protected static ?string $navigationGroup = 'Email';
// protected static ?string $label = 'Aliases';
protected static ?int $navigationSort = 3;
public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\TextInput::make('forward')
->helperText('To create a catch-all use an "*" as alias.')
->required(),
Forms\Components\Select::make('domain')
->options(Domain::get()->pluck('domain', 'domain')->toArray()),
Forms\Components\Textarea::make('to')
->columnSpanFull()
->placeholder('Accepts multiple targets, one entry per line.')
->cols(20)
]);
}
public static function table(Table $table): Table
{
return $table
->columns([
//
])
->filters([
//
])
->actions([
Tables\Actions\EditAction::make(),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DeleteBulkAction::make(),
]),
]);
}
public static function getRelations(): array
{
return [
//
];
}
public static function getPages(): array
{
return [
'index' => Pages\ListEmailAliases::route('/'),
'create' => Pages\CreateEmailAlias::route('/create'),
'edit' => Pages\EditEmailAlias::route('/{record}/edit'),
];
}
}

View file

@ -0,0 +1,12 @@
<?php
namespace Modules\Email\App\Filament\Resources\EmailAliasResource\Pages;
use Modules\Email\App\Filament\Resources\EmailAliasResource;
use Filament\Actions;
use Filament\Resources\Pages\CreateRecord;
class CreateEmailAlias extends CreateRecord
{
protected static string $resource = EmailAliasResource::class;
}

View file

@ -0,0 +1,19 @@
<?php
namespace Modules\Email\App\Filament\Resources\EmailAliasResource\Pages;
use Modules\Email\App\Filament\Resources\EmailAliasResource;
use Filament\Actions;
use Filament\Resources\Pages\EditRecord;
class EditEmailAlias extends EditRecord
{
protected static string $resource = EmailAliasResource::class;
protected function getHeaderActions(): array
{
return [
Actions\DeleteAction::make(),
];
}
}

View file

@ -0,0 +1,19 @@
<?php
namespace Modules\Email\App\Filament\Resources\EmailAliasResource\Pages;
use Modules\Email\App\Filament\Resources\EmailAliasResource;
use Filament\Actions;
use Filament\Resources\Pages\ListRecords;
class ListEmailAliases extends ListRecords
{
protected static string $resource = EmailAliasResource::class;
protected function getHeaderActions(): array
{
return [
Actions\CreateAction::make(),
];
}
}

View file

@ -22,6 +22,8 @@ class EmailBoxResource extends Resource
protected static ?string $navigationGroup = 'Email';
protected static ?string $label = 'Boxes';
protected static ?int $navigationSort = 0;
public static function form(Form $form): Form

View file

@ -13,6 +13,10 @@ class EmailAlias extends Model
/**
* The attributes that are mass assignable.
*/
protected $fillable = [];
protected $fillable = [
'address',
'goto',
'domain',
];
}

View file

@ -13,6 +13,11 @@ class EmailAliasDomain extends Model
/**
* The attributes that are mass assignable.
*/
protected $fillable = [];
protected $fillable = [
'alias_domain',
'target_domain',
];
}

View file

@ -86,6 +86,7 @@ class EmailServiceProvider extends ServiceProvider
{
$this->publishes([module_path($this->moduleName, 'config/config.php') => config_path($this->moduleNameLower.'.php')], 'config');
$this->mergeConfigFrom(module_path($this->moduleName, 'config/config.php'), $this->moduleNameLower);
}
/**