feat(chat): custom branded modal for topic renaming (replaces browser prompt)
This commit is contained in:
@@ -44,6 +44,9 @@ class ChatMessageRequest(BaseModel):
|
|||||||
session_id: Optional[str] = "session_main"
|
session_id: Optional[str] = "session_main"
|
||||||
|
|
||||||
|
|
||||||
|
class UpdateSessionRequest(BaseModel):
|
||||||
|
title: str
|
||||||
|
|
||||||
class CreateSessionRequest(BaseModel):
|
class CreateSessionRequest(BaseModel):
|
||||||
title: Optional[str] = None
|
title: Optional[str] = None
|
||||||
session_id: 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}
|
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}")
|
@router.delete("/sessions/{session_id}")
|
||||||
def delete_chat_session_endpoint(session_id: str, current_user=Depends(get_current_user)):
|
def delete_chat_session_endpoint(session_id: str, current_user=Depends(get_current_user)):
|
||||||
"""Каскадное удаление темы и всех её сообщений."""
|
"""Каскадное удаление темы и всех её сообщений."""
|
||||||
|
|||||||
@@ -31,7 +31,8 @@ async function loadModals() {
|
|||||||
'admin_modal.html',
|
'admin_modal.html',
|
||||||
'snapshot_inspector_modal.html',
|
'snapshot_inspector_modal.html',
|
||||||
'presence_modal.html',
|
'presence_modal.html',
|
||||||
'confirm_modal.html'
|
'confirm_modal.html',
|
||||||
|
'rename_topic_modal.html'
|
||||||
];
|
];
|
||||||
|
|
||||||
const container = document.getElementById('modals-container');
|
const container = document.getElementById('modals-container');
|
||||||
|
|||||||
@@ -119,12 +119,20 @@ window.TopicsManager = (function() {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<button type="button"
|
<div class="flex items-center gap-0.5 opacity-0 group-hover:opacity-100 transition shrink-0 mt-0.5">
|
||||||
onclick="event.stopPropagation(); window.TopicsManager.askDeleteTopic('${session.id}', '${escapeHtml(title)}')"
|
<button type="button"
|
||||||
class="opacity-0 group-hover:opacity-100 p-1 text-slate-400 hover:text-rose-600 rounded transition shrink-0"
|
onclick="event.stopPropagation(); window.TopicsManager.openRenameModal('${session.id}', '${escapeHtml(title)}')"
|
||||||
title="Удалить чат">
|
class="p-1 text-slate-400 hover:text-indigo-600 rounded transition"
|
||||||
<i class="fa-solid fa-trash-can text-xs"></i>
|
title="Переименовать тему">
|
||||||
</button>
|
<i class="fa-solid fa-pencil text-xs"></i>
|
||||||
|
</button>
|
||||||
|
<button type="button"
|
||||||
|
onclick="event.stopPropagation(); window.TopicsManager.askDeleteTopic('${session.id}', '${escapeHtml(title)}')"
|
||||||
|
class="p-1 text-slate-400 hover:text-rose-600 rounded transition"
|
||||||
|
title="Удалить чат">
|
||||||
|
<i class="fa-solid fa-trash-can text-xs"></i>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
}).join("");
|
}).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 {
|
return {
|
||||||
init,
|
init,
|
||||||
loadTopics,
|
loadTopics,
|
||||||
getActiveSessionId,
|
getActiveSessionId,
|
||||||
switchTopic,
|
switchTopic,
|
||||||
createNewTopic,
|
createNewTopic,
|
||||||
askDeleteTopic
|
askDeleteTopic,
|
||||||
|
openRenameModal,
|
||||||
|
closeRenameModal,
|
||||||
|
submitRenameModal
|
||||||
};
|
};
|
||||||
})();
|
})();
|
||||||
|
|||||||
@@ -0,0 +1,33 @@
|
|||||||
|
<div id="rename-topic-modal" class="fixed inset-0 bg-slate-900/60 backdrop-blur-xs z-50 flex items-center justify-center p-4 hidden">
|
||||||
|
<div class="bg-white rounded-2xl shadow-2xl border border-slate-200 max-w-sm w-full p-5 flex flex-col gap-3">
|
||||||
|
<div class="flex items-center justify-between">
|
||||||
|
<h3 class="text-xs font-bold text-slate-800 flex items-center gap-2">
|
||||||
|
<i class="fa-solid fa-pencil text-indigo-600"></i>
|
||||||
|
<span>Переименование темы</span>
|
||||||
|
</h3>
|
||||||
|
<button type="button" onclick="window.TopicsManager.closeRenameModal()" class="text-slate-400 hover:text-slate-600 transition">
|
||||||
|
<i class="fa-solid fa-xmark text-sm"></i>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<form id="rename-topic-form" onsubmit="window.TopicsManager.submitRenameModal(event)" class="flex flex-col gap-3">
|
||||||
|
<input type="hidden" id="rename-topic-session-id" value="" />
|
||||||
|
<div>
|
||||||
|
<label class="block text-[11px] font-semibold text-slate-600 mb-1">Название диалога:</label>
|
||||||
|
<input type="text" id="rename-topic-input" required autocomplete="off"
|
||||||
|
class="w-full text-xs px-3 py-2 border border-slate-300 rounded-lg focus:outline-none focus:border-indigo-500 bg-slate-50 text-slate-800" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex items-center justify-end gap-2 pt-2 border-t border-slate-100">
|
||||||
|
<button type="button" onclick="window.TopicsManager.closeRenameModal()"
|
||||||
|
class="px-3 py-1.5 text-xs text-slate-600 hover:bg-slate-100 rounded-lg transition font-medium">
|
||||||
|
Отмена
|
||||||
|
</button>
|
||||||
|
<button type="submit"
|
||||||
|
class="px-3.5 py-1.5 bg-indigo-600 hover:bg-indigo-700 active:bg-indigo-800 text-white rounded-lg text-xs font-bold transition shadow-xs">
|
||||||
|
Сохранить
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
Reference in New Issue
Block a user