diff --git a/geonode_mapstore_client/client/js/actions/gnviewer.js b/geonode_mapstore_client/client/js/actions/gnviewer.js index d518caef56..0cbff09eef 100644 --- a/geonode_mapstore_client/client/js/actions/gnviewer.js +++ b/geonode_mapstore_client/client/js/actions/gnviewer.js @@ -8,9 +8,11 @@ export const REQUEST_LAYER_CONFIG = 'GEONODE_VIEWER:REQUEST_LAYER_CONFIG'; export const REQUEST_MAP_CONFIG = 'GEONODE_VIEWER:REQUEST_MAP_CONFIG'; +export const REQUEST_NEW_MAP_CONFIG = 'GEONODE_VIEWER:REQUEST_NEW_MAP_CONFIG'; export const REQUEST_GEOSTORY_CONFIG = 'GEONODE_VIEWER:REQUEST_GEOSTORY_CONFIG'; export const REQUEST_DOCUMENT_CONFIG = 'GEONODE_VIEWER:REQUEST_DOCUMENT_CONFIG'; + export function requestLayerConfig(pk) { return { type: REQUEST_LAYER_CONFIG, @@ -25,6 +27,13 @@ export function requestMapConfig(pk) { }; } +export function requestNewMapConfig() { + return { + type: REQUEST_NEW_MAP_CONFIG + }; +} + + export function requestGeoStoryConfig(pk) { return { type: REQUEST_GEOSTORY_CONFIG, diff --git a/geonode_mapstore_client/client/js/epics/__tests__/gnviewer-test.js b/geonode_mapstore_client/client/js/epics/__tests__/gnviewer-test.js new file mode 100644 index 0000000000..d6d4637a7b --- /dev/null +++ b/geonode_mapstore_client/client/js/epics/__tests__/gnviewer-test.js @@ -0,0 +1,41 @@ +import expect from 'expect'; +import { gnViewerRequestNewMapConfig } from '@js/epics/gnviewer'; + +import { requestNewMapConfig } from '@js/actions/gnviewer'; +import MockAdapter from 'axios-mock-adapter'; +import axios from '@mapstore/framework/libs/ajax'; +import { testEpic } from '@mapstore/framework/epics/__tests__/epicTestUtils'; +let mockAxios; + +describe("gnviewer epics", () => { + beforeEach(done => { + mockAxios = new MockAdapter(axios); + setTimeout(done); + }); + afterEach(done => { + delete global.__DEVTOOLS__; + mockAxios.restore(); + setTimeout(done); + }); + + + it("should call mapConfig", (done) => { + mockAxios.onGet().reply(() => [200, {}]); + const NUM_ACTIONS = 1; + testEpic( + gnViewerRequestNewMapConfig, + NUM_ACTIONS, + requestNewMapConfig(), + (actions) => { + try { + expect(actions.map(({ type }) => type)).toEqual(["MAP_CONFIG_LOADED"]); + done(); + } catch (error) { + done(error); + } + }, + { security: { user: { perms: ["add_resource"] } } }); + + }); + +}); diff --git a/geonode_mapstore_client/client/js/epics/gnviewer.js b/geonode_mapstore_client/client/js/epics/gnviewer.js index 4ff26d7eee..d98d982ee7 100644 --- a/geonode_mapstore_client/client/js/epics/gnviewer.js +++ b/geonode_mapstore_client/client/js/epics/gnviewer.js @@ -13,7 +13,8 @@ import { REQUEST_LAYER_CONFIG, REQUEST_MAP_CONFIG, REQUEST_GEOSTORY_CONFIG, - REQUEST_DOCUMENT_CONFIG + REQUEST_DOCUMENT_CONFIG, + REQUEST_NEW_MAP_CONFIG } from '@js/actions/gnviewer'; import { getBaseMapConfiguration } from '@js/api/geonode/config'; import { @@ -122,6 +123,18 @@ export const gnViewerRequestMapConfig = (action$) => }); }); +export const gnViewerRequestNewMapConfig = (action$) => + action$.ofType(REQUEST_NEW_MAP_CONFIG) + .switchMap(() => { + return Observable.defer(getBaseMapConfiguration + ).switchMap((response) => { + return Observable.of(configureMap(response)); + }).catch(() => { + // TODO: implement various error cases + return Observable.empty(); + }); + }); + export const gnViewerRequestGeoStoryConfig = (action$) => action$.ofType(REQUEST_GEOSTORY_CONFIG) .switchMap(({ pk }) => { @@ -165,6 +178,7 @@ export const gnViewerRequestDocumentConfig = (action$) => export default { gnViewerRequestLayerConfig, gnViewerRequestMapConfig, + gnViewerRequestNewMapConfig, gnViewerRequestGeoStoryConfig, gnViewerRequestDocumentConfig }; diff --git a/geonode_mapstore_client/client/js/routes/MapViewer.jsx b/geonode_mapstore_client/client/js/routes/MapViewer.jsx index c81530c463..e653a6d8b1 100644 --- a/geonode_mapstore_client/client/js/routes/MapViewer.jsx +++ b/geonode_mapstore_client/client/js/routes/MapViewer.jsx @@ -16,7 +16,7 @@ import { getMonitoredState } from '@mapstore/framework/utils/PluginsUtils'; import { getConfigProp } from '@mapstore/framework/utils/ConfigUtils'; import PluginsContainer from '@mapstore/framework/components/plugins/PluginsContainer'; import useLazyPlugins from '@js/hooks/useLazyPlugins'; -import { requestMapConfig } from '@js/actions/gnviewer'; +import { requestMapConfig, requestNewMapConfig } from '@js/actions/gnviewer'; const urlQuery = url.parse(window.location.href, true).query; @@ -33,6 +33,7 @@ function MapViewerRoute({ pluginsConfig: propPluginsConfig, params, onUpdate, + onCreate = () => {}, loaderComponent, lazyPlugins, plugins, @@ -47,10 +48,9 @@ function MapViewerRoute({ pluginsEntries: lazyPlugins, pluginsConfig }); - useEffect(() => { - if (!loading) { - onUpdate(pk); + if (!loading && pk !== undefined) { + (pk === "new") ? onCreate() : onUpdate(pk); } }, [loading, pk]); @@ -80,7 +80,9 @@ MapViewerRoute.propTypes = { const ConnectedMapViewerRoute = connect( createSelector([], () => ({})), { - onUpdate: requestMapConfig + onUpdate: requestMapConfig, + onCreate: requestNewMapConfig + } )(MapViewerRoute); diff --git a/geonode_mapstore_client/client/package.json b/geonode_mapstore_client/client/package.json index c93707fd9f..bd3cde35d1 100644 --- a/geonode_mapstore_client/client/package.json +++ b/geonode_mapstore_client/client/package.json @@ -41,5 +41,5 @@ "proxyTargetHost": "localhost:8000", "protocol": "http" } - } + } } diff --git a/geonode_mapstore_client/client/static/mapstore/configs/localConfig.json b/geonode_mapstore_client/client/static/mapstore/configs/localConfig.json index d6520ac6c9..79ccda8612 100644 --- a/geonode_mapstore_client/client/static/mapstore/configs/localConfig.json +++ b/geonode_mapstore_client/client/static/mapstore/configs/localConfig.json @@ -346,7 +346,7 @@ "labelId": "gnhome.map", "value": "map", "type": "link", - "href": "/maps/new", + "href": "/viewer/#/map/new", "authenticated": true, "perms": [{ "type": "user", "value": "add_resource" }] }, @@ -536,7 +536,7 @@ }, { "type": "link", - "href": "/maps/new", + "href": "/viewer/#/map/new", "labelId": "gnhome.createMap", "authenticated": true, "permissions": [], diff --git a/geonode_mapstore_client/client/static/mapstore/configs/map.json b/geonode_mapstore_client/client/static/mapstore/configs/map.json index ea5cfdc92f..4711c03414 100644 --- a/geonode_mapstore_client/client/static/mapstore/configs/map.json +++ b/geonode_mapstore_client/client/static/mapstore/configs/map.json @@ -1,5 +1,19 @@ { "version": 2, + "catalogServices": { + "selectedService": "GeoNode Catalogue", + "services": { + "GeoNode Catalogue": { + "autoload": true, + "layerOptions": { + "tileSize": 512 + }, + "title": "GeoNode Catalogue", + "type": "csw", + "url": "/catalogue/csw" + } + } + }, "map": { "projection": "EPSG:900913", "units": "m",