destinations
This commit is contained in:
39
app/Http/Livewire/Destination/Form.php
Normal file
39
app/Http/Livewire/Destination/Form.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire\Destination;
|
||||
|
||||
use App\Models\StandaloneDocker;
|
||||
use App\Models\SwarmDocker;
|
||||
use Livewire\Component;
|
||||
|
||||
class Form extends Component
|
||||
{
|
||||
public $destination_uuid;
|
||||
public $destination;
|
||||
|
||||
protected $rules = [
|
||||
'destination.name' => 'required',
|
||||
'destination.network' => 'required',
|
||||
'destination.server.ip' => 'required',
|
||||
];
|
||||
public function mount()
|
||||
{
|
||||
$standalone = StandaloneDocker::where('uuid', $this->destination_uuid)->first();
|
||||
$swarm = SwarmDocker::where('uuid', $this->destination_uuid)->first();
|
||||
if (!$standalone && !$swarm) {
|
||||
abort(404);
|
||||
}
|
||||
$this->destination = $standalone ? $standalone->load(['server']) : $swarm->load(['server']);
|
||||
}
|
||||
public function submit()
|
||||
{
|
||||
$this->validate();
|
||||
$this->destination->save();
|
||||
}
|
||||
public function delete()
|
||||
{
|
||||
instantRemoteProcess(['docker network rm -f ' . $this->destination->network], $this->destination->server);
|
||||
$this->destination->delete();
|
||||
return redirect()->route('dashboard');
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ namespace App\Http\Livewire\Destination\New;
|
||||
use App\Models\Server;
|
||||
use App\Models\StandaloneDocker as ModelsStandaloneDocker;
|
||||
use Livewire\Component;
|
||||
use Visus\Cuid2\Cuid2;
|
||||
|
||||
class StandaloneDocker extends Component
|
||||
{
|
||||
@@ -12,7 +13,7 @@ class StandaloneDocker extends Component
|
||||
public string $network;
|
||||
|
||||
public $servers;
|
||||
public int|null $server_id = null;
|
||||
public int $server_id;
|
||||
|
||||
protected $rules = [
|
||||
'name' => 'required|string',
|
||||
@@ -21,13 +22,11 @@ class StandaloneDocker extends Component
|
||||
];
|
||||
public function mount()
|
||||
{
|
||||
$this->name = generateRandomName();
|
||||
$this->servers = Server::where('team_id', session('currentTeam')->id)->get();
|
||||
$this->network = new Cuid2(7);
|
||||
$this->name = generateRandomName();
|
||||
}
|
||||
public function setServerId($server_id)
|
||||
{
|
||||
$this->server_id = $server_id;
|
||||
}
|
||||
|
||||
public function submit()
|
||||
{
|
||||
$this->validate();
|
||||
|
||||
Reference in New Issue
Block a user