2022-09-08 05:46:09 +02:00
|
|
|
import AppConfig from '../../classes/app-config';
|
2023-01-05 01:48:01 +01:00
|
|
|
import { LocalStorageManager, Mindmap, XMLSerializerFactory } from '@wisemapping/editor';
|
2022-09-08 05:46:09 +02:00
|
|
|
|
2022-11-22 04:37:16 +01:00
|
|
|
export const fetchMindmap = async (mapId: number): Promise<Mindmap> => {
|
2022-09-08 05:46:09 +02:00
|
|
|
let mindmap: Mindmap;
|
|
|
|
if (AppConfig.isRestClient()) {
|
|
|
|
const persistence = new LocalStorageManager(`/c/restful/maps/{id}/document/xml`, true);
|
2022-11-22 04:37:16 +01:00
|
|
|
mindmap = await persistence.load(String(mapId));
|
2022-09-08 05:46:09 +02:00
|
|
|
} else {
|
|
|
|
const parser = new DOMParser();
|
|
|
|
const xmlDoc = parser.parseFromString(
|
|
|
|
`
|
|
|
|
<map name="${mapId}" version="tango">
|
|
|
|
<topic central="true" text="This is the map ${mapId}" id="1" fontStyle=";;#ffffff;;;"></topic>
|
|
|
|
</map>
|
|
|
|
`,
|
|
|
|
'text/xml',
|
|
|
|
);
|
|
|
|
|
2022-10-31 06:17:01 +01:00
|
|
|
const serializer = XMLSerializerFactory.getSerializer('tango');
|
2022-11-22 04:37:16 +01:00
|
|
|
mindmap = Promise.resolve(serializer.loadFromDom(xmlDoc, String(mapId)));
|
2022-09-08 05:46:09 +02:00
|
|
|
}
|
|
|
|
return mindmap;
|
|
|
|
};
|