mirror of
https://bitbucket.org/wisemapping/wisemapping-frontend.git
synced 2024-11-10 17:33:24 +01:00
Improve build default options
This commit is contained in:
parent
b853748e0c
commit
5e461c5da3
@ -29,11 +29,11 @@ global.$ = $;
|
||||
let designer = null;
|
||||
|
||||
export function buildDesigner(options) {
|
||||
const container = $(`#${options.container}`);
|
||||
$assert(container, 'container could not be null');
|
||||
const divContainer = $(`#${options.container}`);
|
||||
$assert(divContainer, 'container could not be null');
|
||||
|
||||
// Register load events ...
|
||||
designer = new Designer(options, container);
|
||||
designer = new Designer(options, divContainer);
|
||||
designer.addEvent('loadSuccess', () => {
|
||||
window.mindmapLoadReady = true;
|
||||
console.log('Map loadded successfully');
|
||||
@ -72,8 +72,9 @@ export function buildDesigner(options) {
|
||||
return designer;
|
||||
}
|
||||
|
||||
export function buildDefaultOptions(persistence, readOnly = false) {
|
||||
$assert(persistence, 'persistence must be defined');
|
||||
export function buildOptions(options) {
|
||||
$assert(options.persistenceManager, 'persistence must be defined');
|
||||
|
||||
// Set workspace screen size as default. In this way, resize issues are solved.
|
||||
const containerSize = {
|
||||
height: Number.parseInt(window.screen.height, 10),
|
||||
@ -84,27 +85,28 @@ export function buildDefaultOptions(persistence, readOnly = false) {
|
||||
height: Number.parseInt(window.innerHeight - 70, 10), // Footer and Header
|
||||
width: Number.parseInt(window.innerWidth, 10),
|
||||
};
|
||||
return {
|
||||
readOnly,
|
||||
|
||||
const defaultOptions = {
|
||||
readOnly: false,
|
||||
zoom: 0.85,
|
||||
saveOnLoad: true,
|
||||
size: containerSize,
|
||||
viewPort,
|
||||
container: 'mindplot',
|
||||
locale: 'en',
|
||||
persistenceManager: persistence,
|
||||
};
|
||||
|
||||
return { ...defaultOptions, ...options };
|
||||
}
|
||||
|
||||
export async function loadOptions(jsonConf, persistence, readOnly = false) {
|
||||
export async function loadOptions(jsonConf, options) {
|
||||
const result = await $.ajax({
|
||||
url: jsonConf,
|
||||
dataType: 'json',
|
||||
method: 'get',
|
||||
});
|
||||
result.readOnly = readOnly;
|
||||
result.persistenceManager = persistence;
|
||||
return result;
|
||||
|
||||
return { ...result, ...buildOptions(options) };
|
||||
}
|
||||
|
||||
export function loadExample(exampleFn) {
|
||||
|
@ -1,22 +1,13 @@
|
||||
import { $notify } from '@wisemapping/core-js';
|
||||
import { buildDesigner, buildDefaultOptions } from './components/DesignerBuilder';
|
||||
import { buildDesigner, buildOptions } from './components/DesignerBuilder';
|
||||
import RESTPersistenceManager from './components/RestPersistenceManager';
|
||||
import PersistenceManager from './components/PersistenceManager';
|
||||
import LocalStorageManager from './components/LocalStorageManager';
|
||||
|
||||
global.memoryPersistence = false;
|
||||
global.readOnlyMode = false;
|
||||
global.userOptions = {};
|
||||
global.locale = 'us';
|
||||
global.mindmapLocked = false;
|
||||
global.mapLockedMessage = 'map locked';
|
||||
global.lockSession = 111111;
|
||||
global.lockTimestamp = 11111;
|
||||
|
||||
// Configure designer options ...
|
||||
let persistenceManager;
|
||||
let p;
|
||||
if (!global.memoryPersistence && !global.readOnlyMode) {
|
||||
persistenceManager = new RESTPersistenceManager(
|
||||
p = new RESTPersistenceManager(
|
||||
{
|
||||
documentUrl: 'c/restful/maps/{id}/document',
|
||||
revertUrl: 'c/restful/maps/{id}/history/latest',
|
||||
@ -26,11 +17,12 @@ if (!global.memoryPersistence && !global.readOnlyMode) {
|
||||
},
|
||||
);
|
||||
} else {
|
||||
// persistenceManager = new LocalStorageManager('c/restful/maps/{id}${hid != null ? '/' : ''}${hid != null ? hid : ''}/document/xml${principal != null ? '' : '-pub'}", true);
|
||||
// @todo: review ...
|
||||
persistenceManager = new LocalStorageManager('c/restful/maps/{id}', true);
|
||||
// persistenceManager = new LocalStorageManager('c/restful/maps/{id}${hid != null ? '/' : ''}${hid != null ? hid : ''}/document/xml${principal != null ? '' : '-pub'}", true);
|
||||
p = new LocalStorageManager('c/restful/maps/{id}', true);
|
||||
}
|
||||
const options = buildDefaultOptions(persistenceManager, false);
|
||||
|
||||
const options = buildOptions({ persistenceManager: p, isReadOnly: global.isReadOnly || false });
|
||||
options.zoom = global.userOptions.zoom;
|
||||
|
||||
// Set map id ...
|
||||
@ -45,5 +37,5 @@ const mindmap = persistence.load(global.mapId);
|
||||
designer.loadMap(mindmap);
|
||||
|
||||
if (global.mindmapLocked) {
|
||||
$notify(global.mappL, false);
|
||||
$notify(global.mindmapLockedMsg, false);
|
||||
}
|
||||
|
@ -1,10 +1,10 @@
|
||||
import '../css/editor.less';
|
||||
import { buildDesigner, buildDefaultOptions, loadExample } from '../../../../src/components/DesignerBuilder';
|
||||
import { buildDesigner, buildOptions, loadExample } from '../../../../src/components/DesignerBuilder';
|
||||
import { PersistenceManager, LocalStorageManager } from '../../../../src';
|
||||
|
||||
const example = async () => {
|
||||
const p = new LocalStorageManager('samples/{id}.xml');
|
||||
const options = buildDefaultOptions(p);
|
||||
const options = buildOptions({ persistenceManager: p });
|
||||
const designer = buildDesigner(options);
|
||||
|
||||
designer.addEvent('loadSuccess', () => {
|
||||
|
@ -1,11 +1,11 @@
|
||||
import '../css/embedded.less';
|
||||
import { buildDesigner, buildDefaultOptions, loadExample } from '../../../../src/components/DesignerBuilder';
|
||||
import { buildDesigner, buildOptions, loadExample } from '../../../../src/components/DesignerBuilder';
|
||||
import { PersistenceManager, LocalStorageManager } from '../../../../src';
|
||||
|
||||
const example = async () => {
|
||||
// Options has been defined in by a external ile ?
|
||||
const p = new LocalStorageManager('samples/{id}.xml');
|
||||
const options = buildDefaultOptions(p);
|
||||
const options = buildOptions({ persistenceManager: p });
|
||||
const designer = buildDesigner(options);
|
||||
|
||||
designer.addEvent('loadSuccess', () => {
|
||||
|
@ -1,16 +1,17 @@
|
||||
import '../css/embedded.less';
|
||||
import { buildDesigner, buildDefaultOptions, loadExample } from '../../../../src/components/DesignerBuilder';
|
||||
import { buildDesigner, buildOptions, loadExample } from '../../../../src/components/DesignerBuilder';
|
||||
import { PersistenceManager, LocalStorageManager } from '../../../../src';
|
||||
|
||||
const example = async () => {
|
||||
const p = new LocalStorageManager('samples/{id}.xml');
|
||||
const options = buildDefaultOptions(p, true);
|
||||
const options = buildOptions({ persistenceManager: p, readOnly: false });
|
||||
|
||||
const mapId = 'welcome';
|
||||
const designer = buildDesigner(options);
|
||||
designer.addEvent('loadSuccess', () => {
|
||||
document.getElementById('mindplot').classList.add('ready');
|
||||
});
|
||||
|
||||
// Load map from XML file persisted on disk...
|
||||
const persistence = PersistenceManager.getInstance();
|
||||
const mindmap = persistence.load(mapId);
|
||||
|
@ -13,6 +13,10 @@ module.exports = {
|
||||
optimization: {
|
||||
usedExports: true,
|
||||
},
|
||||
entry: {
|
||||
mindplot: './src/index.js',
|
||||
loader: './src/indexLoader.js',
|
||||
},
|
||||
mode: 'production',
|
||||
devtool: 'source-map',
|
||||
module: {
|
||||
|
@ -4476,6 +4476,14 @@ compression-webpack-plugin@^7.1.2:
|
||||
schema-utils "^3.0.0"
|
||||
serialize-javascript "^5.0.1"
|
||||
|
||||
compression-webpack-plugin@^9.2.0:
|
||||
version "9.2.0"
|
||||
resolved "https://registry.yarnpkg.com/compression-webpack-plugin/-/compression-webpack-plugin-9.2.0.tgz#57fd539d17c5907eebdeb4e83dcfe2d7eceb9ef6"
|
||||
integrity sha512-R/Oi+2+UHotGfu72fJiRoVpuRifZT0tTC6UqFD/DUo+mv8dbOow9rVOuTvDv5nPPm3GZhHL/fKkwxwIHnJ8Nyw==
|
||||
dependencies:
|
||||
schema-utils "^4.0.0"
|
||||
serialize-javascript "^6.0.0"
|
||||
|
||||
compression@^1.7.4:
|
||||
version "1.7.4"
|
||||
resolved "https://registry.yarnpkg.com/compression/-/compression-1.7.4.tgz#95523eff170ca57c29a0ca41e6fe131f41e5bb8f"
|
||||
|
Loading…
Reference in New Issue
Block a user