fix file batch deletion
This commit is contained in:
@@ -227,6 +227,16 @@ export class FileManager {
|
||||
return;
|
||||
}
|
||||
|
||||
// Filter out folders and get only file IDs
|
||||
const fileIds = selectedItems
|
||||
.filter(item => item.type !== 'folder')
|
||||
.map(item => item.id);
|
||||
|
||||
if (fileIds.length === 0) {
|
||||
console.log('[FileManager] No files to download (only folders selected)');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch(`/api/rooms/${this.roomManager.roomId}/files/download`, {
|
||||
method: 'POST',
|
||||
@@ -234,7 +244,7 @@ export class FileManager {
|
||||
'Content-Type': 'application/json',
|
||||
'X-CSRF-Token': document.querySelector('meta[name="csrf-token"]').getAttribute('content')
|
||||
},
|
||||
body: JSON.stringify({ file_ids: selectedItems.map(item => item.id) })
|
||||
body: JSON.stringify({ file_ids: fileIds })
|
||||
});
|
||||
console.log('[FileManager] Download response status:', response.status);
|
||||
|
||||
@@ -256,6 +266,7 @@ export class FileManager {
|
||||
console.log('[FileManager] Download initiated');
|
||||
} catch (error) {
|
||||
console.error('[FileManager] Error downloading files:', error);
|
||||
document.getElementById('fileError').textContent = 'Failed to download files. Please try again.';
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
@@ -322,14 +333,63 @@ export class FileManager {
|
||||
}
|
||||
}
|
||||
|
||||
updateSelection(index, event) {
|
||||
console.log('[FileManager] Updating selection:', { index, event });
|
||||
|
||||
// Prevent selection if clicking on a checkbox or action button
|
||||
if (event.target.classList.contains('select-item-checkbox') || event.target.closest('.file-action-btn')) {
|
||||
return;
|
||||
}
|
||||
|
||||
const checkboxes = document.querySelectorAll('.select-item-checkbox');
|
||||
const checkbox = checkboxes[index];
|
||||
if (!checkbox) return;
|
||||
|
||||
if (event.ctrlKey) {
|
||||
// CTRL + Click: Toggle individual selection
|
||||
checkbox.checked = !checkbox.checked;
|
||||
if (checkbox.checked) {
|
||||
this.selectedItems.add(index);
|
||||
} else {
|
||||
this.selectedItems.delete(index);
|
||||
}
|
||||
} else if (event.shiftKey && this.lastSelectedIndex !== -1) {
|
||||
// SHIFT + Click: Select range
|
||||
const start = Math.min(this.lastSelectedIndex, index);
|
||||
const end = Math.max(this.lastSelectedIndex, index);
|
||||
for (let i = start; i <= end; i++) {
|
||||
checkboxes[i].checked = true;
|
||||
this.selectedItems.add(i);
|
||||
}
|
||||
} else {
|
||||
// Normal click: Select single item
|
||||
const wasChecked = checkbox.checked;
|
||||
checkboxes.forEach(cb => {
|
||||
cb.checked = false;
|
||||
this.selectedItems.delete(parseInt(cb.dataset.index));
|
||||
});
|
||||
checkbox.checked = !wasChecked;
|
||||
if (!wasChecked) {
|
||||
this.selectedItems.add(index);
|
||||
}
|
||||
}
|
||||
|
||||
this.lastSelectedIndex = index;
|
||||
this.roomManager.viewManager.updateMultiSelectUI();
|
||||
}
|
||||
|
||||
getSelectedItems() {
|
||||
console.log('[FileManager] Getting selected items');
|
||||
return Array.from(this.selectedItems).map(index => this.currentFiles[index]);
|
||||
}
|
||||
|
||||
updateSelection(index, event) {
|
||||
console.log('[FileManager] Updating selection:', { index, event });
|
||||
// Implementation of selection logic
|
||||
clearSelection() {
|
||||
console.log('[FileManager] Clearing selection');
|
||||
this.selectedItems.clear();
|
||||
this.lastSelectedIndex = -1;
|
||||
const checkboxes = document.querySelectorAll('.select-item-checkbox');
|
||||
checkboxes.forEach(cb => cb.checked = false);
|
||||
this.roomManager.viewManager.updateMultiSelectUI();
|
||||
}
|
||||
|
||||
navigateToParent() {
|
||||
|
||||
Reference in New Issue
Block a user