Skip to content

Commit

Permalink
[Backport 4.x][Fixes #1053] Include base support for localization in …
Browse files Browse the repository at this point in the history
…gn-document app entry (#1061)
  • Loading branch information
DavidQuartz authored Jul 7, 2022
1 parent 776c84f commit 7abcafb
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 17 deletions.
112 changes: 96 additions & 16 deletions geonode_mapstore_client/client/js/apps/gn-document.js
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand 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(
<div className="gn-media-viewer">
<MediaViewer resource={resource}/>
</div>,
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
})]
: [])
]
});
});
});
});
Expand Down
2 changes: 1 addition & 1 deletion geonode_mapstore_client/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -817,6 +817,11 @@
}
}
],
"document_embed": [
{
"name": "MediaViewer"
}
],
"dataset_viewer": [
{
"name": "ActionNavbar",
Expand Down

0 comments on commit 7abcafb

Please sign in to comment.