The loading icon was appearing during automatic background status checks (every 10 seconds) even when users didn't click anything, which caused confusion and made it seem like something was running unexpectedly. Changes: - Added manualCheckStatus() method to Application, Database, and Service Heading components that wraps the checkStatus() call - Updated status component buttons to call manualCheckStatus() instead of checkStatus() - Added wire:target="manualCheckStatus" to loading directives so the loading icon only appears when users explicitly click the refresh button - Added delay.shortest to prevent flickering on fast operations The automatic wire:poll.10000ms="checkStatus" now runs silently in the background without showing the loading icon, while manual refreshes still provide visual feedback to the user. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
166 lines
5 KiB
PHP
166 lines
5 KiB
PHP
<?php
|
|
|
|
namespace App\Livewire\Project\Service;
|
|
|
|
use App\Actions\Docker\GetContainersStatus;
|
|
use App\Actions\Service\StartService;
|
|
use App\Actions\Service\StopService;
|
|
use App\Enums\ProcessStatus;
|
|
use App\Models\Service;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Livewire\Component;
|
|
use Spatie\Activitylog\Models\Activity;
|
|
|
|
class Heading extends Component
|
|
{
|
|
public Service $service;
|
|
|
|
public array $parameters;
|
|
|
|
public array $query;
|
|
|
|
public $isDeploymentProgress = false;
|
|
|
|
public $docker_cleanup = true;
|
|
|
|
public $title = 'Configuration';
|
|
|
|
public function mount()
|
|
{
|
|
if (str($this->service->status)->contains('running') && is_null($this->service->config_hash)) {
|
|
$this->service->isConfigurationChanged(true);
|
|
$this->dispatch('configurationChanged');
|
|
}
|
|
}
|
|
|
|
public function getListeners()
|
|
{
|
|
$teamId = Auth::user()->currentTeam()->id;
|
|
|
|
return [
|
|
"echo-private:team.{$teamId},ServiceStatusChanged" => 'checkStatus',
|
|
"echo-private:team.{$teamId},ServiceChecked" => 'serviceChecked',
|
|
'refresh' => '$refresh',
|
|
'envsUpdated' => '$refresh',
|
|
];
|
|
}
|
|
|
|
public function checkStatus()
|
|
{
|
|
if ($this->service->server->isFunctional()) {
|
|
GetContainersStatus::dispatch($this->service->server);
|
|
} else {
|
|
$this->dispatch('error', 'Server is not functional.');
|
|
}
|
|
}
|
|
|
|
public function manualCheckStatus()
|
|
{
|
|
$this->checkStatus();
|
|
}
|
|
|
|
public function serviceChecked()
|
|
{
|
|
try {
|
|
$this->service->applications->each(function ($application) {
|
|
$application->refresh();
|
|
});
|
|
$this->service->databases->each(function ($database) {
|
|
$database->refresh();
|
|
});
|
|
if (is_null($this->service->config_hash)) {
|
|
$this->service->isConfigurationChanged(true);
|
|
}
|
|
$this->dispatch('configurationChanged');
|
|
} catch (\Exception $e) {
|
|
return handleError($e, $this);
|
|
} finally {
|
|
$this->dispatch('refresh')->self();
|
|
}
|
|
|
|
}
|
|
|
|
public function checkDeployments()
|
|
{
|
|
try {
|
|
$activity = Activity::where('properties->type_uuid', $this->service->uuid)->latest()->first();
|
|
$status = data_get($activity, 'properties.status');
|
|
if ($status === ProcessStatus::QUEUED->value || $status === ProcessStatus::IN_PROGRESS->value) {
|
|
$this->isDeploymentProgress = true;
|
|
} else {
|
|
$this->isDeploymentProgress = false;
|
|
}
|
|
} catch (\Throwable) {
|
|
$this->isDeploymentProgress = false;
|
|
}
|
|
|
|
return $this->isDeploymentProgress;
|
|
}
|
|
|
|
public function start()
|
|
{
|
|
$activity = StartService::run($this->service, pullLatestImages: true);
|
|
$this->dispatch('activityMonitor', $activity->id);
|
|
}
|
|
|
|
public function forceDeploy()
|
|
{
|
|
try {
|
|
$activities = Activity::where('properties->type_uuid', $this->service->uuid)
|
|
->where(function ($q) {
|
|
$q->where('properties->status', ProcessStatus::IN_PROGRESS->value)
|
|
->orWhere('properties->status', ProcessStatus::QUEUED->value);
|
|
})->get();
|
|
foreach ($activities as $activity) {
|
|
$activity->properties->status = ProcessStatus::ERROR->value;
|
|
$activity->save();
|
|
}
|
|
$activity = StartService::run($this->service, pullLatestImages: true, stopBeforeStart: true);
|
|
$this->dispatch('activityMonitor', $activity->id);
|
|
} catch (\Exception $e) {
|
|
$this->dispatch('error', $e->getMessage());
|
|
}
|
|
}
|
|
|
|
public function stop()
|
|
{
|
|
try {
|
|
StopService::dispatch($this->service, false, $this->docker_cleanup);
|
|
} catch (\Exception $e) {
|
|
$this->dispatch('error', $e->getMessage());
|
|
}
|
|
}
|
|
|
|
public function restart()
|
|
{
|
|
$this->checkDeployments();
|
|
if ($this->isDeploymentProgress) {
|
|
$this->dispatch('error', 'There is a deployment in progress.');
|
|
|
|
return;
|
|
}
|
|
$activity = StartService::run($this->service, stopBeforeStart: true);
|
|
$this->dispatch('activityMonitor', $activity->id);
|
|
}
|
|
|
|
public function pullAndRestartEvent()
|
|
{
|
|
$this->checkDeployments();
|
|
if ($this->isDeploymentProgress) {
|
|
$this->dispatch('error', 'There is a deployment in progress.');
|
|
|
|
return;
|
|
}
|
|
$activity = StartService::run($this->service, pullLatestImages: true, stopBeforeStart: true);
|
|
$this->dispatch('activityMonitor', $activity->id);
|
|
}
|
|
|
|
public function render()
|
|
{
|
|
return view('livewire.project.service.heading', [
|
|
'checkboxes' => [
|
|
['id' => 'docker_cleanup', 'label' => __('resource.docker_cleanup')],
|
|
],
|
|
]);
|
|
}
|
|
}
|