2023-07-26 11:23:47 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Livewire\Project\New;
|
|
|
|
|
|
|
|
use App\Models\Server;
|
2023-08-23 08:14:39 +00:00
|
|
|
use Countable;
|
2023-07-26 11:23:47 +00:00
|
|
|
use Livewire\Component;
|
|
|
|
|
|
|
|
class Select extends Component
|
|
|
|
{
|
|
|
|
public $current_step = 'type';
|
|
|
|
public string $type;
|
|
|
|
public string $server_id;
|
|
|
|
public string $destination_uuid;
|
2023-08-23 08:14:39 +00:00
|
|
|
public Countable|array|Server $servers;
|
2023-07-26 11:23:47 +00:00
|
|
|
public $destinations = [];
|
|
|
|
public array $parameters;
|
|
|
|
|
|
|
|
public function mount()
|
|
|
|
{
|
2023-08-09 13:57:53 +00:00
|
|
|
$this->parameters = get_route_parameters();
|
2023-07-26 11:23:47 +00:00
|
|
|
}
|
2023-08-08 09:51:36 +00:00
|
|
|
|
2023-07-26 11:23:47 +00:00
|
|
|
public function set_type(string $type)
|
|
|
|
{
|
|
|
|
$this->type = $type;
|
2023-08-23 08:14:39 +00:00
|
|
|
if (count($this->servers) === 1) {
|
|
|
|
$server = $this->servers->first();
|
|
|
|
$this->set_server($server);
|
|
|
|
if (count($server->destinations()) === 1) {
|
|
|
|
$this->set_destination($server->destinations()->first()->uuid);
|
|
|
|
}
|
|
|
|
}
|
2023-07-26 11:23:47 +00:00
|
|
|
$this->current_step = 'servers';
|
|
|
|
}
|
2023-08-08 09:51:36 +00:00
|
|
|
|
2023-07-26 11:23:47 +00:00
|
|
|
public function set_server(Server $server)
|
|
|
|
{
|
|
|
|
$this->server_id = $server->id;
|
|
|
|
$this->destinations = $server->destinations();
|
|
|
|
$this->current_step = 'destinations';
|
|
|
|
}
|
2023-08-08 09:51:36 +00:00
|
|
|
|
2023-07-26 11:23:47 +00:00
|
|
|
public function set_destination(string $destination_uuid)
|
|
|
|
{
|
|
|
|
$this->destination_uuid = $destination_uuid;
|
|
|
|
redirect()->route('project.resources.new', [
|
|
|
|
'project_uuid' => $this->parameters['project_uuid'],
|
|
|
|
'environment_name' => $this->parameters['environment_name'],
|
|
|
|
'type' => $this->type,
|
|
|
|
'destination' => $this->destination_uuid,
|
|
|
|
]);
|
|
|
|
}
|
2023-08-08 09:51:36 +00:00
|
|
|
|
2023-07-26 11:23:47 +00:00
|
|
|
public function load_servers()
|
|
|
|
{
|
2023-08-21 08:18:11 +00:00
|
|
|
$this->servers = Server::isUsable()->get();
|
2023-07-26 11:23:47 +00:00
|
|
|
}
|
|
|
|
}
|