|
124 | 124 | ::-webkit-scrollbar-thumb:hover { background: rgba(0,0,0,0.3); } |
125 | 125 | .sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.3); } |
126 | 126 | .sidebar::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.5); } |
| 127 | + |
| 128 | + .delete-btn { |
| 129 | + color: rgba(255,255,255,0.6); |
| 130 | + transition: all 0.2s; |
| 131 | + padding: 5px; |
| 132 | + border-radius: 5px; |
| 133 | + } |
| 134 | + .delete-btn:hover { |
| 135 | + color: #ff4d4d; |
| 136 | + background-color: rgba(255, 77, 77, 0.1); |
| 137 | + } |
| 138 | + .pdf-item.active .delete-btn { |
| 139 | + color: rgba(0,0,0,0.3); |
| 140 | + } |
| 141 | + .pdf-item.active .delete-btn:hover { |
| 142 | + color: #ff4d4d; |
| 143 | + background-color: rgba(255, 77, 77, 0.05); |
| 144 | + } |
127 | 145 | </style> |
128 | 146 | </head> |
129 | 147 | <body> |
@@ -154,8 +172,9 @@ <h5 class="mb-3 mt-2"><i class="fas fa-book me-2"></i>My Library</h5> |
154 | 172 | <div id="pdf-list" class="flex-grow-1 overflow-auto pe-2"> |
155 | 173 | {% for doc in documents %} |
156 | 174 | <div class="pdf-item {% if doc.status == 'FAILED' %}border-danger{% endif %}" data-id="{{ doc.id }}" data-status="{{ doc.status }}"> |
157 | | - <div class="d-flex justify-content-between align-items-center"> |
158 | | - <strong class="text-truncate">{{ doc.title }}</strong> |
| 175 | + <div class="d-flex justify-content-between align-items-start"> |
| 176 | + <strong class="text-truncate" style="max-width: 85%;">{{ doc.title }}</strong> |
| 177 | + <i class="fas fa-trash-alt delete-btn" onclick="deleteDocument(event, {{ doc.id }})" title="Delete document"></i> |
159 | 178 | </div> |
160 | 179 | <small class="text-light opacity-75 d-block mt-1"><i class="far fa-clock me-1"></i>{{ doc.uploaded_at|date:"M d, Y H:i" }}</small> |
161 | 180 | <div class="mt-1"> |
@@ -295,6 +314,58 @@ <h5>Welcome to DocuChat!</h5> |
295 | 314 | document.getElementById('query-input').addEventListener('keypress', function(e) { |
296 | 315 | if (e.key === 'Enter') sendMessage(); |
297 | 316 | }); |
| 317 | + |
| 318 | + async function deleteDocument(event, docId) { |
| 319 | + event.stopPropagation(); // Prevent selecting the document when clicking delete |
| 320 | + |
| 321 | + if (!confirm('Are you sure you want to delete this document and its chat history? This action cannot be undone.')) { |
| 322 | + return; |
| 323 | + } |
| 324 | + |
| 325 | + const item = document.querySelector(`.pdf-item[data-id="${docId}"]`); |
| 326 | + const originalOpacity = item.style.opacity; |
| 327 | + item.style.opacity = '0.5'; |
| 328 | + item.style.pointerEvents = 'none'; |
| 329 | + |
| 330 | + try { |
| 331 | + const response = await fetch(`/delete/${docId}/`, { |
| 332 | + method: 'POST', |
| 333 | + headers: { |
| 334 | + 'X-CSRFToken': '{{ csrf_token }}' |
| 335 | + } |
| 336 | + }); |
| 337 | + |
| 338 | + const data = await response.json(); |
| 339 | + |
| 340 | + if (data.success) { |
| 341 | + item.style.transform = 'translateX(-20px)'; |
| 342 | + item.style.opacity = '0'; |
| 343 | + setTimeout(() => { |
| 344 | + item.remove(); |
| 345 | + if (selectedDocId == docId) { |
| 346 | + selectedDocId = null; |
| 347 | + document.getElementById('query-input').disabled = true; |
| 348 | + document.getElementById('send-btn').disabled = true; |
| 349 | + document.getElementById('current-doc-title').innerText = 'Select a document to begin'; |
| 350 | + document.getElementById('chat-messages').innerHTML = ` |
| 351 | + <div class="text-center mt-5 text-muted"> |
| 352 | + <i class="fas fa-comments fa-4x mb-3 opacity-25"></i> |
| 353 | + <h5>Welcome to DocuChat!</h5> |
| 354 | + <p>Select a processed document from the sidebar to ask questions about its content.</p> |
| 355 | + </div>`; |
| 356 | + } |
| 357 | + }, 300); |
| 358 | + } else { |
| 359 | + alert('Error: ' + (data.error || 'Failed to delete document')); |
| 360 | + item.style.opacity = originalOpacity; |
| 361 | + item.style.pointerEvents = 'auto'; |
| 362 | + } |
| 363 | + } catch (error) { |
| 364 | + alert('Connection error. Failed to delete document.'); |
| 365 | + item.style.opacity = originalOpacity; |
| 366 | + item.style.pointerEvents = 'auto'; |
| 367 | + } |
| 368 | + } |
298 | 369 | </script> |
299 | 370 | </body> |
300 | 371 | </html> |
0 commit comments