lasthourcloud/app/Http/Livewire/Project/Service/Index.php

80 lines
2.3 KiB
PHP
Raw Normal View History

2023-09-20 13:42:41 +00:00
<?php
namespace App\Http\Livewire\Project\Service;
2023-09-21 15:48:31 +00:00
use App\Actions\Service\StartService;
use App\Jobs\ContainerStatusJob;
2023-09-20 13:42:41 +00:00
use App\Models\Service;
2023-09-21 15:48:31 +00:00
use Illuminate\Support\Collection;
2023-09-20 13:42:41 +00:00
use Livewire\Component;
class Index extends Component
{
public Service $service;
public array $parameters;
public array $query;
2023-09-21 15:48:31 +00:00
public Collection $services;
2023-09-20 13:42:41 +00:00
2023-09-21 15:48:31 +00:00
protected $rules = [
'services.*.fqdn' => 'nullable',
];
public function mount()
{
$this->services = collect([]);
2023-09-20 13:42:41 +00:00
$this->parameters = get_route_parameters();
$this->query = request()->query();
$this->service = Service::whereUuid($this->parameters['service_uuid'])->firstOrFail();
2023-09-21 15:48:31 +00:00
foreach ($this->service->applications as $application) {
$this->services->put($application->name, [
'fqdn' => $application->fqdn,
]);
}
// foreach ($this->service->databases as $database) {
// $this->services->put($database->name, $database->fqdn);
// }
2023-09-20 13:42:41 +00:00
}
public function render()
{
return view('livewire.project.service.index')->layout('layouts.app');
}
2023-09-21 15:48:31 +00:00
public function check_status()
{
dispatch_sync(new ContainerStatusJob($this->service->server));
$this->service->refresh();
}
public function submit()
{
try {
if ($this->services->count() === 0) {
return;
}
foreach ($this->services as $name => $value) {
$foundService = $this->service->applications()->whereName($name)->first();
if ($foundService) {
$foundService->fqdn = data_get($value, 'fqdn');
$foundService->save();
return;
}
$foundService = $this->service->databases()->whereName($name)->first();
if ($foundService) {
// $foundService->save();
return;
}
}
} catch (\Throwable $e) {
ray($e);
} finally {
$this->service->parse();
}
}
public function deploy()
{
$this->service->parse();
$activity = StartService::run($this->service);
$this->emit('newMonitorActivity', $activity->id);
}
2023-09-20 13:42:41 +00:00
}