Skip to content

Commit

Permalink
Allow or disable geometry layer edition
Browse files Browse the repository at this point in the history
  • Loading branch information
Gaetanbrl committed Nov 7, 2024
1 parent 6d110a8 commit cb118cd
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 13 deletions.
5 changes: 3 additions & 2 deletions web/client/components/TOC/fragments/LayerFields/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,13 @@ const LayerFields = ({ layer, updateFields = () => {}, ...props }) => {
};
}, []);

const onChange = (name, attribute, value) => {
const onChange = (name, attribute, value, isGeometryType = false) => {
const newFields = fields.map((field) => {
if (field.name === name) {
return {
...field,
[attribute]: value
[attribute]: value,
...(isGeometryType ? {isGeometry: true} : {})
};
}
return field;
Expand Down
17 changes: 9 additions & 8 deletions web/client/components/data/featuregrid/toolbars/Toolbar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,20 +61,20 @@ const standardButtons = {
visible={mode === "EDIT" && !hasChanges && !hasNewFeatures}
onClick={events.switchViewMode}
glyph="arrow-left"/>),
addFeature: ({disabled, mode, hasNewFeatures, hasChanges, hasSupportedGeometry = true, events = {}}) => (<TButton
addFeature: ({disabled, mode, hasNewFeatures, hasChanges, canEditGeometry, hasSupportedGeometry = true, events = {}}) => (<TButton
id="add-feature"
keyProp="add-feature"
tooltipId="featuregrid.toolbar.addNewFeatures"
disabled={disabled}
visible={mode === "EDIT" && !hasNewFeatures && !hasChanges && hasSupportedGeometry}
visible={mode === "EDIT" && canEditGeometry && !hasNewFeatures && !hasChanges && hasSupportedGeometry}
onClick={events.createFeature}
glyph="row-add"/>),
drawFeature: ({isDrawing = false, disabled, isSimpleGeom, mode, selectedCount, hasGeometry, hasSupportedGeometry = true, events = {}}) => (<TButton
drawFeature: ({isDrawing = false, disabled, isSimpleGeom, mode, selectedCount, canEditGeometry, hasGeometry, hasSupportedGeometry = true, events = {}}) => (<TButton
id="draw-feature"
keyProp="draw-feature"
tooltipId={getDrawFeatureTooltip(isDrawing, isSimpleGeom)}
disabled={disabled}
visible={mode === "EDIT" && selectedCount === 1 && (!hasGeometry || hasGeometry && !isSimpleGeom) && hasSupportedGeometry}
visible={mode === "EDIT" && selectedCount === 1 && canEditGeometry && (!hasGeometry || hasGeometry && !isSimpleGeom) && hasSupportedGeometry}
onClick={events.startDrawingFeature}
active={isDrawing}
glyph="pencil-add"/>),
Expand Down Expand Up @@ -103,12 +103,12 @@ const standardButtons = {
visible={mode === "EDIT" && hasChanges || hasNewFeatures}
onClick={events.clearFeatureEditing}
glyph="remove-square"/>),
deleteGeometry: ({disabled, mode, hasGeometry, selectedCount, hasSupportedGeometry = true, events = {}}) => (<TButton
deleteGeometry: ({disabled, mode, hasGeometry, selectedCount, canEditGeometry, hasSupportedGeometry = true, events = {}}) => (<TButton
id="delete-geometry"
keyProp="delete-geometry"
tooltipId="featuregrid.toolbar.deleteGeometry"
disabled={disabled}
visible={mode === "EDIT" && hasGeometry && selectedCount === 1 && hasSupportedGeometry}
visible={mode === "EDIT" && hasGeometry && selectedCount === 1 && hasSupportedGeometry && canEditGeometry}
onClick={events.deleteGeometry}
glyph="polygon-trash"/>),
gridSettings: ({disabled, isColumnsOpen, selectedCount, mode, events = {}}) => (<TButton
Expand Down Expand Up @@ -170,11 +170,11 @@ const standardButtons = {
active={timeSync}
onClick={() => events.setTimeSync && events.setTimeSync(!timeSync)}
glyph="time" />),
snapToFeature: ({snapping, availableSnappingLayers = [], isSnappingLoading, snappingConfig, mode, mapType, editorHeight, pluginCfg, events = {}}) => (<TSplitButton
snapToFeature: ({snapping, availableSnappingLayers = [], canEditGeometry, isSnappingLoading, snappingConfig, mode, mapType, editorHeight, pluginCfg, events = {}}) => (<TSplitButton
id="snap-button"
keyProp="snap-button"
tooltipId={snapping ? "featuregrid.toolbar.disableSnapping" : "featuregrid.toolbar.enableSnapping"}
visible={mode === "EDIT" && (pluginCfg?.snapTool ?? true) && mapType === MapLibraries.OPENLAYERS}
visible={mode === "EDIT" && (pluginCfg?.snapTool ?? true) && mapType === MapLibraries.OPENLAYERS && canEditGeometry}
onClick={() => {
events.toggleSnapping && events.toggleSnapping(!snapping);
}}
Expand Down Expand Up @@ -317,6 +317,7 @@ export default React.memo((props = {}) => {
setShowPopoverSync(getApi().getItem("showPopoverSync") !== null && pluginCfg?.showPopoverSync ? getApi().getItem("showPopoverSync") === "true" : pluginCfg?.showPopoverSync);
}
}, [props.mode]);
// const canEditGeometry = props.isEditingAllowed &&
return (<ButtonGroup id="featuregrid-toolbar" className="featuregrid-toolbar featuregrid-toolbar-margin">

{sortBy(buttons.concat(toolbarItems), ["position"]).map(({Component}) => <Component {...props} showPopoverSync={showPopover} hideSyncPopover={() => setShowPopoverSync(false)} mode={props?.mode ?? "VIEW"} disabled={props.disableToolbar} />)}
Expand Down
4 changes: 3 additions & 1 deletion web/client/plugins/featuregrid/panels/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ import {
timeSyncActive,
isViewportFilterActive,
isFilterByViewportSupported,
selectedLayerSelector
selectedLayerSelector,
canEditGeometrySelector
} from '../../../selectors/featuregrid';
import { mapLayoutValuesSelector } from '../../../selectors/maplayout';
import {isCesium, mapTypeSelector} from '../../../selectors/maptype';
Expand Down Expand Up @@ -95,6 +96,7 @@ const Toolbar = connect(
disableZoomAll: (state) => state && state.featuregrid.virtualScroll || featureCollectionResultSelector(state).features.length === 0,
isSearchAllowed: (state) => !isCesium(state),
isEditingAllowed: isEditingAllowedSelector,
canEditGeometry: canEditGeometrySelector,
hasSupportedGeometry,
isFilterActive,
showTimeSyncButton: showTimeSync,
Expand Down
22 changes: 20 additions & 2 deletions web/client/selectors/featuregrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
* LICENSE file in the root directory of this source tree.
*/

import { head, get, isObject } from 'lodash';
import { head, get, isObject, find } from 'lodash';

import { getLayerFromId } from './layers';
import { findGeometryProperty } from '../utils/ogc/WFS/base';
import { currentLocaleSelector } from './locale';
import { isSimpleGeomType } from '../utils/MapUtils';
import { toChangesMap } from '../utils/FeatureGridUtils';
import { layerDimensionSelectorCreator } from './dimension';
import { isUserAllowedSelectorCreator } from './security';
import { isUserAllowedSelectorCreator, userGroupsEnabledSelector, userRoleSelector } from './security';
import {isCesium, mapTypeSelector} from './maptype';
import { attributesSelector, describeSelector } from './query';
import { createShallowSelectorCreator } from "../utils/ReselectUtils";
Expand Down Expand Up @@ -202,6 +202,24 @@ export const isEditingAllowedSelector = (state) => {
})(state);
return (canEdit || isAllowed) && !isCesium(state);
};
// geometry can be editing according to geom field setting
export const canEditGeometrySelector = (state) => {
const fields = selectedLayerFieldsSelector(state);
const geomField = find(fields, {isGeometry: true});
const canEdit = isEditingAllowedSelector(state);

const userRole = userRoleSelector(state);
const userGroups = userGroupsEnabledSelector(state);
const spreadList = [userRole, ...userGroups];

let geomEditors = geomField?.allowedEditorsRoles;
if (!geomEditors) {
return canEdit;
}
geomEditors = geomEditors.split(",");
return geomEditors.some(value => spreadList.includes(value));
};

export const paginationSelector = state => get(state, "featuregrid.pagination");
export const useLayerFilterSelector = state => get(state, "featuregrid.useLayerFilter", true);

Expand Down

0 comments on commit cb118cd

Please sign in to comment.