mirror of
https://bitbucket.org/wisemapping/wisemapping-frontend.git
synced 2024-11-22 06:37:56 +01:00
Fix error rendered a children node
This commit is contained in:
parent
d8fbf4ecc9
commit
df26a52047
@ -10,7 +10,7 @@ import FreemindConstant from './freemind/FreemindConstant';
|
||||
import VersionNumber from './freemind/importer/VersionNumber';
|
||||
import ObjectFactory from './freemind/ObjectFactory';
|
||||
import FreemindMap from './freemind/Map';
|
||||
import FreeminNode, { Choise } from './freemind/Node';
|
||||
import FreeminNode from './freemind/Node';
|
||||
import Arrowlink from './freemind/Arrowlink';
|
||||
import Richcontent from './freemind/Richcontent';
|
||||
import Icon from './freemind/Icon';
|
||||
@ -19,7 +19,7 @@ import Font from './freemind/Font';
|
||||
|
||||
type PositionNodeType = {x: number, y: number}
|
||||
|
||||
class FreemindExporter implements Exporter {
|
||||
class FreemindExporter extends Exporter {
|
||||
private mindmap: Mindmap;
|
||||
|
||||
private nodeMap: Map<number, FreeminNode> = null;
|
||||
@ -31,9 +31,18 @@ class FreemindExporter implements Exporter {
|
||||
private static wisweToFreeFontSize: Map<number, number> = new Map<number, number>();
|
||||
|
||||
constructor(mindmap: Mindmap) {
|
||||
super(FreemindConstant.SUPPORTED_FREEMIND_VERSION.getVersion(), 'application/xml');
|
||||
this.mindmap = mindmap;
|
||||
}
|
||||
|
||||
exportAndEncode(): Promise<string> {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
|
||||
getContentType(): string {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
|
||||
static {
|
||||
this.wisweToFreeFontSize.set(6, 10);
|
||||
this.wisweToFreeFontSize.set(8, 12);
|
||||
@ -73,7 +82,7 @@ class FreemindExporter implements Exporter {
|
||||
|
||||
if (centralTopic) {
|
||||
this.nodeMap.set(centralTopic.getId(), main);
|
||||
this.setTopicPropertiesToNode(main, centralTopic, true);
|
||||
this.setTopicPropertiesToNode({ freemindNode: main, mindmapTopic: centralTopic, isRoot: true });
|
||||
this.addNodeFromTopic(centralTopic, main);
|
||||
}
|
||||
|
||||
@ -91,9 +100,7 @@ class FreemindExporter implements Exporter {
|
||||
|
||||
if (relationship.getStartArrow() && relationship.getStartArrow()) arrowlink.setStartarrow('Default');
|
||||
|
||||
const cloudEdge: Array<Choise> = srcNode.getArrowlinkOrCloudOrEdge();
|
||||
|
||||
cloudEdge.push(arrowlink);
|
||||
srcNode.setArrowlinkOrCloudOrEdge(arrowlink);
|
||||
}
|
||||
});
|
||||
|
||||
@ -103,37 +110,18 @@ class FreemindExporter implements Exporter {
|
||||
return Promise.resolve(xmlToString);
|
||||
}
|
||||
|
||||
private addNodeFromTopic(mainTopic: INodeModel, destNode: FreeminNode): void {
|
||||
const curretnTopics: Array<INodeModel> = mainTopic.getChildren();
|
||||
|
||||
curretnTopics.forEach((currentTopic: INodeModel) => {
|
||||
const newNode: FreeminNode = this.objectFactory.createNode();
|
||||
this.nodeMap.set(currentTopic.getId(), newNode);
|
||||
|
||||
this.setTopicPropertiesToNode(newNode, currentTopic, false);
|
||||
|
||||
destNode.getArrowlinkOrCloudOrEdge().push(newNode);
|
||||
|
||||
this.addNodeFromTopic(currentTopic, newNode);
|
||||
|
||||
const position: PositionNodeType = currentTopic.getPosition();
|
||||
if (position) {
|
||||
const xPos: number = position.x;
|
||||
newNode.setPosition((xPos < 0 ? 'left' : 'right'));
|
||||
} else newNode.setPosition('left');
|
||||
});
|
||||
}
|
||||
|
||||
private setTopicPropertiesToNode(freemindNode: FreeminNode, mindmapTopic: INodeModel, isRoot: boolean): void {
|
||||
private setTopicPropertiesToNode({ freemindNode, mindmapTopic, isRoot }: { freemindNode: FreeminNode; mindmapTopic: INodeModel; isRoot: boolean; }): void {
|
||||
freemindNode.setId(`ID_${mindmapTopic.getId()}`);
|
||||
|
||||
const text = mindmapTopic.getText();
|
||||
|
||||
if (!text.includes('\n')) {
|
||||
freemindNode.setText(text);
|
||||
} else {
|
||||
const richcontent: Richcontent = this.buildRichcontent(text, 'NODE');
|
||||
freemindNode.getArrowlinkOrCloudOrEdge().push(richcontent);
|
||||
if (text) {
|
||||
if (!text.includes('\n')) {
|
||||
freemindNode.setText(text);
|
||||
} else {
|
||||
const richcontent: Richcontent = this.buildRichcontent(text, 'NODE');
|
||||
freemindNode.setArrowlinkOrCloudOrEdge(richcontent);
|
||||
}
|
||||
}
|
||||
|
||||
const wiseShape: string = mindmapTopic.getShapeType();
|
||||
@ -141,7 +129,7 @@ class FreemindExporter implements Exporter {
|
||||
freemindNode.setBackgorundColor(this.rgbToHex(mindmapTopic.getBackgroundColor()));
|
||||
}
|
||||
|
||||
if (wiseShape && !wiseShape) {
|
||||
if (wiseShape) {
|
||||
const isRootRoundedRectangle = isRoot && TopicShape.ROUNDED_RECT !== wiseShape;
|
||||
const notIsRootLine = !isRoot && TopicShape.LINE !== wiseShape;
|
||||
|
||||
@ -159,13 +147,37 @@ class FreemindExporter implements Exporter {
|
||||
this.addEdgeNode(freemindNode, mindmapTopic);
|
||||
}
|
||||
|
||||
private addNodeFromTopic(mainTopic: INodeModel, destNode: FreeminNode): void {
|
||||
const curretnTopics: Array<INodeModel> = mainTopic.getChildren();
|
||||
|
||||
curretnTopics.forEach((currentTopic: INodeModel) => {
|
||||
const newNode: FreeminNode = this.objectFactory.createNode();
|
||||
this.nodeMap.set(currentTopic.getId(), newNode);
|
||||
|
||||
this.setTopicPropertiesToNode({ freemindNode: newNode, mindmapTopic: currentTopic, isRoot: false });
|
||||
|
||||
destNode.setArrowlinkOrCloudOrEdge(newNode);
|
||||
|
||||
this.addNodeFromTopic(currentTopic, newNode);
|
||||
|
||||
const position: PositionNodeType = currentTopic.getPosition();
|
||||
if (position) {
|
||||
const xPos: number = position.x;
|
||||
newNode.setPosition((xPos < 0 ? 'left' : 'right'));
|
||||
} else newNode.setPosition('left');
|
||||
});
|
||||
}
|
||||
|
||||
private buildRichcontent(text: string, type: string): Richcontent {
|
||||
const richconent: Richcontent = this.objectFactory.createRichcontent();
|
||||
|
||||
richconent.setType(type);
|
||||
|
||||
const textSplit = text.split('\n');
|
||||
|
||||
let html = '<html><body>';
|
||||
|
||||
text.split('\n').forEach((line: string) => {
|
||||
textSplit.forEach((line: string) => {
|
||||
html += `<p>${line.trim()}</p>`;
|
||||
});
|
||||
|
||||
@ -183,7 +195,7 @@ class FreemindExporter implements Exporter {
|
||||
const freemindIcon: Icon = new Icon();
|
||||
|
||||
branches
|
||||
.filter((node: INodeModel) => node.getText !== undefined)
|
||||
.filter((node: INodeModel) => node.getText())
|
||||
.forEach((node: INodeModel) => {
|
||||
node.getFeatures().forEach((feature: FeatureModel) => {
|
||||
const type = feature.getType();
|
||||
@ -196,13 +208,13 @@ class FreemindExporter implements Exporter {
|
||||
if (type === 'note') {
|
||||
const note = feature as NoteModel;
|
||||
const richcontent: Richcontent = this.buildRichcontent(note.getText(), 'NOTE');
|
||||
freemindNode.getArrowlinkOrCloudOrEdge().push(richcontent);
|
||||
freemindNode.setArrowlinkOrCloudOrEdge(richcontent);
|
||||
}
|
||||
|
||||
if (type === 'icon') {
|
||||
const icon = feature as IconModel;
|
||||
freemindIcon.setBuiltin(icon.getIconType());
|
||||
freemindNode.getArrowlinkOrCloudOrEdge().push(freemindIcon);
|
||||
freemindNode.setArrowlinkOrCloudOrEdge(freemindIcon);
|
||||
}
|
||||
});
|
||||
});
|
||||
@ -212,7 +224,7 @@ class FreemindExporter implements Exporter {
|
||||
if (mindmapTopic.getBorderColor()) {
|
||||
const edgeNode: Edge = this.objectFactory.createEdge();
|
||||
edgeNode.setColor(this.rgbToHex(mindmapTopic.getBorderColor()));
|
||||
freemainMap.getArrowlinkOrCloudOrEdge().push(edgeNode);
|
||||
freemainMap.setArrowlinkOrCloudOrEdge(edgeNode);
|
||||
}
|
||||
}
|
||||
|
||||
@ -267,7 +279,7 @@ class FreemindExporter implements Exporter {
|
||||
if (font.getSize() === null) {
|
||||
font.setSize(FreemindExporter.wisweToFreeFontSize.get(8).toString());
|
||||
}
|
||||
freemindNode.getArrowlinkOrCloudOrEdge().push(font);
|
||||
freemindNode.setArrowlinkOrCloudOrEdge(font);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import Edge from './Edge';
|
||||
import Font from './Font';
|
||||
import Icon from './Icon';
|
||||
import Node, { Choise } from './Node';
|
||||
import Richcontent from './Richcontent';
|
||||
|
||||
export default class Map {
|
||||
protected node: Node;
|
||||
@ -38,7 +39,6 @@ export default class Map {
|
||||
|
||||
// Create main node
|
||||
const mainNode: Node = this.node;
|
||||
mainNode.setCentralNode(true);
|
||||
const mainNodeElem = mainNode.toXml(document);
|
||||
mapElem.appendChild(mainNodeElem);
|
||||
|
||||
@ -53,14 +53,16 @@ export default class Map {
|
||||
|
||||
private nodeToXml(childNode: Choise, parentNode: HTMLElement, document: Document): HTMLElement {
|
||||
if (childNode instanceof Node) {
|
||||
childNode.setCentralNode(false);
|
||||
const childNodeXml = childNode.toXml(document);
|
||||
parentNode.appendChild(childNodeXml);
|
||||
|
||||
childNode.getArrowlinkOrCloudOrEdge().forEach((node: Choise) => {
|
||||
const nodeXml = this.nodeToXml(node, childNodeXml, document);
|
||||
childNodeXml.appendChild(nodeXml);
|
||||
});
|
||||
const childrens = childNode.getArrowlinkOrCloudOrEdge();
|
||||
if (childrens.length > 0) {
|
||||
childrens.forEach((node: Choise) => {
|
||||
const nodeXml = this.nodeToXml(node, childNodeXml, document);
|
||||
childNodeXml.appendChild(nodeXml);
|
||||
});
|
||||
}
|
||||
|
||||
return childNodeXml;
|
||||
}
|
||||
@ -100,6 +102,13 @@ export default class Map {
|
||||
return childNodeXml;
|
||||
}
|
||||
|
||||
if (childNode instanceof Richcontent) {
|
||||
const childNodeXml = childNode.toXml(document);
|
||||
parentNode.appendChild(childNodeXml);
|
||||
|
||||
return childNodeXml;
|
||||
}
|
||||
|
||||
return parentNode;
|
||||
}
|
||||
}
|
||||
|
@ -41,8 +41,6 @@ class Node {
|
||||
|
||||
protected ENCRYPTED_CONTENT: string;
|
||||
|
||||
protected centralNode: boolean;
|
||||
|
||||
getArrowlinkOrCloudOrEdge(): Array<Arrowlink | Cloud | Edge | Font | Hook | Icon | Richcontent | Node> {
|
||||
if (!this.arrowlinkOrCloudOrEdge) {
|
||||
this.arrowlinkOrCloudOrEdge = new Array<Arrowlink | Cloud | Edge | Font | Hook | Icon | Richcontent | this>();
|
||||
@ -114,12 +112,8 @@ class Node {
|
||||
return this.ENCRYPTED_CONTENT;
|
||||
}
|
||||
|
||||
getCentralNode(): boolean {
|
||||
return this.centralNode;
|
||||
}
|
||||
|
||||
setArrowlinkOrCloudOrEdge(value: Array<Arrowlink | Cloud | Edge | Font | Hook | Icon | Richcontent | this>): void {
|
||||
this.arrowlinkOrCloudOrEdge = value;
|
||||
setArrowlinkOrCloudOrEdge(value: Arrowlink | Cloud | Edge | Font | Hook | Icon | Richcontent | this): void {
|
||||
this.getArrowlinkOrCloudOrEdge().push(value);
|
||||
}
|
||||
|
||||
setBackgorundColor(value: string): void {
|
||||
@ -186,25 +180,16 @@ class Node {
|
||||
this.ENCRYPTED_CONTENT = value;
|
||||
}
|
||||
|
||||
setCentralNode(value: boolean): void {
|
||||
this.centralNode = value;
|
||||
}
|
||||
|
||||
toXml(document: Document): HTMLElement {
|
||||
// Set node attributes
|
||||
const nodeElem = document.createElement('node');
|
||||
|
||||
if (this.centralNode) {
|
||||
nodeElem.setAttribute('ID', this.ID);
|
||||
nodeElem.setAttribute('TEXT', this.TEXT);
|
||||
|
||||
return nodeElem;
|
||||
}
|
||||
|
||||
nodeElem.setAttribute('ID', this.ID);
|
||||
nodeElem.setAttribute('POSITION', this.POSITION);
|
||||
nodeElem.setAttribute('STYLE', this.STYLE);
|
||||
nodeElem.setAttribute('TEXT', this.TEXT);
|
||||
if (this.ID) nodeElem.setAttribute('ID', this.ID);
|
||||
if (this.POSITION) nodeElem.setAttribute('POSITION', this.POSITION);
|
||||
if (this.STYLE) nodeElem.setAttribute('STYLE', this.STYLE);
|
||||
if (this.BACKGROUND_COLOR) nodeElem.setAttribute('BACKGROUND_COLOR', this.BACKGROUND_COLOR);
|
||||
if (this.COLOR) nodeElem.setAttribute('COLOR', this.COLOR);
|
||||
if (this.TEXT) nodeElem.setAttribute('TEXT', this.TEXT);
|
||||
|
||||
return nodeElem;
|
||||
}
|
||||
|
@ -25,6 +25,11 @@ export default class Richcontent {
|
||||
|
||||
richcontentElem.setAttribute('TYPE', this.type);
|
||||
|
||||
if (this.html) {
|
||||
const htmlElement: HTMLElement = document.createElement(this.html);
|
||||
richcontentElem.appendChild(htmlElement);
|
||||
}
|
||||
|
||||
return richcontentElem;
|
||||
}
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ describe('MD export test execution', () => {
|
||||
|
||||
describe('MM export test execution', () => {
|
||||
test.each(testNames)('Exporting %p suite', async (testName: string) => {
|
||||
// Load mindmap DOM...
|
||||
// Load mindmap DOM..
|
||||
const mindmapPath = path.resolve(__dirname, `./input/${testName}.wxml`);
|
||||
const mapDocument = parseXMLFile(mindmapPath, 'text/xml');
|
||||
|
||||
|
@ -1,7 +1 @@
|
||||
<map version="1.0.1">
|
||||
<node ID="ID_0" TEXT="i18n">
|
||||
<node ID="ID_1" POSITION="right" TEXT="Este es un é con acento"/>
|
||||
<node ID="ID_2" POSITION="left" TEXT="Este es una ñ"/>
|
||||
<node ID="ID_3" POSITION="right" TEXT="這是一個樣本 Japanise。"/>
|
||||
</node>
|
||||
</map>
|
||||
<map version="1.0.1"><node ID="ID_0" TEXT="i18n"><node ID="ID_1" POSITION="right" TEXT="Este es un é con acento"/><node ID="ID_2" POSITION="left" TEXT="Este es una ñ"/><node ID="ID_3" POSITION="right" TEXT="這是一個樣本 Japanise。"/></node></map>
|
Loading…
Reference in New Issue
Block a user