From d4a248dc339d75db139aac0654e637d7e0509f1a Mon Sep 17 00:00:00 2001 From: Aleksandr Pushkov Date: Fri, 23 Oct 2026 20:47:26 +0300 Subject: [PATCH] feat(chat): custom branded modal for topic renaming (replaces browser prompt) --- modules/web_api/routers/chat.py | 14 ++++ modules/web_api/static/js/app.js | 3 +- modules/web_api/static/js/chat/topics.js | 75 +++++++++++++++++-- .../static/modals/rename_topic_modal.html | 33 ++++++++ 4 files changed, 117 insertions(+), 8 deletions(-) create mode 100644 modules/web_api/static/modals/rename_topic_modal.html diff --git a/modules/web_api/routers/chat.py b/modules/web_api/routers/chat.py index 498b350..477ecde 100644 --- a/modules/web_api/routers/chat.py +++ b/modules/web_api/routers/chat.py @@ -44,6 +44,9 @@ class ChatMessageRequest(BaseModel): session_id: Optional[str] = "session_main" +class UpdateSessionRequest(BaseModel): + title: str + class CreateSessionRequest(BaseModel): title: Optional[str] = None session_id: Optional[str] = None @@ -79,6 +82,17 @@ def create_chat_session_endpoint(payload: CreateSessionRequest, current_user=Dep return {"status": "success", "session": session} + +@router.patch("/sessions/{session_id}") +def update_chat_session_endpoint(session_id: str, payload: UpdateSessionRequest, current_user=Depends(get_current_user)): + """Ручное переименование названия диалога оператором.""" + new_title = payload.title.strip() + if not new_title: + raise HTTPException(status_code=400, detail="Название не может быть пустым") + db_update_session_title(session_id=session_id, new_title=new_title) + return {"status": "success", "session_id": session_id, "title": new_title} + + @router.delete("/sessions/{session_id}") def delete_chat_session_endpoint(session_id: str, current_user=Depends(get_current_user)): """Каскадное удаление темы и всех её сообщений.""" diff --git a/modules/web_api/static/js/app.js b/modules/web_api/static/js/app.js index d93c6ec..2569eae 100644 --- a/modules/web_api/static/js/app.js +++ b/modules/web_api/static/js/app.js @@ -31,7 +31,8 @@ async function loadModals() { 'admin_modal.html', 'snapshot_inspector_modal.html', 'presence_modal.html', - 'confirm_modal.html' + 'confirm_modal.html', + 'rename_topic_modal.html' ]; const container = document.getElementById('modals-container'); diff --git a/modules/web_api/static/js/chat/topics.js b/modules/web_api/static/js/chat/topics.js index 8c00e46..8b3a5a9 100644 --- a/modules/web_api/static/js/chat/topics.js +++ b/modules/web_api/static/js/chat/topics.js @@ -119,12 +119,20 @@ window.TopicsManager = (function() { - +
+ + +
`; }).join(""); @@ -275,12 +283,65 @@ window.TopicsManager = (function() { } }); + + function openRenameModal(sessionId, currentTitle) { + const modal = document.getElementById("rename-topic-modal"); + const idInput = document.getElementById("rename-topic-session-id"); + const titleInput = document.getElementById("rename-topic-input"); + + if (idInput) idInput.value = sessionId; + if (titleInput) { + titleInput.value = currentTitle; + setTimeout(() => { + titleInput.focus(); + titleInput.select(); + }, 50); + } + if (modal) modal.classList.remove("hidden"); + } + + function closeRenameModal() { + const modal = document.getElementById("rename-topic-modal"); + if (modal) modal.classList.add("hidden"); + } + + async function submitRenameModal(event) { + if (event) event.preventDefault(); + const sessionId = document.getElementById("rename-topic-session-id")?.value; + const newTitle = document.getElementById("rename-topic-input")?.value.trim(); + + if (!sessionId || !newTitle) return; + closeRenameModal(); + + try { + const res = await fetch('/api/v1/chat/sessions/' + encodeURIComponent(sessionId), { + method: 'PATCH', + headers: { + ...AuthManager.getAuthHeaders(), + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ title: newTitle }) + }); + + if (res.ok) { + await loadTopics(); + } else { + console.error("Ошибка сохранения названия темы"); + } + } catch (e) { + console.error("Ошибка сети при переименовании темы:", e); + } + } + return { init, loadTopics, getActiveSessionId, switchTopic, createNewTopic, - askDeleteTopic + askDeleteTopic, + openRenameModal, + closeRenameModal, + submitRenameModal }; })(); diff --git a/modules/web_api/static/modals/rename_topic_modal.html b/modules/web_api/static/modals/rename_topic_modal.html new file mode 100644 index 0000000..d955792 --- /dev/null +++ b/modules/web_api/static/modals/rename_topic_modal.html @@ -0,0 +1,33 @@ +