diff options
-rw-r--r-- | munia.html | 7 | ||||
-rw-r--r-- | proto.js | 118 | ||||
-rw-r--r-- | src/muniad.cc | 15 | ||||
-rw-r--r-- | src/taskmanager.cc | 15 | ||||
-rw-r--r-- | src/taskmanager.h | 4 |
5 files changed, 126 insertions, 33 deletions
@@ -36,8 +36,9 @@ body { .board { width: *; - min-height: 300px; - padding: 20px;\ + min-height: 100px; + padding: 2px; + margin: 2px; 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, @@ -50,12 +51,12 @@ body { </style> </head> <body id="body"> +<div id="boards" class="boards"></div> <div id="wstask_status">TaskProto not initialized</div> TaskProto: <input type="text" id="input_task_data" value="observe 0" onfocus="clear()"/> <input type="button" value="submit" onclick="task_submit()"/><br/> TaskMessages: <span id="wstask_lastmsg"></span><br/> </div> -<div id="boards" class="boards">!</div> <script type="text/javascript" charset="utf-8" src="/proto.js"></script> </body> @@ -57,6 +57,16 @@ var BrowserDetect = { BrowserDetect.init(); +function createId(boardid, taskid) +{ + return "b" + boardid + "_t" + taskid; +} + +function idFromStr(str) +{ + return str.substring(str.search('t') + 1, str.length); +} + function get_appropriate_ws_url() { var pcol; @@ -95,6 +105,7 @@ try { socket_task.onopen = function() { document.getElementById("wstask_status").style.backgroundColor = "#40ff40"; document.getElementById("wstask_status").textContent = "TaskProto websocket connection opened "; + socket_task.send("observe 0;"); } socket_task.onmessage = function got_packet(msg) { @@ -143,30 +154,23 @@ try { var board = document.getElementById("board_" + observeid); if(!board) { - //alert('missing board') board = document.createElement("div"); - board.name = "board"; board.setAttribute("class", "board"); - board.setAttribute("style", "background-color: black; fixed-width: 100px; min-height: 200px; margin: 4px;"); - //board.setAttribute("ondrop", "drop(this, event)"); - //board.setAttribute("ondragover", "return false"); - //board.setAttribute("draggable", true); - //board.setAttribute("ondragstart", "drag(this, event)"); board.id = "board_" + observeid; boards.appendChild(board); } if(cmd == "remove") { - var task = document.getElementById("board_" + observeid + "task_" + id); + var task = document.getElementById(createId(observeid, id)); task.parentNode.removeChild(task); } else if(cmd == "move") { var parent_id = msg[3]; - var task = document.getElementById("board_" + observeid + "task_" + id); + var task = document.getElementById(createId(observeid, id)); if(parent_id != -1) { - var parent_task = document.getElementById("board_" + observeid + "task_" + parent_id); - parent_task.appendChild(task); + var parent_task = document.getElementById(createId(observeid, parent_id)); + parent_task.appendChild(task); } else { board.appendChild(task); @@ -178,18 +182,23 @@ try { task.name = "task"; task.setAttribute("class", "task"); + task.setAttribute("ondblclick", "editTitle(this, event)"); + task.setAttribute("onclick", "showHideChildren(this, event)"); task.setAttribute("ondrop", "drop(this, event)"); task.setAttribute("ondragover", "return false"); task.setAttribute("draggable", true); task.setAttribute("ondragstart", "drag(this, event)"); + task.setAttribute("title", id); - task.id = "board_" + observeid + "task_" + id; + task.id = createId(observeid, id); - var taskText = document.createTextNode('[' + task.id + ']'); - taskText.id = "txt"; - task.appendChild(taskText); + var txtdiv = document.createElement("div"); + txtdiv.id = createId(observeid, id) + "_txt"; + var txt = document.createTextNode(""); + txtdiv.appendChild(txt); + task.appendChild(txtdiv); - var parent_task = document.getElementById("board_" + observeid + "task_" + parent_id); + var parent_task = document.getElementById(createId(observeid, parent_id)); if(parent_task) { parent_task.appendChild(task); @@ -200,9 +209,12 @@ try { } else if(cmd == "update") { var title = msg[3]; - var task = document.getElementById("board_" + observeid + "task_" + id); - var taskText = document.createTextNode(title); - task.appendChild(taskText); + //var task = document.getElementById(createId(observeid, id)); + var txtdiv = document.getElementById(createId(observeid, id) + "_txt"); + txtdiv.removeChild(txtdiv.firstChild); + + var txt = document.createTextNode(title); + txtdiv.appendChild(txt); } f++; } @@ -230,7 +242,6 @@ function deleteTask(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 } @@ -241,5 +252,70 @@ function drop(target, e) { var id = e.dataTransfer.getData('Text'); var task = document.getElementById(id); - socket_task.send("move " + id.substring(12, id.length) + " " + target.id.substring(12, target.id.length) + ";"); + socket_task.send("move " + idFromStr(id) + " " + idFromStr(target.id) + ";"); +} + +function showHideChildren(target, e) +{ + e.stopPropagation(); + updateid = idFromStr(target.id); + if(target.style.backgroundColor != "red") { + target.style.backgroundColor = "red"; + for(var i = 1; i < target.childNodes.length; i++) { + target.childNodes[i].style.display = "none"; + } + } else { + target.style.backgroundColor = "grey"; + for(var i = 1; i < target.childNodes.length; i++) { + target.childNodes[i].style.display = "block"; + } + } +} + +// +// Butt ugly.. but hey! it works... +// +var updateid; +var divtxt; +var oldtxt; +var oldtitle; +function onKeyUpHandler(target, e) +{ + if(e.which == 13) { // enter + divtxt.removeChild(target); + oldtxt.nodeValue = 'updating...'; + socket_task.send("update " + updateid + " \""+target.value+"\";"); + } + if(e.which == 27) { // escape + divtxt.removeChild(target); + oldtxt.nodeValue = oldtitle; + } +} + +function onLostFocusHandler(target, e) +{ + if(target.value == oldtitle) { + divtxt.removeChild(target); + oldtxt.nodeValue = oldtitle; + } +} + +function editTitle(target, e) +{ + e.stopPropagation(); + updateid = idFromStr(target.id); + if(updateid < 10) return; + var inp = document.createElement("input"); + var txtdiv = document.getElementById(target.id + "_txt"); + divtxt = txtdiv; + oldtxt = txtdiv.firstChild; + oldtitle = oldtxt.nodeValue; + oldtxt.nodeValue = ""; + inp.setAttribute("onkeyup", "onKeyUpHandler(this, event)"); + inp.setAttribute("onblur", "onLostFocusHandler(this, event)"); + inp.setAttribute("style", "border: inherit; padding: inherit; margin: inherit; background: inherit;"); + inp.value = oldtitle; + lineedit = inp; + txtdiv.appendChild(inp); + inp.focus(); } diff --git a/src/muniad.cc b/src/muniad.cc index 741241a..b9651dd 100644 --- a/src/muniad.cc +++ b/src/muniad.cc @@ -38,6 +38,8 @@ #include "http.h" #include "munia_proto.h" #include "debug.h" +#include "taskmanager.h" +extern TaskManager task_manager; static struct libwebsocket_protocols protocols[] = { // first protocol must always be HTTP handler @@ -51,6 +53,7 @@ static struct libwebsocket_protocols protocols[] = { static struct option options[] = { { "help", no_argument, NULL, 'h' }, { "port", required_argument, NULL, 'p' }, + { "file", required_argument, NULL, 'f' }, { "ssl", no_argument, NULL, 's' }, { "killmask", no_argument, NULL, 'k' }, { "interface", required_argument, NULL, 'i' }, @@ -60,6 +63,7 @@ static struct option options[] = { int main(int argc, char **argv) { + const char *db_filename = "/tmp/munia.xml"; int n = 0; const char *cert_path = LOCAL_RESOURCE_PATH"/libwebsockets-test-server.pem"; @@ -84,7 +88,7 @@ int main(int argc, char **argv) "There is NO WARRANTY, to the extent permitted by law.\n"); while(n >= 0) { - n = getopt_long(argc, argv, "ci:khsp:", options, NULL); + n = getopt_long(argc, argv, "ci:khsp:f:", options, NULL); if(n < 0) continue; switch(n) { case 's': @@ -98,19 +102,24 @@ int main(int argc, char **argv) case 'p': port = atoi(optarg); break; - case 'i': + case 'f': + db_filename = strdup(optarg); + break; + case 'i': strncpy(interface_name, optarg, sizeof interface_name); interface_name[(sizeof interface_name) - 1] = '\0'; interface = interface_name; break; case 'h': - fprintf(stderr, "Usage: muniad [--port=<p>] [--ssl]\n"); + fprintf(stderr, "Usage: muniad [--port=<p>] [--ssl] [--file=<f>]\n"); exit(1); } } debug_parse("+all"); + task_manager.init(db_filename); + if(!use_ssl) cert_path = key_path = NULL; context = libwebsocket_create_context(port, interface, protocols, diff --git a/src/taskmanager.cc b/src/taskmanager.cc index 0d15eb6..c7cdb6d 100644 --- a/src/taskmanager.cc +++ b/src/taskmanager.cc @@ -44,10 +44,18 @@ static bool isProtected(taskid_t id) return id < FIRST_TASK_ID; } -TaskManager::TaskManager(std::string file) { +TaskManager::TaskManager() { idCount = FIRST_TASK_ID; - this->file = file; +} + +TaskManager::~TaskManager() { +} + +void TaskManager::init(std::string filename) +{ + printf("Reading tasks from file: %s\n", filename.c_str()); + file = filename; FILE *fp = fopen(file.c_str(), "r"); if(fp) { @@ -87,9 +95,6 @@ TaskManager::TaskManager(std::string file) { tree.toStdOut(); } -TaskManager::~TaskManager() { -} - task_t TaskManager::task(taskid_t t) { return tree.data(t); } diff --git a/src/taskmanager.h b/src/taskmanager.h index 52daa05..e11736b 100644 --- a/src/taskmanager.h +++ b/src/taskmanager.h @@ -40,9 +40,11 @@ typedef std::pair<TaskIdList, TaskIdList> TaskIdListPair; class TaskManager { public: - TaskManager(std::string file = "/tmp/munia.xml"); + TaskManager(); ~TaskManager(); + void init(std::string filename); + 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); |