Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
20 changes: 15 additions & 5 deletions geonode_mapstore_client/client/js/epics/gnresource.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ import {
ResourceTypes,
toMapStoreMapConfig,
getCataloguePath,
isDefaultDatasetSubtype
isDefaultDatasetSubtype,
resourceHasPermission
} from '@js/utils/ResourceUtils';
import {
canAddResource,
Expand Down Expand Up @@ -146,7 +147,7 @@ const resourceTypes = {
])
.then((response) => {
const [, gnLayer] = response ?? [];
if (gnLayer?.has_time) {
if (gnLayer?.has_time && resourceHasPermission(gnLayer, 'change_resourcebase')) {
// fetch timeseries when applicable
return getDatasetTimeSettingsByPk(pk)
.then((timeseries) => response.concat(timeseries));
Expand Down Expand Up @@ -740,11 +741,20 @@ export const gnSelectResourceEpic = (action$, store) =>
.then((compactPermissions) => compactPermissions)
.catch(() => null)
: Promise.resolve(null)
]))
.switchMap(([resource, compactPermissions]) => {
])
.then((response) => {
const [resource] = response ?? [];
if (resource?.has_time && resourceHasPermission(resource, 'change_resourcebase')) {
return getDatasetTimeSettingsByPk(pk)
.then((timeseries) => response.concat(timeseries));
}
return response;
}))
.switchMap((response) => {
const [resource, compactPermissions, timeseries] = response ?? [];
return Observable.of(
setResourceType(resourceType),
setResource(getResourceWithDetail(resource)),
setResource(getResourceWithDetail({...resource, timeseries})),
...(compactPermissions ? [setResourceCompactPermissions(compactPermissions)] : [])
);
})
Expand Down
16 changes: 11 additions & 5 deletions geonode_mapstore_client/client/js/epics/gnsave.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,19 +163,25 @@ const SaveAPI = {
const timeseries = currentResource?.timeseries;
const updatedBody = {
...body,
data: {
...body?.data,
dimensions: timeseries?.has_time ? getDimensions({...body?.data, has_time: true}) : []
},
...(timeseries && { has_time: timeseries?.has_time })
};
const { request, actions } = setDefaultStyle(state, id); // set default style, if modified

return request().then(() => (id
? axios.all([updateDataset(id, updatedBody), updateDatasetTimeSeries(id, timeseries)])
: Promise.resolve())
.then(([_resource]) => {
// perform dataset and timeseries updates sequentially to avoid race conditions
? updateDataset(id, updatedBody).then((resource) =>
updateDatasetTimeSeries(id, timeseries).then(() => resource)
) : Promise.resolve())
.then((_resource) => {
let resource = omit(_resource, 'default_style');
if (timeseries) {
const dimensions = resource?.has_time ? getDimensions({...resource, has_time: true}) : [];
const layerId = layersSelector(state)?.find((l) => l.pk === resource?.pk)?.id;
// actions to be dispacted are added to response array
return [resource, updateNode(layerId, 'layers', { dimensions: dimensions?.length > 0 ? dimensions : undefined }), ...actions];
return [resource, updateNode(layerId, 'layers', { dimensions: get(resource, 'data.dimensions', []) }), ...actions];
}
return [resource, ...actions];
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,20 @@ import HTML from '@mapstore/framework/components/I18N/HTML';
import { getMessageById } from '@mapstore/framework/utils/LocaleUtils';
import InfoPopover from '@mapstore/framework/components/widgets/widget/InfoPopover';

import { TIME_SERIES_PROPERTIES, TIME_ATTRIBUTE_TYPES, TIME_PRECISION_STEPS } from '@js/utils/ResourceUtils';
import { TIME_SERIES_PROPERTIES, TIME_ATTRIBUTE_TYPES, TIME_PRECISION_STEPS, resourceHasPermission } from '@js/utils/ResourceUtils';
import FlexBox from '@mapstore/framework/components/layout/FlexBox';
import Text from '@mapstore/framework/components/layout/Text';

const TimeSeriesSettings = ({ resource, onChange }, context) => {
const timeAttributes = (resource?.attribute_set ?? [])
.filter((attribute) => TIME_ATTRIBUTE_TYPES.includes(attribute.attribute_type))
.map((attribute)=> ({value: attribute.pk, label: attribute.attribute}));
const canChangeResourcebase = resourceHasPermission(resource, 'change_resourcebase');

const [timeseries, setTimeSeries] = useState(resource.timeseries);
const [error, setError] = useState();

if (isEmpty(timeAttributes)) return null;
if (!canChangeResourcebase || isEmpty(timeAttributes)) return null;

const onChangeTimeSettings = (key, value) => {
const _timeseries = {
Expand Down
10 changes: 8 additions & 2 deletions geonode_mapstore_client/client/js/selectors/resource.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ export const getSelectedLayerDataset = (state) => {
return state?.gnresource?.selectedLayerDataset;
};

export const isResourceDetail = (state) => {
return get(state, 'gnresource.data["@ms-detail"]', false);
};

export const getCompactPermissions = (state) => {
const compactPermissions = state?.gnresource?.compactPermissions || {};
return compactPermissions;
Expand Down Expand Up @@ -305,7 +309,8 @@ function isResourceDataEqual(state, initialData = {}, currentData = {}) {
const selectedLayerInitial = getSelectedLayer(state);
const initialLayerData = {...selectedLayerInitial, ...initialData};

const isSettingsEqual = compareObjects(omit(currentData, ['style', 'fields']), omit(initialLayerData, ['style', 'fields']));
const isSettingsEqual = compareObjects(omit(currentData, ['style', 'fields']),
omit(initialLayerData, ['style', 'fields', 'extendedParams', 'pk', '_v_', 'isDataset', 'perms']));
const isStyleEqual = isEmpty(selectedLayer?.availableStyles) || isEmpty(selectedLayer?.style) ? true
: selectedLayer?.style === selectedLayer?.availableStyles?.[0]?.name;
const isAttributesEqual = isEmpty(selectedLayer) ? true : !isEmpty(initialLayerData) && isEqual(initialLayerData?.fields, selectedLayer.fields);
Expand Down Expand Up @@ -338,7 +343,8 @@ export const getResourceDirtyState = (state) => {
if (resourceType === ResourceTypes.DATASET) {
metadataKeys = metadataKeys.concat('timeseries');
}
const { data: initialData = {}, ...resource } = pick(state?.gnresource?.initialResource || {}, metadataKeys);
let { data: initialData = {}, ...resource } = pick(state?.gnresource?.initialResource || {}, metadataKeys);
if (isResourceDetail(state)) initialData = {}; // detail page allows only metadata editing. Data is not editable.
const { compactPermissions, geoLimits } = getPermissionsPayload(state);
const currentData = JSON.parse(JSON.stringify(getDataPayload(state) || {})); // JSON stringify is needed to remove undefined values
// omitting data on thumbnail
Expand Down