Skip to content

Commit

Permalink
Improvement of catalogue routing (#388)
Browse files Browse the repository at this point in the history
  • Loading branch information
allyoucanmap authored Jul 29, 2021
1 parent 8b9497d commit a4324bf
Show file tree
Hide file tree
Showing 59 changed files with 691 additions and 1,399 deletions.
2 changes: 1 addition & 1 deletion geonode_mapstore_client/client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Menu item object contains properties for a list item rendered in a menu. Configu
"labelId": "gnhome.register", // label message id
"type": "link", // one of 'link', 'dropdown', 'divider' or 'filter'
"href": "/account/signup/?next=/",
"badge": "{state.layersTotalCount}", // (menu configuration only) counter badge. variable available: layersTotalCount, mapsTotalCount,
"badge": "{state.datasetsTotalCount}", // (menu configuration only) counter badge. variable available: datasetsTotalCount, mapsTotalCount,
"authenticated": true, // true shows the item only when user authenticated while false only for anonymous user, if undefined the item is always visible
"perms": [], // the value in array define the access to the contents
"allowedRoles": [] // user roles to access to the contents
Expand Down
42 changes: 40 additions & 2 deletions geonode_mapstore_client/client/js/actions/gnresource.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@ export const EDIT_TITLE_RESOURCE = 'GEONODE:EDIT_TITLE_RESOURCE';
export const EDIT_ABSTRACT_RESOURCE = 'GEONODE:EDIT_ABSTRACT_RESOURCE';
export const EDIT_THUMBNAIL_RESOURCE = 'GEONODE:EDIT_THUMBNAIL_RESOURCE';
export const SET_FAVORITE_RESOURCE = 'GEONODE:SET_FAVORITE_RESOURCE';

export const SET_SELECTED_DATASET_PERMISSIONS = "GEONODE:SET_SELECTED_DATASET_PERMISSIONS";

export const REQUEST_RESOURCE_CONFIG = 'GEONODE:REQUEST_RESOURCE_CONFIG';
export const REQUEST_NEW_RESOURCE_CONFIG = 'GEONODE:REQUEST_NEW_RESOURCE_CONFIG';
export const LOADING_RESOURCE_CONFIG = 'GEONODE:LOADING_RESOURCE_CONFIG';
export const RESET_RESOURCE_STATE = 'GEONODE:RESET_RESOURCE_STATE';
export const RESOURCE_CONFIG_ERROR = 'GEONODE:RESOURCE_CONFIG_ERROR';

/**
* Actions for GeoNode resource
Expand Down Expand Up @@ -189,3 +192,38 @@ export function setFavoriteResource(favorite) {
favorite
};
}

export function requestResourceConfig(resourceType, pk, options) {
return {
type: REQUEST_RESOURCE_CONFIG,
resourceType,
pk,
options
};
}
export function requestNewResourceConfig(resourceType) {
return {
type: REQUEST_NEW_RESOURCE_CONFIG,
resourceType
};
}

export function loadingResourceConfig(loading) {
return {
type: LOADING_RESOURCE_CONFIG,
loading
};
}

export function resourceConfigError(message) {
return {
type: RESOURCE_CONFIG_ERROR,
message
};
}

export function resetResourceState() {
return {
type: RESET_RESOURCE_STATE
};
}
75 changes: 0 additions & 75 deletions geonode_mapstore_client/client/js/actions/gnviewer.js

This file was deleted.

13 changes: 7 additions & 6 deletions geonode_mapstore_client/client/js/api/geonode/v2/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ import isObject from 'lodash/isObject';
import castArray from 'lodash/castArray';
import get from 'lodash/get';
import { getUserInfo } from '@js/api/geonode/user';
import { setFilterById } from '@js/utils/GNSearchUtils';
import { setFilterById } from '@js/utils/SearchUtils';
import { ResourceTypes } from '@js/utils/ResourceUtils';

let endpoints = {
// default values
Expand Down Expand Up @@ -407,11 +408,11 @@ export const getResourcesTotalCount = () => {
.then(({ data }) => data.resource_types)
.then((resourceTypes) => {
const keysMap = {
'document': 'documentsTotalCount',
'layer': 'layersTotalCount',
'map': 'mapsTotalCount',
'geostory': 'geostoriesTotalCount',
'dashboard': 'dashboardsTotalCount'
[ResourceTypes.DOCUMENT]: 'documentsTotalCount',
[ResourceTypes.DATASET]: 'datasetsTotalCount',
[ResourceTypes.MAP]: 'mapsTotalCount',
[ResourceTypes.GEOSTORY]: 'geostoriesTotalCount',
[ResourceTypes.DASHBOARD]: 'dashboardsTotalCount'
};
const totalCount = resourceTypes.reduce((acc, { name, count }) => ({
...acc,
Expand Down
56 changes: 37 additions & 19 deletions geonode_mapstore_client/client/js/apps/gn-catalogue.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,7 @@ import annotations from '@mapstore/framework/reducers/annotations';

import SearchRoute from '@js/routes/Search';
import DetailRoute from '@js/routes/Detail';
import DatasetViewerRoute from '@js/routes/DatasetViewer';
import MapViewerRoute from '@js/routes/MapViewer';
import GeoStoryViewerRoute from '@js/routes/GeoStoryViewer';
import DocumentViewerRoute from '@js/routes/DocumentViewer';
import DashboardViewerRoute from '@js/routes/DashboardViewer';
import ViewerRoute from '@js/routes/Viewer';

import gnsearch from '@js/reducers/gnsearch';
import gnresource from '@js/reducers/gnresource';
Expand All @@ -60,14 +56,13 @@ import {
initializeApp,
getPluginsConfiguration
} from '@js/utils/AppUtils';

import { ResourceTypes } from '@js/utils/ResourceUtils';
import { updateGeoNodeSettings } from '@js/actions/gnsettings';

import {
gnCheckSelectedDatasetPermissions,
gnSetDatasetsPermissions
} from '@js/epics';
import gnviewerEpics from '@js/epics/gnviewer';
import gnresourceEpics from '@js/epics/gnresource';
import gnsearchEpics from '@js/epics/gnsearch';
import favoriteEpics from '@js/epics/favorite';
import maplayout from '@mapstore/framework/reducers/maplayout';
Expand All @@ -88,59 +83,82 @@ const requires = {
};

const DEFAULT_LOCALE = {};
const ConnectedRouter = connect((state) => ({
locale: state?.locale || DEFAULT_LOCALE
}))(Router);
const ConnectedRouter = connect(
(state) => ({
locale: state?.locale || DEFAULT_LOCALE
})
)(Router);

const routes = [
{
name: 'dataset_viewer',
path: [
'/dataset/:pk'
],
component: DatasetViewerRoute
pageConfig: {
resourceType: ResourceTypes.DATASET
},
component: ViewerRoute
},
{
name: 'dataset_edit_data_viewer',
path: [
'/dataset/:pk/edit/data'
],
component: DatasetViewerRoute
pageConfig: {
resourceType: ResourceTypes.DATASET
},
component: ViewerRoute
},
{
name: 'dataset_edit_style_viewer',
path: [
'/dataset/:pk/edit/style'
],
component: DatasetViewerRoute
pageConfig: {
resourceType: ResourceTypes.DATASET
},
component: ViewerRoute
},
{
name: 'map_viewer',
path: [
'/map/:pk'
],
component: MapViewerRoute
pageConfig: {
resourceType: ResourceTypes.MAP
},
component: ViewerRoute
},
{
name: 'geostory_viewer',
path: [
'/geostory/:pk'
],
component: GeoStoryViewerRoute
pageConfig: {
resourceType: ResourceTypes.GEOSTORY
},
component: ViewerRoute
},
{
name: 'document_viewer',
path: [
'/document/:pk'
],
component: DocumentViewerRoute
pageConfig: {
resourceType: ResourceTypes.DOCUMENT
},
component: ViewerRoute
},
{
name: 'dashboard_viewer',
path: [
'/dashboard/:pk'
],
component: DashboardViewerRoute
pageConfig: {
resourceType: ResourceTypes.DASHBOARD
},
component: ViewerRoute
},
{
name: 'resources',
Expand Down Expand Up @@ -253,7 +271,7 @@ Promise.all([
gnCheckSelectedDatasetPermissions,
gnSetDatasetsPermissions,
...pluginsDefinition.epics,
...gnviewerEpics,
...gnresourceEpics,
...gnsearchEpics,
...favoriteEpics
},
Expand Down
18 changes: 11 additions & 7 deletions geonode_mapstore_client/client/js/apps/gn-dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import { connect } from 'react-redux';
import main from '@mapstore/framework/components/app/main';
import MainLoader from '@js/components/MainLoader';
import DashboardViewerRoute from '@js/routes/DashboardViewer';
import ViewerRoute from '@js/routes/Viewer';
import Router, { withRoutes } from '@js/components/Router';
import security from '@mapstore/framework/reducers/security';
import maptype from '@mapstore/framework/reducers/maptype';
Expand All @@ -28,15 +28,17 @@ import {
initializeApp,
getPluginsConfiguration
} from '@js/utils/AppUtils';
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 { requestDashboardConfig } from '@js/actions/gnviewer';
import gnviewerEpics from '@js/epics/gnviewer';
import { requestResourceConfig } from '@js/actions/gnresource';
import gnresourceEpics from '@js/epics/gnresource';
const requires = {
ReactSwipe,
SwipeHeader
};
import '@js/observables/persistence';

const DEFAULT_LOCALE = {};
const ConnectedRouter = connect((state) => ({
Expand All @@ -48,10 +50,12 @@ const routes = [{
path: [
'/'
],
component: DashboardViewerRoute
pageConfig: {
resourceType: ResourceTypes.DASHBOARD
},
component: ViewerRoute
}];

import '@js/observables/persistence';

initializeApp();

Expand Down Expand Up @@ -108,7 +112,7 @@ document.addEventListener('DOMContentLoaded', function() {
},
appEpics: {
...configEpics,
...gnviewerEpics
...gnresourceEpics
},
onStoreInit,
geoNodeConfiguration,
Expand All @@ -117,7 +121,7 @@ document.addEventListener('DOMContentLoaded', function() {
// later we could use expression in localConfig
updateGeoNodeSettings.bind(null, settings),
...(geoNodePageConfig.resourceId !== undefined
? [ requestDashboardConfig.bind(null, geoNodePageConfig.resourceId, {
? [ requestResourceConfig.bind(null, ResourceTypes.DASHBOARD, geoNodePageConfig.resourceId, {
readOnly: geoNodePageConfig.isEmbed
}) ]
: [])
Expand Down
Loading

0 comments on commit a4324bf

Please sign in to comment.