From 9e81fcd4bdb089b8f8a05c6fbb586ec2a2a14924 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Sat, 6 Jun 2020 16:04:40 +0200 Subject: Change 'observe' to 'subscribe' (and incidentally 'publish') which is more common lingo. --- TODO | 6 ------ handler.js | 24 ++++++++++----------- proto.js | 27 +++++++++++------------ src/connectionhandler.cc | 38 ++++++++++++++++---------------- src/connectionhandler.h | 8 +++---- src/message.h | 32 +++++++++++++++------------ src/messagehandler.cc | 28 ++++++++++++------------ src/messageparser.cc | 20 ++++++++--------- src/munia_proto.cc | 32 +++++++++++++-------------- src/muniacli.cc | 8 +++---- src/taskmanager.cc | 4 ++-- src/testclient.cc | 18 ++++++++-------- task.js | 56 ++++++++++++++++++++++++------------------------ view.js | 22 +++++++++---------- 14 files changed, 160 insertions(+), 163 deletions(-) delete mode 100644 TODO diff --git a/TODO b/TODO deleted file mode 100644 index e818911..0000000 --- a/TODO +++ /dev/null @@ -1,6 +0,0 @@ -Client observer lists to set instead of lists. - -Add depth to observe and make default client connection "observe 0 2", - ie. observe root node with Projects visible. - -Handling of invalid values in incoming messages (default values?) \ No newline at end of file diff --git a/handler.js b/handler.js index 91857aa..5242cc0 100644 --- a/handler.js +++ b/handler.js @@ -9,7 +9,7 @@ function connectEventHandler(e) document.getElementById("wstask_status").textContent = "TaskProto websocket connection opened "; //login("foobar", "hundemad"); - //observe(0); + //subscribe(0); } document.addEventListener("disconnectEvent", disconnectEventHandler, false); @@ -22,43 +22,43 @@ function disconnectEventHandler(e) document.addEventListener("removeEvent", removeEventHandler, false); function removeEventHandler(e) { - var observeid = e.detail.observeid; + var subscribeid = e.detail.subscribeid; var id = e.detail.id; - var task = findTask(id, observeid); + var task = findTask(id, subscribeid); if(task.parent) task.parent.removeChild(task); } document.addEventListener("moveEvent", moveEventHandler, false); function moveEventHandler(e) { - var observeid = e.detail.observeid; + var subscribeid = e.detail.subscribeid; var id = e.detail.id; var parentid = e.detail.parentid; - var task = findTask(id, observeid); - var new_parent = findTask(parentid, observeid); + var task = findTask(id, subscribeid); + var new_parent = findTask(parentid, subscribeid); if(task != null && new_parent != null) new_parent.addChild(task); } document.addEventListener("createEvent", createEventHandler, false); function createEventHandler(e) { - var observeid = e.detail.observeid; + var subscribeid = e.detail.subscribeid; var id = e.detail.id; var parentid = e.detail.parentid; - var task = new Task(id, observeid); + var task = new Task(id, subscribeid); task.create(); if(parentid == -1) { tasks.push(task); - var board = getBoard(observeid); + var board = getBoard(subscribeid); board.appendChild(task.element); return; } - var parent = findTask(parentid, observeid); + var parent = findTask(parentid, subscribeid); if(parent != null) { parent.addChild(task); } @@ -68,12 +68,12 @@ function createEventHandler(e) document.addEventListener("updateEvent", updateEventHandler, false); function updateEventHandler(e) { - var observeid = e.detail.observeid; + var subscribeid = e.detail.subscribeid; var id = e.detail.id; var name = e.detail.name; var value = e.detail.value; - var task = findTask(id, observeid); + var task = findTask(id, subscribeid); if(task == null) return; task.setAttribute(name, value); diff --git a/proto.js b/proto.js index 4feeceb..7c44141 100644 --- a/proto.js +++ b/proto.js @@ -82,14 +82,14 @@ try { if(msgstr[c] != ' ' || instring == true) msg[idx] += msgstr[c]; } - var observeid = msg[0]; + var subscribeid = msg[0]; var cmd = msg[1]; var id = msg[2]; if(cmd == "remove") { var removeEvent = new CustomEvent("removeEvent", { detail: { - observeid: observeid, + subscribeid: subscribeid, id: id, }, bubbles: true, @@ -100,7 +100,7 @@ try { else if(cmd == "move") { var moveEvent = new CustomEvent("moveEvent", { detail: { - observeid: observeid, + subscribeid: subscribeid, id: id, parentid: msg[3], }, @@ -112,7 +112,7 @@ try { else if(cmd == "create") { var createEvent = new CustomEvent("createEvent", { detail: { - observeid: observeid, + subscribeid: subscribeid, id: id, parentid: msg[3], }, @@ -124,7 +124,7 @@ try { else if(cmd == "update") { var updateEvent = new CustomEvent("updateEvent", { detail: { - observeid: observeid, + subscribeid: subscribeid, id: id, name: msg[3], value: msg[4], @@ -178,14 +178,14 @@ function logout() transmit("logout"); } -function observe(id) +function subscribe(id) { - transmit("observe "+id); + transmit("subscribe "+id); } -function unobserve(id) +function unsubscribe(id) { - transmit("unobserve "+id); + transmit("unsubscribe "+id); } function create(id, parent) @@ -193,15 +193,14 @@ function create(id, parent) transmit("create "+id+" "+parent); } - -function update(id, name, value) +function remove(id) { - transmit("update "+id+" "+name+" "+value); + transmit("remove "+id); } -function remove(id) +function update(id, name, value) { - transmit("remove "+id); + transmit("update "+id+" "+name+" "+value); } function move(id, parent) diff --git a/src/connectionhandler.cc b/src/connectionhandler.cc index d264abe..4cf8fc0 100644 --- a/src/connectionhandler.cc +++ b/src/connectionhandler.cc @@ -74,27 +74,27 @@ bool ConnectionHandler::authenticated(clientid_t clientid) return authlist.find(clientid) != authlist.end() && authlist[clientid]; } -void ConnectionHandler::observe(clientid_t clientid, taskid_t taskid) +void ConnectionHandler::subscribe(clientid_t clientid, taskid_t taskid) { connlist[clientid].insert(taskid); - DEBUG(conn, "Added observer of %d\n", taskid); + DEBUG(conn, "Added subscriber of %d\n", taskid); } -void ConnectionHandler::unobserve(clientid_t clientid, taskid_t taskid) +void ConnectionHandler::unsubscribe(clientid_t clientid, taskid_t taskid) { connlist[clientid].erase(taskid); } -ObserverList ConnectionHandler::observerlist(TaskIdList tasks) +SubscriberList ConnectionHandler::subscriberlist(TaskIdList tasks) { - DEBUG(conn, "Observerlist request (#tasks: %d)\n", (int)tasks.size()); - ObserverList clients; + DEBUG(conn, "Subscriberlist request (#tasks: %d)\n", (int)tasks.size()); + SubscriberList clients; for(TaskIdList::iterator i = tasks.begin(); i != tasks.end(); i++) { taskid_t tid = *i; - DEBUG(conn, "Locating observers of node %d\n", tid); + DEBUG(conn, "Locating subscribers of node %d\n", tid); for(ConnectionList::iterator ci = connlist.begin(); ci != connlist.end(); ci++) { @@ -125,20 +125,20 @@ TEST_BEGIN; ConnectionHandler &h = connection_handler; h.init((clientid_t)1); -h.observe((clientid_t)1, (taskid_t)1); -h.observe((clientid_t)1, (taskid_t)2); +h.subscribe((clientid_t)1, (taskid_t)1); +h.subscribe((clientid_t)1, (taskid_t)2); h.init((clientid_t)2); -h.observe((clientid_t)2, (taskid_t)1); -h.observe((clientid_t)2, (taskid_t)2); +h.subscribe((clientid_t)2, (taskid_t)1); +h.subscribe((clientid_t)2, (taskid_t)2); h.init((clientid_t)3); -h.observe((clientid_t)3, (taskid_t)3); +h.subscribe((clientid_t)3, (taskid_t)3); { TaskIdList tasks; tasks.push_back((taskid_t)1); - ObserverList clst = h.observerlist(tasks); + SubscriberList clst = h.subscriberlist(tasks); TEST_TRUE(clst.find((clientid_t)1) != clst.end(), "Got client 1?"); TEST_TRUE(clst.find((clientid_t)2) != clst.end(), "Got client 2?"); @@ -148,7 +148,7 @@ h.observe((clientid_t)3, (taskid_t)3); { TaskIdList tasks; tasks.push_back((taskid_t)3); - ObserverList clst = h.observerlist(tasks); + SubscriberList clst = h.subscriberlist(tasks); TEST_FALSE(clst.find((clientid_t)1) != clst.end(), "Got client 1?"); TEST_FALSE(clst.find((clientid_t)2) != clst.end(), "Got client 2?"); @@ -158,7 +158,7 @@ h.observe((clientid_t)3, (taskid_t)3); { TaskIdList tasks; tasks.push_back((taskid_t)4); - ObserverList clst = h.observerlist(tasks); + SubscriberList clst = h.subscriberlist(tasks); TEST_FALSE(clst.find((clientid_t)1) != clst.end(), "Got client 1?"); TEST_FALSE(clst.find((clientid_t)2) != clst.end(), "Got client 2?"); @@ -170,7 +170,7 @@ h.observe((clientid_t)3, (taskid_t)3); tasks.push_back((taskid_t)1); tasks.push_back((taskid_t)2); tasks.push_back((taskid_t)3); - ObserverList clst = h.observerlist(tasks); + SubscriberList clst = h.subscriberlist(tasks); TEST_TRUE(clst.find((clientid_t)1) != clst.end(), "Got client 1?"); TEST_TRUE(clst.find((clientid_t)2) != clst.end(), "Got client 2?"); @@ -183,7 +183,7 @@ h.close((clientid_t)1); tasks.push_back((taskid_t)1); tasks.push_back((taskid_t)2); tasks.push_back((taskid_t)3); - ObserverList clst = h.observerlist(tasks); + SubscriberList clst = h.subscriberlist(tasks); TEST_FALSE(clst.find((clientid_t)1) != clst.end(), "Got client 1?"); TEST_TRUE(clst.find((clientid_t)2) != clst.end(), "Got client 2?"); @@ -196,7 +196,7 @@ h.close((clientid_t)2); tasks.push_back((taskid_t)1); tasks.push_back((taskid_t)2); tasks.push_back((taskid_t)3); - ObserverList clst = h.observerlist(tasks); + SubscriberList clst = h.subscriberlist(tasks); TEST_FALSE(clst.find((clientid_t)1) != clst.end(), "Got client 1?"); TEST_FALSE(clst.find((clientid_t)2) != clst.end(), "Got client 2?"); @@ -209,7 +209,7 @@ h.close((clientid_t)3); tasks.push_back((taskid_t)1); tasks.push_back((taskid_t)2); tasks.push_back((taskid_t)3); - ObserverList clst = h.observerlist(tasks); + SubscriberList clst = h.subscriberlist(tasks); TEST_FALSE(clst.find((clientid_t)1) != clst.end(), "Got client 1?"); TEST_FALSE(clst.find((clientid_t)2) != clst.end(), "Got client 2?"); diff --git a/src/connectionhandler.h b/src/connectionhandler.h index 0e28cd3..482c293 100644 --- a/src/connectionhandler.h +++ b/src/connectionhandler.h @@ -39,7 +39,7 @@ typedef struct lws* clientid_t; typedef std::map AuthList; typedef std::map > ConnectionList; -typedef std::list > ObserverList; +typedef std::list > SubscriberList; class ConnectionHandler { @@ -53,10 +53,10 @@ public: void logout(clientid_t clientid); bool authenticated(clientid_t clientid); - void observe(clientid_t clientid, taskid_t taskid); - void unobserve(clientid_t clientid, taskid_t taskid); + void subscribe(clientid_t clientid, taskid_t taskid); + void unsubscribe(clientid_t clientid, taskid_t taskid); - ObserverList observerlist(TaskIdList tasklist); + SubscriberList subscriberlist(TaskIdList tasklist); private: ConnectionList connlist; diff --git a/src/message.h b/src/message.h index ea1c444..bb56932 100644 --- a/src/message.h +++ b/src/message.h @@ -35,14 +35,14 @@ namespace cmd { typedef enum { - observe, - unobserve, - update, - move, - create, - remove, login, logout, + subscribe, + unsubscribe, + create, + remove, + move, + update, error, } cmd_t; }; @@ -53,15 +53,19 @@ typedef struct std::string password; } login_t; +typedef struct +{ +} logout_t; + typedef struct { taskid_t id; -} observe_t; +} subscribe_t; typedef struct { taskid_t id; -} unobserve_t; +} unsubscribe_t; typedef struct { @@ -83,26 +87,26 @@ typedef struct typedef struct { taskid_t id; - std::string name; + std::string attribute; std::string value; } update_t; - typedef struct { cmd::cmd_t cmd; - observe_t observe; - unobserve_t unobserve; + login_t login; + logout_t logout; + subscribe_t subscribe; + unsubscribe_t unsubscribe; create_t create; remove_t remove; move_t move; update_t update; - login_t login; TaskIdList nodes; - // tagret node id (observed task id) used for transmissions only. + // target node id (subscription node id) used for transmissions only. taskid_t tid; } message_t; diff --git a/src/messagehandler.cc b/src/messagehandler.cc index ad9b8bb..5ccf3bf 100644 --- a/src/messagehandler.cc +++ b/src/messagehandler.cc @@ -57,6 +57,14 @@ MessageList handle_msg(MessageList msgList, clientid_t wsi) switch(m.cmd) { + case cmd::login: + // Already handled, before this switch ... case + break; + + case cmd::logout: + connection_handler.logout(wsi); + break; + case cmd::create: { INFO(messagehandler, "Handling create command\n"); @@ -162,17 +170,17 @@ MessageList handle_msg(MessageList msgList, clientid_t wsi) } break; - case cmd::observe: + case cmd::subscribe: { - //connection_handler.observe(wsi, m.observe.id); + //connection_handler.subscribe(wsi, m.subscribe.id); outmsgs.push_back(m); } break; - case cmd::unobserve: - //connection_handler.unobserve(wsi, m.observe.id); + case cmd::unsubscribe: + //connection_handler.unsubscribe(wsi, m.subscribe.id); outmsgs.push_back(m); - DEBUG(handler, "unobserve: %d\n", m.unobserve.id); + DEBUG(handler, "unsubscribe: %d\n", m.unsubscribe.id); break; case cmd::update: @@ -181,7 +189,7 @@ MessageList handle_msg(MessageList msgList, clientid_t wsi) try { m.nodes = task_manager.updateTask(m.update.id, - m.update.name, m.update.value); + m.update.attribute, m.update.value); outmsgs.push_back(m); } catch (std::exception& e) @@ -191,14 +199,6 @@ MessageList handle_msg(MessageList msgList, clientid_t wsi) } break; - case cmd::login: - // Already handled, before this switch ... case - break; - - case cmd::logout: - connection_handler.logout(wsi); - break; - case cmd::error: ERR(messagehandler, "An error occurred.\n"); break; diff --git a/src/messageparser.cc b/src/messageparser.cc index d59cccc..75593f9 100644 --- a/src/messageparser.cc +++ b/src/messageparser.cc @@ -185,8 +185,8 @@ inline static void create_msg_list(MsgTokensList& msgTokensList, // DEBUG(msgparser, "%d\n", t.size()); - if(t[origin] == "observe") m.cmd = cmd::observe; - else if(t[origin] == "unobserve") m.cmd = cmd::unobserve; + if(t[origin] == "subscribe") m.cmd = cmd::subscribe; + else if(t[origin] == "unsubscribe") m.cmd = cmd::unsubscribe; else if(t[origin] == "login") m.cmd = cmd::login; else if(t[origin] == "logout") m.cmd = cmd::logout; else if(t[origin] == "create") m.cmd = cmd::create; @@ -197,26 +197,26 @@ inline static void create_msg_list(MsgTokensList& msgTokensList, switch(m.cmd) { - case cmd::observe: + case cmd::subscribe: { if(t.size() != origin+1+1) { DEBUG(msgparser, "Wrong number of parameters\n"); continue; } - m.observe.id = getId(sym, t[origin+1]);//atoi(t[origin+1].c_str()); + m.subscribe.id = getId(sym, t[origin+1]);//atoi(t[origin+1].c_str()); } break; - case cmd::unobserve: + case cmd::unsubscribe: { if(t.size() != origin+1+1) { DEBUG(msgparser, "Wrong number of parameters\n"); continue; } - m.unobserve.id = getId(sym, t[origin+1]);//atoi(t[origin+1].c_str()); - DEBUG(msgparser, "unobserve @ %d\n", m.unobserve.id); + m.unsubscribe.id = getId(sym, t[origin+1]);//atoi(t[origin+1].c_str()); + DEBUG(msgparser, "unsubscribe @ %d\n", m.unsubscribe.id); } break; @@ -294,7 +294,7 @@ inline static void create_msg_list(MsgTokensList& msgTokensList, continue; } m.update.id = getId(sym, t[origin+1]);//atoi(t[origin+1].c_str()); - m.update.name = t[origin+2]; + m.update.attribute = t[origin+2]; m.update.value = t[origin+3]; } break; @@ -348,7 +348,7 @@ std::string msg_tostring(message_t m) break; case cmd::update: asprintf(&buf, "update %d \"%s\" \"%s\";", - m.update.id, m.update.name.c_str(), m.update.value.c_str()); + m.update.id, m.update.attribute.c_str(), m.update.value.c_str()); break; default: break; @@ -378,7 +378,7 @@ message_t create_msg_update(task_t t, const std::string &attr) message_t m; m.cmd = cmd::update; m.update.id = t.id; - m.update.name = attr; + m.update.attribute = attr; m.update.value = t.attributes[attr]; return m; } diff --git a/src/munia_proto.cc b/src/munia_proto.cc index 6e944cf..333e3c9 100644 --- a/src/munia_proto.cc +++ b/src/munia_proto.cc @@ -211,17 +211,17 @@ int callback_lws_task(struct lws *wsi, while(omi != omsgs.end()) { DEBUG(proto, "Message\n"); - if(omi->cmd == cmd::observe) + if(omi->cmd == cmd::subscribe) { - connection_handler.observe(wsi, omi->observe.id); + connection_handler.subscribe(wsi, omi->subscribe.id); TaskIdList ids; try { - ids = task_manager.subTasks(omi->observe.id); + ids = task_manager.subTasks(omi->subscribe.id); } catch(...) { - DEBUG(proto, "No such node %d\n", omi->observe.id); + DEBUG(proto, "No such node %d\n", omi->subscribe.id); omi++; continue; } @@ -231,7 +231,7 @@ int callback_lws_task(struct lws *wsi, task_t task = task_manager.task(*id); message_t createmsg = create_msg_create(task); - createmsg.tid = omi->observe.id; + createmsg.tid = omi->subscribe.id; msgqueue[wsi].push_back(createmsg); std::map::iterator ai = @@ -239,8 +239,8 @@ int callback_lws_task(struct lws *wsi, while(ai != task.attributes.end()) { message_t updatemsg = create_msg_update(task, ai->first); - DEBUG(observe, "%s\n", ai->first.c_str()); - updatemsg.tid = omi->observe.id; + DEBUG(subscribe, "%s\n", ai->first.c_str()); + updatemsg.tid = omi->subscribe.id; msgqueue[wsi].push_back(updatemsg); ai++; } @@ -248,17 +248,17 @@ int callback_lws_task(struct lws *wsi, id++; } } - else if(omi->cmd == cmd::unobserve) + else if(omi->cmd == cmd::unsubscribe) { - connection_handler.unobserve(wsi, omi->unobserve.id); + connection_handler.unsubscribe(wsi, omi->unsubscribe.id); TaskIdList ids; try { - ids = task_manager.subTasks(omi->unobserve.id); + ids = task_manager.subTasks(omi->unsubscribe.id); } catch(...) { - DEBUG(proto, "No such node %d\n", omi->unobserve.id); + DEBUG(proto, "No such node %d\n", omi->unsubscribe.id); omi++; continue; } @@ -268,9 +268,9 @@ int callback_lws_task(struct lws *wsi, task_t task = task_manager.task(*id); message_t removemsg = create_msg_remove(task); - removemsg.tid = omi->unobserve.id; + removemsg.tid = omi->unsubscribe.id; msgqueue[wsi].push_back(removemsg); - DEBUG(unobserve, "remove id: %d\n", *id); + DEBUG(unsubscribe, "remove id: %d\n", *id); id++; } @@ -281,16 +281,16 @@ int callback_lws_task(struct lws *wsi, DEBUG(proto, "%d nodes affected by command\n", (int)omi->nodes.size()); - ObserverList clients = connection_handler.observerlist(omi->nodes); + SubscriberList clients = connection_handler.subscriberlist(omi->nodes); DEBUG(proto, "Writing message to %d clients\n", (int)clients.size()); - ObserverList::iterator ci = clients.begin(); + SubscriberList::iterator ci = clients.begin(); while(ci != clients.end()) { clientid_t clientid = (*ci).first; taskid_t tid = (*ci).second; - DEBUG(proto, "Observer id of task: %d\n", tid); + DEBUG(proto, "Subscriber id of task: %d\n", tid); message_t msg = *omi; msg.tid = tid; diff --git a/src/muniacli.cc b/src/muniacli.cc index f28c810..843c028 100644 --- a/src/muniacli.cc +++ b/src/muniacli.cc @@ -556,18 +556,18 @@ int main(int argc, char** argv) switch(cmd) { case CREATE: - msgs = "observe " + taskbyid + ";"; + msgs = "subscribe " + taskbyid + ";"; msgs += "create " + taskbyid + ";"; break; case LIST: - msgs = "observe " + taskbyid + ";"; //+ - // "; unobserve " + task + ";"; + msgs = "subscribe " + taskbyid + ";"; //+ + // "; unsubscribe " + task + ";"; break; case REMOVE: msgs = "remove " + taskbyid + ";"; break; case UPDATE: - msgs = "observe " + taskbyid + ";"; + msgs = "subscribe " + taskbyid + ";"; msgs += "update " + taskbyid + " \"" + cmd_opts + "\"; "; break; case DEFAULT: diff --git a/src/taskmanager.cc b/src/taskmanager.cc index 3fafb4e..1b34dde 100644 --- a/src/taskmanager.cc +++ b/src/taskmanager.cc @@ -129,7 +129,7 @@ TaskIdListPair TaskManager::moveTask(taskid_t id, taskid_t to) //task_t t = tree.data(id); // Make sure the new parent exists. This will throw an exception if it doesn't - //task_t t_ = tree.data(to); + //task_t t_ = tree.data(to); //t.parentid = to; @@ -304,7 +304,7 @@ TaskList load_tasklist_from_file(std::string file) { TaskList list; - // create MuniaDb class which handles tasks, db-flush and db-init. + // create MuniaDb class which handles tasks, db-flush and db-init. return list; } diff --git a/src/testclient.cc b/src/testclient.cc index 58e55a1..6733978 100644 --- a/src/testclient.cc +++ b/src/testclient.cc @@ -183,21 +183,21 @@ TEST_BEGIN; static struct test tests[] = { - { "observe 0", BASE, false }, - { "unobserve 0", RMBASE, false }, + { "subscribe 0", BASE, false }, + { "unsubscribe 0", RMBASE, false }, { "create 0", nullptr, false }, - { "observe 0", BASE" 0 create 10 0; 0 update 10 \"\";", false }, + { "subscribe 0", BASE" 0 create 10 0; 0 update 10 \"\";", false }, { "update 10 \"My title\"", "0 update 10 \"My title\";", false }, - { "unobserve 0", "0 remove 10; "RMBASE, false }, - { "observe 0", BASE" 0 create 10 0; 0 update 10 \"My title\";", false }, + { "unsubscribe 0", "0 remove 10; "RMBASE, false }, + { "subscribe 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 }, + //{ "subscribe 0", BASE"0 add title description 5", false }, //{ "add title2 description 0", BASE"0 add title2 description 6", false }, - //{ "unobserve 0", nullptr, false }, - //{ "observe 0", BASE"0 add title description 5; add title description 6", false }, - //{ "unobserve 0", nullptr, false }, + //{ "unsubscribe 0", nullptr, false }, + //{ "subscribe 0", BASE"0 add title description 5; add title description 6", false }, + //{ "unsubscribe 0", nullptr, false }, { nullptr, nullptr, false } }; diff --git a/task.js b/task.js index 0367221..64d95ff 100644 --- a/task.js +++ b/task.js @@ -13,21 +13,21 @@ function idFromStr(str) var tasks = new Array(); -function findTask(id, observeid) +function findTask(id, subscribeid) { for(var i = 0; i < tasks.length; i++) { var task = tasks[i]; - var child = task.findTask(id, observeid); + var child = task.findTask(id, subscribeid); if(child != null) return child; } return null; } -function Task(id, observeid) +function Task(id, subscribeid) { this.id = id; - this.observeid = observeid; + this.subscribeid = subscribeid; this.children = new Array(); this.attributes = {}; this.parent = null; @@ -43,21 +43,21 @@ Task.prototype.dump = function() alert(this.id); } -Task.prototype.findTask = function(id, observeid) +Task.prototype.findTask = function(id, subscribeid) { - if(this.observeid != observeid) return null; + if(this.subscribeid != subscribeid) return null; if(this.id == id) return this; for(var i = 0; i < this.children.length; i++) { var task = this.children[i]; - var child = task.findTask(id, observeid); + var child = task.findTask(id, subscribeid); if(child != null) return child; } return null; } - + Task.prototype.addChild = function(task) { if(task.parent != null) task.parent.removeChild(task); @@ -92,26 +92,26 @@ Task.prototype.create = function() // This is a hack to make it possible to identify the taskid and // oberveid from the node id alone. - task.id = createId(this.observeid, this.id); - -/* - var observe_button = document.createElement("div"); - observe_button.name = "observe_button"; - observe_button.setAttribute("onclick", "observeMe(this, event)"); - observe_button.setAttribute("title", this.id); - observe_button.setAttribute("style", "float: left; display: inline-box; width:14px; height: 14px; border: solid green 2px; cursor: pointer;"); + task.id = createId(this.subscribeid, this.id); + +/* + var subscribe_button = document.createElement("div"); + subscribe_button.name = "subscribe_button"; + subscribe_button.setAttribute("onclick", "subscribeMe(this, event)"); + subscribe_button.setAttribute("title", this.id); + subscribe_button.setAttribute("style", "float: left; display: inline-box; width:14px; height: 14px; border: solid green 2px; cursor: pointer;"); var txt_plus = document.createTextNode("+"); - observe_button.appendChild(txt_plus); - task.appendChild(observe_button); - - var unobserve_button = document.createElement("div"); - unobserve_button.name = "unobserve_button"; - unobserve_button.setAttribute("onclick", "unobserveMe(this, event)"); - unobserve_button.setAttribute("title", this.id); - unobserve_button.setAttribute("style", "float: left; display: inline-box; width:14px; height: 14px; border: solid red 2px; cursor: pointer;"); + subscribe_button.appendChild(txt_plus); + task.appendChild(subscribe_button); + + var unsubscribe_button = document.createElement("div"); + unsubscribe_button.name = "unsubscribe_button"; + unsubscribe_button.setAttribute("onclick", "unsubscribeMe(this, event)"); + unsubscribe_button.setAttribute("title", this.id); + unsubscribe_button.setAttribute("style", "float: left; display: inline-box; width:14px; height: 14px; border: solid red 2px; cursor: pointer;"); var txt_minus = document.createTextNode("-"); - unobserve_button.appendChild(txt_minus); - task.appendChild(unobserve_button); + unsubscribe_button.appendChild(txt_minus); + task.appendChild(unsubscribe_button); */ this.element.appendChild(this.div_id); @@ -126,7 +126,7 @@ Task.prototype.create = function() Task.prototype.setAttribute = function(name, value) { this.attributes[name] = value; - + if(name == "title") { if(this.div_title.firstChild != null) { this.div_title.removeChild(this.div_title.firstChild); @@ -134,4 +134,4 @@ Task.prototype.setAttribute = function(name, value) var title_txt = document.createTextNode(value); this.div_title.appendChild(title_txt); } -} \ No newline at end of file +} diff --git a/view.js b/view.js index 8bb9f87..6104384 100644 --- a/view.js +++ b/view.js @@ -8,27 +8,27 @@ function createTask() task.id = 42; task.dump = function() { alert(this.id); - } + } } */ -function getTask(observeid, id) +function getTask(subscribeid, id) { - + } -function updateTask(observeid, id, name, value) +function updateTask(subscribeid, id, name, value) { } -function getBoard(observeid) +function getBoard(subscribeid) { - var board = document.getElementById("board_" + observeid); + var board = document.getElementById("board_" + subscribeid); if(!board) { board = document.createElement("div"); board.name = "board"; board.setAttribute("class", "board"); - board.id = "board_" + observeid; + board.id = "board_" + subscribeid; boards.appendChild(board); } @@ -60,16 +60,16 @@ function drop(target, e) { move(idFromStr(id), idFromStr(target.id)); } -function observeMe(target, e) +function subscribeMe(target, e) { e.stopPropagation(); - observe(target.title); + subscribe(target.title); } -function unobserveMe(target, e) +function unsubscribeMe(target, e) { e.stopPropagation(); - unobserve(target.title); + unsubscribe(target.title); } function showHideChildren(target, e) -- cgit v1.2.3