fix: service navbar using new realtime events

This commit is contained in:
Andras Bacsai
2023-12-08 12:12:44 +01:00
parent 86c2415210
commit b55bd298f2
16 changed files with 107 additions and 33 deletions

View File

@@ -13,7 +13,15 @@ class Index extends Component
public $databases;
public array $parameters;
public array $query;
protected $listeners = ["refreshStacks", "checkStatus"];
public function getListeners()
{
$userId = auth()->user()->id;
return [
"echo-private:custom.{$userId},ServiceStatusChanged" => 'checkStatus',
"refreshStacks",
"checkStatus",
];
}
public function render()
{
return view('livewire.project.service.index');
@@ -28,7 +36,7 @@ class Index extends Component
}
public function checkStatus()
{
dispatch(new ContainerStatusJob($this->service->server));
dispatch_sync(new ContainerStatusJob($this->service->server));
$this->refreshStacks();
}
public function refreshStacks()

View File

@@ -6,9 +6,6 @@ use Livewire\Component;
class Modal extends Component
{
public function checkStatus() {
$this->dispatch('checkStatus');
}
public function render()
{
return view('livewire.project.service.modal');

View File

@@ -4,25 +4,53 @@ namespace App\Livewire\Project\Service;
use App\Actions\Service\StartService;
use App\Actions\Service\StopService;
use App\Jobs\ContainerStatusJob;
use App\Models\Service;
use Livewire\Component;
use Spatie\Activitylog\Models\Activity;
class Navbar extends Component
{
public Service $service;
public array $parameters;
public array $query;
protected $listeners = ["checkStatus"];
public $isDeploymentProgress = false;
public function checkDeployments() {
$activity = Activity::where('properties->type_uuid', $this->service->uuid)->latest()->first();
$status = data_get($activity, 'properties.status');
if ($status === 'queued' || $status === 'in_progress') {
$this->isDeploymentProgress = true;
} else {
$this->isDeploymentProgress = false;
}
}
public function getListeners()
{
$userId = auth()->user()->id;
return [
"echo-private:custom.{$userId},ServiceStatusChanged" => 'serviceStatusChanged',
];
}
public function serviceStatusChanged()
{
$this->service->refresh();
}
public function render()
{
return view('livewire.project.service.navbar');
}
public function checkStatus() {
public function checkStatus()
{
$this->service->refresh();
}
public function deploy()
{
$this->checkDeployments();
if ($this->isDeploymentProgress) {
$this->dispatch('error', 'There is a deployment in progress.');
return;
}
$this->service->parse();
$activity = StartService::run($this->service);
$this->dispatch('newMonitorActivity', $activity->id);