wisemapping-frontend/packages/mindplot/src/indexLoader.js

81 lines
2.8 KiB
JavaScript
Raw Normal View History

2021-12-25 02:30:36 +01:00
/* eslint-disable import/no-unresolved */
/* eslint-disable no-undef */
2021-12-24 18:40:08 +01:00
/* eslint-disable vars-on-top */
2021-12-25 23:39:34 +01:00
/*
* Copyright [2021] [wisemapping]
*
* Licensed under WiseMapping Public License, Version 1.0 (the "License").
* It is basically the Apache License, Version 2.0 (the "License") plus the
* "powered by wisemapping" text requirement on every single page;
* you may not use this file except in compliance with the License.
* You may obtain a copy of the license at
*
* http://www.wisemapping.org/license
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
2021-12-25 02:30:36 +01:00
import jquery from 'jquery';
2021-12-26 07:59:57 +01:00
import {
$notify,
} from './components/widget/ToolbarNotifier';
import LoadingModal from './components/widget/LoadingModal';
2021-12-26 07:59:57 +01:00
import {
buildDesigner,
buildOptions,
} from './components/DesignerBuilder';
2021-12-23 19:51:26 +01:00
import RESTPersistenceManager from './components/RestPersistenceManager';
import PersistenceManager from './components/PersistenceManager';
2021-12-23 20:55:07 +01:00
import LocalStorageManager from './components/LocalStorageManager';
2021-12-23 19:51:26 +01:00
2021-12-25 02:30:36 +01:00
// This hack is required to initialize Bootstrap. In future, this should be removed.
global.jQuery = jquery;
require('@libraries/bootstrap/js/bootstrap');
const loadingModal = new LoadingModal();
loadingModal.show();
2021-12-23 19:51:26 +01:00
// Configure designer options ...
2021-12-24 20:04:50 +01:00
let persistence;
2021-12-26 07:31:07 +01:00
if (!global.memoryPersistence && !global.readOnly) {
2021-12-26 07:59:57 +01:00
persistence = new RESTPersistenceManager({
documentUrl: '/c/restful/maps/{id}/document',
revertUrl: '/c/restful/maps/{id}/history/latest',
lockUrl: '/c/restful/maps/{id}/lock',
timestamp: global.lockTimestamp,
session: global.lockSession,
});
2021-12-23 19:51:26 +01:00
} else {
persistence = new LocalStorageManager(`/c/restful/maps/{id}/${global.historyId ? `${global.historyId}/` : ''}document/xml${!global.isAuth ? '-pub' : ''}`, true);
2021-12-23 19:51:26 +01:00
}
2021-12-24 01:35:46 +01:00
// Obtain map zoom from query param if it was specified...
const params = new URLSearchParams(window.location.search.substring(1));
const zoomParam = Number.parseFloat(params.get('zoom'), 10);
2021-12-24 20:04:50 +01:00
const options = buildOptions({
persistenceManager: persistence,
2021-12-25 02:30:36 +01:00
readOnly: global.readOnly || false,
2021-12-24 20:04:50 +01:00
mapId: global.mapId,
zoom: zoomParam || global.userOptions.zoom,
2021-12-24 20:04:50 +01:00
});
2021-12-23 19:51:26 +01:00
// Build designer ...
const designer = buildDesigner(options);
designer.addEvent('loadSuccess', () => {
loadingModal.hide();
});
2021-12-23 19:51:26 +01:00
// Load map from XML file persisted on disk...
2021-12-24 20:04:50 +01:00
const instance = PersistenceManager.getInstance();
const mindmap = instance.load(global.mapId);
2021-12-23 19:51:26 +01:00
designer.loadMap(mindmap);
if (global.mindmapLocked) {
2021-12-24 01:35:46 +01:00
$notify(global.mindmapLockedMsg, false);
2021-12-23 19:51:26 +01:00
}