Comments (4)
mindmaps.MindMapModel.createNode(node, parent)
should be the right function for the job. However, it's important you pass a reference to the parent node.
You can get the parent node if you know its id. The id should be part of the node object that is sent to your clients (node.parent). then you can ask MindMapModel.getMindMap().nodes.get(id)
and this SHOULD return the actual node object of the parent.
I have not tested this yet, but this is how I imagined to use it one day to implement collaboration between clients. I am excited to see if you manage to make it work.
Please let me know if you need more support.
from mindmaps.
this is all handled inside mindmaps.MindMapModel
//node is the created node object
//if parent is root
if(node.parentId == null){
//get the root on the clients map
var root = self.getMindMap().getRoot();
var id = root.id;
var parent = self.getMindMap().nodes.get(id);
} else {
//or just grab the parent by the nodes parentId
var id = node.parentId;
var parent = self.getMindMap().nodes.get(id);
}
//then turn the object back into a usable node
var newNode = mindmaps.Node.fromObject(node);
//finally add the node to the clients map
self.createNode(newNode,parent);
works! ...kinda - the node is successfully created on the client's maps, however this triggers an infinite loop where nodes are continuously added back and forth- getting close though!
from mindmaps.
the server logs show that all the duplicate nodes have the same id, so i tried changing the get method to check if a node already exists before adding it
//EDIT: created new function
mindmaps.NodeMap.prototype.exists = function(nodeId) {
if(nodeId in this.nodes){
return true;
} else {
return false;
}
};
and then checking if the node is in the map already with
var check = self.getMindMap().nodes.exists(node.id);
if(check === false){
//code from above comment
}
but still no luck... any ideas?
UPDATE: now the server logs are showing unique id's for each created node, so it's back to the drawing board ...
from mindmaps.
getting closer, at the beginning of mindmaps.MindMapModel
added this.createFired=0;
eventBus.subscribe(mindmaps.Event.NODE_CREATED, function(node) {
if(self.createFired==0){
mindmaps.socket.emit(mindmaps.Event.NODE_CREATED,node);
self.createFired++;
}
});
then after self.createNode(newNode,parent);
, added self.createFired=0;
voila! no more endless loop!
still some slight tweaking before i move on to removing/updating nodes, but i'm calling this one closed
from mindmaps.
Related Issues (20)
- Docker conteiner for self hosted site HOT 1
- app.mindmapmaker.org source code published to github
- Logo Proposal HOT 5
- Mobile UI / Responsive Version
- Saving on Server
- Modify the position of nodes
- Question about node position calculation HOT 1
- Import from outline HOT 1
- possibility to edit text stop
- Plugin fΓΌr Moodle
- Save to file not working
- add parent node HOT 2
- convert to Vue/React + Webpack? HOT 1
- app.mindmapmaker.org - new version ? HOT 8
- defining relationships HOT 2
- PROPOSAL: HOT 1
- proposal: extra data when improt / export
- Feature Request: UI: removable bottom bar HOT 1
- Feature Request: UI: Add `delete node` action for mouse HOT 2
- Idea: Add Textfile export option HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mindmaps.