refactor(activity-monitor): consolidate activity monitoring logic and remove deprecated NewActivityMonitor component
This commit is contained in:
@@ -14,6 +14,8 @@ class ActivityMonitor extends Component
|
||||
|
||||
public $eventToDispatch = 'activityFinished';
|
||||
|
||||
public $eventData = null;
|
||||
|
||||
public $isPollingActive = false;
|
||||
|
||||
public bool $fullHeight = false;
|
||||
@@ -26,10 +28,11 @@ class ActivityMonitor extends Component
|
||||
|
||||
protected $listeners = ['activityMonitor' => 'newMonitorActivity'];
|
||||
|
||||
public function newMonitorActivity($activityId, $eventToDispatch = 'activityFinished')
|
||||
public function newMonitorActivity($activityId, $eventToDispatch = 'activityFinished', $eventData = null)
|
||||
{
|
||||
$this->activityId = $activityId;
|
||||
$this->eventToDispatch = $eventToDispatch;
|
||||
$this->eventData = $eventData;
|
||||
|
||||
$this->hydrateActivity();
|
||||
|
||||
@@ -55,7 +58,11 @@ class ActivityMonitor extends Component
|
||||
if ($user) {
|
||||
$teamId = $user->currentTeam()->id;
|
||||
if (! self::$eventDispatched) {
|
||||
$this->eventToDispatch::dispatch($teamId);
|
||||
if (filled($this->eventData)) {
|
||||
$this->eventToDispatch::dispatch($teamId, $this->eventData);
|
||||
} else {
|
||||
$this->eventToDispatch::dispatch($teamId);
|
||||
}
|
||||
self::$eventDispatched = true;
|
||||
}
|
||||
}
|
||||
@@ -63,7 +70,11 @@ class ActivityMonitor extends Component
|
||||
return;
|
||||
}
|
||||
if (! self::$eventDispatched) {
|
||||
$this->dispatch($this->eventToDispatch);
|
||||
if (filled($this->eventData)) {
|
||||
$this->dispatch($this->eventToDispatch, $this->eventData);
|
||||
} else {
|
||||
$this->dispatch($this->eventToDispatch);
|
||||
}
|
||||
self::$eventDispatched = true;
|
||||
}
|
||||
}
|
||||
|
@@ -1,74 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire;
|
||||
|
||||
use App\Models\User;
|
||||
use Livewire\Component;
|
||||
use Spatie\Activitylog\Models\Activity;
|
||||
|
||||
class NewActivityMonitor extends Component
|
||||
{
|
||||
public ?string $header = null;
|
||||
|
||||
public $activityId;
|
||||
|
||||
public $eventToDispatch = 'activityFinished';
|
||||
|
||||
public $eventData = null;
|
||||
|
||||
public $isPollingActive = false;
|
||||
|
||||
protected $activity;
|
||||
|
||||
protected $listeners = ['newActivityMonitor' => 'newMonitorActivity'];
|
||||
|
||||
public function newMonitorActivity($activityId, $eventToDispatch = 'activityFinished', $eventData = null)
|
||||
{
|
||||
$this->activityId = $activityId;
|
||||
$this->eventToDispatch = $eventToDispatch;
|
||||
$this->eventData = $eventData;
|
||||
|
||||
$this->hydrateActivity();
|
||||
|
||||
$this->isPollingActive = true;
|
||||
}
|
||||
|
||||
public function hydrateActivity()
|
||||
{
|
||||
$this->activity = Activity::find($this->activityId);
|
||||
}
|
||||
|
||||
public function polling()
|
||||
{
|
||||
$this->hydrateActivity();
|
||||
// $this->setStatus(ProcessStatus::IN_PROGRESS);
|
||||
$exit_code = data_get($this->activity, 'properties.exitCode');
|
||||
if ($exit_code !== null) {
|
||||
// if ($exit_code === 0) {
|
||||
// // $this->setStatus(ProcessStatus::FINISHED);
|
||||
// } else {
|
||||
// // $this->setStatus(ProcessStatus::ERROR);
|
||||
// }
|
||||
$this->isPollingActive = false;
|
||||
if ($this->eventToDispatch !== null) {
|
||||
if (str($this->eventToDispatch)->startsWith('App\\Events\\')) {
|
||||
$causer_id = data_get($this->activity, 'causer_id');
|
||||
$user = User::find($causer_id);
|
||||
if ($user) {
|
||||
foreach ($user->teams as $team) {
|
||||
$teamId = $team->id;
|
||||
$this->eventToDispatch::dispatch($teamId);
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
if (! is_null($this->eventData)) {
|
||||
$this->dispatch($this->eventToDispatch, $this->eventData);
|
||||
} else {
|
||||
$this->dispatch($this->eventToDispatch);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -106,7 +106,8 @@ class ValidateAndInstall extends Component
|
||||
if ($this->number_of_tries <= $this->max_tries) {
|
||||
$activity = $this->server->installDocker();
|
||||
$this->number_of_tries++;
|
||||
$this->dispatch('newActivityMonitor', $activity->id, 'init', $this->number_of_tries);
|
||||
// $this->dispatch('newActivityMonitor', $activity->id, 'init', $this->number_of_tries);
|
||||
$this->dispatch('activityMonitor', $activity->id, 'init', $this->number_of_tries);
|
||||
}
|
||||
|
||||
return;
|
||||
|
@@ -1,18 +0,0 @@
|
||||
@php use App\Actions\CoolifyTask\RunRemoteProcess; @endphp
|
||||
<div>
|
||||
@if ($this->activity)
|
||||
@if (isset($header))
|
||||
<div class="flex gap-2 pb-2">
|
||||
{{ $header }}
|
||||
@if ($isPollingActive)
|
||||
<x-loading />
|
||||
@endif
|
||||
</div>
|
||||
@endif
|
||||
<div
|
||||
class="scrollbar flex flex-col-reverse w-full overflow-y-auto border border-solid rounded-sm border-coolgray-300 max-h-[32rem] p-4 pt-6 text-xs dark:text-white">
|
||||
|
||||
<pre class="font-mono whitespace-pre-wrap" @if ($isPollingActive) wire:poll.1000ms="polling" @endif>{{ RunRemoteProcess::decodeOutput($this->activity) }}</pre>
|
||||
</div>
|
||||
@endif
|
||||
</div>
|
@@ -120,7 +120,7 @@
|
||||
@endif
|
||||
|
||||
@endif
|
||||
<livewire:new-activity-monitor header="Docker Installation Logs" />
|
||||
<livewire:activity-monitor header="Docker Installation Logs" />
|
||||
@isset($error)
|
||||
<pre class="font-bold whitespace-pre-line text-error">{!! $error !!}</pre>
|
||||
@endisset
|
||||
|
Reference in New Issue
Block a user