Implement Delete and Rename of File Component
All checks were successful
Neutral/pipeline/head This commit looks good

This commit is contained in:
CICD - Pipeline 2023-03-22 20:41:41 +01:00
parent be3107b7a8
commit bf3c216ee0
4 changed files with 122 additions and 20 deletions

View File

@ -1 +0,0 @@
QH7NXUAqV8dWJ9Lg4aTkDCezpTS5HgJ2DvqznexTbSTxgi

View File

@ -23,6 +23,10 @@
</div>
</div>
<div id="fi_dialog_input">
</div>
<dialog class="fi_addfolder" id="fi_new_folder_dialog">
<h1><i class="fa fa-folder"></i> Créer un dossier</h1>
<p>Nom du dossier :</p>
@ -33,15 +37,6 @@
<button id="fi_add_confirm" class="fi_add_confirm">Ajouter</button>
</dialog>
<dialog class="fi_addfolder" id="_rename">
<h1><i class="fa fa-terminal"></i> Renommer un fichier</h1>
<p><span id="_old_name">/home/gitlab-ci/test</span></p>
<p>Nouveau lien :</p>
<input class="inp" id="_rename_name" type="text">
</div>
<button id="_rename_close" class="fi_add_close">Annuler</button>
<button id="_rename_confirm" class="fi_add_confirm">Editer</button>
</dialog>
<script>
@ -59,6 +54,7 @@
const newFolderConfirm = document.getElementById("fi_add_confirm")
const newFolderName = document.getElementById("fi_add_name")
const newFolderInfo = document.getElementById("fi_folder_info")
const dialogInput = document.getElementById("fi_dialog_input")
const newFolderClose = document.getElementById("fi_add_close")
@ -175,6 +171,7 @@
fiInfo.innerHTML = ""
var fileExplorerList = new Array()
var dialogExlorerList = new Array()
fetch('/filemanager', {
method: 'POST',
@ -310,7 +307,7 @@
if(file.directory == true) {
fileExplorerList.push('<div id="' + file.name + '_directory" class="fi_file row"> <p class="col-lg"><i style="color:yellow;" class="fa fa-folder"></i> ' + file.name + '</p> <p class="col-lg"><i class="fa fa-calendar"></i> Dernière édition : ' + lastedition + '</p> <p class="col-lg"><i class="fas fa-weight-hanging"></i> Taille : ' + file.size + ' octet(s)</p> <div class="col-lg fi_file_btn"> <button id="' + file.name + '_rename" class="fi_rename"><i id="' + file.name + '_trename" class="fas fa-terminal"></i></button> <button id="' + file.name + '_delete" class="fi_delete"><i id="' + file.name + '_tdelete" class="fa fa-trash"></i></button> </div> </div>')
dialogExlorerList.push(' <dialog class="fi_addfolder" id="' + file.name + '_rename_dialog"> <h1><i class="fa fa-terminal"></i> Renommer un dossier</h1> <p><span id="' + file.name + '_old_name"></span></p> <p>Nouveau lien :</p> <input class="inp" id="' + file.name + '_rename_name" type="text"> </div><p id="' + file.name +'_rename_info" style="text-align: start; color: rgb(255, 48, 48);"></p> <button id="' + file.name + '_rename_close" class="fi_add_close">Annuler</button> <button id="' + file.name + '_rename_confirm" class="fi_add_confirm">Editer</button> </dialog>')
}
@ -419,12 +416,13 @@
fileExplorerList.push('<div id="' + file.name + '_directory" class="fi_file row"> <p class="col-lg">' + icon+ '</i> ' + file.name + '</p> <p class="col-lg"><i class="fa fa-calendar"></i> Dernière édition : ' + lastedition + '</p> <p class="col-lg"><i class="fas fa-weight-hanging"></i> Taille : ' + file.size + ' octet(s)</p> <div class="col-lg fi_file_btn"> <button id="' + file.name + '_rename" class="fi_rename"><i id="' + file.name + '_trename" class="fas fa-terminal"></i></button> <button id="' + file + '_download" class="fi_rename"><i id="' + file.name + '_tdownload" class="fas fa-download"></i></button><button id="' + file.name + '_delete" class="fi_delete"><i id="' + file.name + '_tdelete" class="fa fa-trash"></i></button> </div> </div>')
dialogExlorerList.push(' <dialog class="fi_addfolder" id="' + file.name + '_rename_dialog"> <h1><i class="fa fa-terminal"></i> Renommer un fichier</h1> <p><span id="' + file.name + '_old_name"></span></p> <p>Nouveau lien :</p> <input class="inp" id="' + file.name + '_rename_name" type="text"> </div> <p id="' + file.name +'_rename_info" style="text-align: start; color: rgb(255, 48, 48);"></p><button id="' + file.name + '_rename_close" class="fi_add_close">Annuler</button> <button id="' + file.name + '_rename_confirm" class="fi_add_confirm">Editer</button> </dialog>')
}
}
fileExplorer.innerHTML = fileExplorerList.join('')
dialogInput.innerHTML = dialogExlorerList.join('')
const last_dir = document.getElementById("last_directory")
@ -465,9 +463,14 @@
const deleteBtn = document.getElementById(file.name + "_delete")
const renameBtn = document.getElementById(file.name + "_rename")
const renameDialog = document.getElementById(file.name + "_rename_dialog")
const renameOldName = document.getElementById(file.name + "_old_name")
const renameName = document.getElementById(file.name + "_rename_name")
const renameClose = document.getElementById(file.name + "_rename_close")
const renameConfirm = document.getElementById(file.name + "_rename_confirm")
const renameInfo = document.getElementById(file.name + "_rename_info")
if(file.directory == true) {
@ -518,9 +521,13 @@
body: JSON.stringify({"request":"del", "value": file})
})
.then(response => response.json())
.then(response => res(response))
.then(response => res(response, file))
function res(response) {
function res(response, file) {
console.log(file)
if(response.result == "failed") {
@ -552,7 +559,82 @@
renameBtn.addEventListener("click", () => {
console.log(file.name)
renameDialog.showModal()
renameOldName.innerHTML = file.fileDirectory
renameName.value = file.fileDirectory
})
renameClose.addEventListener("click" ,() => {
renameDialog.close()
getDirectory(currentDir.value)
})
renameConfirm.addEventListener("click" ,() => {
var rnjustspace = false
renameInfo.innerHTML = ""
for (var i = 0; i < renameName.value.length; i++) {
var char = renameName.value.charAt(i)
if(char != " ") {
rnjustspace = true
}
}
if(rnjustspace == false) {
renameInfo.innerHTML = "Le nom du dossier ne peut être vide !"
} else {
fetch('/filemanager', {
method: 'POST',
redirect: 'follow',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({"request":"rename", "value": renameName.value, "currentDir" : renameOldName.outerText})
})
.then(response => response.json())
.then(response => res(response))
function res(response) {
if(response.result == "failed") {
content.innerHTML = ' <h1 style="color:red;"><i style="color:yellow; font-size: 2vw;" class="fa fa-warning"></i> Erreur de chargement des données - Erreur : ' + response.content + '</h1>'
console.log("FAILED")
} else if(response.result == "success") {
if(response.content == "ERROR_ALREADY_EXIST") {
renameInfo.innerHTML = "<p>Le nom du dossier est déjà existant !</p>"
} else if(response.content == "ERROR_NOT_MAKEABLE") {
renameInfo.innerHTML = "<p>Vous n'avez pas la permission !</p>"
} else {
renameDialog.close()
getDirectory(currentDir.value)
}
}
}
}
})
}

View File

@ -84,6 +84,8 @@ router.post("/", function(req, res, next) {
} else if(bod.request == "del") {
const file = bod.value
if(fs.existsSync(bod.value.fileDirectory) == false) {
res.send({"result":"success", "content":"ERROR_NOT_EXIST"})
@ -96,6 +98,7 @@ router.post("/", function(req, res, next) {
} else {
fs.rmSync(file.fileDirectory)
}
console.log("DELETED")
@ -114,7 +117,25 @@ router.post("/", function(req, res, next) {
} else if(bod.request == "rename") {
res.send({"result":"failed", "content":"ERROR_NOT_MAKE"})
if(fs.existsSync(bod.value) == true) {
res.send({"result":"success", "content":"ERROR_ALREADY_EXIST"})
} else {
try {
fs.renameSync(bod.currentDir, bod.value)
res.send({"result":"success", "content":"RENAMED"})
} catch(error) {
console.log(error)
res.send({"result":"success", "content":"ERROR_NOT_MAKEABLE"})
}
}
} else if(bod.request == "addfolder") {

View File

@ -9,5 +9,5 @@
"livableToken": true,
"createdAt": 1679260759114
},
"lastconnexion": 1679501732426
"lastconnexion": 1679513878276
}