From 75d85549c6d2a5284593e20c21d61fc5d6200bca Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Mon, 8 Jun 2020 18:24:49 +0200 Subject: Add 'insert before id' to create and move commands. --- src/connectionhandler.cc | 4 +-- src/message.h | 2 ++ src/messagehandler.cc | 13 ++++---- src/messageparser.cc | 77 +++++++++++++++++++++++++----------------------- src/messageparser.h | 4 +-- src/munia_proto.cc | 16 +++++----- src/node.h | 3 +- src/nodemanager.cc | 18 +++++------ src/nodemanager.h | 4 +-- src/nodetree.cc | 54 +++++++++++++++++++++++++-------- src/nodetree.h | 12 ++++---- src/ws/handler.js | 6 ++-- src/ws/node.js | 23 +++++++++++++-- src/ws/proto.js | 6 ++-- src/ws/view.js | 2 +- src/xmlparser.cc | 4 +-- 16 files changed, 155 insertions(+), 93 deletions(-) (limited to 'src') diff --git a/src/connectionhandler.cc b/src/connectionhandler.cc index eb0f935..26cce46 100644 --- a/src/connectionhandler.cc +++ b/src/connectionhandler.cc @@ -77,7 +77,7 @@ bool ConnectionHandler::authenticated(clientid_t clientid) void ConnectionHandler::subscribe(clientid_t clientid, nodeid_t nodeid) { connlist[clientid].insert(nodeid); - DEBUG(conn, "Added subscriber of %d\n", nodeid); + DEBUG(conn, "Added subscriber of %d\n", (int)nodeid); } void ConnectionHandler::unsubscribe(clientid_t clientid, nodeid_t nodeid) @@ -94,7 +94,7 @@ SubscriberList ConnectionHandler::subscriberlist(NodeIdList nodes) { nodeid_t tid = *i; - DEBUG(conn, "Locating subscribers of node %d\n", tid); + DEBUG(conn, "Locating subscribers of node %d\n", (int)tid); for(ConnectionList::iterator ci = connlist.begin(); ci != connlist.end(); ci++) { diff --git a/src/message.h b/src/message.h index 876631c..94b7165 100644 --- a/src/message.h +++ b/src/message.h @@ -71,6 +71,7 @@ typedef struct { nodeid_t id; nodeid_t parentid; + nodeid_t insertbeforeid; } create_t; typedef struct @@ -82,6 +83,7 @@ typedef struct { nodeid_t id; nodeid_t parentid; + nodeid_t insertbeforeid; } move_t; typedef struct diff --git a/src/messagehandler.cc b/src/messagehandler.cc index 0d536c3..2333838 100644 --- a/src/messagehandler.cc +++ b/src/messagehandler.cc @@ -71,7 +71,8 @@ MessageList handle_msg(MessageList msgList, clientid_t wsi) try { nodeid_t id = m.create.id; - m.nodes = node_manager.createNode(m.create.parentid, &id); + m.nodes = node_manager.createNode(m.create.parentid, &id, + m.create.insertbeforeid); m.create.id = id; outmsgs.push_back(m); } @@ -114,7 +115,7 @@ MessageList handle_msg(MessageList msgList, clientid_t wsi) { node_t removenode = node_manager.node(m.move.id); NodeIdListPair tilpair = - node_manager.moveNode(m.move.id, m.move.parentid); + node_manager.moveNode(m.move.id, m.move.parentid, m.move.insertbeforeid); node_t createnode = node_manager.node(m.move.id); // NodeIdList commonAncestors; @@ -157,7 +158,8 @@ MessageList handle_msg(MessageList msgList, clientid_t wsi) message_t removemsg = create_msg_remove(removenode); removemsg.nodes = tilpair.first; - message_t createmsg = create_msg_create(createnode); + message_t createmsg = create_msg_create(createnode, + m.move.insertbeforeid); createmsg.nodes = tilpair.second; outmsgs.push_back(removemsg); @@ -180,7 +182,7 @@ MessageList handle_msg(MessageList msgList, clientid_t wsi) case cmd::unsubscribe: //connection_handler.unsubscribe(wsi, m.subscribe.id); outmsgs.push_back(m); - DEBUG(handler, "unsubscribe: %d\n", m.unsubscribe.id); + DEBUG(handler, "unsubscribe: %d\n", (int)m.unsubscribe.id); break; case cmd::update: @@ -189,7 +191,8 @@ MessageList handle_msg(MessageList msgList, clientid_t wsi) try { m.nodes = node_manager.updateNode(m.update.id, - m.update.attribute, m.update.value); + m.update.attribute, + m.update.value); outmsgs.push_back(m); } catch (std::exception& e) diff --git a/src/messageparser.cc b/src/messageparser.cc index a5b6d71..1b5fd7f 100644 --- a/src/messageparser.cc +++ b/src/messageparser.cc @@ -26,15 +26,14 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ #include "messageparser.h" -#include "nodemanager.h" -#include -#include #include #include #include -#include "hugin.hpp" +#include + +#include "nodemanager.h" typedef std::vector TokenVector; typedef std::list MsgTokensList; @@ -143,7 +142,7 @@ static nodeid_t getId(std::map &sym, std::string token) if(isnumeric) { nodeid_t id = atoi(token.c_str()); - DEBUG(getid, "======= id: %d\n", id); + DEBUG(getid, "======= id: %d\n", (int)id); return id; } @@ -204,7 +203,7 @@ inline static void create_msg_list(MsgTokensList& msgTokensList, DEBUG(msgparser, "Wrong number of parameters\n"); continue; } - m.subscribe.id = getId(sym, t[origin+1]);//atoi(t[origin+1].c_str()); + m.subscribe.id = getId(sym, t[origin+1]); } break; @@ -215,8 +214,8 @@ inline static void create_msg_list(MsgTokensList& msgTokensList, DEBUG(msgparser, "Wrong number of parameters\n"); continue; } - m.unsubscribe.id = getId(sym, t[origin+1]);//atoi(t[origin+1].c_str()); - DEBUG(msgparser, "unsubscribe @ %d\n", m.unsubscribe.id); + m.unsubscribe.id = getId(sym, t[origin+1]); + DEBUG(msgparser, "unsubscribe @ %d\n", (int)m.unsubscribe.id); } break; @@ -243,25 +242,27 @@ inline static void create_msg_list(MsgTokensList& msgTokensList, case cmd::create: { - if(!clientmode && t.size() != origin+1+2) + if(!clientmode && t.size() != origin+1+2+1) { DEBUG(msgparser, "Wrong number of parameters\n"); continue; } - if(clientmode && t.size() != origin+1+2) + if(clientmode && t.size() != origin+1+2+1) { DEBUG(msgparser, "Wrong number of parameters\n"); continue; } if(clientmode) { - m.create.id = getId(sym, t[origin+1]);//atoi(t[origin+1].c_str()); - m.create.parentid = getId(sym, t[origin+2]);// atoi(t[origin+2].c_str()); + m.create.id = getId(sym, t[origin+1]); + m.create.parentid = getId(sym, t[origin+2]); + m.create.insertbeforeid = getId(sym, t[origin+3]); } else { - m.create.id = getId(sym, t[origin+1]);//atoi(t[origin+1].c_str()); - m.create.parentid = getId(sym, t[origin+2]);//atoi(t[origin+1].c_str()); + m.create.id = getId(sym, t[origin+1]); + m.create.parentid = getId(sym, t[origin+2]); + m.create.insertbeforeid = getId(sym, t[origin+3]); } break; } @@ -272,18 +273,19 @@ inline static void create_msg_list(MsgTokensList& msgTokensList, DEBUG(msgparser, "Wrong number of parameters\n"); continue; } - m.remove.id = getId(sym, t[origin+1]);//atoi(t[origin+1].c_str()); + m.remove.id = getId(sym, t[origin+1]); } break; case cmd::move: { - if(t.size() != origin+2+1) + if(t.size() != origin+2+1+1) { DEBUG(msgparser, "Wrong number of parameters\n"); continue; } - m.move.id = getId(sym, t[origin+1]);//atoi(t[origin+1].c_str()); - m.move.parentid = getId(sym, t[origin+2]);//atoi(t[origin+2].c_str()); + m.move.id = getId(sym, t[origin+1]); + m.move.parentid = getId(sym, t[origin+2]); + m.move.insertbeforeid = getId(sym, t[origin+3]); } break; case cmd::update: @@ -293,7 +295,7 @@ inline static void create_msg_list(MsgTokensList& msgTokensList, DEBUG(msgparser, "Wrong number of parameters\n"); continue; } - m.update.id = getId(sym, t[origin+1]);//atoi(t[origin+1].c_str()); + m.update.id = getId(sym, t[origin+1]); m.update.attribute = t[origin+2]; m.update.value = t[origin+3]; } @@ -332,44 +334,44 @@ MessageList parse_msg_client(std::string data) std::string msg_tostring(message_t m) { - char* buf = NULL; + std::string msg; + switch(m.cmd) { case cmd::create: - asprintf(&buf, "create %d %d;", - m.create.id, - m.create.parentid); + msg = "create " + + std::to_string(m.create.id) + " " + + std::to_string(m.create.parentid) + " " + + std::to_string(m.create.insertbeforeid); break; case cmd::remove: - asprintf(&buf, "remove %d;", m.remove.id); + msg = "remove " + std::to_string(m.remove.id); break; case cmd::move: - asprintf(&buf, "move %d %d;", m.move.id, m.move.parentid); + msg = "move " + + std::to_string(m.move.id) + " " + + std::to_string(m.move.parentid) + " " + + std::to_string(m.move.insertbeforeid); break; case cmd::update: - asprintf(&buf, "update %d \"%s\" \"%s\";", - m.update.id, m.update.attribute.c_str(), m.update.value.c_str()); + msg = "update " + + std::to_string(m.update.id) + " \"" + + m.update.attribute + "\" \"" + m.update.value + "\""; break; default: break; } - std::string r; - if(buf) - { - r = buf; - free(buf); - } - - return r; + return msg + ";"; } -message_t create_msg_create(node_t t) +message_t create_msg_create(node_t t, nodeid_t insertbeforeid) { message_t m; m.cmd = cmd::create; m.create.id = t.id; m.create.parentid = t.parentid; + m.create.insertbeforeid = insertbeforeid; return m; } @@ -391,11 +393,12 @@ message_t create_msg_remove(node_t t) return m; } -message_t create_msg_move(nodeid_t id, nodeid_t to) +message_t create_msg_move(nodeid_t id, nodeid_t to, nodeid_t insertbeforeid) { message_t m; m.cmd = cmd::move; m.move.id = id; m.move.parentid = to; + m.move.insertbeforeid = insertbeforeid; return m; } diff --git a/src/messageparser.h b/src/messageparser.h index 4d51c87..85ce5cf 100644 --- a/src/messageparser.h +++ b/src/messageparser.h @@ -37,7 +37,7 @@ MessageList parse_msg_client(std::string msg); //message_t create_msg(cmd::cmd_t type, node_t node); std::string msg_tostring(message_t msg); -message_t create_msg_create(node_t node); +message_t create_msg_create(node_t node, nodeid_t insertbeforeid); message_t create_msg_update(node_t node, const std::string &attr); message_t create_msg_remove(node_t node); -message_t create_msg_move(nodeid_t id, nodeid_t to); +message_t create_msg_move(nodeid_t id, nodeid_t to, nodeid_t insertbeforeid); diff --git a/src/munia_proto.cc b/src/munia_proto.cc index 33de8a3..dfc70d2 100644 --- a/src/munia_proto.cc +++ b/src/munia_proto.cc @@ -141,10 +141,12 @@ int callback_lws_node(struct lws *wsi, { nodeid_t id = j->create.id; nodeid_t parentid = j->create.parentid; + nodeid_t insertbeforeid = j->create.insertbeforeid; msgqueue[wsi].erase(j); // erase create msg msg.cmd = cmd::move; msg.move.id = id; msg.move.parentid = parentid; + msg.move.insertbeforeid = insertbeforeid; } } i++; @@ -159,13 +161,11 @@ int callback_lws_node(struct lws *wsi, { message_t msg = msgqueue[wsi].front(); msgqueue[wsi].pop_front(); - char buf[32]; - sprintf(buf, "%d", msg.tid); if(msgstr.size() > LWS_SEND_BUFFER_PRE_PADDING) { msgstr += " "; } - msgstr += std::string(buf) + " " + msg_tostring(msg); + msgstr += std::to_string(msg.tid) + " " + msg_tostring(msg); } msgstr.append((size_t)LWS_SEND_BUFFER_POST_PADDING, ' '); @@ -221,7 +221,7 @@ int callback_lws_node(struct lws *wsi, } catch(...) { - DEBUG(proto, "No such node %d\n", omi->subscribe.id); + DEBUG(proto, "No such node %d\n", (int)omi->subscribe.id); omi++; continue; } @@ -230,7 +230,7 @@ int callback_lws_node(struct lws *wsi, { node_t node = node_manager.node(*id); - message_t createmsg = create_msg_create(node); + message_t createmsg = create_msg_create(node, -1); createmsg.tid = omi->subscribe.id; msgqueue[wsi].push_back(createmsg); @@ -258,7 +258,7 @@ int callback_lws_node(struct lws *wsi, } catch(...) { - DEBUG(proto, "No such node %d\n", omi->unsubscribe.id); + DEBUG(proto, "No such node %d\n", (int)omi->unsubscribe.id); omi++; continue; } @@ -270,7 +270,7 @@ int callback_lws_node(struct lws *wsi, message_t removemsg = create_msg_remove(node); removemsg.tid = omi->unsubscribe.id; msgqueue[wsi].push_back(removemsg); - DEBUG(unsubscribe, "remove id: %d\n", *id); + DEBUG(unsubscribe, "remove id: %d\n", (int)*id); id++; } @@ -290,7 +290,7 @@ int callback_lws_node(struct lws *wsi, clientid_t clientid = (*ci).first; nodeid_t tid = (*ci).second; - DEBUG(proto, "Subscriber id of node: %d\n", tid); + DEBUG(proto, "Subscriber id of node: %d\n", (int)tid); message_t msg = *omi; msg.tid = tid; diff --git a/src/node.h b/src/node.h index 3f81290..d52528b 100644 --- a/src/node.h +++ b/src/node.h @@ -30,8 +30,9 @@ #include #include #include +#include -typedef unsigned int nodeid_t; +typedef std::int64_t nodeid_t; typedef std::list NodeIdList; typedef struct diff --git a/src/nodemanager.cc b/src/nodemanager.cc index 32a93b4..8c7cb56 100644 --- a/src/nodemanager.cc +++ b/src/nodemanager.cc @@ -81,23 +81,23 @@ void NodeManager::init(std::string filename) t.attributes["title"] = "root"; t.id = ROOT_ID; - tree.insertAsChild(0, ROOT_ID, t); + tree.insertAsChild(0, ROOT_ID, t, -1); t.attributes["title"] = "Finished"; t.id = FINISHED_ID; - tree.insertAsChild(ROOT_ID, FINISHED_ID, t); + tree.insertAsChild(ROOT_ID, FINISHED_ID, t, -1); t.attributes["title"] = "Backlog"; t.id = BACKLOG_ID; - tree.insertAsChild(ROOT_ID, BACKLOG_ID, t); + tree.insertAsChild(ROOT_ID, BACKLOG_ID, t, -1); t.attributes["title"] = "Lost+Found"; t.id = LOSTFOUND_ID; - tree.insertAsChild(ROOT_ID, LOSTFOUND_ID, t); + tree.insertAsChild(ROOT_ID, LOSTFOUND_ID, t, -1); t.attributes["title"] = "Projects"; t.id = PROJECTS_ID; - tree.insertAsChild(ROOT_ID, PROJECTS_ID, t); + tree.insertAsChild(ROOT_ID, PROJECTS_ID, t, -1); } tree.toStdOut(); @@ -113,7 +113,7 @@ nodeid_t NodeManager::createId() return tree.createId(); } -NodeIdListPair NodeManager::moveNode(nodeid_t id, nodeid_t to) +NodeIdListPair NodeManager::moveNode(nodeid_t id, nodeid_t to, nodeid_t beforeId) throw (std::exception) { if(isProtected(id)) @@ -145,7 +145,7 @@ NodeIdListPair NodeManager::moveNode(nodeid_t id, nodeid_t to) ancestors = tree.ancestorList(to); tilcreate.insert(tilcreate.end(), ancestors.begin(), ancestors.end()); - tree.move(id, to); + tree.move(id, to, beforeId); NodeIdListPair tilpair; tilpair.first = tilremove; @@ -210,7 +210,7 @@ NodeIdList NodeManager::updateNode(nodeid_t id, const std::string &name, return affectedNodes; } -NodeIdList NodeManager::createNode(nodeid_t parentid, nodeid_t *pid) +NodeIdList NodeManager::createNode(nodeid_t parentid, nodeid_t *pid, nodeid_t insertbeforeid) throw (std::exception) { NodeIdList affectedNodes; @@ -226,7 +226,7 @@ NodeIdList NodeManager::createNode(nodeid_t parentid, nodeid_t *pid) try { - affectedNodes = tree.insertAsChild(parentid, id, t); + affectedNodes = tree.insertAsChild(parentid, id, t, insertbeforeid); } catch(std::exception& e) { diff --git a/src/nodemanager.h b/src/nodemanager.h index f0bc81e..97d890f 100644 --- a/src/nodemanager.h +++ b/src/nodemanager.h @@ -45,12 +45,12 @@ public: void init(std::string filename); - NodeIdList createNode(nodeid_t parentid, nodeid_t *id) throw (std::exception); + NodeIdList createNode(nodeid_t parentid, nodeid_t *id, nodeid_t insertbeforeid) throw (std::exception); NodeIdList updateNode(nodeid_t id, const std::string &name, const std::string &value) throw (std::exception); NodeIdList removeNode(nodeid_t id) throw (std::exception); - NodeIdListPair moveNode(nodeid_t id, nodeid_t newParent) throw (std::exception); + NodeIdListPair moveNode(nodeid_t id, nodeid_t newParent, nodeid_t beforeId) throw (std::exception); NodeIdList subNodes(nodeid_t) throw (std::exception); diff --git a/src/nodetree.cc b/src/nodetree.cc index 38c20e1..eac919e 100644 --- a/src/nodetree.cc +++ b/src/nodetree.cc @@ -39,9 +39,7 @@ static inline std::string id2str(nodeid_t id) { - char buf[32]; - sprintf(buf, "%u", id); - return buf; + return std::to_string(id); } std::string Node::toXML(std::string prefix) @@ -110,7 +108,8 @@ nodeid_t NodeTree::createId() static nodeid_t rootid = -1; -NodeIdList NodeTree::insertAsChild(nodeid_t parentid, nodeid_t id, node_t data) +NodeIdList NodeTree::insertAsChild(nodeid_t parentid, nodeid_t id, + node_t data, nodeid_t insertBeforeId) throw (std::exception) { NodeIdList affectedNodes; @@ -132,7 +131,7 @@ NodeIdList NodeTree::insertAsChild(nodeid_t parentid, nodeid_t id, node_t data) Node* child = createNode(id); //DEBUG(nodetree, "!!!!!!!id in insert: %d\n", data.id); child->data = data; - insertChild(parent, child); + insertChild(parent, child, insertBeforeId); //affectedNodes.push_back(parentid); affectedNodes.push_back(id); @@ -203,7 +202,7 @@ static bool findNode(Node *needle, Node *haystack) return false; } -NodeIdList NodeTree::move(nodeid_t id, nodeid_t toid) +NodeIdList NodeTree::move(nodeid_t id, nodeid_t toid, nodeid_t beforeId) throw (std::exception) { NodeIdList affectedNodes; @@ -225,7 +224,22 @@ NodeIdList NodeTree::move(nodeid_t id, nodeid_t toid) } child->parent->children.remove(child); - newparent->children.push_back(child); + bool inserted{false}; + for(auto it = newparent->children.begin(); + it != newparent->children.end(); + ++it) + { + if((*it)->id == beforeId) + { + newparent->children.insert(it, child); + inserted = true; + } + } + if(!inserted) + { + // beforeId was not found in parent - inserting last instead. + newparent->children.push_back(child); + } child->parent = newparent; @@ -370,11 +384,27 @@ Node* NodeTree::createNode(nodeid_t id) return node; } -void NodeTree::insertChild(Node* parent, Node* child) +void NodeTree::insertChild(Node* parent, Node* child, nodeid_t insertBeforeId) { if(parent) { - parent->children.push_back(child); + bool inserted{false}; + for(auto it = parent->children.begin(); + it != parent->children.end(); + ++it) + { + if((*it)->id == insertBeforeId) + { + parent->children.insert(it, child); + inserted = true; + } + } + if(!inserted) + { + // beforeId was not found in parent - inserting last instead. + parent->children.push_back(child); + } + } else { @@ -391,7 +421,7 @@ static void printNode(Node* node, std::string prefix) return; } node_t t = node->data; - DEBUG(nodetree, "%s- %u - %s (%p)\n", prefix.c_str(), node->id, + DEBUG(nodetree, "%s- %u - %s (%p)\n", prefix.c_str(), (int)node->id, t.attributes["title"].c_str(), node); NodeList::iterator it; @@ -420,8 +450,8 @@ std::string NodeTree::toXML() return xml; } -void NodeTree::fromXML(std::string xml) +void NodeTree::fromXML(const std::string& xml) { XmlParser p(this); - p.parse(xml.c_str(), xml.size()); + p.parse(xml.data(), xml.size()); } diff --git a/src/nodetree.h b/src/nodetree.h index 8052389..2ab9ec7 100644 --- a/src/nodetree.h +++ b/src/nodetree.h @@ -49,16 +49,17 @@ public: class NodeTree { - friend class XmlParser; public: NodeTree(); ~NodeTree(); nodeid_t createId(); - NodeIdList insertAsChild(nodeid_t parentid, nodeid_t id, node_t data) throw (std::exception); + NodeIdList insertAsChild(nodeid_t parentid, nodeid_t id, node_t data, + nodeid_t insertBeforeId) throw (std::exception); NodeIdList remove(nodeid_t id) throw (std::exception); - NodeIdList move(nodeid_t id, nodeid_t newParentId) throw (std::exception); + NodeIdList move(nodeid_t id, nodeid_t newParentId, + nodeid_t insertBeforeId) throw (std::exception); NodeIdList updateData(nodeid_t id, const std::string &name, const std::string &value) throw (std::exception); node_t data(nodeid_t id) throw (std::exception); @@ -70,13 +71,14 @@ public: void toStdOut(); std::string toXML(); - void fromXML(std::string xml); + void fromXML(const std::string& xml); nodeid_t nextid; private: + friend class XmlParser; Node* createNode(nodeid_t id); - void insertChild(Node* parent, Node* child); + void insertChild(Node* parent, Node* child, nodeid_t insertBeforeId); Node* root; std::map id2node; diff --git a/src/ws/handler.js b/src/ws/handler.js index c0321a9..27eb76e 100644 --- a/src/ws/handler.js +++ b/src/ws/handler.js @@ -38,12 +38,13 @@ function moveEventHandler(e) var subscribeid = e.detail.subscribeid; var id = e.detail.id; var parentid = e.detail.parentid; + var insertBeforeId = e.detail.insertBeforeId; var node = findNode(id, subscribeid); var new_parent = findNode(parentid, subscribeid); if(node != null && new_parent != null) { - new_parent.addChild(node); + new_parent.addChild(node, insertBeforeId); } } @@ -53,6 +54,7 @@ function createEventHandler(e) var subscribeid = e.detail.subscribeid; var id = e.detail.id; var parentid = e.detail.parentid; + var insertBeforeId = e.detail.insertBeforeId; var node = new Node(id, subscribeid); node.create(); @@ -68,7 +70,7 @@ function createEventHandler(e) var parent = findNode(parentid, subscribeid); if(parent != null) { - parent.addChild(node); + parent.addChild(node, insertBeforeId); } } diff --git a/src/ws/node.js b/src/ws/node.js index e2af81e..e9d68b6 100644 --- a/src/ws/node.js +++ b/src/ws/node.js @@ -72,15 +72,32 @@ Node.prototype.findNode = function(id, subscribeid) return null; }; -Node.prototype.addChild = function(node) +Node.prototype.addChild = function(node, insertBeforeId) { if(node.parent != null) { node.parent.removeChild(node); } - this.children.push(node); + node.parent = this; - this.element.appendChild(node.element); + + inserted = false; + for(i = 0; i < this.children.length; ++i) + { + if(this.children[i].id == insertBeforeId) + { + this.children.splice(i - 1, 0, node); + this.element.insertBefore(node.element, this.element.childNodes[i + 2]); + inserted = true; + break; + } + } + + if(inserted == false) + { + this.children.push(node); + this.element.appendChild(node.element); + } }; Node.prototype.removeChild = function(node) diff --git a/src/ws/proto.js b/src/ws/proto.js index 035408f..5eadd70 100644 --- a/src/ws/proto.js +++ b/src/ws/proto.js @@ -129,6 +129,7 @@ try subscribeid: subscribeid, id: id, parentid: msg[3], + insertBeforeId: msg[4], }, bubbles: true, cancelable: true @@ -143,6 +144,7 @@ try subscribeid: subscribeid, id: id, parentid: msg[3], + insertBeforeId: msg[4], }, bubbles: true, cancelable: true @@ -237,7 +239,7 @@ function update(id, name, value) transmit("update "+id+" "+name+" "+value); } -function move(id, parent) +function move(id, parent, before) { - transmit("move "+id+" "+parent); + transmit("move "+id+" "+parent+" "+before); } diff --git a/src/ws/view.js b/src/ws/view.js index e96ec70..4e2d837 100644 --- a/src/ws/view.js +++ b/src/ws/view.js @@ -73,7 +73,7 @@ function drop(target, e) var id = e.dataTransfer.getData('id'); update(idFromStr(id), "dragged", "false"); - move(idFromStr(id), idFromStr(target.id)); + move(idFromStr(id), idFromStr(target.id), -1); } function subscribeMe(target, e) diff --git a/src/xmlparser.cc b/src/xmlparser.cc index 47e217c..257b661 100644 --- a/src/xmlparser.cc +++ b/src/xmlparser.cc @@ -4,7 +4,7 @@ * xmlparser.cc * * Wed Mar 21 09:15:51 CET 2012 - * Copyright 2012 Jonas Suhr Christensen + * Copyright 2012 Jonas Suhr Christensen * jsc@umbraculum.org ****************************************************************************/ @@ -62,7 +62,7 @@ void XmlParser::startTag(std::string name, attributes_t &attr) } node = tree->createNode(id); - tree->insertChild(parent, node); + tree->insertChild(parent, node, -1); // just append, the xml is ordered } if(name == "children") -- cgit v1.2.3