Skip to content

Commit

Permalink
#1710 - Update calls with catalog_list preset (#1711)
Browse files Browse the repository at this point in the history
* #1710 - Update calls with catalog_list preset

* Update presets and api calls

* Add param serializer
  • Loading branch information
dsuren1 authored Apr 16, 2024
1 parent ad5eecf commit 92ce03c
Show file tree
Hide file tree
Showing 4 changed files with 183 additions and 20 deletions.
129 changes: 128 additions & 1 deletion geonode_mapstore_client/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ def run_setup_hooks(*args, **kwargs):
"TIMEOUT": 300,
"OPTIONS": {"MAX_ENTRIES": 10000},
}

settings.REST_API_PRESETS["catalog_list"] = {
"exclude[]": ["*"],
"include[]": [
Expand All @@ -104,15 +103,143 @@ def run_setup_hooks(*args, **kwargs):
"is_published",
"owner",
"perms",
"pk",
"raw_abstract",
"resource_type",
"subtype",
"title",
"executions",
"thumbnail_url"
],
}
settings.REST_API_PRESETS["dataset_list"] = {
"exclude[]": ["*"],
"include[]": [
"advertised",
"detail_url",
"owner",
"perms",
"pk",
"raw_abstract",
"resource_type",
"subtype",
"title",
"data",
"executions",
"thumbnail_url",
"alternate",
"links",
"featureinfo_custom_template",
"has_time",
"default_style",
"ptype",
"extent",
"is_approved",
"is_published"
],
}
settings.REST_API_PRESETS["map_list"] = {
"exclude[]": ["*"],
"include[]": [
"advertised",
"detail_url",
"data",
"is_approved",
"is_copyable",
"is_published",
"owner",
"perms",
"pk",
"raw_abstract",
"resource_type",
"subtype",
"title",
"executions",
"thumbnail_url"
],
}
settings.REST_API_PRESETS["document_list"] = {
"exclude[]": ["*"],
"include[]": [
"pk",
"raw_abstract",
"resource_type",
"subtype",
"title",
"data",
"executions",
"thumbnail_url",
"alternate",
"attribution",
"href"
],
}
settings.REST_API_PRESETS["viewer_common"] = {
"exclude[]": ["*"],
"include[]": [
"abstract",
"advertised",
"alternate",
"attribution",
"category",
"created",
"date",
"date_type",
"detail_url",
"download_urls",
"embed_url",
"executions",
"extent",
"favorite",
"group",
"is_approved",
"is_copyable",
"is_published",
"keywords",
"language",
"last_updated",
"linked_resources",
"links",
"owner",
"perms",
"pk",
"poc",
"raw_abstract",
"regions",
"resource_type",
"sourcetype",
"subtype",
"supplemental_information",
"temporal_extent_end",
"temporal_extent_start",
"thumbnail_url",
"title",
"uuid"
],
}
settings.REST_API_PRESETS["map_viewer"] = {
"include[]": [
"data",
"maplayers"
]
}
settings.REST_API_PRESETS["document_viewer"] = {
"include[]": [
"href",
"extension"
]
}
settings.REST_API_PRESETS["dataset_viewer"] = {
"include[]": [
"featureinfo_custom_template",
"dataset_ows_url",
"default_style",
"ptype",
"store",
"has_time",
"attribute_set"
]
}


def connect_geoserver_style_visual_mode_signal():
Expand Down
58 changes: 40 additions & 18 deletions geonode_mapstore_client/client/js/api/geonode/v2/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import {
getApiToken,
paramsSerializer,
getGeoNodeConfig,
getGeoNodeLocalConfig
getGeoNodeLocalConfig,
API_PRESET
} from '@js/utils/APIUtils';
import merge from 'lodash/merge';
import mergeWith from 'lodash/mergeWith';
Expand Down Expand Up @@ -141,7 +142,7 @@ export const getResources = ({
page,
page_size: pageSize,
'filter{metadata_only}': false, // exclude resources such as services
include: ['executions']
api_preset: API_PRESET.CATALOGS
};
return axios.get(parseDevHostname(endpoints[RESOURCES]), {
params: _params,
Expand Down Expand Up @@ -178,7 +179,8 @@ export const getMaps = ({
}),
...(sort && { sort: isArray(sort) ? sort : [ sort ]}),
page,
page_size: pageSize
page_size: pageSize,
api_preset: API_PRESET.MAPS
},
paramsSerializer
})
Expand Down Expand Up @@ -213,7 +215,8 @@ export const getDatasets = ({
}),
...(sort && { sort: isArray(sort) ? sort : [ sort ]}),
page,
page_size: pageSize
page_size: pageSize,
api_preset: API_PRESET.DATASETS
},
paramsSerializer
})
Expand Down Expand Up @@ -249,7 +252,8 @@ export const getDocumentsByDocType = (docType = 'image', {
...(sort && { sort: isArray(sort) ? sort : [ sort ]}),
'filter{subtype}': [docType],
page,
page_size: pageSize
page_size: pageSize,
api_preset: API_PRESET.DOCUMENTS
},
paramsSerializer
})
Expand Down Expand Up @@ -284,7 +288,7 @@ export const setFavoriteResource = (pk, favorite) => {
export const getResourceByPk = (pk) => {
return axios.get(parseDevHostname(`${endpoints[RESOURCES]}/${pk}`), {
params: {
include: ['executions']
api_preset: API_PRESET.VIEWER_COMMON
}
})
.then(({ data }) => data.resource);
Expand All @@ -303,22 +307,29 @@ export const getLinkedResourcesByPk = (pk) => {
export const getResourceByUuid = (uuid) => {
return axios.get(parseDevHostname(`${endpoints[RESOURCES]}`), {
params: {
'filter{uuid}': uuid
'filter{uuid}': uuid,
api_preset: API_PRESET.VIEWER_COMMON
}
})
.then(({ data }) => data?.resources?.[0]);
};

export const getDatasetByPk = (pk) => {
return axios.get(parseDevHostname(`${endpoints[DATASETS]}/${pk}`))
return axios.get(parseDevHostname(`${endpoints[DATASETS]}/${pk}`), {
params: {
api_preset: [API_PRESET.VIEWER_COMMON, API_PRESET.DATASET]
},
paramsSerializer
})
.then(({ data }) => data.dataset);
};

export const getDocumentByPk = (pk) => {
return axios.get(parseDevHostname(`${endpoints[DOCUMENTS]}/${pk}`), {
params: {
include: ['executions']
}
api_preset: [API_PRESET.VIEWER_COMMON, API_PRESET.DOCUMENT]
},
paramsSerializer
})
.then(({ data }) => data.document);
};
Expand All @@ -328,7 +339,8 @@ export const getDocumentsByPk = (pk) => {
return axios.get(parseDevHostname(`${endpoints[DOCUMENTS]}/`), {
params: {
'filter{pk.in}': pks,
page_size: pks.length
page_size: pks.length,
api_preset: [API_PRESET.VIEWER_COMMON, API_PRESET.DOCUMENT]
},
paramsSerializer
})
Expand All @@ -348,6 +360,7 @@ export const getGeoAppByPk = (pk) => {
return axios.get(parseDevHostname(`${endpoints[GEOAPPS]}/${pk}`), {
params: {
full: true,
api_preset: API_PRESET.VIEWER_COMMON,
include: ['data']
}
})
Expand Down Expand Up @@ -513,7 +526,12 @@ export const getResourceTypes = () => {

export const getDatasetByName = name => {
const url = parseDevHostname(`${endpoints[DATASETS]}/?filter{alternate}=${name}`);
return axios.get(url)
return axios.get(url, {
params: {
exclude: ['*'],
include: ['pk', 'perms', 'alternate']
}
})
.then(({data}) => data?.datasets[0]);
};

Expand All @@ -522,7 +540,9 @@ export const getDatasetsByName = names => {
return axios.get(url, {
params: {
page_size: names.length,
'filter{alternate.in}': names
'filter{alternate.in}': names,
exclude: ['*'],
include: ['pk', 'perms', 'alternate']
}
})
.then(({data}) => data?.datasets);
Expand Down Expand Up @@ -586,8 +606,9 @@ export const getMapByPk = (pk) => {
return axios.get(parseDevHostname(`${endpoints[MAPS]}/${pk}/`),
{
params: {
include: ['data']
}
api_preset: [API_PRESET.VIEWER_COMMON, API_PRESET.MAP]
},
paramsSerializer
})
.then(({ data }) => data?.map);
};
Expand All @@ -597,9 +618,9 @@ export const getMapsByPk = (pk) => {
return axios.get(parseDevHostname(`${endpoints[MAPS]}/`),
{
params: {
include: ['data'],
'filter{pk.in}': pks,
page_size: pks.length
page_size: pks.length,
api_preset: API_PRESET.MAPS
},
paramsSerializer
})
Expand All @@ -611,7 +632,8 @@ export const getFeaturedResources = (page = 1, page_size = 4) => {
params: {
page_size,
page,
'filter{featured}': true
'filter{featured}': true,
api_preset: API_PRESET.CATALOGS
}
}).then(({data}) => data);
};
Expand Down
5 changes: 4 additions & 1 deletion geonode_mapstore_client/client/js/epics/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ export const gnSetDatasetsPermissions = (actions$, { getState = () => {}} = {})
actions$.ofType(MAP_CONFIG_LOADED, ADD_LAYER)
.switchMap((action) => {
if (action.type === MAP_CONFIG_LOADED) {
const layerNames = action.config?.map?.layers?.filter((l) => l?.group !== "background").map((l) => l.name);
const layerNames = action.config?.map?.layers?.filter((l) => l?.group !== "background")?.map((l) => l.name) ?? [];
if (layerNames.length === 0) {
return Rx.Observable.empty();
}
return Rx.Observable.defer(() => getDatasetsByName(layerNames))
.switchMap((layers = []) => {
const stateLayers = layers.map((l) => ({
Expand Down
11 changes: 11 additions & 0 deletions geonode_mapstore_client/client/js/utils/APIUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,17 @@ export const paramsSerializer = (params) => {
return queryParams;
};

export const API_PRESET = {
CATALOGS: 'catalog_list',
DATASETS: 'dataset_list',
DOCUMENTS: 'document_list',
MAPS: 'map_list',
VIEWER_COMMON: 'viewer_common',
DATASET: 'dataset_viewer',
DOCUMENT: 'document_viewer',
MAP: 'map_viewer'
};

export default {
parseDevHostname,
paramsSerializer
Expand Down

0 comments on commit 92ce03c

Please sign in to comment.