ajout de la fonctionnalite de rename on drop

This commit is contained in:
Alexandre_BRAVO 2024-11-26 18:25:30 +01:00
parent 28d6b8d176
commit 2195b52200
2 changed files with 35 additions and 9 deletions

View File

@ -5,7 +5,7 @@
<p>Le fichier "{{ fileName }}" existe déjà. Que voulez-vous faire ?</p> <p>Le fichier "{{ fileName }}" existe déjà. Que voulez-vous faire ?</p>
<div class="flex justify-end mt-4 space-x-2"> <div class="flex justify-end mt-4 space-x-2">
<button @click="toggleOverwrite">Écraser</button> <button @click="toggleOverwrite">Écraser</button>
<button @click="toggleRename">Renommer</button> <button v-if="!isDirectory" @click="toggleRename">Renommer</button>
<button @click="onCancel">Annuler</button> <button @click="onCancel">Annuler</button>
</div> </div>
</div> </div>
@ -49,10 +49,13 @@ export default {
fileName: { fileName: {
type: String, type: String,
required: true required: true
},
isDirectory:{
type: Boolean,
required: true,
} }
}, },
data() { data() {
var oldFileName = this.fileName;
var newFileName = this.fileName; var newFileName = this.fileName;
var extension = ''; var extension = '';
if(!this.isDirectory) { if(!this.isDirectory) {
@ -66,7 +69,6 @@ export default {
displayRename: false, displayRename: false,
displayOverwrite: false, displayOverwrite: false,
forAll: false, forAll: false,
oldFileName,
newFileName, newFileName,
extension, extension,
} }
@ -96,7 +98,7 @@ export default {
this.newFileName = newFileNameWithOriginalExtension; this.newFileName = newFileNameWithOriginalExtension;
} }
this.$emit("rename", { oldFileName: this.oldFileName, newFileName: this.newFileName }); this.$emit("rename", { newFileName: this.newFileName });
} }
}, },
onInputChange() { onInputChange() {

View File

@ -128,7 +128,7 @@
<EditFileName v-if="!editDialogDisabled" :initialFileName="initialFileName" :isDirectory="isDirectory" <EditFileName v-if="!editDialogDisabled" :initialFileName="initialFileName" :isDirectory="isDirectory"
@update="updateFileName" @close="closeEditDialog"> @update="updateFileName" @close="closeEditDialog">
</EditFileName> </EditFileName>
<FileExistsDialog v-if="!fileExistDialogDisabled" :fileName="initialFileName" @overwrite="setOverwrite" @rename="" @cancel="cancelDrop"> <FileExistsDialog v-if="!fileExistDialogDisabled" :fileName="initialFileName" :isDirectory="isDirectory" @overwrite="setOverwrite" @rename="setRename" @cancel="cancelDrop">
</FileExistsDialog> </FileExistsDialog>
</div> </div>
</template> </template>
@ -196,6 +196,8 @@ export default {
overwrite: false, overwrite: false,
applyToAll: false, applyToAll: false,
cancelOperation: false, cancelOperation: false,
rename: false,
newElemName: '',
}; };
}, },
async mounted() { async mounted() {
@ -259,7 +261,6 @@ export default {
try { try {
const client = getClient(); const client = getClient();
let filePath = ''; 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}`; filePath = `${this.root_path}${this.current_dir}${this.newFileName}`;
} }
@ -349,6 +350,8 @@ export default {
} }
this.overwrite = false; this.overwrite = false;
this.applyToAll = false; this.applyToAll = false;
this.rename = false;
this.newElemName = '';
}, },
async moveFilesOfFolder(folder, parentPath) { async moveFilesOfFolder(folder, parentPath) {
await this.createFolder(folder, parentPath + '/'); await this.createFolder(folder, parentPath + '/');
@ -378,13 +381,22 @@ export default {
} }
} }
}, },
async moveFileToTarget(file, parentPath) { async moveFileToTarget(file, parentPath, newName = null) {
this.isDirectory = false;
try { try {
const client = getClient(); const client = getClient();
// Assurez-vous que le chemin parent est correctement formaté // Assurez-vous que le chemin parent est correctement formaté
let fullPath = ''; let fullPath = '';
fullPath = `${this.root_path}${this.current_dir}${parentPath}${file.name}`; if(!this.rename) {
fullPath = `${this.root_path}${this.current_dir}${parentPath}${file.name}`;
}
else if (this.rename && newName){
fullPath = `${this.root_path}${this.current_dir}${parentPath}${newName}`;
}
else {
return null;
}
if (ArrayBuffer.isView(file.content)) { if (ArrayBuffer.isView(file.content)) {
file.content = Buffer.from(file.content); file.content = Buffer.from(file.content);
@ -409,7 +421,13 @@ export default {
await this.sleep(50); await this.sleep(50);
} }
if(!this.cancelOperation){ if(!this.cancelOperation){
await this.moveFileToTarget(file,parentPath); if(this.rename) {
await this.moveFileToTarget(file, parentPath, this.newElemName);
this.rename = false;
}
else{
await this.moveFileToTarget(file,parentPath);
}
} }
} }
} catch (error) { } catch (error) {
@ -417,6 +435,7 @@ export default {
} }
}, },
async createFolder(folder, parentPath) { async createFolder(folder, parentPath) {
this.isDirectory = true;
try { try {
const client = getClient(); const client = getClient();
let fullPath = ''; let fullPath = '';
@ -505,6 +524,11 @@ export default {
this.applyToAll = options.forAll; this.applyToAll = options.forAll;
this.fileExistDialogDisabled = true; this.fileExistDialogDisabled = true;
}, },
setRename(options) {
this.rename = true;
this.newElemName = options.newFileName;
this.fileExistDialogDisabled = true;
},
/** /**
* Check si un fichier ou un dossier existe deja sur le serveur * Check si un fichier ou un dossier existe deja sur le serveur
* @param path le chemin du fichier/dossier * @param path le chemin du fichier/dossier