diff --git a/routes/__pycache__/main.cpython-313.pyc b/routes/__pycache__/main.cpython-313.pyc index 48f270d..249de6a 100644 Binary files a/routes/__pycache__/main.cpython-313.pyc and b/routes/__pycache__/main.cpython-313.pyc differ diff --git a/routes/__pycache__/room_files.cpython-313.pyc b/routes/__pycache__/room_files.cpython-313.pyc index d4ac50d..4e92dc2 100644 Binary files a/routes/__pycache__/room_files.cpython-313.pyc and b/routes/__pycache__/room_files.cpython-313.pyc differ diff --git a/routes/room_files.py b/routes/room_files.py index a836d0b..72849b0 100644 --- a/routes/room_files.py +++ b/routes/room_files.py @@ -557,32 +557,49 @@ def download_zip(room_id): @login_required def search_room_files(room_id): """ - Search for files in a room by name. + Search for files in a room by name, including files in subfolders. Args: room_id (int): ID of the room to search in Returns: - JSON response containing matching files + JSON response containing matching files with their full paths """ room = Room.query.get_or_404(room_id) if not user_has_permission(room, 'can_view'): abort(403) query = request.args.get('query', '').strip().lower() + # Search RoomFile for this room - files = RoomFile.query.filter(RoomFile.room_id==room_id).all() + files = RoomFile.query.filter(RoomFile.room_id==room_id, RoomFile.deleted==False).all() matches = [] + for f in files: - if query in f.name.lower(): + # Create full path by combining folder path and filename + full_path = f"{f.path}/{f.name}" if f.path else f.name + + if query in f.name.lower() or query in full_path.lower(): + uploader_full_name = None + uploader_profile_pic = None + if f.uploader: + uploader_full_name = f.uploader.username + if getattr(f.uploader, 'last_name', None): + uploader_full_name += ' ' + f.uploader.last_name + uploader_profile_pic = f.uploader.profile_picture if getattr(f.uploader, 'profile_picture', None) else None + matches.append({ 'name': f.name, 'type': f.type, 'size': f.size if f.type == 'file' else '-', 'modified': f.modified, - 'uploaded_by': f.uploader.username if f.uploader else None, + 'uploaded_by': uploader_full_name, + 'uploader_profile_pic': uploader_profile_pic, 'uploaded_at': f.uploaded_at.isoformat() if f.uploaded_at else None, 'path': f.path, + 'full_path': full_path, # Add full path to the response + 'starred': current_user in f.starred_by }) + return jsonify(matches) @room_files_bp.route('//move', methods=['POST']) diff --git a/static/js/rooms/searchManager.js b/static/js/rooms/searchManager.js index 2da39b1..f72aa74 100644 --- a/static/js/rooms/searchManager.js +++ b/static/js/rooms/searchManager.js @@ -22,6 +22,7 @@ export class SearchManager { this.roomManager = roomManager; this.searchInput = document.getElementById('quickSearchInput'); this.clearSearchBtn = document.getElementById('clearSearchBtn'); + this.isSearching = false; } /** @@ -35,9 +36,11 @@ export class SearchManager { // Create debounced search function const debouncedSearch = this.debounce((searchTerm) => { if (searchTerm) { + this.isSearching = true; this.performSearch(searchTerm); this.clearSearchBtn.style.display = 'block'; } else { + this.isSearching = false; this.roomManager.fileManager.fetchFiles(); // Reset to show all files this.clearSearchBtn.style.display = 'none'; } @@ -53,6 +56,7 @@ export class SearchManager { if (this.clearSearchBtn) { this.clearSearchBtn.addEventListener('click', () => { this.searchInput.value = ''; + this.isSearching = false; this.roomManager.fileManager.fetchFiles(); // Reset to show all files this.clearSearchBtn.style.display = 'none'; }); @@ -60,20 +64,25 @@ export class SearchManager { } /** - * Performs the search operation on the current file list. - * Filters files based on name and type matching the search term. + * Performs the search operation using the server-side search endpoint. * @param {string} searchTerm - The term to search for */ performSearch(searchTerm) { - if (!this.roomManager.fileManager.currentFiles) return; - - const filteredFiles = this.roomManager.fileManager.currentFiles.filter(file => { - const searchLower = searchTerm.toLowerCase(); - return file.name.toLowerCase().includes(searchLower) || - (file.type && file.type.toLowerCase().includes(searchLower)); - }); - - this.roomManager.viewManager.renderFiles(filteredFiles); + // Fetch all files from the server for searching + fetch(`/api/rooms/${this.roomManager.roomId}/search?query=${encodeURIComponent(searchTerm)}`) + .then(response => response.json()) + .then(files => { + // Modify the file objects to show full paths in search results + const modifiedFiles = files.map(file => ({ + ...file, + displayName: this.isSearching ? file.full_path : file.name + })); + + this.roomManager.viewManager.renderFiles(modifiedFiles); + }) + .catch(error => { + console.error('Error performing search:', error); + }); } /** diff --git a/static/js/rooms/viewManager.js b/static/js/rooms/viewManager.js index 8253353..2b33d2e 100644 --- a/static/js/rooms/viewManager.js +++ b/static/js/rooms/viewManager.js @@ -255,6 +255,11 @@ export class ViewManager { const size = isFolder ? '-' : this.formatFileSize(file.size); const modified = new Date(file.modified).toLocaleString(); + // Create file name element + const name = document.createElement('span'); + name.className = 'file-name'; + name.textContent = file.displayName || file.name; + return ` - ${file.name} + ${name.outerHTML} ${size} ${modified} @@ -294,6 +299,11 @@ export class ViewManager { const size = isFolder ? '-' : this.formatFileSize(file.size); const modified = new Date(file.modified).toLocaleString(); + // Create file name element + const name = document.createElement('span'); + name.className = 'file-name'; + name.textContent = file.displayName || file.name; + return `
-
${file.name}
+
${name.outerHTML}
${modified}
${size}