diff --git a/static/js/rooms/fileManager.js b/static/js/rooms/fileManager.js index 034f0f9..441b525 100644 --- a/static/js/rooms/fileManager.js +++ b/static/js/rooms/fileManager.js @@ -44,35 +44,49 @@ export class FileManager { } } - async deleteFile(fileId) { - console.log('[FileManager] Deleting file:', fileId); + async deleteFile(filename, path = '') { + console.log('[FileManager] Deleting file:', { filename, path }); + const csrfToken = document.querySelector('meta[name="csrf-token"]').getAttribute('content'); + try { - const response = await fetch(`/api/rooms/${this.roomManager.roomId}/files/${fileId}`, { + let url = `/api/rooms/${this.roomManager.roomId}/files/${encodeURIComponent(filename)}`; + if (path) { + url += `?path=${encodeURIComponent(path)}`; + } + + const response = await fetch(url, { method: 'DELETE', headers: { - 'X-CSRF-Token': document.querySelector('meta[name="csrf-token"]').getAttribute('content') + 'X-CSRFToken': csrfToken } }); - console.log('[FileManager] Delete response status:', response.status); if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } const result = await response.json(); - console.log('[FileManager] Delete result:', result); - if (result.success) { - this.currentFiles = this.currentFiles.filter(file => file.id !== fileId); - await this.roomManager.viewManager.renderFiles(this.currentFiles); - console.log('[FileManager] File deleted and view updated'); - return { success: true, message: 'File moved to trash' }; + console.log('[FileManager] File deleted successfully'); + await this.fetchFiles(); + // Clear any existing error message + const errorEl = document.getElementById('fileError'); + if (errorEl) { + errorEl.textContent = ''; + } } else { - throw new Error(result.message || 'Failed to delete file'); + console.error('[FileManager] Failed to delete file:', result.error); + const errorEl = document.getElementById('fileError'); + if (errorEl) { + errorEl.textContent = result.error || 'Failed to delete file.'; + } } } catch (error) { console.error('[FileManager] Error deleting file:', error); - return { success: false, message: error.message }; + const errorEl = document.getElementById('fileError'); + if (errorEl) { + errorEl.textContent = 'Failed to delete file. Please try again.'; + } } } diff --git a/static/js/rooms/modalManager.js b/static/js/rooms/modalManager.js index 6944510..a01dc2e 100644 --- a/static/js/rooms/modalManager.js +++ b/static/js/rooms/modalManager.js @@ -56,12 +56,29 @@ export class ModalManager { } showDeleteModal(filename, path = '') { + console.log('[ModalManager] Showing delete modal for:', { filename, path }); const fileNameEl = document.getElementById('deleteFileName'); const labelEl = document.getElementById('deleteConfirmLabel'); + const confirmBtn = document.getElementById('confirmDeleteBtn'); if (fileNameEl) fileNameEl.textContent = filename; if (labelEl) labelEl.textContent = 'Move to Trash'; + // Store the file info in the FileManager + this.roomManager.fileManager.fileToDelete = { + name: filename, + path: path + }; + + // Set up the confirm button click handler + if (confirmBtn) { + confirmBtn.onclick = () => { + console.log('[ModalManager] Delete confirmed for:', { filename, path }); + this.roomManager.fileManager.deleteFile(filename, path); + this.deleteModal.hide(); + }; + } + this.deleteModal.show(); } diff --git a/static/js/rooms/room.js b/static/js/rooms/room.js index b92263c..6d94432 100644 --- a/static/js/rooms/room.js +++ b/static/js/rooms/room.js @@ -49,6 +49,9 @@ class RoomManager { await this.fileManager.fetchFiles(); console.log('[RoomManager] Files fetched'); + // Render breadcrumb after files are fetched + this.viewManager.renderBreadcrumb(); + console.log('[RoomManager] Initializing search...'); // Initialize search this.searchManager.initialize(); @@ -65,11 +68,42 @@ class RoomManager { } } + navigateToFolder(folderName) { + console.log('[RoomManager] Navigating to folder:', folderName); + const newPath = this.currentPath ? `${this.currentPath}/${folderName}` : folderName; + this.navigateTo(newPath); + } + + navigateToParent() { + console.log('[RoomManager] Navigating to parent folder'); + if (!this.currentPath) return; + + const parts = this.currentPath.split('/'); + parts.pop(); // Remove the last part + const newPath = parts.join('/'); + this.navigateTo(newPath); + } + + navigateTo(path) { + console.log('[RoomManager] Navigating to path:', path); + this.currentPath = path; + // Update the URL with the current path + const url = new URL(window.location); + if (this.currentPath) { + url.searchParams.set('path', this.currentPath); + } else { + url.searchParams.delete('path'); + } + window.history.replaceState({}, '', url); + this.fileManager.fetchFiles().then(() => { + // Render breadcrumb after files are fetched + this.viewManager.renderBreadcrumb(); + }); + } + getPathFromUrl() { const urlParams = new URLSearchParams(window.location.search); - const path = urlParams.get('path') || ''; - console.log('[RoomManager] Getting path from URL:', path); - return path; + return urlParams.get('path') || ''; } initializeEventListeners() { @@ -117,54 +151,18 @@ class RoomManager { } } -// Initialize the room manager when the script loads -function initializeRoom() { - console.log('[RoomManager] Starting room initialization...'); +// Initialize the room manager when the DOM is loaded +document.addEventListener('DOMContentLoaded', () => { + const config = { + roomId: document.querySelector('meta[name="room-id"]').getAttribute('content'), + canDelete: document.querySelector('meta[name="can-delete"]').getAttribute('content') === 'true', + canShare: document.querySelector('meta[name="can-share"]').getAttribute('content') === 'true', + canUpload: document.querySelector('meta[name="can-upload"]').getAttribute('content') === 'true', + canDownload: document.querySelector('meta[name="can-download"]').getAttribute('content') === 'true', + canRename: document.querySelector('meta[name="can-rename"]').getAttribute('content') === 'true', + canMove: document.querySelector('meta[name="can-move"]').getAttribute('content') === 'true' + }; - try { - // Wait for all meta tags to be available - const requiredMetaTags = [ - 'room-id', - 'can-delete', - 'can-share', - 'can-upload', - 'can-download', - 'can-rename', - 'can-move' - ]; - - console.log('[RoomManager] Checking required meta tags...'); - const missingTags = requiredMetaTags.filter(tag => !document.querySelector(`meta[name="${tag}"]`)); - - if (missingTags.length > 0) { - console.error('[RoomManager] Missing required meta tags:', missingTags); - return; - } - - console.log('[RoomManager] All meta tags found, creating config...'); - const config = { - roomId: document.querySelector('meta[name="room-id"]').getAttribute('content'), - canDelete: document.querySelector('meta[name="can-delete"]').getAttribute('content') === 'true', - canShare: document.querySelector('meta[name="can-share"]').getAttribute('content') === 'true', - canUpload: document.querySelector('meta[name="can-upload"]').getAttribute('content') === 'true', - canDownload: document.querySelector('meta[name="can-download"]').getAttribute('content') === 'true', - canRename: document.querySelector('meta[name="can-rename"]').getAttribute('content') === 'true', - canMove: document.querySelector('meta[name="can-move"]').getAttribute('content') === 'true' - }; - - console.log('[RoomManager] Config created:', config); - window.roomManager = new RoomManager(config); - } catch (error) { - console.error('[RoomManager] Error during initialization:', error); - } -} - -// Wait for DOM to be fully loaded -if (document.readyState === 'loading') { - console.log('[RoomManager] DOM still loading, waiting for DOMContentLoaded...'); - document.addEventListener('DOMContentLoaded', initializeRoom); -} else { - console.log('[RoomManager] DOM already loaded, initializing with delay...'); - // If DOM is already loaded, wait a bit to ensure all scripts are loaded - setTimeout(initializeRoom, 0); -} \ No newline at end of file + // Create and expose the room manager instance + window.roomManager = new RoomManager(config); +}); \ No newline at end of file diff --git a/static/js/rooms/viewManager.js b/static/js/rooms/viewManager.js index a40d5f8..98beef7 100644 --- a/static/js/rooms/viewManager.js +++ b/static/js/rooms/viewManager.js @@ -89,24 +89,35 @@ export class ViewManager { const upBtn = document.getElementById('upBtn'); const path = this.roomManager.currentPath; + // Always show the root node + let html = ` + + + + + + `; + if (!path) { - console.log('[ViewManager] No path, hiding breadcrumb'); - breadcrumb.innerHTML = ''; + console.log('[ViewManager] No path, showing only root'); + breadcrumb.innerHTML = html; upBtn.style.display = 'none'; return; } console.log('[ViewManager] Building breadcrumb for path:', path); const parts = path.split('/').filter(Boolean); - let html = ''; let currentPath = ''; parts.forEach((part, index) => { currentPath += '/' + part; html += ` - ${index > 0 ? '' : ''} - + + ${part} @@ -115,6 +126,17 @@ export class ViewManager { breadcrumb.innerHTML = html; upBtn.style.display = 'inline-block'; + upBtn.onclick = () => this.roomManager.navigateToParent(); + upBtn.style.color = 'var(--primary-color)'; + upBtn.style.borderColor = 'var(--primary-color)'; + upBtn.onmouseover = () => { + upBtn.style.backgroundColor = 'var(--primary-color)'; + upBtn.style.color = 'white'; + }; + upBtn.onmouseout = () => { + upBtn.style.backgroundColor = 'transparent'; + upBtn.style.color = 'var(--primary-color)'; + }; console.log('[ViewManager] Breadcrumb rendered'); } @@ -179,7 +201,9 @@ export class ViewManager { const modified = new Date(file.modified).toLocaleString(); return ` -