summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonas Suhr Christensen <jsc@umbraculum.org>2012-05-17 12:10:57 +0200
committerJonas Suhr Christensen <jsc@umbraculum.org>2012-05-17 12:10:57 +0200
commit69f1a4dfc0d3a7a1462d87a31b11197a638c5746 (patch)
treeeb4be65262797896b928ab01bd5d1b12644cbe1b
parent2b542db3b553e73bdd58f54f657776715fd5472d (diff)
parentc2def65a701a973cde305d8c221d01beeb33eb84 (diff)
Merge branch 'master' of https://git.oftal.dk/munia
Conflicts: src/taskmanager.cc
-rw-r--r--TODO6
-rw-r--r--munia.html6
-rw-r--r--proto.js524
-rw-r--r--src/Makefile.am2
-rw-r--r--src/messagehandler.cc47
-rw-r--r--src/messageparser.cc8
-rw-r--r--src/messageparser.h1
-rw-r--r--src/munia_proto.cc53
-rw-r--r--src/muniacli.cc2
-rw-r--r--src/taskmanager.cc19
-rw-r--r--src/taskmanager.h5
-rw-r--r--src/tasktree.cc3
-rw-r--r--src/tasktree.h2
13 files changed, 257 insertions, 421 deletions
diff --git a/TODO b/TODO
new file mode 100644
index 0000000..26fa257
--- /dev/null
+++ b/TODO
@@ -0,0 +1,6 @@
+Add depth to observe and make default client connection "observe 0 2",
+ ie. observe root node with Projects visible.
+
+Make move commands transform into a delete and create event.
+Collapse delete and create events to move event before transmission if
+ both exist for the same client. \ No newline at end of file
diff --git a/munia.html b/munia.html
index 894160f..cddf8da 100644
--- a/munia.html
+++ b/munia.html
@@ -50,13 +50,9 @@ body {
</head>
<body id="body">
<div id="wstask_status">TaskProto not initialized</div>
-<div id="wsobserve_status">ObserveProto not initialized</div>
-TaskProto: <input type="text" id="input_task_data" value="add title description -1" onfocus="clear()"/>
+TaskProto: <input type="text" id="input_task_data" value="observe 0" onfocus="clear()"/>
<input type="button" value="submit" onclick="task_submit()"/><br/>
-ObserveProto: <input type="text" id="input_observe_data" value="observe 0" onfocus="clear()"/>
-<input type="button" value="submit" onclick="observe_submit()"/><br/>
TaskMessages: <span id="wstask_lastmsg"></span><br/>
-ObserveMessages: <span id="wsobserve_lastmsg"></span>
</div>
<div id="board" class="board"></div>
<script type="text/javascript" charset="utf-8" src="/proto.js"></script>
diff --git a/proto.js b/proto.js
index 4b0581f..74eeabd 100644
--- a/proto.js
+++ b/proto.js
@@ -55,8 +55,6 @@ var BrowserDetect = {
};
-//document.cursor = crosshair;
-
BrowserDetect.init();
function get_appropriate_ws_url()
@@ -64,434 +62,168 @@ function get_appropriate_ws_url()
var pcol;
var u = document.URL;
- /*
- * We open the websocket encrypted if this page came on an
- * https:// url itself, otherwise unencrypted
- */
-
- if (u.substring(0, 5) == "https") {
- pcol = "wss://";
- u = u.substr(8);
- } else {
- pcol = "ws://";
- if (u.substring(0, 4) == "http")
- u = u.substr(7);
- }
+ /*
+ * We open the websocket encrypted if this page came on an
+ * https:// url itself, otherwise unencrypted
+ */
+
+ if (u.substring(0, 5) == "https") {
+ pcol = "wss://";
+ u = u.substr(8);
+ } else {
+ pcol = "ws://";
+ if (u.substring(0, 4) == "http")
+ u = u.substr(7);
+ }
- u = u.split('/');
+ u = u.split('/');
- return pcol + u[0];
+ return pcol + u[0];
}
-
-//document.getElementById("create_task").style.display = '';
-
-/* lws-task protocol */
-
-var down = 0;
-var no_last = 1;
-var last_x = 0, last_y = 0;
-var ctx;
var socket_task;
-//var socket_observe;
-var color = "#000000";
-var dragged = "";
var board = document.getElementById("board");
-board.setAttribute("ondrop", "dropInBody(event)");
-board.setAttribute("ondragover", "return false");
-board.setAttribute("ondragenter", "return dragenter(this)");
-board.setAttribute("ondragleave", "return dragleave(this)");
-
if (BrowserDetect.browser == "Firefox") {
- socket_task = new MozWebSocket(get_appropriate_ws_url(), "lws-task-protocol");
-// socket_observe = new MozWebSocket(get_appropriate_ws_url(), "lws-observe-protocol");
+ socket_task = new MozWebSocket(get_appropriate_ws_url(), "lws-task-protocol");
} else {
- socket_task = new WebSocket(get_appropriate_ws_url(), "lws-task-protocol");
-// socket_observe = new WebSocket(get_appropriate_ws_url(), "lws-observe-protocol");
+ socket_task = new WebSocket(get_appropriate_ws_url(), "lws-task-protocol");
}
try {
- socket_task.onopen = function() {
- document.getElementById("wstask_status").style.backgroundColor = "#40ff40";
- document.getElementById("wstask_status").textContent = "TaskProto websocket connection opened ";
- // document.getElementById("box").style.display = "none";
- }
-
- socket_task.onmessage = function got_packet(msg) {
- document.getElementById("wstask_lastmsg").textContent = msg.data;
-
- var msgs = new Array();
- var idx = 0;
- msgs[idx] = '';
- var c = 0;
- var instring = false;
- for(c = 0; c < msg.data.length; c++) {
- if(msg.data[c] == '"' && c > 0 && msg.data[c - 1] != '\\') instring = !instring;
- if(msg.data[c] == ';' && instring == false) {
- idx++;
+ socket_task.onopen = function() {
+ document.getElementById("wstask_status").style.backgroundColor = "#40ff40";
+ document.getElementById("wstask_status").textContent = "TaskProto websocket connection opened ";
+ }
+
+ socket_task.onmessage = function got_packet(msg) {
+ document.getElementById("wstask_lastmsg").textContent = msg.data;
+
+ var msgs = new Array();
+ var idx = 0;
msgs[idx] = '';
- }
- if(msg.data[c] != ';' || instring == true) msgs[idx] += msg.data[c];
- }
-
- f = 0;
- while (f < msgs.length - 1) {
- var msg = new Array();
- instring = false;
- idx = 0;
- msg[idx] = '';
- for(c = 0; c < msgs[f].length; c++) {
- if(msgs[f][c] == '"' && c > 0 && msgs[f][c - 1] != '\\') {
- instring = !instring;
- continue;
- }
- if(msgs[f][c] == ' ' && instring == false) {
- msg[idx] = msg[idx].replace("\\\\","\\").replace("\\\"","\"");
- idx++;
- msg[idx] = '';
+ var c = 0;
+ var instring = false;
+ for(c = 0; c < msg.data.length; c++) {
+ if(msg.data[c] == '"' && c > 0 && msg.data[c - 1] != '\\') instring = !instring;
+ if(msg.data[c] == ';' && instring == false) {
+ idx++;
+ msgs[idx] = '';
+ }
+ if(msg.data[c] != ';' || instring == true) msgs[idx] += msg.data[c];
}
- if(msgs[f][c] != ' ' || instring == true) msg[idx] += msgs[f][c];
- }
-
- var cmd = msg[0];
- if(cmd == "del") {
- var id = msg[1];
- var task = document.getElementById("task_" + id);
- //todo: remove from parent not board
- board.removeChild(task);
- }
- else if(cmd == "move") {
- var id = msg[1];
- var parent_id = msg[2];
-// var left = msg[2];
-// var top = msg[3];
- var task = document.getElementById("task_" + id);
- if(parent_id != -1) {
- var parent_task = document.getElementById("task_" + parent_id);
- parent_task.appendChild(task);
- }
- else {
- board.appendChild(task);
+ f = 0;
+ while (f < msgs.length - 1) {
+ var msg = new Array();
+ instring = false;
+ idx = 0;
+
+ // strip padding and trailing whitespace.
+ var msgstr = msgs[f].replace(/^\s+||\s+$/g,'');
+
+ msg[idx] = '';
+ for(c = 0; c < msgstr.length; c++) {
+ if(msgstr[c] == '"' && c > 0 && msgstr[c - 1] != '\\') {
+ instring = !instring;
+ continue;
+ }
+ if(msgstr[c] == ' ' && instring == false) {
+ msg[idx] = msg[idx].replace("\\\\","\\").replace("\\\"","\"");
+ idx++;
+ msg[idx] = '';
+ }
+ if(msgstr[c] != ' ' || instring == true) msg[idx] += msgstr[c];
+ }
+
+ var observeid = msg[0];
+ var cmd = msg[1];
+ var id = msg[2];
+
+ if(cmd == "remove") {
+ var task = document.getElementById("task_" + id);
+ task.parentNode.removeChild(task);
+ }
+ else if(cmd == "move") {
+ var parent_id = msg[3];
+ var task = document.getElementById("task_" + id);
+ if(parent_id != -1) {
+ var parent_task = document.getElementById("task_" + parent_id);
+ parent_task.appendChild(task);
+ }
+ else {
+ board.appendChild(task);
+ }
+ }
+ else if(cmd == "create") {
+ var parent_id = msg[3];
+ var task = document.createElement("div");
+
+ task.name = "task";
+ task.setAttribute("class", "task");
+ task.setAttribute("ondrop", "drop(this, event)");
+ task.setAttribute("ondragover", "return false");
+ task.setAttribute("draggable", true);
+ task.setAttribute("ondragstart", "drag(this, event)");
+
+ task.id = "task_" + id;
+
+ var taskText = document.createTextNode('[' + task.id + ']');
+ taskText.id = "txt";
+ task.appendChild(taskText);
+
+ var parent_task = document.getElementById("task_" + parent_id);
+
+ if(parent_task) {
+ parent_task.appendChild(task);
+ }
+ else {
+ board.appendChild(task);
+ }
+ }
+ else if(cmd == "update") {
+ var title = msg[3];
+ var task = document.getElementById("task_" + id);
+ var taskText = document.createTextNode(title);
+ task.appendChild(taskText);
+ }
+ f++;
}
-// task.parentNode.removeChild(task);
-// board.removeChild(task);
-// parent_task.appendChild(task);
-// task.style.left = left + "px";
-// task.style.top = top + "px";
- }
- else if(cmd == "add") {
- var id = msg[1];
- var title = msg[2];
- var description = msg[3];
- var parent_id = msg[4];
-
- var task = document.createElement("div");
- task.name = "task";
- task.setAttribute("class", "task");
- task.setAttribute("ondrop", "drop(this, event)");
- task.setAttribute("ondragenter", "return dragenter(this)");
- task.setAttribute("ondragleave", "return dragleave(this)");
- task.setAttribute("ondragover", "return false");
- task.setAttribute("draggable", true);
- task.setAttribute("ondragstart", "drag(this, event)");
-
- task.id = "task_" + id;
-
- var taskText = document.createTextNode(title + ": " + description + " :" + task.id);
- taskText.id = "txt";
- task.appendChild(taskText);
-
-// task.style.position = "absolute";
-// task.style.left = left + "px";
-// task.style.top = top + "px";
-// task.setAttribute("onMouseDown", "dragged = '" + id + "';");
-
-// var dlButton = document.createElement("input");
-// dlButton.type = "button";
-// dlButton.value = "Remove";
-// dlButton.onclick = "deleteTask(document.getElementById(" + task.id + ").id";
-// dlButton.setAttribute("onclick", "deleteTask(" + id +")");
-// task.appendChild(dlButton);
-
-// board.appendChild(task);
-
- var parent_task = document.getElementById("task_" + parent_id);
-
- if(parent_task) {
- parent_task.appendChild(task);
- }
- else {
- board.appendChild(task);
- }
- }
- else if(cmd == "update") {
- var id = msg[1];
- var title = msg[2];
- var description = msg[3];
-
- var task = document.getElementById("task_" + id);
-
- var taskText = document.createTextNode(title + ": " + description + " :" + task.id);
- task.appendChild(taskText);
- }
- f++;
-// document.getElementById("box").style.top = i[3] + "px";
-// document.getElementById("box").style.left = i[2] + "px";
-// document.getElementById("box").style.display = "block";
- }
- }
-
- socket_task.onclose = function(){
- document.getElementById("wstask_status").style.backgroundColor = "#ff4040";
- document.getElementById("wstask_status").textContent = "TaskProto websocket connection CLOSED ";
- }
-} catch(exception) {
- alert('<p>Error' + exception + '</p>');
-}
-
-/*
-try {
- socket_observe.onopen = function() {
- document.getElementById("wsobserve_status").style.backgroundColor = "#40ff40";
- document.getElementById("wsobserve_status").textContent = "ObserveProto websocket connection opened ";
- // document.getElementById("box").style.display = "none";
- }
-
- socket_observe.onmessage = function got_packet(msg) {
- document.getElementById("wsobserve_lastmsg").textContent = msg.data;
-
- var msgs = new Array();
- var idx = 0;
- msgs[idx] = '';
- var c = 0;
- var instring = false;
- for(c = 0; c < msg.data.length; c++) {
- if(msg.data[c] == '"' && c > 0 && msg.data[c - 1] != '\\') instring = !instring;
- if(msg.data[c] == ';' && instring == false) {
- idx++;
- msgs[idx] = '';
- }
- if(msg.data[c] != ';' || instring == true) msgs[idx] += msg.data[c];
}
- f = 0;
- while (f < msgs.length - 1) {
- var msg = new Array();
- instring = false;
- idx = 0;
- msg[idx] = '';
- for(c = 0; c < msgs[f].length; c++) {
- if(msgs[f][c] == '"' && c > 0 && msgs[f][c - 1] != '\\') {
- instring = !instring;
- continue;
- }
- if(msgs[f][c] == ' ' && instring == false) {
- msg[idx] = msg[idx].replace("\\\\","\\").replace("\\\"","\"");
- idx++;
- msg[idx] = '';
- }
- if(msgs[f][c] != ' ' || instring == true) msg[idx] += msgs[f][c];
- }
-
- var cmd = msg[0];
-
- if(cmd == "del") {
- var id = msg[1];
- var task = document.getElementById("task_" + id);
- //todo: remove from parent not board
- board.removeChild(task);
- }
- else if(cmd == "move") {
- var id = msg[1];
- var parent_id = msg[2];
-// var left = msg[2];
-// var top = msg[3];
- var task = document.getElementById("task_" + id);
- if(parent_id != -1) {
- var parent_observe = document.getElementById("task_" + parent_id);
- parent_observe.appendChild(task);
- }
- else {
- board.appendChild(task);
- }
-// task.parentNode.removeChild(task);
-// board.removeChild(task);
-// parent_observe.appendChild(task);
-// task.style.left = left + "px";
-// task.style.top = top + "px";
- }
- else if(cmd == "add") {
- var id = msg[1];
- var title = msg[2];
- var description = msg[3];
- var parent_id = msg[4];
-
- var task = document.createElement("div");
- task.name = "task";
- task.setAttribute("class", "task");
- task.setAttribute("ondrop", "drop(this, event)");
- task.setAttribute("ondragenter", "return dragenter(this)");
- task.setAttribute("ondragleave", "return dragleave(this)");
- task.setAttribute("ondragover", "return false");
- task.setAttribute("draggable", true);
- task.setAttribute("ondragstart", "drag(this, event)");
-
- task.id = "task_" + id;
-
- var taskText = document.createTextNode(title + ": " + description + " :" + task.id);
- taskText.id = "txt";
- task.appendChild(taskText);
-
-// task.style.position = "absolute";
-// task.style.left = left + "px";
-// task.style.top = top + "px";
-// task.setAttribute("onMouseDown", "dragged = '" + id + "';");
-
-// var dlButton = document.createElement("input");
-// dlButton.type = "button";
-// dlButton.value = "Remove";
-// dlButton.onclick = "deleteTask(document.getElementById(" + task.id + ").id";
-// dlButton.setAttribute("onclick", "deleteTask(" + id +")");
-// task.appendChild(dlButton);
-
-// board.appendChild(task);
-
- var parent_observe = document.getElementById("task_" + parent_id);
-
- if(parent_observe) {
- parent_observe.appendChild(task);
- }
- else {
- board.appendChild(task);
- }
- }
- else if(cmd == "update") {
- var id = msg[1];
- var title = msg[2];
- var description = msg[3];
-
- var task = document.getElementById("task_" + id);
-
- var taskText = document.createTextNode(title + ": " + description + " :" + task.id);
- task.appendChild(taskText);
- }
- f++;
-// document.getElementById("box").style.top = i[3] + "px";
-// document.getElementById("box").style.left = i[2] + "px";
-// document.getElementById("box").style.display = "block";
+ socket_task.onclose = function(){
+ document.getElementById("wstask_status").style.backgroundColor = "#ff4040";
+ document.getElementById("wstask_status").textContent = "TaskProto websocket connection CLOSED ";
}
- }
-
- socket_observe.onclose = function(){
- document.getElementById("wsobserve_status").style.backgroundColor = "#ff4040";
- document.getElementById("wsobserve_status").textContent = "ObserveProto websocket connection CLOSED ";
- }
} catch(exception) {
- alert('<p>Error' + exception + '</p>');
-}
-*/
-
-//var canvas = document.createElement('canvas');
-//canvas.height = 600;
-//canvas.width = 800;
-//ctx = canvas.getContext("2d");
-
-//document.addEventListener('mousemove', ev_mousemove, false);
-//document.addEventListener('mouseup', ev_mouseup, false);
-/*
-canvas.addEventListener('mousedown', ev_mousedown, false);
-//cancas.addEventListener('dragend', ev_mousemove, false);
-*/
-
-//offsetX = offsetY = 0;
-//element = canvas;
-//if (element.offsetParent) {
-// do {
-// offsetX += element.offsetLeft;
-// offsetY += element.offsetTop;
-// } while ((element = element.offsetParent));
-//}
-
-function update_color() {
- color = document.getElementById("color").value;
+ alert('<p>Error' + exception + '</p>');
}
-//function ev_mouseup(ev) {
-// dragged = '';
-//}
-
-//function ev_mousemove (ev)
-//{
- // if(dragged == '') return;
-//
-// var x, y;
-// x = ev.clientX;
-// y = ev.clientY;
-
-// socket_observe.send("move " + dragged + " " + x + " " + y);
-//}
-
function task_submit() {
- var data = document.getElementById("input_task_data").value;
- socket_task.send(data);
-}
-/*
-function observe_submit() {
- var data = document.getElementById("input_observe_data").value;
- socket_observe.send(data);
+ var data = document.getElementById("input_task_data").value;
+ socket_task.send(data);
}
-*/
+
function clear() {
- document.getElementById("input_data").value = "";
+ document.getElementById("input_data").value = "";
}
function deleteTask(id) {
- socket_task.send("del " + id + ";");
+ socket_task.send("del " + id + ";");
}
function drag(target, e) {
- e.target.style.opacity = '0.4';
- e.dataTransfer.setData('Text', target.id);
- e.stopPropagation(); // <--- this fixes the drag target problem
+ e.target.style.opacity = '0.4';
+ e.dataTransfer.setData('Text', target.id);
+ e.stopPropagation(); // <--- this fixes the drag target problem
}
function drop(target, e) {
- this.style.opacity = '1.0';
- e.preventDefault();
- e.stopPropagation();
-
- var id = e.dataTransfer.getData('Text');
- var task = document.getElementById(id);
-// task.parentNode.removeChild(task);
-// alert("move " + id.substring(5, id.length) + " " + target.id.substring(5,target.id.length) + ";");
- socket_task.send("move " + id.substring(5, id.length) + " " + target.id.substring(5, target.id.length) + ";");
-
-// target.appendChild(task);
-}
-
-function dragenter(obj) {
- obj.style.backgroundColor = 'red';
- return false;
-}
+ e.preventDefault();
+ e.stopPropagation();
-function dragleave(obj) {
- obj.style.backgroundColor = 'grey';
- return false;
+ var id = e.dataTransfer.getData('Text');
+ var task = document.getElementById(id);
+ socket_task.send("move " + id.substring(5, id.length) + " " + target.id.substring(5, target.id.length) + ";");
}
-
-function dropInBody(e) {
- e.preventDefault();
- e.stopPropagation();
-
- var id = e.dataTransfer.getData('Text');
- var task = document.getElementById(id);
-// task.parentNode.removeChild(task);
-// alert("move " + id.substring(5, id.length) + " " + target.id.substring(5,target.id.length) + ";");
- socket_task.send("move " + id.substring(5, id.length) + " -1;");
-
-// target.appendChild(task);
-}
-
diff --git a/src/Makefile.am b/src/Makefile.am
index 01ef438..0e59695 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -27,7 +27,7 @@ muniacli_LDADD = $(LIBWEBSOCKETS_LIBS)
muniacli_CXXFLAGS = $(LIBWEBSOCKETS_CFLAGS)
-muniad_SOURCES = \
+muniacli_SOURCES = \
muniacli.cc
EXTRA_DIST = \
diff --git a/src/messagehandler.cc b/src/messagehandler.cc
index cdc7246..a394f08 100644
--- a/src/messagehandler.cc
+++ b/src/messagehandler.cc
@@ -86,8 +86,51 @@ MessageList handle_msg(MessageList msgList, clientid_t wsi) {
{
INFO(messagehandler, "Handling move command\n");
try {
- m.nodes = task_manager.moveTask(m.move.id, m.move.parentid);
- outmsgs.push_back(m);
+ task_t removetask = task_manager.task(m.move.id);
+ TaskIdListPair tilpair = task_manager.moveTask(m.move.id, m.move.parentid);
+ task_t createtask = task_manager.task(m.move.id);
+
+ /*
+ TaskIdList commonAncestors;
+ TaskIdList removeAncestors;
+ TaskIdList createAncestors;
+
+ // find command ancestors and fill ancestors for remove command
+ for(TaskIdList::iterator it_remove = tilpair.first.begin();
+ it_remove != tilpair.first.end(); it_remove++) {
+ taskid_t removeid = *it;
+ bool common = false;
+ for(TaskIdList::iterator it_create = tilpair.second.begin();
+ it_create = != tilpair.second.end(); it_create++) {
+ taskid_t createid = *id;
+ if(removeid == createid) {
+ commandAncestors.push_back(removeid);
+ common = true;
+ }
+ }
+ if(!common) {
+ removeAncestors.push_back(removeid);
+ }
+ }
+
+ // fill ancestors for create command
+ for(TaskIdList::iterator it_create = tilpair.second.begin();
+ it_create = != tilpair.second.end(); it_create++) {
+ taskid_t createid = *id;
+ if(removeid == createid) {
+ commandAncestors.push_back(removeid);
+ common = true;
+ }
+ }
+ */
+
+ message_t removemsg = create_msg_remove(removetask);
+ removemsg.nodes = tilpair.first;
+ message_t createmsg = create_msg_create(createtask);
+ createmsg.nodes = tilpair.second;
+
+ outmsgs.push_back(removemsg);
+ outmsgs.push_back(createmsg);
}
catch (std::exception& e) {
DEBUG(messagehandler, "Error moving task\n");
diff --git a/src/messageparser.cc b/src/messageparser.cc
index 804eb12..62923be 100644
--- a/src/messageparser.cc
+++ b/src/messageparser.cc
@@ -245,6 +245,14 @@ message_t create_msg_remove(task_t t) {
return m;
}
+message_t create_msg_move(taskid_t id, taskid_t to) {
+ message_t m;
+ m.cmd = cmd::move;
+ m.move.id = id;
+ m.move.parentid = to;
+ return m;
+}
+
#ifdef TEST_MSGPARSER
//Additional dependency files
//deps:
diff --git a/src/messageparser.h b/src/messageparser.h
index 6ebac3e..11b11cb 100644
--- a/src/messageparser.h
+++ b/src/messageparser.h
@@ -38,5 +38,6 @@ std::string msg_tostring(message_t msg);
message_t create_msg_create(task_t task);
message_t create_msg_update(task_t task);
message_t create_msg_remove(task_t task);
+message_t create_msg_move(taskid_t id, taskid_t to);
#endif/*__MUNIA_MESSAGEPARSER_H__*/
diff --git a/src/munia_proto.cc b/src/munia_proto.cc
index d9b068f..3022042 100644
--- a/src/munia_proto.cc
+++ b/src/munia_proto.cc
@@ -147,30 +147,62 @@ int callback_lws_task(struct libwebsocket_context * context,
std::string msgstr;
msgstr.append((size_t)LWS_SEND_BUFFER_PRE_PADDING, ' ');
+ int c = 0;
+ message_t prevmsg;
+ std::queue<message_t> messages;
while(msgqueue[wsi].size() > 0) {
message_t msg = msgqueue[wsi].front();
msgqueue[wsi].pop();
+
+ //Rewriting delete id followed by create id to move to_id from_id
+ // look at previous message from create commands
+ if(c > 0 && // look backward (skip first entry)
+ msg.cmd == cmd::create && // look from create commands
+ prevmsg.cmd == cmd::remove && // if previous msg is a remove command
+ msg.create.id == prevmsg.remove.id) { // and commands have same id
+
+ printf("\tprevmsg: %s, msg: %s\n", msg_tostring(prevmsg).c_str(),
+ msg_tostring(msg).c_str());
+ message_t movemsg = create_msg_move(msg.create.id, msg.create.parentid);
+ msg = movemsg;
+ }
+ else if(c > 0) {
+ messages.push(prevmsg);
+ }
+
+ prevmsg = msg;
+ c++;
+ }
+ if(c > 0) { // Push last msg
+ messages.push(prevmsg);
+ }
+
+ // create msg string
+ // while(msgqueue[wsi].size() > 0) {
+ while(messages.size() > 0) {
+ message_t msg = messages.front();
+ messages.pop();
char buf[32];
sprintf(buf, "%d", msg.tid);
+ printf("msg: %s\n", msg_tostring(msg).c_str());
if(msgstr.size() > LWS_SEND_BUFFER_PRE_PADDING) msgstr += " ";
msgstr += std::string(buf) + " " + msg_tostring(msg);
}
msgstr.append((size_t)LWS_SEND_BUFFER_POST_PADDING, ' ');
-
+
int n = libwebsocket_write(wsi, (unsigned char *)
- msgstr.c_str() +
- LWS_SEND_BUFFER_PRE_PADDING,
- msgstr.length() -
- LWS_SEND_BUFFER_POST_PADDING -
- LWS_SEND_BUFFER_PRE_PADDING,
- LWS_WRITE_TEXT);
+ msgstr.c_str() +
+ LWS_SEND_BUFFER_PRE_PADDING,
+ msgstr.length() -
+ LWS_SEND_BUFFER_POST_PADDING -
+ LWS_SEND_BUFFER_PRE_PADDING,
+ LWS_WRITE_TEXT);
if(n < 0) {
fprintf(stderr, "ERROR writing to socket");
exit(1);
- }
- }
-
+ } }
+
break;
/*
@@ -228,7 +260,6 @@ int callback_lws_task(struct libwebsocket_context * context,
id++;
}
-
} else {
printf("%d nodes affected by command\n", omi->nodes.size());
diff --git a/src/muniacli.cc b/src/muniacli.cc
index 3620a85..a84de65 100644
--- a/src/muniacli.cc
+++ b/src/muniacli.cc
@@ -34,7 +34,7 @@
#include <libwebsockets.h>
enum demo_protocols {
- PROTOCOL_TASK,
+ PROTOCOL_TASK
};
static int callback_task(struct libwebsocket_context *me,
diff --git a/src/taskmanager.cc b/src/taskmanager.cc
index 60b01d6..89de0b3 100644
--- a/src/taskmanager.cc
+++ b/src/taskmanager.cc
@@ -39,6 +39,11 @@ TaskManager task_manager;
#define PROJECTS_ID 4
#define FIRST_TASK_ID 10
+static bool isProtected(taskid_t id)
+{
+ return id < FIRST_TASK_ID;
+}
+
TaskManager::TaskManager() {
idCount = FIRST_TASK_ID;
@@ -80,7 +85,10 @@ taskid_t TaskManager::createId() {
TaskIdListPair TaskManager::moveTask(taskid_t id, taskid_t to)
throw (std::exception) {
+ if(isProtected(id)) return TaskIdListPair();
+
/*
+
TaskIdList affectedTasks;
try {
@@ -91,11 +99,11 @@ TaskIdListPair TaskManager::moveTask(taskid_t id, taskid_t to)
}
*/
- task_t t = data(id);
+ task_t t = tree.data(id);
t.parentid = to;
- TaskIdListRemove tilremove = tree.remove(id);
- TaskIdListCreate tilcreate = tree.create(to, id, t);
+ TaskIdList tilremove = tree.remove(id);
+ TaskIdList tilcreate = tree.insertAsChild(to, id, t);
TaskIdListPair tilpair;
tilpair.first = tilremove;
@@ -106,6 +114,9 @@ TaskIdListPair TaskManager::moveTask(taskid_t id, taskid_t to)
TaskIdList TaskManager::removeTask(taskid_t id)
throw (std::exception) {
+
+ if(isProtected(id)) return TaskIdList();
+
TaskIdList affectedTasks;
if(tree.bfs(id).size() > 1) throw std::exception();
@@ -123,6 +134,8 @@ TaskIdList TaskManager::removeTask(taskid_t id)
TaskIdList TaskManager::updateTask(taskid_t id, task_t t)
throw (std::exception) {
+ if(isProtected(id)) return TaskIdList();
+
TaskIdList affectedTasks;
try {
diff --git a/src/taskmanager.h b/src/taskmanager.h
index dc0cf1c..0f0d96e 100644
--- a/src/taskmanager.h
+++ b/src/taskmanager.h
@@ -36,6 +36,8 @@
#include "task.h"
#include "tasktree.h"
+typedef std::pair<TaskIdList, TaskIdList> TaskIdListPair;
+
class TaskManager {
public:
TaskManager();
@@ -44,7 +46,8 @@ public:
TaskIdList createTask(taskid_t parentid, taskid_t *id) throw (std::exception);
TaskIdList updateTask(taskid_t id, task_t task) throw (std::exception);
TaskIdList removeTask(taskid_t id) throw (std::exception);
- TaskIdList moveTask(taskid_t id, taskid_t newParent) throw (std::exception);
+
+ TaskIdListPair moveTask(taskid_t id, taskid_t newParent) throw (std::exception);
TaskIdList subTasks(taskid_t) throw (std::exception);
diff --git a/src/tasktree.cc b/src/tasktree.cc
index fc84efa..5c58e3c 100644
--- a/src/tasktree.cc
+++ b/src/tasktree.cc
@@ -124,6 +124,7 @@ TaskIdList TaskTree::remove(taskid_t id)
return affectedNodes;
}
+/*
TaskIdList TaskTree::move(taskid_t id, taskid_t toid)
throw (std::exception)
{
@@ -156,7 +157,9 @@ TaskIdList TaskTree::move(taskid_t id, taskid_t toid)
return affectedNodes;
}
+*/
+
TaskIdList TaskTree::updateData(taskid_t id, task_t t)
throw (std::exception)
{
diff --git a/src/tasktree.h b/src/tasktree.h
index d82b9a4..41a29be 100644
--- a/src/tasktree.h
+++ b/src/tasktree.h
@@ -52,7 +52,7 @@ public:
TaskIdList insertAsChild(taskid_t parentid, taskid_t id, task_t data) throw (std::exception);
TaskIdList remove(taskid_t id) throw (std::exception);
- TaskIdList move(taskid_t id, taskid_t newParentId) throw (std::exception);
+ // TaskIdList move(taskid_t id, taskid_t newParentId) throw (std::exception);
TaskIdList updateData(taskid_t id, task_t t) throw (std::exception);
task_t data(taskid_t id) throw (std::exception);