summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--munia.html40
-rw-r--r--proto.js186
-rw-r--r--src/Makefile.am10
-rw-r--r--src/connectionhandler.cc5
-rw-r--r--src/connectionhandler.h3
-rw-r--r--src/muniad.cc23
-rw-r--r--src/task_proto.cc2
-rw-r--r--src/xmlparser.h3
8 files changed, 221 insertions, 51 deletions
diff --git a/munia.html b/munia.html
index 260abc9..894160f 100644
--- a/munia.html
+++ b/munia.html
@@ -3,6 +3,14 @@
<head>
<title>Munia</title>
<style>
+/* Prevent the text contents of draggable elements from being selectable. */
+[draggable] {
+ -moz-user-select: none;
+ -khtml-user-select: none;
+ -webkit-user-select: none;
+ user-select: none;
+}
+
body {
cursor: default;
}
@@ -16,31 +24,39 @@ body {
-o-user-select: none;
user-select: none;
cursor: move;
- background-color: grey;
+ background-color: #888;
border-style: solid;
border-width: medium;
- border-radius: 15px;
+/* border-radius: 15px;*/
padding: 4px;
margin: 6px;
-}
-
-.task:hover {
- background-color:yellow;
+ max-width: 300px;
}
.board {
- background-color: #666;
width: *;
min-height: 300px;
- padding: 20px;
+ padding: 20px;\
+
+ background: -moz-linear-gradient(left center, rgb(0,0,0), rgb(79,79,79), rgb(21,21,21));
+ background: -webkit-gradient(linear, left top, right top,
+ color-stop(0, rgb(0,0,0)),
+ color-stop(0.50, rgb(79,79,79)),
+ color-stop(1, rgb(21,21,21)));
+ background: -webkit-linear-gradient(left center, rgb(0,0,0), rgb(79,79,79), rgb(21,21,21));
+ background: -ms-linear-gradient(left center, rgb(0,0,0), rgb(79,79,79), rgb(21,21,21));
}
</style>
</head>
<body id="body">
-<div id="wslm_status">Not initialized</div>
-<input type="text" id="input_data" value="add title description -1" onfocus="clear()"/>
-<input type="button" value="submit" onclick="submit()"/>
-<div id="wslm_lastmsg"></div>
+<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()"/>
+<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 c21ec5e..0baf22d 100644
--- a/proto.js
+++ b/proto.js
@@ -92,7 +92,8 @@ var down = 0;
var no_last = 1;
var last_x = 0, last_y = 0;
var ctx;
-var socket_lm;
+var socket_task;
+var socket_observe;
var color = "#000000";
var dragged = "";
@@ -104,20 +105,22 @@ board.setAttribute("ondragleave", "return dragleave(this)");
if (BrowserDetect.browser == "Firefox") {
- socket_lm = new MozWebSocket(get_appropriate_ws_url(), "lws-task-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_lm = new WebSocket(get_appropriate_ws_url(), "lws-task-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_lm.onopen = function() {
- document.getElementById("wslm_status").style.backgroundColor = "#40ff40";
- document.getElementById("wslm_status").textContent = " websocket connection opened ";
+ 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_lm.onmessage = function got_packet(msg) {
- document.getElementById("wslm_lastmsg").textContent = msg.data;
+ socket_task.onmessage = function got_packet(msg) {
+ document.getElementById("wstask_lastmsg").textContent = msg.data;
var msgs = new Array();
var idx = 0;
@@ -241,9 +244,149 @@ try {
}
}
- socket_lm.onclose = function(){
- document.getElementById("wslm_status").style.backgroundColor = "#ff4040";
- document.getElementById("wslm_status").textContent = " 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('<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_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>');
@@ -286,12 +429,17 @@ function update_color() {
// x = ev.clientX;
// y = ev.clientY;
-// socket_lm.send("move " + dragged + " " + x + " " + y);
+// socket_observe.send("move " + dragged + " " + x + " " + y);
//}
-function submit() {
- var data = document.getElementById("input_data").value;
- socket_lm.send(data);
+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() {
@@ -299,15 +447,17 @@ function clear() {
}
function deleteTask(id) {
- socket_lm.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
}
function drop(target, e) {
+ this.style.opacity = '1.0';
e.preventDefault();
e.stopPropagation();
@@ -315,7 +465,7 @@ function drop(target, e) {
var task = document.getElementById(id);
// task.parentNode.removeChild(task);
// alert("move " + id.substring(5, id.length) + " " + target.id.substring(5,target.id.length) + ";");
- socket_lm.send("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);
}
@@ -338,7 +488,7 @@ function dropInBody(e) {
var task = document.getElementById(id);
// task.parentNode.removeChild(task);
// alert("move " + id.substring(5, id.length) + " " + target.id.substring(5,target.id.length) + ";");
- socket_lm.send("move " + id.substring(5, id.length) + " -1;");
+ socket_task.send("move " + id.substring(5, id.length) + " -1;");
// target.appendChild(task);
}
diff --git a/src/Makefile.am b/src/Makefile.am
index 8c2cc25..781422d 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -7,25 +7,29 @@ muniad_LDADD = $(LIBWEBSOCKETS_LIBS) $(EXPAT_LIBS)
muniad_CXXFLAGS = $(LIBWEBSOCKETS_CFLAGS) $(EXPAT_CFLAGS) -I/usr/local/include
muniad_SOURCES = \
- debug.cc \
muniad.cc \
+ connectionhandler.cc \
+ debug.cc \
log.cc \
http.cc \
- msgparser.cc \
+ messageparser.cc \
saxparser.cc \
task.cc \
task_proto.cc \
+ observe_proto.cc \
xml_encode_decode.cc \
xmlparser.cc
EXTRA_DIST = \
debug.h \
+ connectionhandler.h \
log.h \
http.h \
- msgparser.h \
+ messageparser.h \
saxparser.h \
task.h \
task_proto.h \
+ observe_proto.h \
xml_encode_decode.h \
xmlparser.h
diff --git a/src/connectionhandler.cc b/src/connectionhandler.cc
index 61738e2..6fdcd51 100644
--- a/src/connectionhandler.cc
+++ b/src/connectionhandler.cc
@@ -27,6 +27,9 @@
*/
#include "connectionhandler.h"
+// Global ConnectionHandler.
+ConnectionHandler connection_handler;
+
ConnectionHandler::ConnectionHandler()
{
}
@@ -77,7 +80,7 @@ std::set<clientid_t> ConnectionHandler::observerlist(TaskIdList tasks)
TEST_BEGIN;
-ConnectionHandler h;
+ConnectionHandler &h = connection_handler;
h.init((clientid_t)1);
h.observe((clientid_t)1, (taskid_t)1);
diff --git a/src/connectionhandler.h b/src/connectionhandler.h
index ab46320..9aba0cb 100644
--- a/src/connectionhandler.h
+++ b/src/connectionhandler.h
@@ -53,4 +53,7 @@ private:
ConnectionList connlist;
};
+// Global ConnectionHandler
+extern ConnectionHandler connection_handler;
+
#endif/*__MUNIA_CONNECTIONHANDLER_H__*/
diff --git a/src/muniad.cc b/src/muniad.cc
index 4523d8a..a414462 100644
--- a/src/muniad.cc
+++ b/src/muniad.cc
@@ -37,25 +37,18 @@
#include "http.h"
#include "task_proto.h"
-
-/* list of supported protocols and callbacks */
+#include "observe_proto.h"
static struct libwebsocket_protocols protocols[] = {
- /* first protocol must always be HTTP handler */
-
- {
- "http-only", /* name */
- callback_http, /* callback */
- 0 /* per_session_data_size */
+ // first protocol must always be HTTP handler
+ { "http-only", callback_http, 0 },
+ { "lws-task-protocol", callback_lws_task,
+ sizeof(struct per_session_data__lws_task)
},
- {
- "lws-task-protocol",
- callback_lws_task,
- sizeof(struct per_session_data__lws_task)
+ { "lws-observe-protocol", callback_lws_observe,
+ sizeof(struct per_session_data__lws_observe)
},
- {
- NULL, NULL, 0 /* End of list */
- }
+ { NULL, NULL, 0 } // End of list
};
static struct option options[] = {
diff --git a/src/task_proto.cc b/src/task_proto.cc
index d273344..6a4e762 100644
--- a/src/task_proto.cc
+++ b/src/task_proto.cc
@@ -34,7 +34,7 @@
#include <map>
#include "task.h"
-#include "msgparser.h"
+#include "messageparser.h"
#include "xmlparser.h"
static void dump_handshake_info(struct lws_tokens *lwst)
diff --git a/src/xmlparser.h b/src/xmlparser.h
index 85a0600..a92a515 100644
--- a/src/xmlparser.h
+++ b/src/xmlparser.h
@@ -40,7 +40,8 @@ public:
void endTag(std::string name);
void characterData(std::string& data);
- TaskList tasklist;
+ TaskIdList tasklist;
+
protected:
int readData(char* data, size_t size);