importReactfrom"react";
importMindElixir, { E } from"mind-elixir";
importaxiosfrom'axios';
classMindmapextendsReact.Component {
componentDidMount() {
this.dynamicWidth = window.innerWidth;
this.dynamicHeight = window.innerHeight;
.then(res=> {
if (res.data == "1") {
.then(res2=> {
this.ME = newMindElixir({
el:"#map",
direction:MindElixir.LEFT,
data:this.renderExistentMindmap(res2.data),
draggable:true, // default true
contextMenu:true, // default true
toolBar:true, // default true
nodeMenu:true, // default true
keypress:true// default true
});
this.ME.bus.addListener('operation', operation=> {
console.log(operation)
if (operation.name == 'finishEdit' || operation.name == 'editStyle') {
this.saveMindmapNode(operation.obj)
} elseif (operation.name == 'removeNode') {
this.deleteMindmapNode(operation.obj.id)
}
})
this.ME.init();
})
} else {
this.ME = newMindElixir({
el:"#map",
direction:MindElixir.LEFT,
data:MindElixir.new("New Mindmap"),
draggable:true, // default true
contextMenu:true, // default true
toolBar:true, // default true
nodeMenu:true, // default true
keypress:true// default true
});
this.ME.bus.addListener('operation', operation=> {
console.log(operation)
if (operation.name == 'finishEdit' || operation.name == 'editStyle') {
this.saveMindmapNode(operation.obj)
} elseif (operation.name == 'removeNode') {
this.deleteMindmapNode(operation.obj.id)
}
})
this.saveMindmapNode(this.ME.nodeData)
this.ME.init();
}
})
}
render() {
return (
<divid="map"style={{ height:window.innerHeight + 'px', width:'100%' }}/>
);
}
deleteMindmapNode(mindmapNodeId) {
.then(res=> {
console.log(res);
console.log(res.data);
})
}
saveMindmapNode(node) {
topic: (node.topic == undefined ? "" : node.topic),
id:node.id,
style: (node.style == undefined ? "" : node.style),
parent: (node.parent == undefined ? "" : node.parent.id),
tags: (node.tags == undefined ? [] : node.tags),
icons: (node.icons == undefined ? [] : node.icons),
hyperLink: (node.hyperLink == undefined ? "" : node.hyperLink)
})
.then(res=> {
console.log(res);
console.log(res.data);
})
}
renderExistentMindmap(data) {
letroot = data[0]
letnodeData = {
id:root.id,
topic:root.topic,
root:true,
style: {
background:root.style.background,
color:root.style.color,
fontSize:root.style.fontSize,
},
hyperLink:root.hyperLink,
children: []
}
this.createTree(nodeData, data)
return { nodeData }
}
createTree(nodeData, data) {
for(leti = 1; i < data.length; i++) {
if(data[i].parent == nodeData.id) {
letnewNode = {
id:data[i].id,
topic:data[i].topic,
root:false,
style: {
background:data[i].style.background,
color:data[i].style.color,
fontSize:data[i].style.fontSize,
},
hyperLink:data[i].hyperLink,
children: []
}
nodeData.children.push(newNode)
this.createTree(newNode, data)
}
}
}
}
exportdefaultMindmap;