Skip to content

Commit

Permalink
Added area editor (geosolutions-it#2891)
Browse files Browse the repository at this point in the history
  • Loading branch information
kappu72 authored and offtherailz committed May 14, 2018
1 parent 4ca7bad commit bf5ad67
Show file tree
Hide file tree
Showing 36 changed files with 1,184 additions and 110 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@
"url": "0.10.3",
"uuid": "3.0.1",
"w3c-schemas": "1.3.1",
"wellknown": "0.5.0",
"wkt-parser": "https://github.com/geosolutions-it/wkt-parser/tarball/mapstore2_fixes",
"xml2js": "0.4.17"
},
Expand Down
11 changes: 9 additions & 2 deletions web/client/actions/rulesmanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,14 @@ const EDIT_RULE = "RULES_MANAGER:EDIT_RULE";
const CLEAN_EDITING = "RULES_MANAGER:CLEAN_EDITING";
const SAVE_RULE = "RULES_MANAGER:SAVE_RULE";
const RULE_SAVED = "RULES_MANAGER:RULE_SAVED";
const DELETE_RULES = "RULES_MANAGER: DELETE_RULES";
const DELETE_RULES = "RULES_MANAGER:DELETE_RULES";
const CACHE_CLEAN = "RULES_MANAGER:CACHE_CLEAN";

function onCacheClean() {
return {
type: CACHE_CLEAN
};
}
function delRules(ids) {
return {
type: DELETE_RULES,
Expand Down Expand Up @@ -277,5 +283,6 @@ module.exports = {
EDIT_RULE, onEditRule,
CLEAN_EDITING, cleanEditing,
SAVE_RULE, saveRule, RULE_SAVED,
DELETE_RULES, delRules
DELETE_RULES, delRules,
CACHE_CLEAN, onCacheClean
};
4 changes: 2 additions & 2 deletions web/client/api/WMS.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,10 @@ const Api = {
},
getBBox: function(record, bounds) {
let layer = record;
let bbox = (layer.EX_GeographicBoundingBox || CoordinatesUtils.getWMSBoundingBox(layer.BoundingBox) || (layer.LatLonBoundingBox && layer.LatLonBoundingBox.$) || layer.latLonBoundingBox);
let bbox = (layer.EX_GeographicBoundingBox || layer.exGeographicBoundingBox || CoordinatesUtils.getWMSBoundingBox(layer.BoundingBox) || (layer.LatLonBoundingBox && layer.LatLonBoundingBox.$) || layer.latLonBoundingBox);
while (!bbox && layer.Layer && layer.Layer.length) {
layer = layer.Layer[0];
bbox = (layer.EX_GeographicBoundingBox || CoordinatesUtils.getWMSBoundingBox(layer.BoundingBox) || (layer.LatLonBoundingBox && layer.LatLonBoundingBox.$) || layer.latLonBoundingBox);
bbox = (layer.EX_GeographicBoundingBox || layer.exGeographicBoundingBox || CoordinatesUtils.getWMSBoundingBox(layer.BoundingBox) || (layer.LatLonBoundingBox && layer.LatLonBoundingBox.$) || layer.latLonBoundingBox);
}
if (!bbox) {
bbox = {
Expand Down
20 changes: 14 additions & 6 deletions web/client/api/geoserver/GeoFence.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ const assign = require('object-assign');

const ConfigUtils = require('../../utils/ConfigUtils');
const EMPTY_RULE = {
constraints: {
allowedStyles: {style: []}
},
constraints: {},
ipaddress: "",
layer: "",
request: "",
Expand All @@ -25,14 +23,24 @@ const EMPTY_RULE = {
const cleanConstraints = (rule) => {
if (!rule.constraints ) {
return rule;
}else if (rule.grant === "DENY") {
const {constraints: omit, ...r} = rule;
return r;
}
let constraints = {...rule.constraints};
constraints.allowedStyles = constraints.allowedStyles && constraints.allowedStyles.style || [];
constraints.attributes = constraints.attributes && constraints.attributes.attribute || [];
constraints.restrictedAreaWkt = constraints.restrictedAreaWkt || "";
return {...rule, constraints};
};
var Api = {

cleanCache: () => {
return axios.get('rest/geofence/ruleCache/invalidate', Api.addBaseUrlGS())
.then(function(response) {
return response.data;
}
);
},
loadRules: function(page, rulesFiltersValues, entries = 10) {
const params = {
page,
Expand Down Expand Up @@ -92,9 +100,9 @@ var Api = {

updateRule: function(rule) {
// id, priority and grant aren't updatable
const {id, priority, grant, position, ...others} = rule;
const {id, priority, grant, position, ...others} = cleanConstraints(rule);
const newRule = {...EMPTY_RULE, ...others};
return axios.put(`geofence/rest/rules/id/${id}`, cleanConstraints(newRule), this.addBaseUrl({
return axios.put(`geofence/rest/rules/id/${id}`, newRule, this.addBaseUrl({
'headers': {
'Content': 'application/json'
}
Expand Down
41 changes: 41 additions & 0 deletions web/client/components/manager/rulesmanager/MapModal.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* Copyright 2018, GeoSolutions Sas.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
const React = require('react');

const enhancer = require("./enhancers/Map");
const autoMapType = require('../../map/enhancers/autoMapType');
const mapType = require('../../map/enhancers/mapType');
const autoResize = require('../../map/enhancers/autoResize');
const onMapViewChanges = require('../../map/enhancers/onMapViewChanges');
const withDraw = require("../../map/enhancers/withDraw");
const {compose} = require('recompose');

const MapWitDraw = compose(
enhancer,
onMapViewChanges,
autoResize(0),
autoMapType,
mapType,
withDraw()
)(require('../../map/BaseMap'));

const Portal = require('react-overlays').Portal;

module.exports = ({layer, onMapReady = () => {}}) => {
return (
<Portal container={document.querySelector('.rules-data-gird')}>
<div className="rules-manager-map-modal" style={{position: "absolute", zIndex: 11, top: 0, bottom: 0, width: "100%"}}>
<MapWitDraw
onMapReady={onMapReady}
options={{ style: { margin: 10, height: 'calc(100% - 20px)' }}}
layer={layer}
tools={["draw"]}/>
</div>
</Portal>);
};

63 changes: 63 additions & 0 deletions web/client/components/manager/rulesmanager/RoiCql.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/**
* Copyright 2018, GeoSolutions Sas.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/

const React = require('react');
const PropTypes = require('prop-types');
const Button = require("../../misc/toolbar/ToolbarButton");
const ContainerDimensions = require('react-container-dimensions').default;
const {Controlled: Codemirror} = require('react-codemirror2');
require('codemirror/lib/codemirror.css');
require('codemirror/mode/sql/sql');
const LocaleUtils = require('../../../utils/LocaleUtils');


class RoiCql extends React.Component {
static propTypes = {
wkt: PropTypes.string,
onChangeFilter: PropTypes.func
};
static contextTypes = {
messages: PropTypes.object
};
constructor(props) {
super(props);
this.state = {cql: props.wkt};
}
componentWillReceiveProps({wkt: nw}) {
if (nw !== this.props.wkt) {
this.setState({cql: nw});
}
}
onChange = (editor, data, value) => {
this.setState(() => ({cql: value}));
}
render() {
return (
<ContainerDimensions>
{({width}) =>
<div style={{width, display: "flex", flexDirection: "column"}}>
<Codemirror
value={this.state.cql}
onBeforeChange={this.onChange}
options={{
mode: {name: "sql"},
lineNumbers: true,
lineWrapping: true
}}/>
<Button disabled={this.props.wkt === this.state.cql} text={LocaleUtils.getMessageById(this.context.messages, "rulesmanager.apply")} onClick={this.apply}/>
</div>}
</ContainerDimensions>);
}
apply = () => {
if (this.props.onChangeFilter) {
this.props.onChangeFilter(this.state.cql);
}
}
}

module.exports = RoiCql;
Loading

0 comments on commit bf5ad67

Please sign in to comment.