- Added tone instruction retrieval to SupportReplyService. - Improved user feedback when no relevant article is found. - Included article URL and tone instruction in LLM prompt. - Updated response format to include source information. - Enhanced article management UI with search functionality and editing capabilities. - Introduced a new API endpoint for nearest articles based on vector search. - Added confidence badge component to display article confidence levels. - Implemented tests for article searching, editing, and nearest article API. - Removed obsolete .htaccess file.
172 lines
5.5 KiB
PHP
172 lines
5.5 KiB
PHP
<?php
|
|
|
|
namespace App\Livewire\Admin;
|
|
|
|
use App\Services\AdminArticleService;
|
|
use App\Services\AdminQuickReplyService;
|
|
use Livewire\Component;
|
|
use Livewire\WithPagination;
|
|
|
|
class ArticleManager extends Component
|
|
{
|
|
use WithPagination;
|
|
|
|
public string $title = '';
|
|
|
|
public string $content = '';
|
|
|
|
public string $note = '';
|
|
|
|
public array $allowedActions = [];
|
|
|
|
public string $search = '';
|
|
|
|
public ?int $editingArticleId = null;
|
|
|
|
public string $editTitle = '';
|
|
|
|
public string $editContent = '';
|
|
|
|
public array $articleNotes = [];
|
|
|
|
public array $articleAllowedActions = [];
|
|
|
|
public array $articleQuickReplies = [];
|
|
|
|
public function save(AdminArticleService $service): void
|
|
{
|
|
$this->validate([
|
|
'title' => ['required', 'string', 'max:255'],
|
|
'content' => ['required', 'string', 'max:12000'],
|
|
'note' => ['nullable', 'string', 'max:12000'],
|
|
'allowedActions' => ['array'],
|
|
'allowedActions.*' => ['string', 'in:domain_inf'],
|
|
]);
|
|
|
|
$service->create($this->title, $this->content, $this->note, $this->allowedActions);
|
|
|
|
$this->reset(['title', 'content', 'note', 'allowedActions']);
|
|
$this->dispatch('article-saved');
|
|
session()->flash('success', 'Article opgeslagen en embedding wordt automatisch verwerkt.');
|
|
}
|
|
|
|
public function deleteArticle(int $articleId, AdminArticleService $service): void
|
|
{
|
|
$deleted = $service->deleteById($articleId);
|
|
|
|
if ($deleted) {
|
|
session()->flash('success', "Artikel #{$articleId} is verwijderd.");
|
|
} else {
|
|
session()->flash('success', "Artikel #{$articleId} bestond niet meer.");
|
|
}
|
|
|
|
$this->resetPage();
|
|
}
|
|
|
|
public function updatedSearch(): void
|
|
{
|
|
$this->resetPage();
|
|
}
|
|
|
|
public function startEdit(int $articleId, AdminArticleService $service): void
|
|
{
|
|
$article = $service->findById($articleId);
|
|
if ($article === null) {
|
|
session()->flash('success', "Artikel #{$articleId} bestaat niet meer.");
|
|
|
|
return;
|
|
}
|
|
|
|
$this->editingArticleId = $article->id;
|
|
$this->editTitle = $article->title;
|
|
$this->editContent = $article->content;
|
|
}
|
|
|
|
public function cancelEdit(): void
|
|
{
|
|
$this->reset(['editingArticleId', 'editTitle', 'editContent']);
|
|
$this->resetValidation(['editTitle', 'editContent']);
|
|
}
|
|
|
|
public function saveEdit(AdminArticleService $service): void
|
|
{
|
|
if ($this->editingArticleId === null) {
|
|
return;
|
|
}
|
|
|
|
$this->validate([
|
|
'editTitle' => ['required', 'string', 'max:255'],
|
|
'editContent' => ['required', 'string', 'max:12000'],
|
|
]);
|
|
|
|
$updated = $service->updateContent($this->editingArticleId, $this->editTitle, $this->editContent);
|
|
|
|
session()->flash('success', $updated
|
|
? "Artikel #{$this->editingArticleId} is bijgewerkt en wordt opnieuw geindexeerd."
|
|
: "Artikel #{$this->editingArticleId} bestaat niet meer.");
|
|
|
|
$this->cancelEdit();
|
|
}
|
|
|
|
public function saveMetadata(int $articleId, AdminArticleService $service): void
|
|
{
|
|
$this->validate([
|
|
"articleNotes.{$articleId}" => ['nullable', 'string', 'max:12000'],
|
|
"articleAllowedActions.{$articleId}" => ['array'],
|
|
"articleAllowedActions.{$articleId}.*" => ['string', 'in:domain_inf'],
|
|
"articleQuickReplies.{$articleId}" => ['array'],
|
|
"articleQuickReplies.{$articleId}.*" => ['integer', 'exists:quick_replies,id'],
|
|
]);
|
|
|
|
$updated = $service->updateMetadata(
|
|
$articleId,
|
|
$this->articleNotes[$articleId] ?? null,
|
|
$this->articleAllowedActions[$articleId] ?? [],
|
|
$this->articleQuickReplies[$articleId] ?? []
|
|
);
|
|
|
|
session()->flash('success', $updated
|
|
? "Metadata voor artikel #{$articleId} is opgeslagen."
|
|
: "Artikel #{$articleId} bestaat niet meer.");
|
|
}
|
|
|
|
public function approveDraft(int $articleId, AdminArticleService $service): void
|
|
{
|
|
$approved = $service->approveDraft($articleId);
|
|
|
|
if ($approved) {
|
|
session()->flash('success', "Conceptartikel #{$articleId} is gevalideerd en gepubliceerd.");
|
|
} else {
|
|
session()->flash('success', "Conceptartikel #{$articleId} bestaat niet meer.");
|
|
}
|
|
}
|
|
|
|
public function render(AdminArticleService $service, AdminQuickReplyService $quickReplyService)
|
|
{
|
|
$articles = $service->paginate(10, $this->search);
|
|
$this->fillArticleMetadataState($articles->items());
|
|
|
|
return view('livewire.admin.article-manager', [
|
|
'articles' => $articles,
|
|
'quickReplyOptions' => $quickReplyService->activeOptions(),
|
|
]);
|
|
}
|
|
|
|
private function fillArticleMetadataState(array $articles): void
|
|
{
|
|
foreach ($articles as $article) {
|
|
if (! array_key_exists($article->id, $this->articleNotes)) {
|
|
$this->articleNotes[$article->id] = $article->note ?? '';
|
|
}
|
|
|
|
if (! array_key_exists($article->id, $this->articleAllowedActions)) {
|
|
$this->articleAllowedActions[$article->id] = $article->allowed_actions ?? [];
|
|
}
|
|
|
|
if (! array_key_exists($article->id, $this->articleQuickReplies)) {
|
|
$this->articleQuickReplies[$article->id] = $article->quickReplies->pluck('id')->map(fn ($id) => (int) $id)->all();
|
|
}
|
|
}
|
|
}
|
|
}
|