From f4b130c25db123b28594a0f4abe739635e507faa Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Fri, 4 May 2012 17:05:46 +0200 Subject: Errornous target name. --- src/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 = \ -- cgit v1.2.3 From 7da71469707ae9394e457f1d212b192aa3970707 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Sat, 5 May 2012 10:42:47 +0200 Subject: Update javascript to wrk with the new protocol. --- munia.html | 5 +- proto.js | 607 +++++++++++++++++++++++++++++++------------------------------ 2 files changed, 307 insertions(+), 305 deletions(-) diff --git a/munia.html b/munia.html index 894160f..ec01af8 100644 --- a/munia.html +++ b/munia.html @@ -51,12 +51,9 @@ body {
TaskProto not initialized
ObserveProto not initialized
-TaskProto: +TaskProto:
-ObserveProto: -
TaskMessages:
-ObserveMessages:
diff --git a/proto.js b/proto.js index 4b0581f..c229473 100644 --- a/proto.js +++ b/proto.js @@ -64,23 +64,23 @@ 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]; } @@ -105,293 +105,298 @@ 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"); + // socket_observe = new MozWebSocket(get_appropriate_ws_url(), "lws-observe-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"); + // socket_observe = new WebSocket(get_appropriate_ws_url(), "lws-observe-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 "; + // 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] = ''; - } - 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; + 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 == 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_task = document.getElementById("task_" + parent_id); - parent_task.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]; + + if(cmd == "del") { + var id = msg[2]; + var task = document.getElementById("task_" + id); + //todo: remove from parent not board + board.removeChild(task); + } + else if(cmd == "move") { + var id = msg[2]; + 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); + } + // task.parentNode.removeChild(task); + // board.removeChild(task); + // parent_task.appendChild(task); + // task.style.left = left + "px"; + // task.style.top = top + "px"; + } + else if(cmd == "create") { + var id = msg[2]; + var parent_id = msg[3]; + // var title = msg[3]; + // var description = 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); + var taskText = document.createTextNode('[' + 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[2]; + var title = msg[3]; + var description = 'N/A';//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"; } - else { - board.appendChild(task); - } -// 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 "; - } + socket_task.onclose = function(){ + document.getElementById("wstask_status").style.backgroundColor = "#ff4040"; + document.getElementById("wstask_status").textContent = "TaskProto websocket connection CLOSED "; + } } catch(exception) { - alert('

Error' + exception + '

'); + alert('

Error' + exception + '

'); } /* -try { + 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"; + 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]; - } + 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]; - } + 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]; + 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]; + 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)"); + 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"; + 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); + // 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); + parent_observe.appendChild(task); } else { - board.appendChild(task); + 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); + } + 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"; - } + } + f++; + // document.getElementById("box").style.top = i[3] + "px"; + // document.getElementById("box").style.left = i[2] + "px"; + // document.getElementById("box").style.display = "block"; + } } socket_observe.onclose = function(){ - document.getElementById("wsobserve_status").style.backgroundColor = "#ff4040"; - document.getElementById("wsobserve_status").textContent = "ObserveProto websocket connection CLOSED "; + document.getElementById("wsobserve_status").style.backgroundColor = "#ff4040"; + document.getElementById("wsobserve_status").textContent = "ObserveProto websocket connection CLOSED "; } -} catch(exception) { + } catch(exception) { alert('

Error' + exception + '

'); -} + } */ //var canvas = document.createElement('canvas'); @@ -402,9 +407,9 @@ try { //document.addEventListener('mousemove', ev_mousemove, false); //document.addEventListener('mouseup', ev_mouseup, false); /* -canvas.addEventListener('mousedown', ev_mousedown, false); -//cancas.addEventListener('dragend', ev_mousemove, false); -*/ + canvas.addEventListener('mousedown', ev_mousedown, false); + //cancas.addEventListener('dragend', ev_mousemove, false); + */ //offsetX = offsetY = 0; //element = canvas; @@ -414,9 +419,9 @@ canvas.addEventListener('mousedown', ev_mousedown, false); // offsetY += element.offsetTop; // } while ((element = element.offsetParent)); //} - + function update_color() { - color = document.getElementById("color").value; + color = document.getElementById("color").value; } //function ev_mouseup(ev) { @@ -425,7 +430,7 @@ function update_color() { //function ev_mousemove (ev) //{ - // if(dragged == '') return; +// if(dragged == '') return; // // var x, y; // x = ev.clientX; @@ -435,63 +440,63 @@ function update_color() { //} function task_submit() { - var data = document.getElementById("input_task_data").value; - socket_task.send(data); + var data = document.getElementById("input_task_data").value; + socket_task.send(data); } /* -function observe_submit() { + function observe_submit() { var data = document.getElementById("input_observe_data").value; socket_observe.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); + 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; + obj.style.backgroundColor = 'red'; + return false; } function dragleave(obj) { - obj.style.backgroundColor = 'grey'; - return false; + obj.style.backgroundColor = 'grey'; + return false; } 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); + 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); } -- cgit v1.2.3 From 19fe0e08586e9e4063d507ff45b25315f5cf5bc7 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Sat, 5 May 2012 10:52:29 +0200 Subject: More fixes for new protocol. --- TODO | 1 + munia.html | 1 - proto.js | 58 +++++++++++++++++++++------------------------------------- 3 files changed, 22 insertions(+), 38 deletions(-) create mode 100644 TODO diff --git a/TODO b/TODO new file mode 100644 index 0000000..200a30e --- /dev/null +++ b/TODO @@ -0,0 +1 @@ +Server segfaults on 'remove 0' diff --git a/munia.html b/munia.html index ec01af8..cddf8da 100644 --- a/munia.html +++ b/munia.html @@ -50,7 +50,6 @@ body {
TaskProto not initialized
-
ObserveProto not initialized
TaskProto:
TaskMessages:
diff --git a/proto.js b/proto.js index c229473..4cbbfc7 100644 --- a/proto.js +++ b/proto.js @@ -161,15 +161,13 @@ try { var observeid = msg[0]; var cmd = msg[1]; + var id = msg[2]; - if(cmd == "del") { - var id = msg[2]; + if(cmd == "remove") { var task = document.getElementById("task_" + id); - //todo: remove from parent not board - board.removeChild(task); + task.parentNode.removeChild(task); } else if(cmd == "move") { - var id = msg[2]; var parent_id = msg[3]; var task = document.getElementById("task_" + id); if(parent_id != -1) { @@ -179,19 +177,11 @@ try { else { board.appendChild(task); } - // task.parentNode.removeChild(task); - // board.removeChild(task); - // parent_task.appendChild(task); - // task.style.left = left + "px"; - // task.style.top = top + "px"; } else if(cmd == "create") { - var id = msg[2]; var parent_id = msg[3]; - // var title = msg[3]; - // var description = msg[4]; - var task = document.createElement("div"); + task.name = "task"; task.setAttribute("class", "task"); task.setAttribute("ondrop", "drop(this, event)"); @@ -203,24 +193,23 @@ try { task.id = "task_" + id; - // var taskText = document.createTextNode(title + ": " + description + " :" + task.id); var taskText = document.createTextNode('[' + 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); + //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); @@ -232,20 +221,15 @@ try { } } else if(cmd == "update") { - - var id = msg[2]; var title = msg[3]; - var description = 'N/A';//msg[3]; - var task = document.getElementById("task_" + id); - - var taskText = document.createTextNode(title + ": " + description + " :" + task.id); + var taskText = document.createTextNode(title); 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"; + //document.getElementById("box").style.top = i[3] + "px"; + //document.getElementById("box").style.left = i[2] + "px"; + //document.getElementById("box").style.display = "block"; } } -- cgit v1.2.3 From c5fb4fd4d89086399762ac844b53564d98ff2d4e Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Sat, 5 May 2012 11:09:34 +0200 Subject: Fix move task by drag'n'drop. --- proto.js | 261 +-------------------------------------------------------------- 1 file changed, 2 insertions(+), 259 deletions(-) diff --git a/proto.js b/proto.js index 4cbbfc7..74eeabd 100644 --- a/proto.js +++ b/proto.js @@ -55,8 +55,6 @@ var BrowserDetect = { }; -//document.cursor = crosshair; - BrowserDetect.init(); function get_appropriate_ws_url() @@ -83,40 +81,20 @@ function get_appropriate_ws_url() 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"); } else { socket_task = new WebSocket(get_appropriate_ws_url(), "lws-task-protocol"); - // socket_observe = new WebSocket(get_appropriate_ws_url(), "lws-observe-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) { @@ -185,8 +163,6 @@ try { 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)"); @@ -196,21 +172,7 @@ try { var taskText = document.createTextNode('[' + 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) { @@ -227,9 +189,6 @@ try { 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"; } } @@ -241,198 +200,11 @@ try { alert('

Error' + exception + '

'); } -/* - 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_observe.onclose = function(){ - document.getElementById("wsobserve_status").style.backgroundColor = "#ff4040"; - document.getElementById("wsobserve_status").textContent = "ObserveProto websocket connection CLOSED "; - } - } catch(exception) { - alert('

Error' + exception + '

'); - } -*/ - -//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; -} - -//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); - } -*/ + function clear() { document.getElementById("input_data").value = ""; } @@ -448,39 +220,10 @@ function drag(target, e) { } 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; } - -function dragleave(obj) { - obj.style.backgroundColor = 'grey'; - return false; -} - -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); -} - -- cgit v1.2.3 From 33bfd025958e4485f4647d22fb9aec5d7d94db81 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Thu, 10 May 2012 08:55:01 +0200 Subject: Ignore remove/move/update commands on protected taskids (root, Finished, etc...) --- TODO | 2 +- src/muniacli.cc | 2 +- src/taskmanager.cc | 13 +++++++++++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/TODO b/TODO index 200a30e..8b13789 100644 --- a/TODO +++ b/TODO @@ -1 +1 @@ -Server segfaults on 'remove 0' + 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 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 b50e9a6..87cf2b0 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; @@ -79,6 +84,9 @@ taskid_t TaskManager::createId() { TaskIdList TaskManager::moveTask(taskid_t id, taskid_t to) throw (std::exception) { + + if(isProtected(id)) return TaskIdList(); + TaskIdList affectedTasks; try { @@ -93,6 +101,9 @@ TaskIdList 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(); @@ -110,6 +121,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 { -- cgit v1.2.3 From c2def65a701a973cde305d8c221d01beeb33eb84 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Thu, 17 May 2012 10:05:43 +0200 Subject: A couple of TODOs --- TODO | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/TODO b/TODO index 8b13789..26fa257 100644 --- a/TODO +++ b/TODO @@ -1 +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 -- cgit v1.2.3