diff --git a/web/Modules/Customer/App/Filament/Resources/DatabaseResource.php b/web/Modules/Customer/App/Filament/Resources/DatabaseResource.php index d8fe192..67bb58a 100644 --- a/web/Modules/Customer/App/Filament/Resources/DatabaseResource.php +++ b/web/Modules/Customer/App/Filament/Resources/DatabaseResource.php @@ -21,6 +21,8 @@ class DatabaseResource extends Resource protected static ?string $navigationIcon = 'heroicon-o-circle-stack'; + protected static ?int $navigationSort = 1; + public static function form(Form $form): Form { $systemUsername = ''; diff --git a/web/Modules/Customer/App/Filament/Resources/DomainResource.php b/web/Modules/Customer/App/Filament/Resources/DomainResource.php new file mode 100644 index 0000000..4e4c6f9 --- /dev/null +++ b/web/Modules/Customer/App/Filament/Resources/DomainResource.php @@ -0,0 +1,305 @@ +id] = $hostingSubscription->domain . ' - '.$hostingSubscription->customer->name; + } + + return $form + ->schema([ + + Tabs::make('Tabs') + ->tabs([ + Tabs\Tab::make('General') + ->schema([ + + Select::make('hosting_subscription_id') + ->label('Hosting Subscription') + ->options($hostingSubscriptions) + ->columnSpanFull() + ->required(), + + TextInput::make('domain') + ->unique(Domain::class, 'domain', ignoreRecord: true) + ->label('Domain'), + + + RadioDeck::make('server_application_type') + ->default('apache_php') + ->options(ServerApplicationType::class) + ->icons(ServerApplicationType::class) + ->descriptions(ServerApplicationType::class) + ->required() + ->live() + ->color('primary') + ->columns(3), + + // PHP Configuration + Select::make('server_application_settings.php_version') + ->hidden(function (Get $get) { + return $get('server_application_type') !== 'apache_php'; + }) + ->default('8.3') + ->label('PHP Version') + ->options(SupportedApplicationTypes::getPHPVersions()) + ->columns(5) + ->required(), + + // End of PHP Configuration + + // Node.js Configuration + Select::make('server_application_settings.nodejs_version') + ->hidden(function (Get $get) { + return $get('server_application_type') !== 'apache_nodejs'; + }) + ->label('Node.js Version') + ->default('20') + ->options(SupportedApplicationTypes::getNodeJsVersions()) + ->columns(6) + ->required(), + + // End of Node.js Configuration + + // Python Configuration + + Select::make('server_application_settings.python_version') + ->hidden(function (Get $get) { + return $get('server_application_type') !== 'apache_python'; + }) + ->label('Python Version') + ->default('3.10') + ->options(SupportedApplicationTypes::getPythonVersions()) + ->columns(6) + ->required(), + + // End of Python Configuration + + // Ruby Configuration + + Select::make('server_application_settings.ruby_version') + ->hidden(function (Get $get) { + return $get('server_application_type') !== 'apache_ruby'; + }) + ->label('Ruby Version') + ->default('3.4') + ->options(SupportedApplicationTypes::getRubyVersions()) + ->columns(6) + ->required(), + ]), + Tabs\Tab::make('Git') + ->schema([ + + TextInput::make('git_repository_url') + ->label('Repository URL'), + + Actions::make([ + + Actions\Action::make('clone_repository') + // ->icon('heroicon-m-refresh') + //->requiresConfirmation() + ->action(function(Get $get, $record) { + + // Run command + $domainPublic = $record->domain_public; + $gitRepositoryUrl = $get('git_repository_url'); + + shell_exec('rm -rf ' . $domainPublic); + $command = 'git clone '.$gitRepositoryUrl . ' ' . $domainPublic; + $output = shell_exec($command); + + $record->configureVirtualHost(); + + }), + + ]), + + + ]), + + Tabs\Tab::make('Node.js') + ->schema([ + + Tabs::make('Tabs Node.js') + ->tabs([ + + Tabs\Tab::make('Dashboard') + ->schema([ + + Actions::make([ + + Actions\Action::make('restart_nodejs') + // ->icon('heroicon-m-refresh') + ->requiresConfirmation() + ->action(function() { + // Restart Node.js + }), + + ]), + + Select::make('nodejs_version') + ->label('Node.js version') + ->options([ + '14.x' => '14.x', + '16.x' => '16.x', + ]) + ->columnSpanFull() + ->default('14.x'), + + Select::make('package_manager') + ->label('Package manager') + ->options([ + 'npm' => 'npm', + 'yarn' => 'yarn', + ]) + ->columnSpanFull() + ->default('npm'), + + TextInput::make('document_root') + ->label('Document root') + ->columnSpanFull() + ->default('/public_html'), + + Select::make('application_mode') + ->label('Application mode') + ->options([ + 'development' => 'Development', + 'production' => 'Production', + ]) + ->columnSpanFull() + ->default('production'), + + TextInput::make('application_startup_file') + ->label('Application startup file') + ->columnSpanFull() + ->default('app.js'), + + KeyValue::make('custom_environment_variables') + ->label('Custom Environment variables') + ->columnSpanFull() + ->helperText('Add custom environment variables for your Node.js application. Separate key and value with an equal sign. Example: KEY=VALUE') + + ]), + + Tabs\Tab::make('Run Node.js commands') + ->schema([ + + Select::make('node_version') + ->label('Node.js version') + ->options([ + '14.x' => '14.x', + '16.x' => '16.x', + ]) + ->default('14.x'), + + Select::make('package_manager') + ->label('Package manager') + ->options([ + 'npm' => 'npm', + 'yarn' => 'yarn', + ]) + ->default('npm'), + + TextInput::make('command') + ->label('Command') + ->default('start'), + + Actions::make([ + + Actions\Action::make('run_command') + // ->icon('heroicon-m-refresh') + ->requiresConfirmation() + ->action(function() { + // Run command + }), + + ]), + + + ]), + + ]) + + ]), + ]) + ->columnSpanFull() + ->activeTab(1), + + ]); + } + + public static function table(Table $table): Table + { + return $table + ->columns([ + Tables\Columns\TextColumn::make('domain') + ->searchable() + ->sortable(), + + Tables\Columns\TextColumn::make('hostingSubscription.hostingPlan.name') + ->searchable() + ->sortable(), + ]) + ->defaultSort('id', 'desc') + ->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\ListDomains::route('/'), + 'create' => Pages\CreateDomain::route('/create'), + 'edit' => Pages\EditDomain::route('/{record}/edit'), + ]; + } +} diff --git a/web/Modules/Customer/App/Filament/Resources/DomainResource/Pages/CreateDomain.php b/web/Modules/Customer/App/Filament/Resources/DomainResource/Pages/CreateDomain.php new file mode 100644 index 0000000..a231b86 --- /dev/null +++ b/web/Modules/Customer/App/Filament/Resources/DomainResource/Pages/CreateDomain.php @@ -0,0 +1,12 @@ + 'array', ]; + protected static function booted(): void + { + static::addGlobalScope('customer', function (Builder $query) { + if (auth()->check() && auth()->guard()->name == 'web_customer') { + $query->whereHas('hostingSubscription', function ($query) { + $query->where('customer_id', auth()->user()->id); + }); + } + }); + } + public static function boot() { parent::boot();