Change file tree doesn't reload on upload/delete

This commit is contained in:
amcmanu3 2023-01-28 19:10:27 -05:00
parent a46a962c86
commit e0541b1ec0
2 changed files with 28 additions and 11 deletions

View File

@ -965,7 +965,7 @@ class Helpers:
rel = os.path.join(folder, raw_filename)
dpath = os.path.join(folder, filename)
if os.path.isdir(rel):
output += f"""<li class="tree-item" data-path="{dpath}">
output += f"""<li id="{dpath}li" class="tree-item" data-path="{dpath}">
\n<div id="{dpath}" data-path="{dpath}" data-name="{filename}" class="tree-caret tree-ctx-item tree-folder">
<span id="{dpath}span" class="files-tree-title" data-path="{dpath}" data-name="{filename}" onclick="getDirView(event)">
<i style="color: var(--info);" class="far fa-folder"></i>
@ -976,7 +976,7 @@ class Helpers:
\n"""
else:
if filename != "crafty_managed.txt":
output += f"""<li
output += f"""<li id="{dpath}li"
class="d-block tree-ctx-item tree-file tree-item"
data-path="{dpath}"
data-name="{filename}"
@ -1004,7 +1004,7 @@ class Helpers:
dpath = os.path.join(folder, filename)
rel = os.path.join(folder, raw_filename)
if os.path.isdir(rel):
output += f"""<li class="tree-item" data-path="{dpath}">
output += f"""<li id="{dpath}li" class="tree-item" data-path="{dpath}">
\n<div id="{dpath}" data-path="{dpath}" data-name="{filename}" class="tree-caret tree-ctx-item tree-folder">
<span id="{dpath}span" class="files-tree-title" data-path="{dpath}" data-name="{filename}" onclick="getDirView(event)">
<i style="color: var(--info);" class="far fa-folder"></i>
@ -1014,7 +1014,7 @@ class Helpers:
</div><li>"""
else:
if filename != "crafty_managed.txt":
output += f"""<li
output += f"""<li id="{dpath}li"
class="d-block tree-ctx-item tree-file tree-item"
data-path="{dpath}"
data-name="{filename}"

View File

@ -697,7 +697,7 @@
});
}
function sendFile(file, path, serverId, left, onProgress) {
async function sendFile(file, path, serverId, left, onProgress) {
let xmlHttpRequest = new XMLHttpRequest();
let token = getCookie("_xsrf")
let fileName = file.name
@ -719,7 +719,23 @@
onProgress(Math.floor(event.loaded / event.total * 100)), false);
xmlHttpRequest.addEventListener('load', (event) => {
if (event.target.responseText == 'success') {
console.log('Upload for file', file.name, 'was successful!')
console.log('Upload for file', file.name, 'was successful!');
par_el = document.getElementById(path + "ul");
let name = file.name;
console.log(par_el)
let full_path = path + '/' + name
var items = par_el.getElementsByTagName("li");
let flag = false;
for (var k = 0; k < items.length; ++k) {
if ($(items[k]).attr("data-name") == name) {
console.log("FLAGGED")
flag = true;
}
}
if (!flag) {
$(par_el).append('<li id=' + '"' + full_path.toString() + 'li' + '"' + 'class="tree-ctx-item tree-file tree-item" data-path=' + '"' + full_path.toString() + '"' + ' data-name=' + '"' + name.toString() + '"' + ' onclick="clickOnFile(event)" ><span style="margin-right: 6px;"><i class="far fa-file"></i></span>' + name + '</li>');
}
return true;
}
else {
alert('Upload failed with response: ' + event.target.responseText);
@ -735,7 +751,7 @@
let uploadWaitDialog;
let doUpload = true;
function uploadFilesE(event) {
async function uploadFilesE(event) {
path = event.target.parentElement.getAttribute('data-path');
$(function () {
var uploadHtml = "<div>" +
@ -795,7 +811,7 @@
`;
$('#upload-progress-bar-parent').append(progressHtml);
sendFile(files.files[i], path, serverId, nFiles - i - 1, (progress) => {
response = await sendFile(files.files[i], path, serverId, nFiles - i - 1, (progress) => {
$(`#upload-progress-bar-${i + 1}`).attr('aria-valuenow', progress)
$(`#upload-progress-bar-${i + 1}`).css('width', progress + '%')
});
@ -996,7 +1012,6 @@
function hideUploadBox() {
if (!uploadWaitDialog) return;
uploadWaitDialog.modal('hide');
getTreeView();
}
function createFileE(event) {
@ -1074,7 +1089,8 @@
callback: function (result) {
if (!result) return;
deleteFile(path, function () {
getTreeView()
el = document.getElementById(path + "li");
$(el).remove();
document.getElementById('files-tree-nav').style.display = 'none';
});
}
@ -1102,7 +1118,8 @@
callback: function (result) {
if (!result) return;
deleteDir(path, function () {
getTreeView()
el = document.getElementById(path + "li");
$(el).remove();
document.getElementById('files-tree-nav').style.display = 'none';
});
}