F diff --git a/loggedin.js b/loggedin.js
--- a/loggedin.js
+++ b/loggedin.js
move_file("/trash", filename, path_combine(get_path(), filename));
}
- function delete_file(filename) {
- var file_full_path = path_combine(get_path(), filename);
+ function restore_from_trash(filename) {
+ var split = filename.split("/");
+ var new_filename = split.pop();
+ var new_directory = "/" + split.join("/");
+
+ move_file(new_directory, filename, new_filename);
+ }
+ function delete_file(filename) {
var data = new FormData();
- data.append('path', file_full_path);
+ data.append('folder', get_path());
+ data.append('filename', filename);
var xhr = new XMLHttpRequest();
xhr.open('POST', '/php/delete.php', true);
function add_file_visuals(fileview) {
+ var is_in_trash = focus.pwd.length == 1 && focus.pwd[0] == "trash";
+
var visuals = document.createElement('div');
fileview.visuals = visuals;
visuals.oncontextmenu = (e) => {
if (!dragging) {
- context(e, [
+
+ var context_list = [
['Open', () => {
focus.pwd.push(fileview.filename);
openfile(fileview.is_directory);
- }],
+ }],
['Open in New Window', () => {alert('not implemented')}],
- ['Rename', () => { rename_file(fileview.filename); }],
- ['Share', () => {alert('not implemented')}],
- ['Delete', () => { move_to_trash(fileview.filename); }],
- ]);
+ ];
+
+ if (is_in_trash) {
+ context_list.push(['Restore', () => { restore_from_trash(fileview.filename); }]);
+ context_list.push(['Delete forever', () => { delete_file(fileview.filename); }]);
+ } else {
+ context_list.push(
+ ['Rename', () => { rename_file(fileview.filename); }],
+ ['Share', () => {alert('not implemented')}],
+ ['Delete', () => { move_to_trash(fileview.filename); }]
+ );
+ }
+
+ context(e, context_list);
}
e.preventDefault();
e.stopPropagation();
visuals.classList.add('file');
filename.classList.add('filename');
- filename.innerText = fileview.filename;
- if (fileview.mimetype == "pending")
- visuals.classList.add('pending');
+ if (is_in_trash) {
+ var split = fileview.filename.split("/");
+ filename.innerText = split[split.length - 1];
+ } else {
+ filename.innerText = fileview.filename;
+ }
visuals.appendChild(img);
visuals.appendChild(filename);
F diff --git a/php/database.php b/php/database.php
--- a/php/database.php
+++ b/php/database.php
we remove the node and
1. move the file represented by the node to the trash folder
2. remove the file
- 3. if node is a directory - delete all children nodes
depends on the conf file
*/
function delete_node_by_id(int $node_id)
}
}
-
- function unlink_nodes(int $dir_id, int $node_id)
- {
- $prep=$this->pdo->prepare("delete from node_links
- where directory_id=:dir_id and node_id=:node_id
- ");
- $prep->bindParam(':dir_id',$dir_id);
- $prep->bindParam(':node_id',$node_id);
- if($prep->execute()==false)
- {
- error_log("there was an error with the first statement in unlink_nodes");
- return;
- }
- $prep=$this->pdo->prepare("select node_id
- from node_links
- where node_id=:id
- ");
- $prep->bindParam(':id',$node_id);
- if($prep->execute()==false)
- {
- error_log("there was an error with the second statement in unlink_nodes");
- return;
- }
- if(count($prep->fetchALL(PDO::FETCH_ASSOC))==0)
- {
- delete_node_by_id($node_id);
- }
-
-
- }
-
function create_home_directory():int
{
$ret=$this->create_dangling_directory();
F diff --git a/sql/fileshare.sql b/sql/fileshare.sql
--- a/sql/fileshare.sql
+++ b/sql/fileshare.sql
drop table if exists node_access;
drop table if exists users;
drop table if exists node_links;
- drop table if exists trash;
- drop trigger if exists delete_on_zero_links;
drop table if exists nodes;
node_id int not null,
name varchar(100) not null default 'no name',
note varchar(200) not null default "",
+ check (directory_id != node_id),
foreign key (directory_id) references nodes(node_id) on delete cascade,
foreign key (node_id) references nodes(node_id) on delete cascade
);
- create table trash (
- node_id int not null,
- foreign key (node_id) references nodes(node_id) on delete cascade
- );
-
- create trigger delete_on_zero_links
- after delete
- on node_links
- for each row
- insert into trash
- select nodes.node_id
- from nodes
- where nodes.node_id not in (select node_id from node_links) and nodes.node_id=old.node_id;
-
- /*
- create trigger delete_links
- after delete
- on nodes
- for each row
- delete from
- */