diff --git a/geonode_mapstore_client/client/js/apps/gn-document.js b/geonode_mapstore_client/client/js/apps/gn-document.js index f0ffd9eb46..232930e0d1 100644 --- a/geonode_mapstore_client/client/js/apps/gn-document.js +++ b/geonode_mapstore_client/client/js/apps/gn-document.js @@ -5,22 +5,57 @@ * This source code is licensed under the BSD-style license found in the * LICENSE file in the root directory of this source tree. */ -import React from 'react'; -import ReactDOM from 'react-dom'; +import { connect } from 'react-redux'; +import main from '@mapstore/framework/components/app/main'; +import ViewerRoute from '@js/routes/Viewer'; +import MainLoader from '@js/components/MainLoader'; +import Router, { withRoutes } from '@js/components/Router'; +import security from '@mapstore/framework/reducers/security'; +import gnresource from '@js/reducers/gnresource'; +import gnsettings from '@js/reducers/gnsettings'; +import { updateGeoNodeSettings } from '@js/actions/gnsettings'; import { getEndpoints, getConfiguration, - getAccountInfo, - getDocumentByPk + getAccountInfo } from '@js/api/geonode/v2'; import { setupConfiguration, - initializeApp + initializeApp, + getPluginsConfiguration, + storeEpicsCache } from '@js/utils/AppUtils'; -import MediaViewer from '@js/components/MediaViewer'; +import { ResourceTypes } from '@js/utils/ResourceUtils'; +import pluginsDefinition from '@js/plugins/index'; +import ReactSwipe from 'react-swipeable-views'; +import SwipeHeader from '@mapstore/framework/components/data/identify/SwipeHeader'; +import { requestResourceConfig } from '@js/actions/gnresource'; +import gnresourceEpics from '@js/epics/gnresource'; +const requires = { + ReactSwipe, + SwipeHeader +}; +import '@js/observables/persistence'; initializeApp(); +const DEFAULT_LOCALE = {}; +const ConnectedRouter = connect((state) => ({ + locale: state?.locale || DEFAULT_LOCALE +}))(Router); + + +const routes = [{ + name: 'document_embed', + path: [ + '/' + ], + pageConfig: { + resourceType: ResourceTypes.DOCUMENT + }, + component: ViewerRoute +}]; + document.addEventListener('DOMContentLoaded', function() { getEndpoints().then(() => { Promise.all([ @@ -30,18 +65,63 @@ document.addEventListener('DOMContentLoaded', function() { .then(([localConfig, user]) => { setupConfiguration({ localConfig, user }) .then(({ + securityState, + geoNodeConfiguration, + pluginsConfigKey, + configEpics, + onStoreInit, geoNodePageConfig, - targetId = 'ms-container' + targetId = 'ms-container', + settings }) => { - getDocumentByPk(geoNodePageConfig.resourceId) - .then((resource) => { - ReactDOM.render( -
- -
, - document.getElementById(targetId) - ); - }); + + const appEpics = { + ...configEpics, + ...gnresourceEpics + }; + + storeEpicsCache(appEpics); + + main({ + targetId, + appComponent: withRoutes(routes)(ConnectedRouter), + pluginsConfig: getPluginsConfiguration(localConfig.plugins, pluginsConfigKey), + loaderComponent: MainLoader, + lazyPlugins: pluginsDefinition.lazyPlugins, + pluginsDef: { + plugins: { + ...pluginsDefinition.plugins + }, + requires: { + ...requires, + ...pluginsDefinition.requires + } + }, + initialState: { + defaultState: { + ...securityState + } + }, + themeCfg: null, + appReducers: { + gnresource, + gnsettings, + security + }, + appEpics, + onStoreInit, + geoNodeConfiguration, + initialActions: [ + // add some settings in the global state to make them accessible in the monitor state + // later we could use expression in localConfig + updateGeoNodeSettings.bind(null, settings), + ...(geoNodePageConfig.resourceId !== undefined + ? [requestResourceConfig.bind(null, ResourceTypes.DOCUMENT, geoNodePageConfig.resourceId, { + readOnly: geoNodePageConfig.isEmbed + })] + : []) + ] + }); }); }); }); diff --git a/geonode_mapstore_client/client/package.json b/geonode_mapstore_client/client/package.json index 63b0cad0a2..65926532e4 100644 --- a/geonode_mapstore_client/client/package.json +++ b/geonode_mapstore_client/client/package.json @@ -26,7 +26,7 @@ "author": "GeoSolutions", "license": "BSD-2-Clause", "devDependencies": { - "@mapstore/project": "1.0.23", + "@mapstore/project": "1.0.24", "dotenv": "10.0.0", "jsdoc-to-markdown": "7.1.0" }, diff --git a/geonode_mapstore_client/client/static/mapstore/configs/localConfig.json b/geonode_mapstore_client/client/static/mapstore/configs/localConfig.json index 8191c2e3e1..c0179461af 100644 --- a/geonode_mapstore_client/client/static/mapstore/configs/localConfig.json +++ b/geonode_mapstore_client/client/static/mapstore/configs/localConfig.json @@ -817,6 +817,11 @@ } } ], + "document_embed": [ + { + "name": "MediaViewer" + } + ], "dataset_viewer": [ { "name": "ActionNavbar",