Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions geonode_mapstore_client/client/js/api/geonode/v2/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,8 @@ export const setFavoriteResource = (pk, favorite) => {
export const getResourceByPk = (pk) => {
return axios.get(getEndpointUrl(RESOURCES, `/${pk}`), {
params: {
api_preset: API_PRESET.VIEWER_COMMON
api_preset: API_PRESET.VIEWER_COMMON,
include_i18n: true
}
})
.then(({ data }) => data.resource);
Expand Down Expand Up @@ -305,7 +306,8 @@ export const getResourceByUuid = (uuid) => {
export const getDatasetByPk = (pk) => {
return axios.get(getEndpointUrl(DATASETS, `/${pk}`), {
params: {
api_preset: [API_PRESET.VIEWER_COMMON, API_PRESET.DATASET]
api_preset: [API_PRESET.VIEWER_COMMON, API_PRESET.DATASET],
include_i18n: true
},
...paramsSerializer()
})
Expand Down Expand Up @@ -570,7 +572,8 @@ export const getDatasetByName = name => {
return axios.get(url, {
params: {
exclude: ['*'],
include: ['pk', 'perms', 'alternate']
include: ['pk', 'perms', 'alternate'],
include_i18n: true
}
})
.then(({data}) => data?.datasets[0]);
Expand Down
20 changes: 20 additions & 0 deletions geonode_mapstore_client/client/js/epics/__tests__/gnsave-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,26 @@ describe('gnsave epics', () => {
{layers: {flat: [{name: "testLayer", id: "test_id", perms: ['download_resourcebase']}], selected: ["test_id"]}});
});

it('test gnSetDatasetsPermissions trigger updateNode for ADD_LAYER and set title in multilanguage', (done) => {
mockAxios.onGet().reply(() => [200,
{datasets: [{title: 'testLayer Default', title_en: 'testLayer EN', title_it: 'testLayerIT'}]}]);
const NUM_ACTIONS = 1;
testEpic(gnSetDatasetsPermissions, NUM_ACTIONS, addLayer({name: "testLayer", pk: "1", extendedParams: {pk: "1"}}), (actions) => {
try {
expect(actions.map(({type}) => type)).toEqual(["UPDATE_NODE"]);
expect(actions[0].options.title).toEqual({
"default": 'testLayer Default',
'en-US': 'testLayer EN',
'it-IT': 'testLayerIT'
});
done();
} catch (error) {
done(error);
}
},
{layers: {flat: [{name: "testLayer", id: "test_id", perms: ['download_resourcebase']}], selected: ["test_id"]}});
});

it('should trigger saveResource (gnSaveDirectContent)', (done) => {
const NUM_ACTIONS = 3;
const pk = 1;
Expand Down
18 changes: 10 additions & 8 deletions geonode_mapstore_client/client/js/utils/AppUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,14 +321,16 @@ export function setupConfiguration({
settings: localConfig.geoNodeSettings,
MapStoreAPI: window.MapStoreAPI,
onStoreInit: (store) => {
store.addActionListener((action) => {
const act = action.type === 'PERFORM_ACTION' && action.action || action; // Needed to works also in debug
(actionListeners[act.type] || [])
.concat(actionListeners['*'] || [])
.forEach((listener) => {
listener.call(null, act);
});
});
if (store.addActionListener) {
store.addActionListener((action) => {
const act = action.type === 'PERFORM_ACTION' && action.action || action; // Needed to works also in debug
(actionListeners[act.type] || [])
.concat(actionListeners['*'] || [])
.forEach((listener) => {
listener.call(null, act);
});
});
}
},
configEpics: {
gnMapStoreApiEpic: actionTrigger.epic
Expand Down
34 changes: 33 additions & 1 deletion geonode_mapstore_client/client/js/utils/ResourceUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { getGeoNodeLocalConfig, parseDevHostname } from '@js/utils/APIUtils';
import { ProcessTypes, ProcessStatus } from '@js/utils/ResourceServiceUtils';
import { determineResourceType } from '@js/utils/FileUtils';
import { createDefaultStyle } from '@mapstore/framework/utils/StyleUtils';
import { getSupportedLocales } from '@mapstore/framework/utils/LocaleUtils';
/**
* @module utils/ResourceUtils
*/
Expand Down Expand Up @@ -153,6 +154,35 @@ export const getDimensions = ({links, has_time: hasTime} = {}) => {
return dimensions;
};

const getLocalizedValue = (resource, key, locale = '') => {
if (resource[`${key}_${locale}`]) {
return resource[`${key}_${locale}`];
}
const languageCode = locale.split('-')[0];
if (resource[`${key}_${languageCode}`]) {
return resource[`${key}_${languageCode}`];
}
return null;
};

export const getLocalizedValues = (resource, key, defaultValue) => {
const supportedLocales = getSupportedLocales() || {};
const translations = Object.values(supportedLocales)
.map(({ code }) => {
const value = getLocalizedValue(resource, key, code);
return value ? [code, value] : null;
})
.filter(value => value !== null);

if (translations.length) {
return {
...Object.fromEntries(translations),
'default': defaultValue
};
}
return defaultValue;
};

/**
* convert resource layer configuration to a mapstore layer object
* @param {object} resource geonode layer resource
Expand All @@ -165,7 +195,7 @@ export const resourceToLayerConfig = (resource) => {
attribute_set: attributeSet = [],
links = [],
featureinfo_custom_template: template,
title,
title: defaultTitle,
perms,
pk,
default_style: defaultStyle,
Expand All @@ -175,6 +205,8 @@ export const resourceToLayerConfig = (resource) => {
data: layerSettings
} = resource;

const title = getLocalizedValues(resource, 'title', defaultTitle);

const bbox = getExtentFromResource(resource);
const defaultStyleParams = defaultStyle && {
defaultStyle: {
Expand Down
Loading