summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/messagehandler.cc14
-rw-r--r--src/taskmanager.cc4
-rw-r--r--src/tasktree.cc48
-rw-r--r--src/testclient.cc2
4 files changed, 49 insertions, 19 deletions
diff --git a/src/messagehandler.cc b/src/messagehandler.cc
index 8217bde..cdc7246 100644
--- a/src/messagehandler.cc
+++ b/src/messagehandler.cc
@@ -63,8 +63,18 @@ MessageList handle_msg(MessageList msgList, clientid_t wsi) {
{
INFO(messagehandler, "Handling remove command\n");
try {
- m.nodes = task_manager.removeTask(m.remove.id);
- outmsgs.push_back(m);
+ TaskIdList ids = task_manager.subTasks(m.remove.id);
+ TaskIdList::reverse_iterator id = ids.rbegin();
+ while(id != ids.rend()) {
+ task_t task = task_manager.task(*id);
+
+ message_t m = create_msg_remove(task);
+ m.nodes = task_manager.removeTask(task.id);
+
+ outmsgs.push_back(m);
+ id++;
+ printf("!!!\n");
+ }
}
catch (std::exception& e) {
DEBUG(messagehandler, "Error remove task\n");
diff --git a/src/taskmanager.cc b/src/taskmanager.cc
index 2dda0e0..b50e9a6 100644
--- a/src/taskmanager.cc
+++ b/src/taskmanager.cc
@@ -94,7 +94,9 @@ TaskIdList TaskManager::moveTask(taskid_t id, taskid_t to)
TaskIdList TaskManager::removeTask(taskid_t id)
throw (std::exception) {
TaskIdList affectedTasks;
-
+
+ if(tree.bfs(id).size() > 1) throw std::exception();
+
try {
affectedTasks = tree.remove(id);
}
diff --git a/src/tasktree.cc b/src/tasktree.cc
index 77c8fc8..fc84efa 100644
--- a/src/tasktree.cc
+++ b/src/tasktree.cc
@@ -90,22 +90,38 @@ TaskIdList TaskTree::insertAsChild(taskid_t parentid, taskid_t id, task_t data)
TaskIdList TaskTree::remove(taskid_t id)
throw (std::exception)
{
- //todo: move all childrin to lost+found
- WARN(tasktree, "Feature not implemneted yet\n");
TaskIdList affectedNodes;
- return affectedNodes;
-
- /*
- try {
- node_t* node = id2node.at(id);
-
+ affectedNodes.push_back(id);
+ TaskIdList ancestors = ancestorList(id);
+ concatTaskIdLists(affectedNodes, ancestors);
+
+// printf("Removing %d\n", id);
+
+// printf("!!!!!affected nodes %d\n", affectedNodes.size());
+
+ node_t* node = id2node[id];
+
+// printf("node: %p, id %d, parent %p\n", node, node->data.id, node->parent);
+
+// printf("!!!!!size %d\n", node->parent->children.size());
+ node->parent->children.remove(node);
+ for(NodeList::iterator it = node->parent->children.begin();
+ it != node->parent->children.end();
+ it++) {
+// printf("%p\n", *it);
}
- catch (std::exception& e) {
- throw std::exception();
+// printf("!!!!!size %d\n", node->parent->children.size());
+
+ TaskIdList idlist = bfs(id);
+ TaskIdList::reverse_iterator it = idlist.rbegin();
+ while(it != idlist.rend()) {
+ task_t task = data(*it);
+// node_t* n = id2node[task.id];
+// delete(n);
+ it++;
}
return affectedNodes;
- */
}
TaskIdList TaskTree::move(taskid_t id, taskid_t toid)
@@ -125,6 +141,8 @@ TaskIdList TaskTree::move(taskid_t id, taskid_t toid)
child->parent->children.remove(child);
newparent->children.push_back(child);
+ child->parent = newparent;
+
affectedNodes.push_back(id);
// affectedNodes.push_back(child->parent->id);
TaskIdList ancestors = ancestorList(id);
@@ -233,10 +251,10 @@ TaskIdList TaskTree::ancestorList(taskid_t id)
}
// printf("Collected %d ancestors to %u\n", ancestors.size(), id);
- for(TaskIdList::iterator it = ancestors.begin();
- it != ancestors.end(); it++) {
+// for(TaskIdList::iterator it = ancestors.begin();
+// it != ancestors.end(); it++) {
// printf("\tancestor %u\n", *it);
- }
+// }
return ancestors;
}
@@ -256,7 +274,7 @@ void TaskTree::insertChild(node_t* parent, node_t* child) {
static void printNode(node_t* node, std::string prefix) {
if(!node) return;
task_t t = node->data;
- printf("%s- %u - %s\n", prefix.c_str(), t.id, t.title.c_str());
+ printf("%s- %u - %s (%p)\n", prefix.c_str(), t.id, t.title.c_str(), node);
NodeList::iterator it;
for(it = node->children.begin(); it != node->children.end(); it++) {
diff --git a/src/testclient.cc b/src/testclient.cc
index 5379b50..f608ce0 100644
--- a/src/testclient.cc
+++ b/src/testclient.cc
@@ -197,8 +197,8 @@ static struct test tests[] = {
{ "observe 0", BASE" 0 create 10 0; 0 update 10 \"My title\";", false },
{ "move 10 1", "0 move 10 1;", false },
{ "create 10", "0 create 11 10;", false },
- /*
{ "remove 10", "0 remove 11; 0 remove 10;", false },
+ /*
{ "observe 0", BASE"0 add title description 5", false },
{ "add title2 description 0", BASE"0 add title2 description 6", false },
{ "unobserve 0", NULL, false },