Add generic api schema and scripts model
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace App\Livewire;
|
||||
|
||||
use App\Models\Bot;
|
||||
use Jantinnerezo\LivewireAlert\Facades\LivewireAlert;
|
||||
use Livewire\Component;
|
||||
|
||||
class BotsList extends Component
|
||||
@@ -25,6 +27,47 @@ class BotsList extends Component
|
||||
}
|
||||
}
|
||||
|
||||
public function deleteBot(int $botId): void
|
||||
{
|
||||
$bot = \App\Models\Bot::find($botId);
|
||||
|
||||
if ($bot) {
|
||||
LivewireAlert::title('Are you sure you want to delete ' . $bot->name . '?')
|
||||
->asConfirm()
|
||||
->onConfirm('confirmDelete', [$bot])
|
||||
->show();
|
||||
}
|
||||
}
|
||||
|
||||
public function confirmDelete(Bot $bot): void
|
||||
{
|
||||
$bot->delete();
|
||||
$this->bots = \App\Models\Bot::all(); // Refresh the list
|
||||
flash()->success("Bot '{$bot->name}' has been deleted.");
|
||||
}
|
||||
|
||||
public function runBot($botId)
|
||||
{
|
||||
$bot = \App\Models\Bot::find($botId);
|
||||
|
||||
if ($bot) {
|
||||
LivewireAlert::title('Are you sure you want to run ' . $bot->name . '?')
|
||||
->asConfirm()
|
||||
->onConfirm('confirmRunBot', [$bot])
|
||||
->show();
|
||||
}
|
||||
}
|
||||
|
||||
public function confirmRunBot(Bot $bot): void
|
||||
{
|
||||
// Dispatch the job to run the bot
|
||||
$class = new $bot->class($bot->config ?? []);
|
||||
|
||||
$class->run();
|
||||
|
||||
flash()->success("Bot '{$bot->name}' is being executed.");
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.bots-list');
|
||||
|
||||
Reference in New Issue
Block a user