ajout favoris et probleme dragend resolu
This commit is contained in:
parent
8f580aa924
commit
f62cbf4941
@ -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 @zip-upload="handleZipUpload" @file-upload="handleFileUpload" zipUrl="http://localhost:8000/dummyZip.zip"/>
|
||||
<WebContentViewer @zip-upload="handleZipUpload" @file-upload="handleFileUpload" @dragEnded="toggleDragEnded" 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" :zip="zip"/>
|
||||
<FileTable :file="sharedFile" :zip="zip" :dragEnded="dragEnded" @dragEnded="toggleDragEnded"/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -31,6 +31,7 @@ export default {
|
||||
return {
|
||||
sharedFile: null,
|
||||
zip: null,
|
||||
dragEnded: false,
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
@ -40,6 +41,9 @@ export default {
|
||||
handleZipUpload(zip) {
|
||||
this.zip = zip;
|
||||
},
|
||||
toggleDragEnded(){
|
||||
this.dragEnded = !this.dragEnded;
|
||||
},
|
||||
},
|
||||
}
|
||||
</script>
|
||||
|
@ -1,4 +1,21 @@
|
||||
<template>
|
||||
<div>
|
||||
<!-- Boutons pour fichiers :thumbsup: -->
|
||||
<div class="flex flex-row gap-2 p-2">
|
||||
<div
|
||||
:class="getClassButton('default')"
|
||||
@click="changeTab('default')"
|
||||
>
|
||||
Tous les fichiers
|
||||
</div>
|
||||
<div
|
||||
:class="getClassButton('favorites')"
|
||||
@click="changeTab('favorites')"
|
||||
>
|
||||
Favoris
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex flex-col h-full w-full border">
|
||||
<!-- Breadcrumb -->
|
||||
<div class="flex flex-row mt-1 ml-3 items-start container">
|
||||
@ -55,17 +72,18 @@
|
||||
<!-- Contenu -->
|
||||
<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)">
|
||||
isDragging && isDroppable ? 'border-green-500 border-4 border-dashed transition-all ease-in-out' :
|
||||
isDragging && !isDroppable ? 'border-red-500 border-4 border-dashed transition-all ease-in-out !cursor-no-drop' : ''
|
||||
]" @drop.prevent="onDrop" @dragover.prevent="onDragOver" @dragenter.prevent="onDragEnter"
|
||||
@dragleave.prevent="onDragLeave($event)" @dragend="onDragEnd">
|
||||
|
||||
<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"
|
||||
@click="handleClickElem(file)">
|
||||
|
||||
<!-- Nom -->
|
||||
<div class="w-7/12 flex items-center px-4 py-2 border-r border-gray-300 cursor-pointer">
|
||||
<div class="w-12 h-12 flex items-center justify-center cursor-pointer">
|
||||
<div class="w-7/12 flex items-center px-4 py-2 border-r border-gray-300">
|
||||
<div class="w-12 h-12 flex items-center justify-center">
|
||||
<template v-if="file.type === 'directory'">
|
||||
<svg fill="currentColor" viewBox="0 0 24 24" class="text-NcBlue w-10 h-10 ">
|
||||
<path
|
||||
@ -74,7 +92,7 @@
|
||||
</svg>
|
||||
</template>
|
||||
<template v-if="file.type === 'file' && file.basename.split('.').pop() !== 'zip'">
|
||||
<div class="flex items-center justify-center cursor-pointer">
|
||||
<div :class="['flex items-center justify-center']">
|
||||
<svg viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg" xml:space="preserve"
|
||||
class="w-10 h-10"
|
||||
style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2">
|
||||
@ -96,17 +114,17 @@
|
||||
</div>
|
||||
|
||||
<!-- Type -->
|
||||
<div class="w-2/12 px-4 py-2 border-r border-gray-300 cursor-pointer">
|
||||
<div class="w-2/12 px-4 py-2 border-r border-gray-300">
|
||||
{{ file.type === 'directory' ? 'Dossier' : 'Fichier' }}
|
||||
</div>
|
||||
|
||||
<!-- Taille -->
|
||||
<div class="w-2/12 px-4 py-2 cursor-pointer">
|
||||
<div class="w-2/12 px-4 py-2">
|
||||
{{ file.type === 'directory' ? '-' : formatFileSize(file.size) }}
|
||||
</div>
|
||||
|
||||
<!-- Options -->
|
||||
<div class="w-1/12 px-4 py-2 cursor-pointer" @click.stop>
|
||||
<div class="w-1/12 px-4 py-2" @click.stop>
|
||||
<NcActions>
|
||||
<NcActionButton @click="deleteElem(file)">
|
||||
<template #icon>
|
||||
@ -131,13 +149,14 @@
|
||||
<FileExistsDialog v-if="!fileExistDialogDisabled" :fileName="initialFileName" :isDirectory="isDirectory" @overwrite="setOverwrite" @rename="setRename" @cancel="cancelDrop">
|
||||
</FileExistsDialog>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
|
||||
|
||||
<script>
|
||||
// NextCloud Components
|
||||
import { getClient, getRootPath } from '@nextcloud/files/dav';
|
||||
import { getClient, getRootPath, getFavoriteNodes } 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';
|
||||
@ -176,6 +195,19 @@ export default {
|
||||
type: Object,
|
||||
default: null,
|
||||
},
|
||||
dragEnded: {
|
||||
type: Boolean,
|
||||
Required: true,
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
dragEnded(val) {
|
||||
if(val === true) {
|
||||
this.isDragging = false;
|
||||
this.isDroppable = false;
|
||||
this.$emit('dragEnded');
|
||||
}
|
||||
}
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
@ -187,6 +219,7 @@ export default {
|
||||
newFileName: '',
|
||||
isTransfering: false,
|
||||
isDragging: false,
|
||||
isDroppable: true,
|
||||
editDialogDisabled: true,
|
||||
fileExistDialogDisabled: true,
|
||||
initialFileName: '', // Nom originel du fichier/dossier a edite
|
||||
@ -198,6 +231,7 @@ export default {
|
||||
cancelOperation: false,
|
||||
rename: false,
|
||||
newElemName: '',
|
||||
currentTab: 'default',
|
||||
};
|
||||
},
|
||||
async mounted() {
|
||||
@ -205,10 +239,28 @@ export default {
|
||||
this.breadcrumbParts = this.getBreadcrumbParts();
|
||||
},
|
||||
methods: {
|
||||
async changeTab(name) {
|
||||
this.currentTab = name;
|
||||
this.current_dir = '/';
|
||||
await this.fetchFiles();
|
||||
if(this.currentTab === 'default'){
|
||||
this.isDroppable = true;
|
||||
}
|
||||
else {
|
||||
this.isDroppable = false;
|
||||
}
|
||||
},
|
||||
async fetchFiles() {
|
||||
try {
|
||||
const client = getClient();
|
||||
const directoryItems = await client.getDirectoryContents(this.root_path + this.current_dir);
|
||||
let directoryItems;
|
||||
if (this.currentTab === 'default'){
|
||||
directoryItems = await client.getDirectoryContents(this.root_path + this.current_dir);
|
||||
}
|
||||
else if(this.currentTab === 'favorites'){
|
||||
let favoriteNodes = await getFavoriteNodes(client);
|
||||
directoryItems = this.computeFavoritesNodes(favoriteNodes);
|
||||
}
|
||||
|
||||
this.files = directoryItems.map(file => ({
|
||||
basename: file.basename,
|
||||
@ -220,6 +272,29 @@ export default {
|
||||
console.error('Erreur lors de la récupération des fichiers et dossiers :', error);
|
||||
}
|
||||
},
|
||||
computeFavoritesNodes(favoriteNodes) {
|
||||
let directoryItems = [];
|
||||
|
||||
let i = 0;
|
||||
favoriteNodes.forEach(element => {
|
||||
// Création de l'objet elemData pour chaque élément
|
||||
let elemData = {
|
||||
basename: element._data.displayname,
|
||||
etag: element._attributes.etag,
|
||||
filename: element._attributes.filename,
|
||||
lastmod: element._attributes.lastmod,
|
||||
mime: element._data.mime,
|
||||
size: element._data.size,
|
||||
type: element._attributes.type,
|
||||
};
|
||||
|
||||
// Ajout de elemData à directoryItems, indexé par un identifiant unique (par exemple, basename)
|
||||
directoryItems[i] = elemData;
|
||||
i++;
|
||||
});
|
||||
|
||||
return directoryItems;
|
||||
},
|
||||
formatFileSize(size) {
|
||||
if (size < 1024) return `${size} B`;
|
||||
if (size < 1024 * 1024) return `${(size / 1024).toFixed(2)} KB`;
|
||||
@ -287,22 +362,37 @@ export default {
|
||||
},
|
||||
onDragOver(event) {
|
||||
event.preventDefault();
|
||||
if(this.currentTab === 'favorites' && this.current_dir === '/'){
|
||||
event.dataTransfer.dropEffect = 'none';
|
||||
this.isDroppable = false;
|
||||
}
|
||||
else{
|
||||
this.isDroppable = true;
|
||||
}
|
||||
if (!this.isDragging) {
|
||||
this.isDragging = true;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
},
|
||||
onDragEnter(event){
|
||||
event.preventDefault()
|
||||
},
|
||||
onDragLeave(event) {
|
||||
event.preventDefault();
|
||||
if (event.target === event.currentTarget) {
|
||||
this.isDragging = false;
|
||||
}
|
||||
},
|
||||
onDragEnd() {
|
||||
this.isDragging = false;
|
||||
console.log('feur2')
|
||||
},
|
||||
async onDrop(event) {
|
||||
event.preventDefault();
|
||||
this.isDragging = false; // Pour enlever le contour rouge si on ne peut pas drop sinon il reste affiche
|
||||
if(this.isDroppable){
|
||||
try {
|
||||
this.isDragging = false;
|
||||
this.isTransfering = true;
|
||||
const file = this.file;
|
||||
const zip = this.zip;
|
||||
@ -352,6 +442,9 @@ export default {
|
||||
this.applyToAll = false;
|
||||
this.rename = false;
|
||||
this.newElemName = '';
|
||||
}
|
||||
this.isDroppable = true;
|
||||
console.log('feur')
|
||||
},
|
||||
async moveFilesOfFolder(folder, parentPath) {
|
||||
await this.createFolder(folder, parentPath + '/');
|
||||
@ -389,7 +482,7 @@ export default {
|
||||
|
||||
let fullPath = '';
|
||||
if(!this.rename) {
|
||||
fullPath = `${this.root_path}${this.current_dir}${parentPath}${file.name}`;
|
||||
fullPath = `${this.root_path}${this.current_dir}${parentPath}/${file.name}`;
|
||||
}
|
||||
else if (this.rename && newName){
|
||||
fullPath = `${this.root_path}${this.current_dir}${parentPath}${newName}`;
|
||||
@ -543,6 +636,17 @@ export default {
|
||||
this.cancelOperation = true;
|
||||
this.closeFileExistsDialog();
|
||||
},
|
||||
getClassButton(name) {
|
||||
let cssStyle = "flex h-12 w-32 text-sm py-2 transition-colors font-medium border-r last:border-r-0 justify-center items-center";
|
||||
|
||||
if(this.currentTab === name) {
|
||||
cssStyle += ' bg-blue-400 text-white';
|
||||
} else {
|
||||
cssStyle += ' hover:bg-gray-100 text-gray-700 bg-gray-300';
|
||||
}
|
||||
|
||||
return cssStyle;
|
||||
},
|
||||
async sleep(ms) {
|
||||
return new Promise(resolve => setTimeout(resolve, ms));
|
||||
}
|
||||
|
@ -27,7 +27,7 @@
|
||||
<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)">
|
||||
@click="toggleFolder(file)" v-if="file.isDirectory" draggable="true" @dragstart="onDragStart(file)" @dragend="onDragEnd">
|
||||
<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>
|
||||
@ -219,6 +219,10 @@ export default {
|
||||
console.error('Erreur lors du chargement du contenu du ZIP :', error);
|
||||
}
|
||||
},
|
||||
onDragEnd(event) {
|
||||
event.preventDefault();
|
||||
this.$emit('dragEnded');
|
||||
},
|
||||
|
||||
formatFileSize(size) {
|
||||
if (size < 1024) return `${size} B`;
|
||||
|
@ -683,6 +683,10 @@ video {
|
||||
width: 6rem;
|
||||
}
|
||||
|
||||
.w-32 {
|
||||
width: 8rem;
|
||||
}
|
||||
|
||||
.w-4\/6 {
|
||||
width: 66.666667%;
|
||||
}
|
||||
@ -725,10 +729,22 @@ video {
|
||||
animation: spin 1s linear infinite;
|
||||
}
|
||||
|
||||
.cursor-not-allowed {
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.cursor-pointer {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.cursor-no-drop {
|
||||
cursor: no-drop;
|
||||
}
|
||||
|
||||
.\!cursor-no-drop {
|
||||
cursor: no-drop !important;
|
||||
}
|
||||
|
||||
.flex-row {
|
||||
flex-direction: row;
|
||||
}
|
||||
@ -757,6 +773,10 @@ video {
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.gap-2 {
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.space-x-2 > :not([hidden]) ~ :not([hidden]) {
|
||||
--tw-space-x-reverse: 0;
|
||||
margin-right: calc(0.5rem * var(--tw-space-x-reverse));
|
||||
@ -823,6 +843,11 @@ video {
|
||||
border-color: rgb(34 197 94 / var(--tw-border-opacity, 1));
|
||||
}
|
||||
|
||||
.border-red-500 {
|
||||
--tw-border-opacity: 1;
|
||||
border-color: rgb(239 68 68 / var(--tw-border-opacity, 1));
|
||||
}
|
||||
|
||||
.bg-NcBlack {
|
||||
--tw-bg-opacity: 1;
|
||||
background-color: rgb(23 23 23 / var(--tw-bg-opacity, 1));
|
||||
@ -841,6 +866,11 @@ video {
|
||||
background-color: rgb(219 234 254 / var(--tw-bg-opacity, 1));
|
||||
}
|
||||
|
||||
.bg-blue-400 {
|
||||
--tw-bg-opacity: 1;
|
||||
background-color: rgb(96 165 250 / var(--tw-bg-opacity, 1));
|
||||
}
|
||||
|
||||
.bg-blue-500 {
|
||||
--tw-bg-opacity: 1;
|
||||
background-color: rgb(59 130 246 / var(--tw-bg-opacity, 1));
|
||||
@ -860,6 +890,11 @@ video {
|
||||
background-color: rgb(229 231 235 / 0.1);
|
||||
}
|
||||
|
||||
.bg-gray-300 {
|
||||
--tw-bg-opacity: 1;
|
||||
background-color: rgb(209 213 219 / var(--tw-bg-opacity, 1));
|
||||
}
|
||||
|
||||
.bg-gray-700 {
|
||||
--tw-bg-opacity: 1;
|
||||
background-color: rgb(55 65 81 / var(--tw-bg-opacity, 1));
|
||||
@ -874,6 +909,10 @@ video {
|
||||
--tw-bg-opacity: 0.5;
|
||||
}
|
||||
|
||||
.p-2 {
|
||||
padding: 0.5rem;
|
||||
}
|
||||
|
||||
.p-4 {
|
||||
padding: 1rem;
|
||||
}
|
||||
@ -901,6 +940,11 @@ video {
|
||||
line-height: 1.75rem;
|
||||
}
|
||||
|
||||
.text-sm {
|
||||
font-size: 0.875rem;
|
||||
line-height: 1.25rem;
|
||||
}
|
||||
|
||||
.text-xs {
|
||||
font-size: 0.75rem;
|
||||
line-height: 1rem;
|
||||
@ -968,6 +1012,12 @@ video {
|
||||
transition-duration: 150ms;
|
||||
}
|
||||
|
||||
.transition-colors {
|
||||
transition-property: color, background-color, border-color, text-decoration-color, fill, stroke;
|
||||
transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
|
||||
transition-duration: 150ms;
|
||||
}
|
||||
|
||||
.ease-in-out {
|
||||
transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
|
||||
}
|
||||
@ -976,6 +1026,10 @@ video {
|
||||
border-bottom-width: 0px;
|
||||
}
|
||||
|
||||
.last\:border-r-0:last-child {
|
||||
border-right-width: 0px;
|
||||
}
|
||||
|
||||
.hover\:bg-NcGray:hover {
|
||||
--tw-bg-opacity: 1;
|
||||
background-color: rgb(33 33 33 / var(--tw-bg-opacity, 1));
|
||||
@ -991,6 +1045,11 @@ video {
|
||||
background-color: rgb(29 78 216 / var(--tw-bg-opacity, 1));
|
||||
}
|
||||
|
||||
.hover\:bg-gray-100:hover {
|
||||
--tw-bg-opacity: 1;
|
||||
background-color: rgb(243 244 246 / var(--tw-bg-opacity, 1));
|
||||
}
|
||||
|
||||
.hover\:bg-gray-300:hover {
|
||||
--tw-bg-opacity: 1;
|
||||
background-color: rgb(209 213 219 / var(--tw-bg-opacity, 1));
|
||||
|
Loading…
x
Reference in New Issue
Block a user