This commit is contained in:
2025-05-28 12:32:40 +02:00
parent ef4b4ab39f
commit d77dcec068
3 changed files with 125 additions and 16 deletions

View File

@@ -8,6 +8,8 @@ export class FileManager {
this.batchDeleteItems = null; this.batchDeleteItems = null;
this.fileToDelete = null; this.fileToDelete = null;
this.fileToDeletePath = ''; this.fileToDeletePath = '';
this.fileToMove = null;
this.fileToMovePath = '';
console.log('[FileManager] Initialized with roomManager:', roomManager); console.log('[FileManager] Initialized with roomManager:', roomManager);
} }
@@ -112,38 +114,135 @@ export class FileManager {
} }
async moveFile(fileId, targetPath) { async moveFile(fileId, targetPath) {
console.log('[FileManager] Moving file:', { fileId, targetPath }); console.log('[FileManager] Starting moveFile...');
console.log('[FileManager] Parameters:', { fileId, targetPath });
try { try {
const response = await fetch(`/api/rooms/${this.roomManager.roomId}/files/${fileId}/move`, { const file = this.currentFiles.find(f => f.id === fileId);
console.log('[FileManager] Found file to move:', file);
if (!file) {
console.error('[FileManager] File not found with ID:', fileId);
throw new Error('File not found');
}
console.log('[FileManager] Sending move request...');
const response = await fetch(`/api/rooms/${this.roomManager.roomId}/move`, {
method: 'POST', method: 'POST',
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
'X-CSRF-Token': document.querySelector('meta[name="csrf-token"]').getAttribute('content') 'X-CSRF-Token': document.querySelector('meta[name="csrf-token"]').getAttribute('content')
}, },
body: JSON.stringify({ target_path: targetPath }) body: JSON.stringify({
filename: file.name,
source_path: file.path || '',
target_path: targetPath
})
}); });
console.log('[FileManager] Move response status:', response.status); console.log('[FileManager] Move response status:', response.status);
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const result = await response.json(); const result = await response.json();
console.log('[FileManager] Move result:', result); console.log('[FileManager] Move response data:', result);
if (result.success) { if (result.success) {
this.currentFiles = this.currentFiles.filter(file => file.id !== fileId); console.log('[FileManager] Move successful, updating view...');
this.currentFiles = this.currentFiles.filter(f => f.id !== fileId);
await this.roomManager.viewManager.renderFiles(this.currentFiles); await this.roomManager.viewManager.renderFiles(this.currentFiles);
console.log('[FileManager] File moved and view updated'); console.log('[FileManager] View updated after move');
return { success: true, message: 'File moved successfully' }; return { success: true, message: 'File moved successfully' };
} else { } else {
console.error('[FileManager] Move failed:', result.message);
throw new Error(result.message || 'Failed to move file'); throw new Error(result.message || 'Failed to move file');
} }
} catch (error) { } catch (error) {
console.error('[FileManager] Error moving file:', error); console.error('[FileManager] Error in moveFile:', error);
console.error('[FileManager] Error details:', {
message: error.message,
stack: error.stack
});
return { success: false, message: error.message }; return { success: false, message: error.message };
} }
} }
async moveFileConfirmed() {
console.log('[FileManager] Starting moveFileConfirmed...');
console.log('[FileManager] Current state:', {
fileToMove: this.fileToMove,
fileToMovePath: this.fileToMovePath,
currentFiles: this.currentFiles
});
if (!this.fileToMove) {
console.error('[FileManager] No file selected for move operation');
document.getElementById('moveError').textContent = 'No file selected for move.';
return;
}
const targetPath = document.getElementById('moveTargetFolder').value;
console.log('[FileManager] Selected target path:', targetPath);
const csrfToken = document.querySelector('meta[name="csrf-token"]').getAttribute('content');
console.log('[FileManager] CSRF Token:', csrfToken ? 'Present' : 'Missing');
// Get the file from currentFiles using the filename
console.log('[FileManager] Attempting to find file with name:', this.fileToMove);
const file = this.currentFiles.find(f => f.name === this.fileToMove);
console.log('[FileManager] Found file:', file);
if (!file) {
console.error('[FileManager] File not found in currentFiles. Available files:', this.currentFiles);
document.getElementById('moveError').textContent = 'File not found.';
return;
}
console.log('[FileManager] Preparing move request with data:', {
filename: file.name,
source_path: this.fileToMovePath,
target_path: targetPath
});
try {
const url = `/api/rooms/${this.roomManager.roomId}/move`;
console.log('[FileManager] Sending request to:', url);
const response = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-CSRFToken': csrfToken
},
body: JSON.stringify({
filename: file.name,
source_path: this.fileToMovePath,
target_path: targetPath
})
});
console.log('[FileManager] Response status:', response.status);
const result = await response.json();
console.log('[FileManager] Response data:', result);
if (result.success) {
console.log('[FileManager] Move successful, refreshing files...');
await this.fetchFiles();
this.fileToMove = null;
this.fileToMovePath = '';
this.roomManager.modalManager.moveModal.hide();
document.getElementById('moveError').textContent = '';
console.log('[FileManager] Move operation completed successfully');
} else {
console.error('[FileManager] Move failed:', result.error);
document.getElementById('moveError').textContent = result.error || 'Move failed.';
}
} catch (error) {
console.error('[FileManager] Error during move operation:', error);
console.error('[FileManager] Error details:', {
message: error.message,
stack: error.stack
});
document.getElementById('moveError').textContent = 'Move failed.';
}
}
async toggleStar(filename, path) { async toggleStar(filename, path) {
console.log('[FileManager] Toggling star for:', filename, 'path:', path); console.log('[FileManager] Toggling star for:', filename, 'path:', path);

View File

@@ -189,12 +189,21 @@ export class ModalManager {
}); });
} }
showMoveModal(filename, path) { showMoveModal(fileId, path) {
console.log('[ModalManager] Showing move modal for file:', { fileId, path });
document.getElementById('moveError').textContent = ''; document.getElementById('moveError').textContent = '';
// Set the file to move in the FileManager
this.roomManager.fileManager.fileToMove = fileId;
this.roomManager.fileManager.fileToMovePath = path;
console.log('[ModalManager] Set fileToMove:', this.roomManager.fileManager.fileToMove);
console.log('[ModalManager] Set fileToMovePath:', this.roomManager.fileManager.fileToMovePath);
fetch(`/api/rooms/${this.roomManager.roomId}/folders`) fetch(`/api/rooms/${this.roomManager.roomId}/folders`)
.then(r => r.json()) .then(r => r.json())
.then(folders => { .then(folders => {
console.log('[ModalManager] Fetched folders:', folders);
const select = document.getElementById('moveTargetFolder'); const select = document.getElementById('moveTargetFolder');
select.innerHTML = '<option value="">Root Folder</option>'; select.innerHTML = '<option value="">Root Folder</option>';
@@ -216,11 +225,12 @@ export class ModalManager {
select.innerHTML += `<option value="${folderPath}">${indent}${displayName}</option>`; select.innerHTML += `<option value="${folderPath}">${indent}${displayName}</option>`;
}); });
console.log('[ModalManager] Showing move modal');
this.moveModal.show(); this.moveModal.show();
}) })
.catch(error => { .catch(error => {
document.getElementById('moveError').textContent = 'Failed to load folders.'; console.error('[ModalManager] Error fetching folders:', error);
console.error('Error loading folders:', error); document.getElementById('moveError').textContent = 'Failed to load folders. Please try again.';
}); });
} }

View File

@@ -266,7 +266,7 @@ export class ViewManager {
if (this.roomManager.canMove) { if (this.roomManager.canMove) {
actions.push(` actions.push(`
<button class="btn btn-sm file-action-btn" title="Move" onclick="window.roomManager.modalManager.showMoveModal('${file.id}')" <button class="btn btn-sm file-action-btn" title="Move" onclick="window.roomManager.modalManager.showMoveModal('${file.name}', '${file.path || ''}')"
style="background-color:var(--primary-opacity-8);color:var(--primary-color);"> style="background-color:var(--primary-opacity-8);color:var(--primary-color);">
<i class="fas fa-arrows-alt"></i> <i class="fas fa-arrows-alt"></i>
</button> </button>