F diff --git a/loggedin.js b/loggedin.js
--- a/loggedin.js
+++ b/loggedin.js
the_file.onchange = on_file_added;
var pwd = [];
+ const pending_uploads = [];
var context_menu = null;
- var dragging = null;
- var dragging_placeholder = null;
- var dragging_offset_x = 0, dragging_offset_y = 0;
class FileView {
constructor(filename, visuals, mimetype, is_directory) {
return;
}
+ var fileview = add_file_visuals(filename_input.value, false, "pending");
+
// Send the form asynchronously through the fetch api
fetch(upload_form.action, {
method: upload_form.method,
body: new FormData(upload_form)
}).then((resp) => {
if (resp.status == 200) {
- load_dir();
+ done_upload(fileview);
} else {
alert("Upload failed");
}
}, () => {
alert("Upload failed")
});
+
+ pending_uploads.push(fileview);
}
else {
alert("No files selected");
}
}
+ function done_upload(fileview) {
+ var index = pending_uploads.indexOf(fileview);
+ if (index >= 0)
+ pending_uploads.splice(index, 1);
+
+ load_dir();
+ }
+
function load_dir() {
+
while (the_path.children.length > 1)
the_path.removeChild(the_path.lastChild);
files = [];
var json = JSON.parse(this.responseText);
+ console.log(json);
for (const f of json) {
- var view = new FileView(f.name, null, f.mimetype, f.is_directory && f.is_directory != "0");
- files.push(view);
+ add_file_visuals(f.name, f.is_directory && f.is_directory != "0", f.mimetype);
}
-
- files.sort((a, b) => {
- if (a.is_directory && !b.is_directory)
- return -1;
- if (!a.is_directory && b.is_directory)
- return 1;
- return a.filename.localeCompare(b.filename);
- });
-
- for (const f of files) {
- add_file_visuals(f);
- }
-
};
xhr.send(data);
}
xhr.send(data);
}
- function begin_drag(e, fileview) {
- if (dragging) {
- alert("AAAAAAAAAAAAAA");
- }
-
- dragging_placeholder = document.createElement('div');
- fileview.visuals.parentNode.insertBefore(dragging_placeholder, fileview.visuals);
-
- dragging = fileview.visuals;
-
- var elemRect = dragging.getBoundingClientRect();
-
- dragging_offset_x = elemRect.width - (elemRect.left - e.clientX);
- dragging_offset_y = elemRect.top - e.clientY;
-
- dragging.style.position = "absolute";
- dragging.style.top = "0px";
- dragging.style.left = "0px";
- dragging.style.width = elemRect.width + "px";
- dragging.style.height = elemRect.height + "px";
- document.body.appendChild(dragging);
- }
-
- function add_file_visuals(fileview) {
- var visuals = document.createElement('div');
- fileview.visuals = visuals;
+ function add_file_visuals(name, is_directory, mimetype) {
+ var fileDiv = document.createElement('div');
var img = document.createElement('img');
var filename = document.createElement('div');
- if (fileview.is_directory!=0) {
+ if (is_directory!=0) {
img.src="/mimeicons/directory.png";
- visuals.onclick = () => {
+ fileDiv.onclick = () => {
pwd.push(name);
load_dir();
}
} else {
- img.src=`/mimeicons/${fileview.mimetype.replace("/", "-")}.png`;
+ img.src=`/mimeicons/${mimetype.replace("/", "-")}.png`;
}
- visuals.oncontextmenu = (e) => {
+ fileDiv.oncontextmenu = (e) => {
context(e, [
['Open', () => {
if (is_directory) {
alert('not implemented');
}
}],
- ['Rename', () => { rename_file(fileview.filename); }],
+ ['Rename', () => { rename_file(name); }],
['Share', () => {alert('not implemented')}],
- ['Delete', () => { delete_file(fileview.filename); }],
+ ['Delete', () => { delete_file(name); }],
]);
e.preventDefault();
}
- visuals.ondragstart = (e) => {
- begin_drag(e, fileview);
- e.preventDefault();
- };
-
- visuals.classList.add('file');
+ fileDiv.classList.add('file');
filename.classList.add('filename');
- filename.innerText = fileview.filename;
+ filename.innerText = name;
+
+ if (mimetype == "pending")
+ fileDiv.classList.add('pending');
- if (fileview.mimetype == "pending")
- visuals.classList.add('pending');
+ fileDiv.appendChild(img);
+ fileDiv.appendChild(filename);
- visuals.appendChild(img);
- visuals.appendChild(filename);
+ current_directory.appendChild(fileDiv);
- current_directory.appendChild(visuals);
+ var file = new FileView(name, fileDiv, mimetype, is_directory);
+ files.push(file);
+ return file;
}
function begin_upload() {
context_menu.style.left = e.clientX + "px";
context_menu.style.top = e.clientY + "px";
+
for (const e of entries) {
const li = document.createElement('li');
li.innerText = e[0];
context_menu.remove();
}
- document.body.onmousemove = (e) => {
- if (dragging) {
- dragging.style.left = (e.clientX - dragging_offset_x) + "px";
- dragging.style.top = (e.clientY + dragging_offset_y) + "px";
- }
- }
-
load_dir();
F diff --git a/mimeicons/application-x-empty.png b/mimeicons/application-x-empty.png
deleted file mode 100644
B Binary files a/mimeicons/application-x-empty.png and /dev/null differ
F diff --git a/php/mkdir.php b/php/mkdir.php
new file mode 100644
--- /dev/null
+++ b/php/mkdir.php
+ <?php
+ require_once "database.php";
+ require_once "user.php";
+ require_once "node.php";
+
+ session_start();
+ $parent_directory=$_POST['parent_directory'];
+ $dirname=$_POST['dirname'];
+ $user=$_SESSION['user_object'];
+
+ create_directory($parent_directory,$dirname,"",$user);
+
+
+ ?>
F diff --git a/php/node.php b/php/node.php
--- a/php/node.php
+++ b/php/node.php
require_once "user.php";
- /*returns an assoc arrat of Node-s*/
/*path is in terms of the simulated filesystem*/
function get_directory(string $abstract_path,User $user)
{
}
if($component=strtok($abstract_path,"/")==false)
{
- return $database->get_links_of($user->home_directory);
+ return $user->home_directory;
}
$current_dir=$database->get_node_id($component,$user->home_directory);
if($current_dir==NULL)
if($current_dir==NULL)
return NULL;
}
- return $database->get_links_of($current_dir);
+ return $current_dir;
+ }
+
+ /*returns an assoc arrat of Node-s*/
+ /*path is in terms of the simulated filesystem*/
+ function get_directory_contents(string $abstract_path,User $user)
+ {
+ global $database;
+ $dir_id=get_directory($abstract_path,$user);
+ if($dir_id==NULL)
+ return NULL;
+ return $database->get_links_of($dir_id);
+ }
+
+ /*path is in terms of the simulated filesystem*/
+ function create_directory(string $abstract_path,string $directory_name,string $note,User $user)
+ {
+ global $database;
+ $dir_id=$database->create_dangling_directory();
+ $parent_dir_id=get_directory($abstract_path,$user);
+ $database->link_nodes($parent_dir_id,$dir_id,$directory_name,$note);
}
?>
F diff --git a/php/readdir.php b/php/readdir.php
--- a/php/readdir.php
+++ b/php/readdir.php
<?php
require_once "node.php";
session_start();
- $user=$_SESSION["user_object"];
+ $user=$_SESSION['user_object'];
//echo '[ { "name": "file1.txt", "mimetype": "text/plain", "is_directory": false }, { "name": "file2.pdf", "mimetype": "application/pdf", "is_directory": false }, { "name": "dir", "mimetype": "", "is_directory": true } ] ';
- $ret=get_directory("/",$user);
+ $ret=get_directory_contents("/",$user);
$json=json_encode($ret);
echo $json;
?>