This commit is contained in:
Bozhidar 2024-09-11 14:17:39 +03:00
parent a0b96b6d95
commit 08f84c2829
7 changed files with 118 additions and 31 deletions

View file

@ -0,0 +1,71 @@
<?php
namespace Modules\Customer\App\Filament\Pages;
use App\GitClient;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\Wizard;
use Filament\Forms\Form;
use Filament\Forms\Set;
use Filament\Pages\Page;
class CloneGitRepository extends Page
{
protected static ?string $navigationLabel = 'Clone Git Repository';
protected static string $view = 'customer::filament.pages.clone-git-repository';
protected static ?string $slug = 'git-repositories/clone';
protected static bool $shouldRegisterNavigation = false;
public function getTitle(): string
{
return 'Clone Git Repository';
}
public function form(Form $form): Form
{
return $form
->schema([
Wizard::make([
Wizard\Step::make('Repository')
->schema([
TextInput::make('url')
->label('URL')
->required()
->columnSpanFull()
->live()
->afterStateUpdated(function ($state, Set $set) {
$repoDetails = GitClient::getRepoDetailsByUrl($state);
if (isset($repoDetails['name'])) {
$set('name', $repoDetails['owner'] .'/'. $repoDetails['name']);
}
})
->placeholder('Enter the URL of the repository'),
Select::make('git_ssh_key_id')
->label('SSH Key')
->options(\App\Models\GitSshKey::all()->pluck('name', 'id'))
->columnSpanFull()
->live()
->required(),
]),
Wizard\Step::make('Delivery')
->schema([
// ...
]),
Wizard\Step::make('Billing')
->schema([
// ...
]),
])->columnSpanFull()
]);
}
}

View file

@ -23,23 +23,44 @@ class GitRepositoryResource extends Resource
protected static ?string $navigationGroup = 'Git';
public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\TextInput::make('url')
->label('URL')
->required()
Forms\Components\Wizard::make([
Forms\Components\Wizard\Step::make('Order')
->schema([
// ...
]),
Forms\Components\Wizard\Step::make('Delivery')
->schema([
// ...
]),
Forms\Components\Wizard\Step::make('Billing')
->schema([
// ...
]),
])->columnSpanFull()
]);
}
public static function ___form(Form $form): Form
{
$gitSSHKeys = \App\Models\GitSshKey::all()->pluck('name', 'id');
return $form
->schema([
Forms\Components\Select::make('git_ssh_key_id')
->label('SSH Key')
->options($gitSSHKeys)
->columnSpanFull()
->live()
->afterStateUpdated(function ($state, Forms\Set $set) use (&$branches, &$tags) {
$repoDetails = GitClient::getRepoDetailsByUrl($state);
if (isset($repoDetails['name'])) {
$set('name', $repoDetails['owner'] .'/'. $repoDetails['name']);
}
})
->placeholder('Enter the URL of the repository'),
->required(),
Forms\Components\TextInput::make('name')
@ -113,7 +134,6 @@ class GitRepositoryResource extends Resource
{
return [
'index' => Pages\ListGitRepositories::route('/'),
'create' => Pages\CreateGitRepository::route('/create'),
'edit' => Pages\EditGitRepository::route('/{record}/edit'),
];
}

View file

@ -1,19 +0,0 @@
<?php
namespace Modules\Customer\App\Filament\Resources\GitRepositoryResource\Pages;
use Modules\Customer\App\Filament\Resources\GitRepositoryResource;
use Filament\Actions;
use Filament\Resources\Pages\CreateRecord;
class CreateGitRepository extends CreateRecord
{
protected static string $resource = GitRepositoryResource::class;
protected static ?string $navigationLabel = 'Clone Git Repository';
public function getTitle(): string
{
return 'Clone Git Repository';
}
}

View file

@ -13,7 +13,10 @@ class ListGitRepositories extends ListRecords
protected function getHeaderActions(): array
{
return [
Actions\CreateAction::make(),
Actions\Action::make('clone_new_repository')
->label('Clone New Repository')
->url('/customer/git-repositories/clone')
->icon('heroicon-o-plus'),
];
}
}

View file

@ -0,0 +1,9 @@
<x-filament-panels::page>
<div class="mt-4">
{{$this->form}}
</div>
</x-filament-panels::page>

View file

@ -20,5 +20,7 @@ class GitRepository extends Model
'status_message',
'dir',
'domain_id',
'git_ssh_key_id',
];
}

View file

@ -27,6 +27,7 @@ return new class extends Migration
$table->string('dir')->nullable();
$table->unsignedBigInteger('domain_id');
$table->unsignedBigInteger('git_ssh_key_id');
$table->timestamps();
});