Skip to content

Commit 9c37ee0

Browse files
committed
PATCH debugger
enable i81n for catalog list multilang layers refact title i18n and add test
1 parent 7d0cbb2 commit 9c37ee0

File tree

5 files changed

+68
-15
lines changed

5 files changed

+68
-15
lines changed

geonode_mapstore_client/apps.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ def run_setup_hooks(*args, **kwargs):
119119
settings.REST_API_PRESETS["catalog_list"] = {
120120
"exclude[]": ["*"],
121121
"include[]": [
122+
"include_i18n",
122123
"advertised",
123124
"detail_url",
124125
"is_approved",

geonode_mapstore_client/client/js/api/geonode/v2/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,7 @@ export const getResourceTypes = () => {
566566
};
567567

568568
export const getDatasetByName = name => {
569-
const url = getEndpointUrl(DATASETS, `/?filter{alternate}=${name}`);
569+
const url = getEndpointUrl(DATASETS, `/?filter{alternate}=${name}&include_i18n=true`);
570570
return axios.get(url, {
571571
params: {
572572
exclude: ['*'],

geonode_mapstore_client/client/js/epics/__tests__/gnsave-test.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,26 @@ describe('gnsave epics', () => {
257257
{layers: {flat: [{name: "testLayer", id: "test_id", perms: ['download_resourcebase']}], selected: ["test_id"]}});
258258
});
259259

260+
it('test gnSetDatasetsPermissions trigger updateNode for ADD_LAYER and set title in multilanguage', (done) => {
261+
mockAxios.onGet().reply(() => [200,
262+
{datasets: [{title: 'testLayer Default', title_en: 'testLayer EN', title_it: 'testLayerIT'}]}]);
263+
const NUM_ACTIONS = 1;
264+
testEpic(gnSetDatasetsPermissions, NUM_ACTIONS, addLayer({name: "testLayer", pk: "1", extendedParams: {pk: "1"}}), (actions) => {
265+
try {
266+
expect(actions.map(({type}) => type)).toEqual(["UPDATE_NODE"]);
267+
expect(actions[0].options.title).toEqual({
268+
default: 'testLayer Default',
269+
'en-US': 'testLayer EN',
270+
'it-IT': 'testLayerIT'
271+
});
272+
done();
273+
} catch (error) {
274+
done(error);
275+
}
276+
},
277+
{layers: {flat: [{name: "testLayer", id: "test_id", perms: ['download_resourcebase']}], selected: ["test_id"]}});
278+
});
279+
260280
it('should trigger saveResource (gnSaveDirectContent)', (done) => {
261281
const NUM_ACTIONS = 3;
262282
const pk = 1;

geonode_mapstore_client/client/js/epics/index.js

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,23 @@ import { UPDATE_RESOURCES } from "@mapstore/framework/plugins/ResourcesCatalog/a
2828
import { startAsyncProcess, STOP_ASYNC_PROCESS } from "@js/actions/resourceservice";
2929
import { error as errorNotification } from "@mapstore/framework/actions/notifications";
3030
import { getProcessErrorInfo } from "@js/utils/ErrorUtils";
31+
import axios from '@mapstore/framework/libs/ajax';
32+
import { getSupportedLocales } from '@mapstore/framework/utils/LocaleUtils';
3133

3234
// We need to include missing epics. The plugins that normally include this epic is not used.
3335

36+
function localeCodeToBCP47(iso2) {
37+
const supportedLocales = getSupportedLocales();
38+
supportedLocales['hy'] = {
39+
code: 'hy-AM',
40+
description: 'Armenian'
41+
};
42+
supportedLocales['ru'] = {
43+
code: 'ru-RU',
44+
description: 'Russian'
45+
};
46+
return supportedLocales[iso2] ? supportedLocales[iso2].code : iso2;
47+
}
3448
/**
3549
* @module epics/index
3650
*/
@@ -97,7 +111,7 @@ export const gnFetchMissingLayerData = (action$, { getState } = {}) =>
97111

98112
/**
99113
* Checks the permissions for layers when a map is loaded and when a new layer is added
100-
* to a map
114+
* to a map and update layer in multi-language support for layer title in TOC
101115
*/
102116
export const gnSetDatasetsPermissions = (actions$, { getState = () => {}} = {}) =>
103117
actions$.ofType(MAP_CONFIG_LOADED, ADD_LAYER)
@@ -122,11 +136,27 @@ export const gnSetDatasetsPermissions = (actions$, { getState = () => {}} = {})
122136
// skip layers of non-geonode origin
123137
if (!action.layer?.extendedParams?.pk) return Rx.Observable.empty();
124138

125-
return Rx.Observable.defer(() => getDatasetByName(action.layer?.name))
126-
.switchMap((layer = {}) => {
127-
const layerId = layersSelector(getState())?.find((la) => la.name === layer.alternate)?.id;
128-
return Rx.Observable.of(updateNode(layerId, 'layer', {perms: layer.perms}));
129-
});
139+
if (action.type === ADD_LAYER) {
140+
141+
return Rx.Observable.defer(() => getDatasetByName(action.layer?.name))
142+
.switchMap((layer = {}) => {
143+
const layerId = layersSelector(getState())?.find((la) => la.name === layer.alternate)?.id;
144+
const layerPk = layer?.pk;
145+
146+
/*
147+
* Multilang support for only layer title in TOC
148+
*/
149+
const title = Object.keys(layer)
150+
.filter(key => key.startsWith('title_'))
151+
.reduce((acc, key) => {
152+
const code = localeCodeToBCP47(key.replace('title_', ''));
153+
acc[code] = layer[key];
154+
return acc;
155+
}, {default: layer.title}) || layer.title;
156+
157+
return Rx.Observable.of(updateNode(layerId, 'layer', {perms: layer.perms, title}));
158+
});
159+
}
130160
});
131161

132162
export const updateMapLayoutEpic = msUpdateMapLayoutEpic;

geonode_mapstore_client/client/js/utils/AppUtils.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -321,14 +321,16 @@ export function setupConfiguration({
321321
settings: localConfig.geoNodeSettings,
322322
MapStoreAPI: window.MapStoreAPI,
323323
onStoreInit: (store) => {
324-
store.addActionListener((action) => {
325-
const act = action.type === 'PERFORM_ACTION' && action.action || action; // Needed to works also in debug
326-
(actionListeners[act.type] || [])
327-
.concat(actionListeners['*'] || [])
328-
.forEach((listener) => {
329-
listener.call(null, act);
330-
});
331-
});
324+
if (store.addActionListener) {
325+
store.addActionListener((action) => {
326+
const act = action.type === 'PERFORM_ACTION' && action.action || action; // Needed to works also in debug
327+
(actionListeners[act.type] || [])
328+
.concat(actionListeners['*'] || [])
329+
.forEach((listener) => {
330+
listener.call(null, act);
331+
});
332+
});
333+
}
332334
},
333335
configEpics: {
334336
gnMapStoreApiEpic: actionTrigger.epic

0 commit comments

Comments
 (0)