2022-09-08 05:46:09 +02:00
|
|
|
import AppConfig from '../../classes/app-config';
|
|
|
|
import exampleMap from '../../classes/client/mock-client/example-map.wxml';
|
|
|
|
import {
|
|
|
|
PersistenceManager,
|
|
|
|
RESTPersistenceManager,
|
|
|
|
LocalStorageManager,
|
|
|
|
Mindmap,
|
|
|
|
MockPersistenceManager,
|
2022-10-31 06:17:01 +01:00
|
|
|
XMLSerializerFactory,
|
2022-09-08 05:46:09 +02:00
|
|
|
} from '@wisemapping/editor';
|
|
|
|
|
|
|
|
export const buildPersistenceManagerForEditor = (mode: string): PersistenceManager => {
|
|
|
|
let persistenceManager: PersistenceManager;
|
|
|
|
if (AppConfig.isRestClient()) {
|
|
|
|
if (mode === 'edition-owner' || mode === 'edition-editor') {
|
|
|
|
persistenceManager = new RESTPersistenceManager({
|
|
|
|
documentUrl: '/c/restful/maps/{id}/document',
|
|
|
|
revertUrl: '/c/restful/maps/{id}/history/latest',
|
|
|
|
lockUrl: '/c/restful/maps/{id}/lock',
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
persistenceManager = new LocalStorageManager(
|
|
|
|
`/c/restful/maps/{id}/${global.historyId ? `${global.historyId}/` : ''}document/xml${
|
|
|
|
mode === 'showcase' ? '-pub' : ''
|
|
|
|
}`,
|
|
|
|
true,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
persistenceManager.addErrorHandler((error) => {
|
|
|
|
if (error.errorType === 'session-expired') {
|
|
|
|
// TODO: this line was in RestPersistenceClient, do something similar here
|
|
|
|
//client.sessionExpired();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
persistenceManager = new MockPersistenceManager(exampleMap);
|
|
|
|
}
|
|
|
|
return persistenceManager;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const getMindmapFromPersistence = (mapId: string): Mindmap => {
|
|
|
|
let mindmap: Mindmap;
|
|
|
|
if (AppConfig.isRestClient()) {
|
|
|
|
const persistence = new LocalStorageManager(`/c/restful/maps/{id}/document/xml`, true);
|
|
|
|
mindmap = persistence.load(String(mapId));
|
|
|
|
} 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-09-08 05:46:09 +02:00
|
|
|
mindmap = serializer.loadFromDom(xmlDoc, String(mapId));
|
|
|
|
}
|
|
|
|
return mindmap;
|
|
|
|
};
|