Add bot logs
All checks were successful
Deploy App / deploy (push) Successful in 11s

This commit is contained in:
2025-08-31 21:54:18 +02:00
parent 77ebc6bce1
commit 378355ad5b
16 changed files with 355 additions and 20 deletions

35
app/Livewire/BotLogs.php Normal file
View File

@@ -0,0 +1,35 @@
<?php
namespace App\Livewire;
use App\Models\BotLog;
use Illuminate\Support\Facades\Auth;
use Livewire\Component;
use Livewire\WithoutUrlPagination;
use Livewire\WithPagination;
class BotLogs extends Component
{
use WithPagination;
use WithoutUrlPagination;
// public function mount()
// {
// $this->getLogs();
// }
// public function getLogs(): void
// {
// $this->logs = Auth::user()->bots->pluck('logs')->flatten()->sortByDesc('created_at');
// }
public function render()
{
return view('livewire.bot-logs', [
'logs' => BotLog::whereHas('bot', fn($q) => $q->where('user_id', Auth::id()))
->orderBy('created_at', 'desc')
->latest()
->paginate(10),
]);
}
}

View File

@@ -12,11 +12,21 @@ class BotsList extends Component
{
public $bots;
public string $query = '';
public function mount()
{
$this->bots = Auth::user()->bots;
}
public function search()
{
$this->bots = Auth::user()->bots()
->where('name', 'like', '%' . $this->query . '%')
->orWhere('class', 'like', '%' . $this->query . '%')
->get();
}
public function toggleBot($botId)
{
$bot = \App\Models\Bot::find($botId);
@@ -62,8 +72,13 @@ class BotsList extends Component
public function confirmRunBot(Bot $bot): void
{
$log = $bot->logs()->create([
'status' => 'pending',
'started_at' => now(),
]);
// Dispatch the job to run the bot
dispatch(new RunBot($bot));
dispatch(new RunBot($bot, $log));
flash()->success("Bot '{$bot->name}' is being executed.");
}

38
app/Livewire/ViewBot.php Normal file
View File

@@ -0,0 +1,38 @@
<?php
namespace App\Livewire;
use App\Jobs\RunBot;
use App\Models\Bot;
use Jantinnerezo\LivewireAlert\Facades\LivewireAlert;
use Livewire\Component;
class ViewBot extends Component
{
public Bot $bot;
public function runBot()
{
LivewireAlert::title('Are you sure you want to run ' . $this->bot->name . '?')
->asConfirm()
->onConfirm('confirmRunBot')
->show();
}
public function confirmRunBot(): void
{
$log = $this->bot->logs()->create([
'status' => 'pending',
]);
// Dispatch the job to run the bot
dispatch(new RunBot($this->bot, $log));
flash()->success("Bot '{$this->bot->name}' is being executed.");
}
public function render()
{
return view('livewire.view-bot');
}
}