transfert cochedList

This commit is contained in:
GMrrc 2024-12-11 15:38:32 +01:00
parent 12a3664654
commit cefedd56cb
2 changed files with 45 additions and 19 deletions

View File

@ -408,6 +408,11 @@ export default {
this.isTransfering = true; this.isTransfering = true;
const file = this.file; const file = this.file;
if (file.isList) {
await this.moveListOfFiles(file);
return;
}
if (!file) return; if (!file) return;
if (file.isDirectory) { if (file.isDirectory) {
await this.moveFilesOfFolder(file, ''); await this.moveFilesOfFolder(file, '');
@ -437,6 +442,18 @@ export default {
} }
this.isDroppable = true; this.isDroppable = true;
}, },
async moveListOfFiles(files) {
for (const file of files) {
if (file.isDirectory) {
await this.moveFilesOfFolder(file, '');
} else {
if (file.content && typeof file.content.arrayBuffer === 'function') {
file.content = await file.content.arrayBuffer();
}
await this.moveFileToTarget(file, '');
}
}
},
async moveFilesOfFolder(folder, parentPath) { async moveFilesOfFolder(folder, parentPath) {
await this.createFolder(folder, parentPath + '/'); await this.createFolder(folder, parentPath + '/');
const checkChildrenInChildren = (folder) => { const checkChildrenInChildren = (folder) => {

View File

@ -18,8 +18,7 @@
<div class="flex items-center"> <div class="flex items-center">
<input type="checkbox" id="checkbox-file" <input type="checkbox" id="checkbox-file"
class="form-checkbox h-5 w-5 text-blue-600 transition duration-150 ease-in-out cursor-pointer" class="form-checkbox h-5 w-5 text-blue-600 transition duration-150 ease-in-out cursor-pointer"
@change="handleCheckboxChange(file, $event)" @change="handleCheckboxChange(file, $event)" :checked="isChecked(file)">
:checked="isChecked(file)">
</div> </div>
@ -52,8 +51,7 @@
<div class="flex items-center"> <div class="flex items-center">
<input type="checkbox" id="checkbox-file" <input type="checkbox" id="checkbox-file"
class="form-checkbox h-5 w-5 text-blue-600 transition duration-150 ease-in-out cursor-pointer" class="form-checkbox h-5 w-5 text-blue-600 transition duration-150 ease-in-out cursor-pointer"
@change="handleCheckboxChange(file, $event)" @change="handleCheckboxChange(file, $event)" :checked="isChecked(file)">
:checked="isChecked(file)">
</div> </div>
<template> <template>
@ -309,29 +307,40 @@ export default {
} }
}, },
async onDragStart(file, event) { async onDragStart(file, event) {
const getFilesFromFolder = (folder) => {
const files = [];
if (!folder.children || folder.children.length === 0) return files;
for (let i = 0; i < folder.children.length; i++) {
const child = folder.children[i];
if (child.isDirectory) {
files.push(...getFilesFromFolder(child));
} else {
files.push(child);
}
}
return files;
};
// Si des fichiers sont cochés, utiliser cette liste // Si des fichiers sont cochés, utiliser cette liste
if (this.cochedFiles.length > 0) { if (this.cochedFiles.length > 0) {
const folder = {
name: file.name,
isDirectory: true,
children: this.cochedFiles,
unzip: Promise.all(this.cochedFiles.map(file => file.unzip))
};
try { try {
console.log('Fichiers cochés :', this.cochedFiles); const files = getFilesFromFolder(folder);
const filesToUnzip = files.map(file => file.unzip);
await Promise.all(filesToUnzip);
this.$emit('file-upload', folder);
} catch (error) { } catch (error) {
console.error('Erreur lors du drag start avec fichiers cochés :', error); console.error('Erreur lors du drag start :', error);
} }
} else { } else {
// Logique existante pour un seul fichier/dossier // Logique existante pour un seul fichier/dossier
const getFilesFromFolder = (folder) => {
const files = [];
if (!folder.children || folder.children.length === 0) return files;
for (let i = 0; i < folder.children.length; i++) {
const child = folder.children[i];
if (child.isDirectory) {
files.push(...getFilesFromFolder(child));
} else {
files.push(child);
}
}
return files;
};
try { try {
if (file.isDirectory) { if (file.isDirectory) {