Move mindmap loader as part of Client.

This commit is contained in:
Paulo Gustavo Veiga 2022-01-31 19:24:38 -08:00
parent bea6a15282
commit 63a8e76e8f
8 changed files with 73 additions and 42 deletions

View File

@ -24,7 +24,7 @@ class LocalStorageManager extends PersistenceManager {
private forceLoad: boolean; private forceLoad: boolean;
constructor(documentUrl, forceLoad) { constructor(documentUrl: string, forceLoad: boolean) {
super(); super();
this.documentUrl = documentUrl; this.documentUrl = documentUrl;
this.forceLoad = forceLoad; this.forceLoad = forceLoad;

View File

@ -26,7 +26,7 @@ class FeatureModel {
private _type: FeatureType; private _type: FeatureType;
private _attributes: Record<string, unknown>; private _attributes;
/** /**
* @constructs * @constructs

View File

@ -40,7 +40,7 @@ class XMLSerializerPela implements XMLMindmapSerializer {
const mapElem = document.createElement('map'); const mapElem = document.createElement('map');
const name = mindmap.getId(); const name = mindmap.getId();
if ($defined(name)) { if ($defined(name)) {
mapElem.setAttribute('name', this.rmXmlInv(name)); mapElem.setAttribute('name', this._rmXmlInv(name));
} }
const version = mindmap.getVersion(); const version = mindmap.getVersion();
if ($defined(version)) { if ($defined(version)) {
@ -72,7 +72,7 @@ class XMLSerializerPela implements XMLMindmapSerializer {
return document; return document;
} }
_topicToXML(document: Document, topic: NodeModel) { protected _topicToXML(document: Document, topic: NodeModel) {
const parentTopic = document.createElement('topic'); const parentTopic = document.createElement('topic');
// Set topic attributes... // Set topic attributes...
@ -168,10 +168,10 @@ class XMLSerializerPela implements XMLMindmapSerializer {
const key = attributesKeys[attrIndex]; const key = attributesKeys[attrIndex];
const value = attributes[key]; const value = attributes[key];
if (key === 'text') { if (key === 'text') {
const cdata = document.createCDATASection(this.rmXmlInv(value)); const cdata = document.createCDATASection(this._rmXmlInv(value));
featureDom.appendChild(cdata); featureDom.appendChild(cdata);
} else { } else {
featureDom.setAttribute(key, this.rmXmlInv(value)); featureDom.setAttribute(key, this._rmXmlInv(value));
} }
} }
parentTopic.appendChild(featureDom); parentTopic.appendChild(featureDom);
@ -187,12 +187,12 @@ class XMLSerializerPela implements XMLMindmapSerializer {
return parentTopic; return parentTopic;
} }
_noteTextToXML(document: Document, elem: Element, text: string) { protected _noteTextToXML(document: Document, elem: Element, text: string) {
if (text.indexOf('\n') === -1) { if (text.indexOf('\n') === -1) {
elem.setAttribute('text', this.rmXmlInv(text)); elem.setAttribute('text', this._rmXmlInv(text));
} else { } else {
const textDom = document.createElement('text'); const textDom = document.createElement('text');
const cdata = document.createCDATASection(this.rmXmlInv(text)); const cdata = document.createCDATASection(this._rmXmlInv(text));
textDom.appendChild(cdata); textDom.appendChild(cdata);
elem.appendChild(textDom); elem.appendChild(textDom);
} }
@ -284,7 +284,7 @@ class XMLSerializerPela implements XMLMindmapSerializer {
return mindmap; return mindmap;
} }
_deserializeNode(domElem: Element, mindmap: Mindmap) { protected _deserializeNode(domElem: Element, mindmap: Mindmap) {
const type = domElem.getAttribute('central') != null ? 'CentralTopic' : 'MainTopic'; const type = domElem.getAttribute('central') != null ? 'CentralTopic' : 'MainTopic';
// Load attributes... // Load attributes...
@ -493,8 +493,7 @@ class XMLSerializerPela implements XMLMindmapSerializer {
* @param in The String whose non-valid characters we want to remove. * @param in The String whose non-valid characters we want to remove.
* @return The in String, stripped of non-valid characters. * @return The in String, stripped of non-valid characters.
*/ */
// eslint-disable-next-line class-methods-use-this protected _rmXmlInv(str: string) {
rmXmlInv(str) {
if (str == null || str === undefined) return null; if (str == null || str === undefined) return null;
let result = ''; let result = '';

View File

@ -1,3 +1,4 @@
import { Mindmap } from '@wisemapping/mindplot';
import Client, { import Client, {
AccountInfo, AccountInfo,
BasicMapInfo, BasicMapInfo,
@ -16,6 +17,9 @@ class CacheDecoratorClient implements Client {
constructor(client: Client) { constructor(client: Client) {
this.client = client; this.client = client;
} }
fetchMindmap(id: number): Mindmap {
return this.client.fetchMindmap(id);
}
deleteAccount(): Promise<void> { deleteAccount(): Promise<void> {
return this.client.deleteAccount(); return this.client.deleteAccount();

View File

@ -1,3 +1,4 @@
import { Mindmap } from '@wisemapping/mindplot';
import { Locale, LocaleCode } from '../app-i18n'; import { Locale, LocaleCode } from '../app-i18n';
export type NewUser = { export type NewUser = {
@ -102,6 +103,9 @@ interface Client {
fetchHistory(id: number): Promise<ChangeHistory[]>; fetchHistory(id: number): Promise<ChangeHistory[]>;
revertHistory(id: number, cid: number): Promise<void>; revertHistory(id: number, cid: number): Promise<void>;
fetchMindmap(id:number): Mindmap;
} }
export default Client; export default Client;

View File

@ -1,3 +1,5 @@
import { Mindmap } from '@wisemapping/mindplot';
import XMLSerializerTango from '@wisemapping/mindplot/src/components/persistence/XMLSerializerTango';
import Client, { import Client, {
AccountInfo, AccountInfo,
BasicMapInfo, BasicMapInfo,
@ -107,6 +109,17 @@ class MockClient implements Client {
this.labels = [label1, label2, label3]; 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> { deleteMapPermission(id: number, email: string): Promise<void> {
let perm = this.permissionsByMap.get(id) || []; let perm = this.permissionsByMap.get(id) || [];
perm = perm.filter((p) => p.email != email); perm = perm.filter((p) => p.email != email);

View File

@ -1,3 +1,4 @@
import { LocalStorageManager, Mindmap } from '@wisemapping/mindplot';
import axios from 'axios'; import axios from 'axios';
import Client, { import Client, {
ErrorInfo, ErrorInfo,
@ -21,6 +22,16 @@ export default class RestClient implements Client {
this.sessionExpired = sessionExpired; 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> { deleteMapPermission(id: number, email: string): Promise<void> {
const handler = (success: () => void, reject: (error: ErrorInfo) => void) => { const handler = (success: () => void, reject: (error: ErrorInfo) => void) => {
axios axios

View File

@ -10,7 +10,11 @@ import FormControlLabel from '@material-ui/core/FormControlLabel';
import Radio from '@material-ui/core/Radio'; import Radio from '@material-ui/core/Radio';
import Select from '@material-ui/core/Select'; import Select from '@material-ui/core/Select';
import MenuItem from '@material-ui/core/MenuItem'; 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 ExportFormat = 'svg' | 'jpg' | 'png' | 'txt' | 'mm' | 'wxml' | 'xls' | 'md';
type ExportGroup = 'image' | 'document' | 'mindmap-tool'; type ExportGroup = 'image' | 'document' | 'mindmap-tool';
@ -30,6 +34,7 @@ const ExportDialog = ({
const intl = useIntl(); const intl = useIntl();
const [submit, setSubmit] = React.useState<boolean>(false); const [submit, setSubmit] = React.useState<boolean>(false);
const { map } = fetchMapById(mapId); const { map } = fetchMapById(mapId);
const client: Client = useSelector(activeInstance);
const [exportGroup, setExportGroup] = React.useState<ExportGroup>( const [exportGroup, setExportGroup] = React.useState<ExportGroup>(
enableImgExport ? 'image' : 'document' enableImgExport ? 'image' : 'document'
@ -83,12 +88,7 @@ const ExportDialog = ({
size = workspace.getSize(); size = workspace.getSize();
mindmap = designer.getMindmap(); mindmap = designer.getMindmap();
} else { } else {
// Load mindmap ... mindmap = client.fetchMindmap(mapId);
const persistence = new LocalStorageManager(
`/c/restful/maps/{id}/document/xml`,
true
);
mindmap = persistence.load(mapId.toString());
} }
let exporter: Exporter; let exporter: Exporter;