diff options
author | Alex Vitkov <alexvitkov98@gmail.com> | 2021-02-13 15:39:40 +0200 |
---|---|---|
committer | Alex Vitkov <alexvitkov98@gmail.com> | 2021-02-13 15:39:40 +0200 |
commit | 89d41b1b139fda772e129873f0921b1a4e535094 (patch) | |
tree | 9ceb65faaa1df1572ac9ecca01031a8cd9ca0c6d | |
parent | 714b2e851734447a6701af88fc56091a3d75d7c1 (diff) | |
download | fileup-89d41b1b139fda772e129873f0921b1a4e535094.tar.gz |
qutebrowser
-rw-r--r-- | css/style.css | 4 | ||||
-rw-r--r-- | loggedin.js | 51 | ||||
-rw-r--r-- | php/move.php | 29 |
3 files changed, 54 insertions, 30 deletions
diff --git a/css/style.css b/css/style.css index d60a4cf..f20b121 100644 --- a/css/style.css +++ b/css/style.css @@ -291,6 +291,10 @@ input[type=submit]:hover { } .filecontents { + background: white; +} + +.filecontents { padding: 0.8rem; font-size: 1.1rem; } diff --git a/loggedin.js b/loggedin.js index eba58ba..53aa7c7 100644 --- a/loggedin.js +++ b/loggedin.js @@ -115,7 +115,6 @@ function openfile_nondir() { } function opendir() { - update_path_visuals(); var data = new FormData(); @@ -138,10 +137,12 @@ function opendir() { } files.sort((a, b) => { - if (a.is_directory && !b.is_directory) - return -1; - if (!a.is_directory && b.is_directory) - return 1; + if (get_path() == "/" && a.filename == "trash") + return 2; + if (a.is_directory && !b.is_directory) + return -1; + if (!a.is_directory && b.is_directory) + return 1; return a.filename.localeCompare(b.filename); }); @@ -164,6 +165,10 @@ function openfile(is_directory) { } } +function move_to_trash(filename) { + move_file("/trash", filename, path_combine(get_path(), filename)); +} + function delete_file(filename) { var file_full_path = path_combine(get_path(), filename); @@ -196,11 +201,15 @@ function rename_file(filename) { xhr.send(data); } -function move_file(new_folder, filename) { +function move_file(new_folder, filename, new_filename) { + if (!new_filename) + new_filename = filename; + var data = new FormData(); - data.append('old_folder', get_path()); - data.append('new_folder', new_folder); - data.append('filename', filename); + data.append('old_folder', get_path()); + data.append('new_folder', new_folder); + data.append('filename', filename); + data.append('new_filename',new_filename); var xhr = new XMLHttpRequest(); xhr.open('POST', '/php/move.php', true); @@ -248,7 +257,7 @@ function begin_drag(e, obj) { var elemRect = dragging.getBoundingClientRect(); dragging_offset_x = e.clientX - elemRect.left; dragging_offset_y = -e.clientY + elemRect.top; - + if (dragging_placeholder) obj.parentNode.insertBefore(dragging_placeholder, obj); @@ -285,16 +294,20 @@ function end_drag(_e) { function drop_handler(dst, src) { if (dst.is_directory) { - move_file(path_combine(get_path(), dst.filename), src.filename); + if (get_path() == "/" && dst.filename == "trash") { + move_to_trash(src.filename); + } else { + move_file(path_combine(get_path(), dst.filename), src.filename); + } } else { alert(`Dropped ${dst.filename} on ${src.filename}`); } } function add_link_functionality(link, length) { - link.onclick = () => { + link.onclick = (e) => { focus.pwd.length = length, - openfile(true); + openfile(true); } link.onmouseup = (e) => { @@ -326,10 +339,10 @@ function make_window(pwd) { var h2 = document.createElement('h2'); wnd_html.appendChild(h2); - h2.onmousedown = (e) => { - begin_drag(e, wnd_html); - e.preventDefault(); - }; + //h2.onmousedown = (e) => { + //begin_drag(e, wnd_html); + // e.preventDefault(); + //}; path = document.createElement('div'); path.classList.add('path'); @@ -393,7 +406,7 @@ function add_file_visuals(fileview) { var filename = document.createElement('div'); if (fileview.is_directory) { - if (fileview.filename == "trash") + if (get_path() == "/" && fileview.filename == "trash") img.src="/mimeicons/user-trash.png"; else img.src="/mimeicons/directory.png"; @@ -416,7 +429,7 @@ function add_file_visuals(fileview) { ['Open in New Window', () => {alert('not implemented')}], ['Rename', () => { rename_file(fileview.filename); }], ['Share', () => {alert('not implemented')}], - ['Delete', () => { delete_file(fileview.filename); }], + ['Delete', () => { move_to_trash(fileview.filename); }], ]); } e.preventDefault(); diff --git a/php/move.php b/php/move.php index 3b1bf05..945c697 100644 --- a/php/move.php +++ b/php/move.php @@ -13,7 +13,12 @@ if (!isset($_POST['old_folder']) || !isset($_POST['new_folder']) || !isset($_POS exit(1); } -$filename = $_POST["filename"]; +$new_filename = $_POST["filename"]; +$old_filename = $_POST["filename"]; + +if (isset($_POST['new_filename'])) + $new_filename = $_POST['new_filename']; + $old_folder = $_POST["old_folder"]; $new_folder = $_POST["new_folder"]; $user = $_SESSION['user_object']; @@ -30,8 +35,8 @@ if (!$old_dir || !$new_dir) { // Check if the filename is taken in the new dir $contents_of_new_dir = $database->get_links_of($new_dir); foreach ($contents_of_new_dir as $c) { - if ($c['name'] == $filename) { - error_log("filename $filename taken in $new_folder"); + if ($c['name'] == $new_filename) { + error_log("filename $new_filename taken in $new_folder"); http_response_code(409); exit(0); } @@ -41,14 +46,14 @@ foreach ($contents_of_new_dir as $c) { $file_node = null; $contents_of_old_dir = $database->get_links_of($old_dir); foreach ($contents_of_old_dir as $c) { - if ($c['name'] == $filename) { + if ($c['name'] == $old_filename) { $file_node = $c['id']; break; } } if ($file_node == null) { - error_log("/php/move.php failed - file $old_folder/$filename doesn't exist"); + error_log("/php/move.php failed - file $old_folder/$new_filename doesn't exist"); http_response_code(409); exit(0); } @@ -57,16 +62,18 @@ if ($file_node == null) { // Update the node_link $move = $database->pdo->prepare(" UPDATE node_links - SET directory_id = :new_dir + SET directory_id = :new_dir, + name = :new_filename WHERE directory_id = :old_dir AND node_id = :file_node - AND name = :filename + AND name = :old_filename "); -$move->bindParam(':new_dir', $new_dir); -$move->bindParam(':old_dir', $old_dir); -$move->bindParam(':file_node', $file_node); -$move->bindParam(':filename', $filename); +$move->bindParam(':new_dir', $new_dir); +$move->bindParam(':old_dir', $old_dir); +$move->bindParam(':file_node', $file_node); +$move->bindParam(':old_filename', $old_filename); +$move->bindParam(':new_filename', $new_filename); if(!$move->execute()) { error_log("extremely sad shit"); |