This commit is contained in:
Bozhidar 2024-05-09 11:42:27 +03:00
parent 030d73cf77
commit 9c40235dba
7 changed files with 200 additions and 4 deletions

View file

@ -3,6 +3,7 @@
namespace App\Filament\Resources;
use App\Filament\Resources\HostingSubscriptionResource\Pages;
use app\Filament\Resources\HostingSubscriptionResource\Pages\ManageHostingSubscriptionFtpAccounts;
use App\Models\Customer;
use App\Models\Domain;
use App\Models\HostingSubscription;
@ -188,6 +189,7 @@ class HostingSubscriptionResource extends Resource
Pages\EditHostingSubscription::class,
Pages\ManageHostingSubscriptionDatabases::class,
Pages\ManageHostingSubscriptionBackups::class,
ManageHostingSubscriptionFtpAccounts::class
]);
}
@ -207,6 +209,7 @@ class HostingSubscriptionResource extends Resource
'edit' => Pages\EditHostingSubscription::route('/{record}/edit'),
'databases' => Pages\ManageHostingSubscriptionDatabases::route('/{record}/databases'),
'backups' => Pages\ManageHostingSubscriptionBackups::route('/{record}/backups'),
'ftp-accounts' => Pages\ManageHostingSubscriptionFtpAccounts::route('/{record}/ftp-accounts'),
];
}

View file

@ -47,7 +47,7 @@ class ManageHostingSubscriptionBackups extends ManageRelatedRecords
public static function getNavigationLabel(): string
{
return 'Manage Backups';
return 'Backups';
}
public function form(Form $form): Form
@ -99,7 +99,7 @@ class ManageHostingSubscriptionBackups extends ManageRelatedRecords
}
return $table
->recordTitleAttribute('id')
->recordTitleAttribute('file_name')
->columns([
Tables\Columns\TextColumn::make('backup_type')

View file

@ -41,7 +41,7 @@ class ManageHostingSubscriptionDatabases extends ManageRelatedRecords
public static function getNavigationLabel(): string
{
return 'Manage Databases';
return 'Databases';
}
public function form(Form $form): Form

View file

@ -0,0 +1,134 @@
<?php
namespace app\Filament\Resources\HostingSubscriptionResource\Pages;
use App\BackupStorage;
use App\Filament\Enums\BackupStatus;
use App\Filament\Enums\HostingSubscriptionBackupType;
use App\Filament\Resources\Blog\PostResource;
use App\Filament\Resources\HostingSubscriptionResource;
use App\Models\Backup;
use App\Models\DatabaseUser;
use App\Models\HostingSubscriptionBackup;
use App\Models\RemoteDatabaseServer;
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Infolists\Components\IconEntry;
use Filament\Infolists\Components\TextEntry;
use Filament\Infolists\Infolist;
use Filament\Resources\Pages\ManageRelatedRecords;
use Filament\Tables;
use Filament\Tables\Table;
use Illuminate\Contracts\Support\Htmlable;
use Illuminate\Support\Carbon;
use JaOcero\RadioDeck\Forms\Components\RadioDeck;
class ManageHostingSubscriptionFtpAccounts extends ManageRelatedRecords
{
protected static string $resource = HostingSubscriptionResource::class;
protected static string $relationship = 'ftpAccounts';
protected static ?string $navigationIcon = 'heroicon-o-inbox-stack';
public function getTitle(): string|Htmlable
{
$recordTitle = $this->getRecordTitle();
$recordTitle = $recordTitle instanceof Htmlable ? $recordTitle->toHtml() : $recordTitle;
return "Manage {$recordTitle} FTP Accounts";
}
public function getBreadcrumb(): string
{
return 'FTP Accounts';
}
public static function getNavigationLabel(): string
{
return 'FTP Accounts';
}
public function form(Form $form): Form
{
$systemUsername = $this->record->system_username;
return $form
->schema([
Forms\Components\TextInput::make('username')
->label('Username')
->required(),
Forms\Components\TextInput::make('password')
->label('Password')
->required(),
Forms\Components\TextInput::make('confirm_password')
->label('Confirm Password')
->same('password')
->required(),
Forms\Components\TextInput::make('path')
->label('Home Directory')
->prefix('/home/' . $systemUsername . '/')
->required(),
Forms\Components\TextInput::make('quota')
->label('Quota'),
Forms\Components\Toggle::make('unlimited_quota')
->label('Unlimited Quota')
->default(false),
])
->columns(1);
}
public function infolist(Infolist $infolist): Infolist
{
return $infolist
->columns(1)
->schema([
//TextEntry::make('id')->label('id'),
TextEntry::make('username')->label('Username'),
TextEntry::make('path')->label('Home Directory'),
TextEntry::make('quota')->label('Quota'),
IconEntry::make('unlimited_quota')->label('Unlimited Quota'),
]);
}
public function table(Table $table): Table
{
return $table
->recordTitleAttribute('username')
->columns([
Tables\Columns\TextColumn::make('username')
->label('Username'),
Tables\Columns\TextColumn::make('path')
->label('Home Directory')
->default('/'),
])
->filters([
//
])
->headerActions([
Tables\Actions\CreateAction::make(),
//
])
->actions([
Tables\Actions\ViewAction::make(),
Tables\Actions\EditAction::make(),
Tables\Actions\DeleteAction::make(),
])
->groupedBulkActions([
Tables\Actions\DeleteBulkAction::make(),
]);
}
}

View file

@ -109,6 +109,11 @@ class HostingSubscription extends Model
return $this->hasMany(Domain::class);
}
public function ftpAccounts()
{
return $this->hasMany(HostingSubscriptionFtpAccount::class);
}
private function _createLinuxWebUser($model): array
{
$findCustomer = Customer::where('id', $model->customer_id)->first();

View file

@ -0,0 +1,19 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class HostingSubscriptionFtpAccount extends Model
{
use HasFactory;
protected $fillable = [
'username',
'password',
'path',
'quota',
'unlimited_quota',
];
}

View file

@ -0,0 +1,35 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('hosting_subscription_ftp_accounts', function (Blueprint $table) {
$table->id();
$table->bigInteger('hosting_subscription_id')->nullable();
$table->string('username')->nullable();
$table->string('password')->nullable();
$table->string('path')->nullable();
$table->string('quota')->nullable();
$table->tinyInteger('unlimited_quota')->nullable();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('hosting_subscription_ftp_accounts');
}
};