Skip to content

Commit 98af27d

Browse files
committed
multilang layers
1 parent 37167f9 commit 98af27d

File tree

2 files changed

+62
-5
lines changed

2 files changed

+62
-5
lines changed

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/index.js

Lines changed: 61 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ import { error as errorNotification } from "@mapstore/framework/actions/notifica
3030
import { getProcessErrorInfo } from "@js/utils/ErrorUtils";
3131
import axios from '@mapstore/framework/libs/ajax';
3232

33+
import { getMetadataSchema } from '@js/api/geonode/v2/metadata';
34+
3335
// We need to include missing epics. The plugins that normally include this epic is not used.
3436

3537
/**
@@ -130,14 +132,69 @@ export const gnSetDatasetsPermissions = (actions$, { getState = () => {}} = {})
130132
// });
131133
if (action.type === ADD_LAYER) {
132134

133-
//TODO considering rest param: include_i18n=true
134-
135135
return Rx.Observable.defer(() => getDatasetByName(action.layer?.name))
136136
.switchMap((layer = {}) => {
137137
const layerId = layersSelector(getState())?.find((la) => la.name === layer.alternate)?.id;
138138
const layerPk = layer?.pk;
139-
//todo
140-
return Rx.Observable.of(updateNode(layerId, 'layer', {perms: layer.perms}));
139+
140+
//TODO get settings MULTILANG_FIELDS from settings.py or get METADATA for specific layer
141+
142+
// http://localhost/api/v2/metadata/instance/16
143+
// getMetadataByPk(layerPk)
144+
// .then(({ schema }) => {
145+
// //non contiene informazioni sulla multilingua della risorsa specifica
146+
// });
147+
148+
//TODO we need to preload metadata schema at boot ???
149+
return Rx.Observable.of(
150+
getMetadataSchema()
151+
.then(({ schema }) => {
152+
layer._schema = schema;
153+
const multilangFields = Object.keys(schema.properties).filter(prop =>
154+
schema.properties[prop]['geonode:multilang'] === true
155+
);
156+
//only for layer title used in the TOC
157+
if (multilangFields.includes('title')) {
158+
159+
//all alng codes for titles fields
160+
const titleLangCodes = Object.entries(schema.properties)
161+
.filter(([key, value]) => value['geonode:multilang-group'] === 'title')
162+
.reduce((acc, [key, value]) => {
163+
//return values of 'geonode:multilang-lang'
164+
const langCode = value['geonode:multilang-lang'];
165+
if (langCode) {
166+
acc.push(langCode);
167+
}
168+
return acc;
169+
}, []);
170+
171+
//build a structure like:
172+
// title: {
173+
// default: "geosolutions:label light",
174+
// "it-IT": "title_IT",
175+
// "en-US": "title_EN"
176+
// }
177+
const titleObjectMultilang = titleLangCodes.reduce((acc, langCode) => {
178+
const propKey = `title_${langCode}`;
179+
acc[langCode] = layer[propKey];
180+
return acc;
181+
}, { default: layer.title });
182+
183+
return updateNode(layerId, 'layer', {
184+
perms: layer.perms,
185+
//MS multilang node structure
186+
// "title": {
187+
// "default": "geosolutions:label light",
188+
// "it-IT": "title_IT",
189+
// "en-US": "title_EN"
190+
// },
191+
title: titleObjectMultilang
192+
});
193+
}
194+
})
195+
);
196+
//old code without multilang support
197+
//return Rx.Observable.of(updateNode(layerId, 'layer', {perms: layer.perms, titles}));
141198
});
142199
}
143200
});

0 commit comments

Comments
 (0)