@@ -98,7 +88,6 @@ import ChevronRightIcon from 'vue-material-design-icons/ChevronRight.vue';
import ChevronDownIcon from 'vue-material-design-icons/ChevronDown.vue';
import Loading from 'vue-material-design-icons/Loading.vue';
import { ref } from 'vue';
-import path from 'path';
export default {
name: 'WebContentViewer',
@@ -120,6 +109,7 @@ export default {
zipSize: 0,
currentDir: '',
breadcrumbParts: [],
+ cochedFiles: [],
};
},
props: {
@@ -247,6 +237,59 @@ export default {
event.preventDefault();
this.$emit('dragEnded');
},
+ handleCheckboxChange(file, event) {
+ if (event.target.checked) {
+ this.cocheFile(file);
+
+ // Si c'est un dossier, cocher récursivement tous les fichiers enfants
+ if (file.isDirectory && file.children) {
+ this.cocheFilesRecursively(file.children);
+ }
+ } else {
+ this.decocheFile(file);
+
+ // Si c'est un dossier, décocher récursivement tous les fichiers enfants
+ if (file.isDirectory && file.children) {
+ this.decocheFilesRecursively(file.children);
+ }
+ }
+ },
+ getFullPath(file) {
+ if (!file.parentPath || file.parentPath === '') {
+ return file.name;
+ } else {
+ return `${file.parentPath}/${file.name}`;
+ }
+ },
+ cocheFile(file) {
+ if (!this.cochedFiles.some(f => this.getFullPath(f) === this.getFullPath(file))) {
+ this.cochedFiles.push(file);
+ console.log(this.cochedFiles);
+ }
+ },
+ decocheFile(file) {
+ this.cochedFiles = this.cochedFiles.filter(f => this.getFullPath(f) !== this.getFullPath(file));
+ console.log(this.cochedFiles);
+ },
+ cocheFilesRecursively(files) {
+ files.forEach(file => {
+ this.cocheFile(file);
+ if (file.isDirectory && file.children) {
+ this.cocheFilesRecursively(file.children);
+ }
+ });
+ },
+ decocheFilesRecursively(files) {
+ files.forEach(file => {
+ this.decocheFile(file);
+ if (file.isDirectory && file.children) {
+ this.decocheFilesRecursively(file.children);
+ }
+ });
+ },
+ isChecked(file) {
+ return this.cochedFiles.some(f => this.getFullPath(f) === this.getFullPath(file));
+ },
formatFileSize(size) {
if (size < 1024) return `${size} B`;
if (size < 1024 * 1024) return `${(size / 1024).toFixed(2)} KB`;
@@ -274,13 +317,13 @@ export default {
},
async dragZip() {
try {
- const zip = {name: this.zipName, url: this.zipUrl};
+ const zip = { name: this.zipName, url: this.zipUrl };
this.$emit('zip-upload', zip);
} catch (error) {
console.error('Erreur lors du drag du ZIP :', error);
}
},
- async onDragStart(file) {
+ async onDragStart(file, event) {
const getFilesFromFolder = (folder) => {
const files = [];
if (!folder.children || folder.children.length === 0) return files;
@@ -295,18 +338,38 @@ export default {
}
return files;
};
+
+ if (this.cochedFiles.length > 0) {
- try {
- if (file.isDirectory) {
- const files = getFilesFromFolder(file);
- const filesToUnzip = files.map(file => file.unzip);
- await Promise.all(filesToUnzip);
- } else {
- await file.unzip;
+ const folder = {
+ // Si des fichiers sont cochés, utiliser cette liste
+ name: file.name,
+ isDirectory: true,
+ isList: true,
+ children: this.cochedFiles,
+ unzip: Promise.all(this.cochedFiles.map(file => file.unzip))
+ };
+ try {
+ await folder.unzip;
+ this.$emit('file-upload', folder);
+ } catch (error) {
+ console.error('Erreur lors du drag start :', error);
+ }
+
+ } else {
+ // Logique existante pour un seul fichier/dossier
+ try {
+ if (file.isDirectory) {
+ const files = getFilesFromFolder(file);
+ const filesToUnzip = files.map(file => file.unzip);
+ await Promise.all(filesToUnzip);
+ } else {
+ await file.unzip;
+ }
+ this.$emit('file-upload', file);
+ } catch (error) {
+ console.error('Erreur lors du drag start :', error);
}
- this.$emit('file-upload', file);
- } catch (error) {
- console.error('Erreur lors du drag start :', error);
}
},
isVisible(file){
@@ -342,6 +405,44 @@ export default {
isDirectory: true,
};
+ Object.keys(this.folderMap).forEach(key => {
+ this.folderMap[key] = false;
+ });
+ this.toggleFolder(file)
+ },
+ isVisible(file){
+ let parentPath = file.parentPath;
+ if(this.currentDir === parentPath){
+ return true;
+ }
+ else{
+ return false;
+ }
+ },
+ getBreadcrumbParts() {
+ // Si le currentDir est un simple '/', on le renvoie sous forme de tableau vide.
+ if (this.currentDir === '') return [];
+ return this.currentDir.split('/').filter(part => part);
+ },
+ generateCrumbHref(index) {
+ const parts = this.breadcrumbParts.slice(0, index + 1);
+ return parts.join('/');
+ },
+ handleClickBreadcrumb(index) {
+ if (this.isTransfering) return;
+ let dir = '';
+ if (index >= -1) {
+ dir = this.generateCrumbHref(index);
+ }
+ this.currentDir = dir;
+ this.breadcrumbParts = this.getBreadcrumbParts();
+ //console.log('cur : ', this.currentDir)
+ let file = {
+ fullPath : dir,
+ parentPath: this.generateCrumbHref(index -1),
+ isDirectory: true,
+ };
+
Object.keys(this.folderMap).forEach(key => {
this.folderMap[key] = false;
});