Initial commit
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire;
|
||||
|
||||
use App\Models\Chatbot;
|
||||
use App\Services\WeaviateService;
|
||||
use Illuminate\Support\Str;
|
||||
use Livewire\Component;
|
||||
|
||||
class ChatbotManager extends Component
|
||||
{
|
||||
public string $name = '';
|
||||
public string $slug = '';
|
||||
public string $statusMessage = '';
|
||||
public string $statusType = '';
|
||||
|
||||
public function createChatbot()
|
||||
{
|
||||
// Auto-generate slug if empty
|
||||
if (empty($this->slug)) {
|
||||
$this->slug = Str::slug($this->name);
|
||||
} else {
|
||||
$this->slug = Str::slug($this->slug);
|
||||
}
|
||||
|
||||
$this->validate([
|
||||
'name' => 'required|string|max:100',
|
||||
'slug' => 'required|string|unique:chatbots,slug|max:100',
|
||||
]);
|
||||
|
||||
$chatbot = Chatbot::create([
|
||||
'name' => $this->name,
|
||||
'slug' => $this->slug,
|
||||
]);
|
||||
|
||||
$this->name = '';
|
||||
$this->slug = '';
|
||||
$this->statusMessage = "Le chatbot '{$chatbot->name}' a été créé avec succès !";
|
||||
$this->statusType = 'success';
|
||||
}
|
||||
|
||||
public function deleteChatbot(int $id, WeaviateService $weaviateService)
|
||||
{
|
||||
$chatbot = Chatbot::find($id);
|
||||
if ($chatbot) {
|
||||
$name = $chatbot->name;
|
||||
|
||||
// Delete data in Weaviate for this chatbot
|
||||
$weaviateService->clearChatbotData((string) $chatbot->id);
|
||||
|
||||
// Delete database records
|
||||
$chatbot->delete();
|
||||
|
||||
$this->statusMessage = "Le chatbot '{$name}' et toutes ses données vectorielles ont été supprimés.";
|
||||
$this->statusType = 'success';
|
||||
}
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
$chatbots = Chatbot::latest()->get();
|
||||
return view('livewire.chatbot-manager', compact('chatbots'));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user