forked from geosolutions-it/geonode-mapstore-client
-
Notifications
You must be signed in to change notification settings - Fork 113
/
Copy pathgn-dashboard.js
143 lines (131 loc) · 5.51 KB
/
gn-dashboard.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/*
* Copyright 2020, GeoSolutions Sas.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
import { connect } from 'react-redux';
import main from '@mapstore/framework/components/app/main';
import MainLoader from '@js/components/MainLoader';
import ViewerRoute from '@js/routes/Viewer';
import Router, { withRoutes } from '@js/components/Router';
import controls from '@mapstore/framework/reducers/controls';
import security from '@mapstore/framework/reducers/security';
import maptype from '@mapstore/framework/reducers/maptype';
import dashboard from '@mapstore/framework/reducers/dashboard';
import widgets from '@mapstore/framework/reducers/widgets';
import gnresource from '@js/reducers/gnresource';
import gnsettings from '@js/reducers/gnsettings';
import { updateGeoNodeSettings } from '@js/actions/gnsettings';
import {
getEndpoints,
getConfiguration,
getAccountInfo
} from '@js/api/geonode/v2';
import {
setupConfiguration,
initializeApp,
getPluginsConfiguration,
getPluginsConfigOverride,
addQueryPlugins
} from '@js/utils/AppUtils';
import { ResourceTypes } from '@js/utils/ResourceUtils';
import pluginsDefinition, { storeEpicsNamesToExclude, cleanEpics } 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 { DASHBOARD_ROUTES, appRouteComponentTypes } from '@js/utils/AppRoutesUtils';
import '@js/observables/persistence';
const DEFAULT_LOCALE = {};
const ConnectedRouter = connect((state) => ({
locale: state?.locale || DEFAULT_LOCALE,
user: state?.security?.user || null
}))(Router);
const viewer = {
[appRouteComponentTypes.VIEWER]: ViewerRoute
};
const routes = DASHBOARD_ROUTES.map(({component, ...config}) => ({...config, component: viewer[component]}));
initializeApp();
document.addEventListener('DOMContentLoaded', function() {
getEndpoints().then(() => {
Promise.all([
getConfiguration(),
getAccountInfo()
])
.then(([localConfig, user]) => {
setupConfiguration({ localConfig, user })
.then(({
securityState,
geoNodeConfiguration,
pluginsConfigKey,
configEpics,
onStoreInit,
geoNodePageConfig,
targetId = 'ms-container',
settings,
query
}) => {
const appEpics = cleanEpics({
...configEpics,
...gnresourceEpics
});
storeEpicsNamesToExclude(appEpics);
main({
targetId,
appComponent: withRoutes(routes)(ConnectedRouter),
pluginsConfig: addQueryPlugins(
getPluginsConfigOverride(getPluginsConfiguration(localConfig.plugins, pluginsConfigKey)),
query
),
loaderComponent: MainLoader,
pluginsDef: {
plugins: {
...pluginsDefinition.plugins
},
requires: {
...requires,
...pluginsDefinition.requires
}
},
initialState: {
defaultState: {
maptype: {
mapType: 'openlayers'
},
...securityState
}
},
themeCfg: null,
appReducers: {
controls,
dashboard,
gnresource,
gnsettings,
security,
maptype,
widgets
},
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.DASHBOARD, geoNodePageConfig.resourceId, {
readOnly: geoNodePageConfig.isEmbed
}) ]
: [])
]
});
});
});
});
});