mirror of
https://bitbucket.org/wisemapping/wisemapping-frontend.git
synced 2024-11-11 01:43:23 +01:00
Move mindmap loader as part of Client.
This commit is contained in:
parent
bea6a15282
commit
63a8e76e8f
@ -24,7 +24,7 @@ class LocalStorageManager extends PersistenceManager {
|
||||
|
||||
private forceLoad: boolean;
|
||||
|
||||
constructor(documentUrl, forceLoad) {
|
||||
constructor(documentUrl: string, forceLoad: boolean) {
|
||||
super();
|
||||
this.documentUrl = documentUrl;
|
||||
this.forceLoad = forceLoad;
|
||||
|
@ -26,7 +26,7 @@ class FeatureModel {
|
||||
|
||||
private _type: FeatureType;
|
||||
|
||||
private _attributes: Record<string, unknown>;
|
||||
private _attributes;
|
||||
|
||||
/**
|
||||
* @constructs
|
||||
|
@ -40,7 +40,7 @@ class XMLSerializerPela implements XMLMindmapSerializer {
|
||||
const mapElem = document.createElement('map');
|
||||
const name = mindmap.getId();
|
||||
if ($defined(name)) {
|
||||
mapElem.setAttribute('name', this.rmXmlInv(name));
|
||||
mapElem.setAttribute('name', this._rmXmlInv(name));
|
||||
}
|
||||
const version = mindmap.getVersion();
|
||||
if ($defined(version)) {
|
||||
@ -72,7 +72,7 @@ class XMLSerializerPela implements XMLMindmapSerializer {
|
||||
return document;
|
||||
}
|
||||
|
||||
_topicToXML(document: Document, topic: NodeModel) {
|
||||
protected _topicToXML(document: Document, topic: NodeModel) {
|
||||
const parentTopic = document.createElement('topic');
|
||||
|
||||
// Set topic attributes...
|
||||
@ -168,10 +168,10 @@ class XMLSerializerPela implements XMLMindmapSerializer {
|
||||
const key = attributesKeys[attrIndex];
|
||||
const value = attributes[key];
|
||||
if (key === 'text') {
|
||||
const cdata = document.createCDATASection(this.rmXmlInv(value));
|
||||
const cdata = document.createCDATASection(this._rmXmlInv(value));
|
||||
featureDom.appendChild(cdata);
|
||||
} else {
|
||||
featureDom.setAttribute(key, this.rmXmlInv(value));
|
||||
featureDom.setAttribute(key, this._rmXmlInv(value));
|
||||
}
|
||||
}
|
||||
parentTopic.appendChild(featureDom);
|
||||
@ -187,12 +187,12 @@ class XMLSerializerPela implements XMLMindmapSerializer {
|
||||
return parentTopic;
|
||||
}
|
||||
|
||||
_noteTextToXML(document: Document, elem: Element, text: string) {
|
||||
protected _noteTextToXML(document: Document, elem: Element, text: string) {
|
||||
if (text.indexOf('\n') === -1) {
|
||||
elem.setAttribute('text', this.rmXmlInv(text));
|
||||
elem.setAttribute('text', this._rmXmlInv(text));
|
||||
} else {
|
||||
const textDom = document.createElement('text');
|
||||
const cdata = document.createCDATASection(this.rmXmlInv(text));
|
||||
const cdata = document.createCDATASection(this._rmXmlInv(text));
|
||||
textDom.appendChild(cdata);
|
||||
elem.appendChild(textDom);
|
||||
}
|
||||
@ -284,7 +284,7 @@ class XMLSerializerPela implements XMLMindmapSerializer {
|
||||
return mindmap;
|
||||
}
|
||||
|
||||
_deserializeNode(domElem: Element, mindmap: Mindmap) {
|
||||
protected _deserializeNode(domElem: Element, mindmap: Mindmap) {
|
||||
const type = domElem.getAttribute('central') != null ? 'CentralTopic' : 'MainTopic';
|
||||
|
||||
// Load attributes...
|
||||
@ -493,8 +493,7 @@ class XMLSerializerPela implements XMLMindmapSerializer {
|
||||
* @param in The String whose non-valid characters we want to remove.
|
||||
* @return The in String, stripped of non-valid characters.
|
||||
*/
|
||||
// eslint-disable-next-line class-methods-use-this
|
||||
rmXmlInv(str) {
|
||||
protected _rmXmlInv(str: string) {
|
||||
if (str == null || str === undefined) return null;
|
||||
|
||||
let result = '';
|
||||
|
@ -1,3 +1,4 @@
|
||||
import { Mindmap } from '@wisemapping/mindplot';
|
||||
import Client, {
|
||||
AccountInfo,
|
||||
BasicMapInfo,
|
||||
@ -16,6 +17,9 @@ class CacheDecoratorClient implements Client {
|
||||
constructor(client: Client) {
|
||||
this.client = client;
|
||||
}
|
||||
fetchMindmap(id: number): Mindmap {
|
||||
return this.client.fetchMindmap(id);
|
||||
}
|
||||
|
||||
deleteAccount(): Promise<void> {
|
||||
return this.client.deleteAccount();
|
||||
@ -106,7 +110,7 @@ class CacheDecoratorClient implements Client {
|
||||
}
|
||||
|
||||
revertHistory(id: number, cid: number): Promise<void> {
|
||||
return this.client.revertHistory(id,cid);
|
||||
return this.client.revertHistory(id, cid);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
import { Mindmap } from '@wisemapping/mindplot';
|
||||
import { Locale, LocaleCode } from '../app-i18n';
|
||||
|
||||
export type NewUser = {
|
||||
@ -102,6 +103,9 @@ interface Client {
|
||||
|
||||
fetchHistory(id: number): Promise<ChangeHistory[]>;
|
||||
revertHistory(id: number, cid: number): Promise<void>;
|
||||
|
||||
fetchMindmap(id:number): Mindmap;
|
||||
|
||||
}
|
||||
|
||||
export default Client;
|
||||
|
@ -1,3 +1,5 @@
|
||||
import { Mindmap } from '@wisemapping/mindplot';
|
||||
import XMLSerializerTango from '@wisemapping/mindplot/src/components/persistence/XMLSerializerTango';
|
||||
import Client, {
|
||||
AccountInfo,
|
||||
BasicMapInfo,
|
||||
@ -107,6 +109,17 @@ class MockClient implements Client {
|
||||
|
||||
this.labels = [label1, label2, label3];
|
||||
}
|
||||
fetchMindmap(id: number): Mindmap {
|
||||
const parser = new DOMParser();
|
||||
const xmlDoc = parser.parseFromString(`
|
||||
<map name="${id}" version="tango">
|
||||
<topic central="true" text="This is the map ${id}" id="1" fontStyle=";;#ffffff;;;"></topic>
|
||||
</map>
|
||||
`, 'text/xml');
|
||||
|
||||
const serializer = new XMLSerializerTango();
|
||||
return serializer.loadFromDom(xmlDoc, String(id));
|
||||
}
|
||||
deleteMapPermission(id: number, email: string): Promise<void> {
|
||||
let perm = this.permissionsByMap.get(id) || [];
|
||||
perm = perm.filter((p) => p.email != email);
|
||||
@ -325,8 +338,8 @@ class MockClient implements Client {
|
||||
|
||||
registerNewUser(user: NewUser): Promise<void> {
|
||||
console.log('user:' + user);
|
||||
if(user.email=="error@example.com"){
|
||||
return Promise.reject({msg:"Unexpected error"});
|
||||
if (user.email == "error@example.com") {
|
||||
return Promise.reject({ msg: "Unexpected error" });
|
||||
}
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
import { LocalStorageManager, Mindmap } from '@wisemapping/mindplot';
|
||||
import axios from 'axios';
|
||||
import Client, {
|
||||
ErrorInfo,
|
||||
@ -21,6 +22,16 @@ export default class RestClient implements Client {
|
||||
this.sessionExpired = sessionExpired;
|
||||
}
|
||||
|
||||
fetchMindmap(id: number): Mindmap {
|
||||
// Load mindmap ...
|
||||
const persistence = new LocalStorageManager(
|
||||
`/c/restful/maps/{id}/document/xml`,
|
||||
true
|
||||
);
|
||||
const mindmap = persistence.load(String(id));
|
||||
return mindmap;
|
||||
}
|
||||
|
||||
deleteMapPermission(id: number, email: string): Promise<void> {
|
||||
const handler = (success: () => void, reject: (error: ErrorInfo) => void) => {
|
||||
axios
|
||||
|
@ -10,7 +10,11 @@ import FormControlLabel from '@material-ui/core/FormControlLabel';
|
||||
import Radio from '@material-ui/core/Radio';
|
||||
import Select from '@material-ui/core/Select';
|
||||
import MenuItem from '@material-ui/core/MenuItem';
|
||||
import { Designer, TextExporterFactory, ImageExporterFactory, Exporter, Mindmap, LocalStorageManager } from '@wisemapping/mindplot';
|
||||
import { Designer, TextExporterFactory, ImageExporterFactory, Exporter, Mindmap } from '@wisemapping/mindplot';
|
||||
import Client from '../../../../classes/client';
|
||||
import { activeInstance } from '../../../../redux/clientSlice';
|
||||
|
||||
import { useSelector } from 'react-redux';
|
||||
|
||||
type ExportFormat = 'svg' | 'jpg' | 'png' | 'txt' | 'mm' | 'wxml' | 'xls' | 'md';
|
||||
type ExportGroup = 'image' | 'document' | 'mindmap-tool';
|
||||
@ -30,6 +34,7 @@ const ExportDialog = ({
|
||||
const intl = useIntl();
|
||||
const [submit, setSubmit] = React.useState<boolean>(false);
|
||||
const { map } = fetchMapById(mapId);
|
||||
const client: Client = useSelector(activeInstance);
|
||||
|
||||
const [exportGroup, setExportGroup] = React.useState<ExportGroup>(
|
||||
enableImgExport ? 'image' : 'document'
|
||||
@ -83,12 +88,7 @@ const ExportDialog = ({
|
||||
size = workspace.getSize();
|
||||
mindmap = designer.getMindmap();
|
||||
} else {
|
||||
// Load mindmap ...
|
||||
const persistence = new LocalStorageManager(
|
||||
`/c/restful/maps/{id}/document/xml`,
|
||||
true
|
||||
);
|
||||
mindmap = persistence.load(mapId.toString());
|
||||
mindmap = client.fetchMindmap(mapId);
|
||||
}
|
||||
|
||||
let exporter: Exporter;
|
||||
|
Loading…
Reference in New Issue
Block a user