ajout fonctionalite ecraser et annuler depot
This commit is contained in:
commit
28d6b8d176
1
src/.gitignore
vendored
Normal file
1
src/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
output.css
|
@ -5,12 +5,12 @@
|
||||
<!-- Première section -->
|
||||
<div
|
||||
class="w-full sm:w-1/3 max-sm:h-2/5 p-4 sm:m-6 rounded-xl bg-NcBlack/40">
|
||||
<WebContentViewer @file-upload="handleFileUpload" zipUrl="http://localhost:8000/dummyZip.zip"/>
|
||||
<WebContentViewer @zip-upload="handleZipUpload" @file-upload="handleFileUpload" zipUrl="http://localhost:8000/dummyZip.zip"/>
|
||||
</div>
|
||||
<!-- Deuxième section -->
|
||||
<div
|
||||
class="w-full sm:w-2/3 max-sm:h-3/5 p-4 sm:m-6 bg-NcBlack rounded-xl">
|
||||
<FileTable :file="sharedFile"/>
|
||||
<FileTable :file="sharedFile" :zip="zip"/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -30,12 +30,16 @@ export default {
|
||||
data() {
|
||||
return {
|
||||
sharedFile: null,
|
||||
zip: null,
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
handleFileUpload(file) {
|
||||
this.sharedFile = file;
|
||||
},
|
||||
handleZipUpload(zip) {
|
||||
this.zip = zip;
|
||||
},
|
||||
},
|
||||
}
|
||||
</script>
|
||||
|
1
src/assets/package-x-generic.svg
Normal file
1
src/assets/package-x-generic.svg
Normal file
@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24"><path fill="#969696" d="M5.12,5H18.87L17.93,4H5.93L5.12,5M20.54,5.23C20.83,5.57 21,6 21,6.5V19A2,2 0 0,1 19,21H5A2,2 0 0,1 3,19V6.5C3,6 3.17,5.57 3.46,5.23L4.84,3.55C5.12,3.21 5.53,3 6,3H18C18.47,3 18.88,3.21 19.15,3.55L20.54,5.23M6,18H12V15H6V18Z"/></svg>
|
After Width: | Height: | Size: 339 B |
@ -56,7 +56,8 @@
|
||||
<div :class="[
|
||||
'overflow-y-auto h-full rounded-xl',
|
||||
isDragging ? 'border-green-500 border-4 border-dashed transition-all ease-in-out' : ''
|
||||
]" @drop.prevent="onDrop" @dragover.prevent="onDragOver" @dragenter.prevent @dragleave.prevent="onDragLeave($event)" >
|
||||
]" @drop.prevent="onDrop" @dragover.prevent="onDragOver" @dragenter.prevent
|
||||
@dragleave.prevent="onDragLeave($event)">
|
||||
|
||||
<div v-for="file in files" :key="file.filename"
|
||||
class="flex h-16 items-center hover:bg-NcGray rounded-lg border-b last:border-b-0 border-gray-300"
|
||||
@ -72,7 +73,7 @@
|
||||
</path>
|
||||
</svg>
|
||||
</template>
|
||||
<template v-else>
|
||||
<template v-if="file.type === 'file' && file.basename.split('.').pop() !== 'zip'">
|
||||
<div class="flex items-center justify-center cursor-pointer">
|
||||
<svg viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg" xml:space="preserve"
|
||||
class="w-10 h-10"
|
||||
@ -84,6 +85,12 @@
|
||||
</svg>
|
||||
</div>
|
||||
</template>
|
||||
<template v-if="file.type === 'file' && file.basename.split('.').pop() === 'zip'">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" class="w-10 h-10 ">
|
||||
<path fill="#969696"
|
||||
d="M5.12,5H18.87L17.93,4H5.93L5.12,5M20.54,5.23C20.83,5.57 21,6 21,6.5V19A2,2 0 0,1 19,21H5A2,2 0 0,1 3,19V6.5C3,6 3.17,5.57 3.46,5.23L4.84,3.55C5.12,3.21 5.53,3 6,3H18C18.47,3 18.88,3.21 19.15,3.55L20.54,5.23M6,18H12V15H6V18Z" />
|
||||
</svg>
|
||||
</template>
|
||||
</div>
|
||||
<div class="ml-4 cursor-pointer max-sm:max-w-32 truncate">{{ file.basename }}</div>
|
||||
</div>
|
||||
@ -118,7 +125,8 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<EditFileName v-if="!editDialogDisabled" :initialFileName="initialFileName" :isDirectory="isDirectory" @update="updateFileName" @close="closeEditDialog">
|
||||
<EditFileName v-if="!editDialogDisabled" :initialFileName="initialFileName" :isDirectory="isDirectory"
|
||||
@update="updateFileName" @close="closeEditDialog">
|
||||
</EditFileName>
|
||||
<FileExistsDialog v-if="!fileExistDialogDisabled" :fileName="initialFileName" @overwrite="setOverwrite" @rename="" @cancel="cancelDrop">
|
||||
</FileExistsDialog>
|
||||
@ -128,9 +136,8 @@
|
||||
|
||||
|
||||
<script>
|
||||
import { getClient, getRootPath } from '@nextcloud/files/dav';
|
||||
|
||||
// NextCloud Components
|
||||
import { getClient, getRootPath } from '@nextcloud/files/dav';
|
||||
import NcBreadcrumbs from '@nextcloud/vue/dist/Components/NcBreadcrumbs.js';
|
||||
import NcBreadcrumb from '@nextcloud/vue/dist/Components/NcBreadcrumb.js';
|
||||
import NcActions from '@nextcloud/vue/dist/Components/NcActions.js';
|
||||
@ -165,6 +172,10 @@ export default {
|
||||
type: Object,
|
||||
default: null,
|
||||
},
|
||||
zip: {
|
||||
type: Object,
|
||||
default: null,
|
||||
},
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
@ -177,7 +188,7 @@ export default {
|
||||
isTransfering: false,
|
||||
isDragging: false,
|
||||
editDialogDisabled: true,
|
||||
fileExistDialogDisabled:true,
|
||||
fileExistDialogDisabled: true,
|
||||
initialFileName: '', // Nom originel du fichier/dossier a edite
|
||||
isDirectory: false, // Si l'element a edite est un dossier ou non
|
||||
transferProgress: 0,
|
||||
@ -249,10 +260,10 @@ export default {
|
||||
const client = getClient();
|
||||
let filePath = '';
|
||||
console.log(this.newFileName)
|
||||
if(this.current_dir[this.current_dir.length - 1] === '/') {
|
||||
if (this.current_dir[this.current_dir.length - 1] === '/') {
|
||||
filePath = `${this.root_path}${this.current_dir}${this.newFileName}`;
|
||||
}
|
||||
else{
|
||||
else {
|
||||
filePath = `${this.root_path}${this.current_dir}/${this.newFileName}`;
|
||||
}
|
||||
const alreadyExists = await this.elemtAlreadyExists(filePath);
|
||||
@ -262,7 +273,7 @@ export default {
|
||||
this.isAddFilePopupVisible = false;
|
||||
await this.fetchFiles();
|
||||
}
|
||||
else{
|
||||
else {
|
||||
alert(`Vous ne pouvez pas creer le dossier : ${this.newFileName} car un autre dossier porte deja le meme nom.`);
|
||||
}
|
||||
} catch (error) {
|
||||
@ -293,11 +304,30 @@ export default {
|
||||
this.isDragging = false;
|
||||
this.isTransfering = true;
|
||||
const file = this.file;
|
||||
const zip = this.zip;
|
||||
console.log(file);
|
||||
if (!file) return;
|
||||
console.log(zip);
|
||||
|
||||
|
||||
if (!file && !zip) return;
|
||||
|
||||
if (zip) {
|
||||
const response = await fetch(zip.url);
|
||||
this.transferProgress = 25;
|
||||
if (!response.ok) {
|
||||
throw new Error(`Erreur lors du téléchargement : ${response.statusText}`);
|
||||
}
|
||||
const zipFile = await response.arrayBuffer();
|
||||
this.transferProgress = 50;
|
||||
|
||||
await this.moveFileToTarget({
|
||||
name: zip.name,
|
||||
content: zipFile
|
||||
}, '');
|
||||
this.transferProgress = 100;
|
||||
} else {
|
||||
if (file.isDirectory) {
|
||||
await this.moveFilesOfFolder(file,'');
|
||||
await this.moveFilesOfFolder(file, '');
|
||||
} else {
|
||||
this.transferProgress = 25;
|
||||
if (file.content && typeof file.content.arrayBuffer === 'function') {
|
||||
@ -307,7 +337,7 @@ export default {
|
||||
await this.moveFileToTarget(file, '');
|
||||
this.transferProgress = 100;
|
||||
}
|
||||
|
||||
}
|
||||
this.isTransfering = false;
|
||||
this.transferProgress = 0;
|
||||
this.cancelOperation = false;
|
||||
@ -372,10 +402,10 @@ export default {
|
||||
// Recharge les fichiers après l'opération
|
||||
await this.fetchFiles();
|
||||
}
|
||||
else{
|
||||
else {
|
||||
this.initialFileName = file.name;
|
||||
this.fileExistDialogDisabled = false;
|
||||
while(!this.fileExistDialogDisabled) {
|
||||
while (!this.fileExistDialogDisabled) {
|
||||
await this.sleep(50);
|
||||
}
|
||||
if(!this.cancelOperation){
|
||||
@ -393,14 +423,14 @@ export default {
|
||||
fullPath = `${this.root_path}${this.current_dir}${parentPath}${folder.name}`;
|
||||
|
||||
const alreadyExists = await this.elemtAlreadyExists(fullPath);
|
||||
if(!alreadyExists) {
|
||||
if (!alreadyExists) {
|
||||
await client.createDirectory(fullPath);
|
||||
await this.fetchFiles();
|
||||
}
|
||||
else if(!this.applyToAll){
|
||||
this.initialFileName = folder.name;
|
||||
this.fileExistDialogDisabled = false;
|
||||
while(!this.fileExistDialogDisabled) {
|
||||
while (!this.fileExistDialogDisabled) {
|
||||
await this.sleep();
|
||||
}
|
||||
if(this.overwrite && !this.applyToAll) {
|
||||
@ -411,13 +441,13 @@ export default {
|
||||
console.error('Erreur lors de la création du dossier :', error);
|
||||
}
|
||||
},
|
||||
async deleteElem(file){
|
||||
async deleteElem(file) {
|
||||
const client = getClient()
|
||||
try{
|
||||
try {
|
||||
let path = this.root_path + this.current_dir + "/" + file.basename;
|
||||
await client.deleteFile(path);
|
||||
}
|
||||
catch(error){
|
||||
catch (error) {
|
||||
console.error('Erreur lors de la suppression d\'un element : ', error);
|
||||
}
|
||||
|
||||
@ -428,10 +458,10 @@ export default {
|
||||
* @param file le ficher/dossier dont on veut editer le nom
|
||||
*/
|
||||
async editElem(file) {
|
||||
if(file.type === 'file'){
|
||||
if (file.type === 'file') {
|
||||
this.isDirectory = false;
|
||||
}
|
||||
else{
|
||||
else {
|
||||
this.isDirectory = true;
|
||||
}
|
||||
this.initialFileName = file.basename;
|
||||
@ -450,21 +480,21 @@ export default {
|
||||
* Change le nom du fichier sur le serveur Cloud via un client WebDAV
|
||||
* @param names Contient un initialFileName et un newFileName
|
||||
*/
|
||||
async updateFileName(names){
|
||||
if(names.initialFileName !== names.newFileName){
|
||||
async updateFileName(names) {
|
||||
if (names.initialFileName !== names.newFileName) {
|
||||
const client = getClient()
|
||||
try{
|
||||
try {
|
||||
const oldName = this.root_path + this.current_dir + names.initialFileName;
|
||||
const newName = this.root_path + this.current_dir + names.newFileName;
|
||||
let alreadyExists = await this.elemtAlreadyExists(newName);
|
||||
if(!alreadyExists) {
|
||||
await client.moveFile(oldName,newName);
|
||||
if (!alreadyExists) {
|
||||
await client.moveFile(oldName, newName);
|
||||
}
|
||||
else{
|
||||
else {
|
||||
alert(`Vous ne pouvez pas renommez le fichier/dossier : ${names.newFileName} car un autre fichier/dossier porte deja le meme nom.`);
|
||||
}
|
||||
}
|
||||
catch(error){
|
||||
catch (error) {
|
||||
console.error('Erreur lors du renommage d\'un element : ', error);
|
||||
}
|
||||
await this.fetchFiles();
|
||||
@ -479,7 +509,7 @@ export default {
|
||||
* Check si un fichier ou un dossier existe deja sur le serveur
|
||||
* @param path le chemin du fichier/dossier
|
||||
*/
|
||||
async elemtAlreadyExists(path){
|
||||
async elemtAlreadyExists(path) {
|
||||
const client = getClient();
|
||||
let exists = await client.exists(path);
|
||||
|
||||
|
@ -4,16 +4,30 @@
|
||||
<div class="w-4/6 px-4 py-2 text-gray-500 font-semibold border-r border-gray-300">Nom</div>
|
||||
<div class="w-2/6 px-4 py-2 text-gray-500 font-semibold">Taille</div>
|
||||
</div>
|
||||
|
||||
<div class="flex h-16 hover:bg-NcGray items-center pl-4 cursor-pointer rounded-lg border-b last:border-b-0 border-gray-300" v-if="!isLoading"
|
||||
draggable="true" @dragstart="dragZip()">
|
||||
<template>
|
||||
<div class="flex items-center justify-center cursor-pointer">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" class="w-10 h-10 ">
|
||||
<path fill="#969696" d="M5.12,5H18.87L17.93,4H5.93L5.12,5M20.54,5.23C20.83,5.57 21,6 21,6.5V19A2,2 0 0,1 19,21H5A2,2 0 0,1 3,19V6.5C3,6 3.17,5.57 3.46,5.23L4.84,3.55C5.12,3.21 5.53,3 6,3H18C18.47,3 18.88,3.21 19.15,3.55L20.54,5.23M6,18H12V15H6V18Z"/>
|
||||
</svg>
|
||||
</div>
|
||||
</template>
|
||||
<div class="w-4/6 flex items-center px-4 py-2 cursor-pointer">
|
||||
<div class="truncate max-sm:max-w-32 max-w-64 cursor-pointer">{{ zipName }}</div>
|
||||
|
||||
</div>
|
||||
<div class="w-2/6 py-2 cursor-pointer">
|
||||
{{ formatFileSize(zipSize) }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="!isLoading && zipContent.length !== 0" class="overflow-y-auto h-full">
|
||||
<div v-for="(file, index) in sortedFiles" :key="file.fullPath" class="flex flex-col">
|
||||
|
||||
<div
|
||||
class="flex h-16 hover:bg-NcGray items-center pl-4 cursor-pointer rounded-lg border-b last:border-b-0 border-gray-300"
|
||||
@click="toggleFolder(file)"
|
||||
v-if="file.isDirectory"
|
||||
draggable="true"
|
||||
@dragstart="onDragStart(file)"
|
||||
>
|
||||
<div class="flex h-16 hover:bg-NcGray items-center pl-4 cursor-pointer rounded-lg border-b last:border-b-0 border-gray-300"
|
||||
@click="toggleFolder(file)" v-if="file.isDirectory" draggable="true" @dragstart="onDragStart(file)">
|
||||
<div class="w-4/6 flex items-center py-2 border-r border-gray-300 cursor-pointer">
|
||||
<div class="w-12 h-12 flex items-center justify-center cursor-pointer">
|
||||
<template>
|
||||
@ -27,10 +41,8 @@
|
||||
<div class="w-4/6 flex items-center py-2 border-r border-gray-300 cursor-pointer">
|
||||
<!-- Icône dynamique pour plié/déplié -->
|
||||
<div class="w-12 h-12 flex items-center justify-center cursor-pointer">
|
||||
<component
|
||||
:is="folderMap[file.fullPath] ? ChevronDownIcon : ChevronRightIcon"
|
||||
class="text-NcBlue w-6 h-6"
|
||||
/>
|
||||
<component :is="folderMap[file.fullPath] ? ChevronDownIcon : ChevronRightIcon"
|
||||
class="text-NcBlue w-6 h-6" />
|
||||
</div>
|
||||
<span class="ml-2 truncate cursor-pointer">{{ file.name }}</span>
|
||||
</div>
|
||||
@ -38,12 +50,8 @@
|
||||
<div class="w-1/6 px-4 py-2 cursor-pointer">-</div>
|
||||
</div>
|
||||
|
||||
<div
|
||||
class="flex h-16 hover:bg-NcGray items-center pl-4 cursor-pointer rounded-lg border-b last:border-b-0 border-gray-300"
|
||||
v-else
|
||||
draggable="true"
|
||||
@dragstart="onDragStart(file, $event)"
|
||||
>
|
||||
<div class="flex h-16 hover:bg-NcGray items-center pl-4 cursor-pointer rounded-lg border-b last:border-b-0 border-gray-300"
|
||||
v-else draggable="true" @dragstart="onDragStart(file, $event)">
|
||||
<template>
|
||||
<div class="flex items-center justify-center cursor-pointer">
|
||||
<svg viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg" xml:space="preserve"
|
||||
@ -56,7 +64,7 @@
|
||||
</div>
|
||||
</template>
|
||||
<div class="w-4/6 flex items-center px-4 py-2 cursor-pointer">
|
||||
<div class="truncate max-sm:max-w-32 max-w-64">{{ file.name }}</div>
|
||||
<div class="truncate max-sm:max-w-32 max-w-64 cursor-pointer">{{ file.name }}</div>
|
||||
|
||||
</div>
|
||||
<div class="w-2/6 py-2 cursor-pointer">
|
||||
@ -67,7 +75,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="isLoading" class="flex h-full items-center justify-center">
|
||||
<component :is="Loading" class="text-white w-24 h-24 animate-spin" :size="40"/>
|
||||
<component :is="Loading" class="text-white w-24 h-24 animate-spin" :size="40" />
|
||||
</div>
|
||||
<div v-if="!isLoading && zipContent.length === 0" class="flex h-full items-center justify-center">
|
||||
<span class="text-gray-500">Aucun contenu à afficher</span>
|
||||
@ -94,6 +102,8 @@ export default {
|
||||
ChevronDownIcon,
|
||||
isLoading: ref(false),
|
||||
Loading,
|
||||
zipName: '',
|
||||
zipSize: 0,
|
||||
};
|
||||
},
|
||||
props: {
|
||||
@ -146,7 +156,9 @@ export default {
|
||||
try {
|
||||
const response = await fetch(this.zipUrl);
|
||||
const zipData = await response.blob();
|
||||
this.zipName = this.zipUrl.split('/').pop();
|
||||
const zip = await JSZip.loadAsync(zipData);
|
||||
this.zipSize = zipData.size;
|
||||
|
||||
const files = [];
|
||||
|
||||
@ -219,6 +231,14 @@ export default {
|
||||
const currentState = this.folderMap[file.fullPath];
|
||||
this.$set(this.folderMap, file.fullPath, !currentState);
|
||||
},
|
||||
async dragZip() {
|
||||
try {
|
||||
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) {
|
||||
|
||||
const getFilesFromFolder = (folder) => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user