mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-02 22:46:16 +00:00
init
This commit is contained in:
33
app/Http/Livewire/ServerSshKeys/AddExistingKey.php
Normal file
33
app/Http/Livewire/ServerSshKeys/AddExistingKey.php
Normal file
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire\ServerSshKeys;
|
||||
|
||||
use App\Models\Server;
|
||||
use App\Models\SshKey;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Livewire\Component;
|
||||
|
||||
class AddExistingKey extends Component
|
||||
{
|
||||
public Server $server;
|
||||
|
||||
public string $key_id = '';
|
||||
|
||||
public function add(): void
|
||||
{
|
||||
$key = SshKey::query()->findOrFail($this->all()['key_id']);
|
||||
|
||||
$key->deployTo($this->server);
|
||||
|
||||
$this->emitTo(ServerKeysList::class, '$refresh');
|
||||
|
||||
$this->dispatchBrowserEvent('added', true);
|
||||
}
|
||||
|
||||
public function render(): View
|
||||
{
|
||||
return view('livewire.server-ssh-keys.add-existing-key', [
|
||||
'keys' => SshKey::all(),
|
||||
]);
|
||||
}
|
||||
}
|
36
app/Http/Livewire/ServerSshKeys/AddNewKey.php
Normal file
36
app/Http/Livewire/ServerSshKeys/AddNewKey.php
Normal file
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire\ServerSshKeys;
|
||||
|
||||
use App\Actions\SshKey\CreateSshKey;
|
||||
use App\Models\Server;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Livewire\Component;
|
||||
|
||||
class AddNewKey extends Component
|
||||
{
|
||||
public Server $server;
|
||||
|
||||
public string $name;
|
||||
|
||||
public string $public_key;
|
||||
|
||||
public function add(): void
|
||||
{
|
||||
$key = app(CreateSshKey::class)->create(
|
||||
auth()->user(),
|
||||
$this->all()
|
||||
);
|
||||
|
||||
$key->deployTo($this->server);
|
||||
|
||||
$this->emitTo(ServerKeysList::class, '$refresh');
|
||||
|
||||
$this->dispatchBrowserEvent('added', true);
|
||||
}
|
||||
|
||||
public function render(): View
|
||||
{
|
||||
return view('livewire.server-ssh-keys.add-new-key');
|
||||
}
|
||||
}
|
40
app/Http/Livewire/ServerSshKeys/ServerKeysList.php
Normal file
40
app/Http/Livewire/ServerSshKeys/ServerKeysList.php
Normal file
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire\ServerSshKeys;
|
||||
|
||||
use App\Models\Server;
|
||||
use App\Models\SshKey;
|
||||
use App\Traits\RefreshComponentOnBroadcast;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Livewire\Component;
|
||||
|
||||
class ServerKeysList extends Component
|
||||
{
|
||||
use RefreshComponentOnBroadcast;
|
||||
|
||||
public Server $server;
|
||||
|
||||
public int $deleteId;
|
||||
|
||||
protected $listeners = [
|
||||
'$refresh',
|
||||
];
|
||||
|
||||
public function delete(): void
|
||||
{
|
||||
$key = SshKey::query()->findOrFail($this->deleteId);
|
||||
|
||||
$key->deleteFrom($this->server);
|
||||
|
||||
$this->refreshComponent([]);
|
||||
|
||||
$this->dispatchBrowserEvent('confirmed', true);
|
||||
}
|
||||
|
||||
public function render(): View
|
||||
{
|
||||
return view('livewire.server-ssh-keys.server-keys-list', [
|
||||
'keys' => $this->server->sshKeys,
|
||||
]);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user