Skip to content

Commit

Permalink
Add manual edit style. Add translations and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
offtherailz committed Nov 4, 2016
1 parent ae78032 commit 334bc30
Show file tree
Hide file tree
Showing 12 changed files with 359 additions and 17 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"react-motion": "0.4.4",
"react-router": "2.4.0",
"react-router-redux": "2.1.0",
"react-select": "1.0.0-beta14",
"react-select": "1.0.0-rc.1",
"react-transform-catch-errors": "1.0.2",
"redbox-react": "1.2.4",
"redux-devtools": "3.1.1",
Expand Down
24 changes: 23 additions & 1 deletion web/client/actions/__tests__/layers-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ var {
removeLayer,
showSettings,
hideSettings,
updateSettings
updateSettings,
getLayerCapabilities
} = require('../layers');

describe('Test correctness of the layers actions', () => {
Expand Down Expand Up @@ -167,4 +168,25 @@ describe('Test correctness of the layers actions', () => {
expect(action.type).toBe(UPDATE_SETTINGS);
expect(action.options).toEqual({opacity: 0.5, size: 500});
});
it('get layer capabilities', (done) => {
const layer = {
id: "TEST_ID",
name: 'testworkspace:testlayer',
title: 'Layer',
visibility: true,
storeIndex: 9,
type: 'shapefile',
url: 'base/web/client/test-resources/geoserver/wms'
};
const actionCall = getLayerCapabilities(layer);
expect(actionCall).toExist();
actionCall((action)=> {
expect(action).toExist();
expect(action.options).toExist();
expect(action.type === UPDATE_NODE);
if (action.options.capabilities) {
done();
}
});
});
});
6 changes: 5 additions & 1 deletion web/client/actions/layers.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,9 @@ function getLayerCapabilities(layer, options) {
}
return (dispatch) => {
// TODO, look ad current cached capabilities;
dispatch(updateNode(layer.id, "id", {
capabilitiesLoading: true
}));
return WMS.getCapabilities(reqUrl, options).then((capabilities) => {
let layers = _.get(capabilities, "capability.layer.layer");
let layerCapability;
Expand All @@ -213,14 +216,15 @@ function getLayerCapabilities(layer, options) {
if (layerCapability) {
dispatch(updateNode(layer.id, "id", {
capabilities: layerCapability,
capabilitiesLoading: null,
boundingBox: layerCapability.latLonBoundingBox,
availableStyles: layerCapability.style && (Array.isArray(layerCapability.style) ? layerCapability.style : [layerCapability.style])
}));
}
// return dispatch(updateNode(layer.id, "id", {capabilities: capabilities || {"error": "no describe Layer found"}}));

}).catch((error) => {
dispatch(updateNode(layer.id, "id", {capabilities: {error: "error getting capabilities", details: error}} ));
dispatch(updateNode(layer.id, "id", {capabilitiesLoading: null, capabilities: {error: "error getting capabilities", details: error}} ));

// return dispatch(updateNode(layer.id, "id", {capabilities: capabilities || {"error": "no describe Layer found"}}));

Expand Down
39 changes: 25 additions & 14 deletions web/client/components/TOC/fragments/settings/WMSStyle.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

var React = require('react');
// const Message = require('../../../I18N/Message');
const Message = require('../../../I18N/Message');
const Select = require('react-select');
const {Button, Glyphicon, Alert} = require('react-bootstrap');

Expand All @@ -29,28 +29,39 @@ const WMSStyle = React.createClass({
};
},
renderLegend() {
if (this.props.element && this.props.element.availableStyles) {
let i = this.props.element.availableStyles.findIndex((item) => item.name === this.props.element.style);
if (i >= 0) {
let style = this.props.element.availableStyles[i];
let legendUrl = style.legendURL && style.legendURL[0];
}
}
// legend can not added because of this issue
// https://github.com/highsource/ogc-schemas/issues/183
return null;
},
renderError() {
if (this.props.element && this.props.element.capabilities && this.props.element && this.props.element.capabilities.error) {
return <Alert bsStyle="danger">There was an error getting layer's style list</Alert>;
return <Alert bsStyle="danger"><Message msgId="layerProperties.styleListLoadError" /></Alert>;
}
},
render() {
let options = [{label: "Default Style", value: ""}].concat((this.props.element.availableStyles || []).map((item) => {
return {label: item.title || item.name, value: item.name};
}));
let currentStyleIndex = this.props.element.style && this.props.element.availableStyles && this.props.element.availableStyles.findIndex( el => el.name === this.props.element.style);
if (!(currentStyleIndex >= 0) && this.props.element.style) {
options.push({label: this.props.element.style, value: this.props.element.style });
}
return (<form ref="style">
<Select
allowCreate={true}
<Select.Creatable
key="styles-dropdown"
options={[{label: "Default Style", value: ""}].concat((this.props.element.availableStyles && this.props.element.availableStyles || []).map((item) => {
return {label: item.title || item.name, value: item.name};
}))}
options={options}
isLoading={this.props.element && this.props.element.capabilitiesLoading}
value={this.props.element.style || ""}
onOpen={() => {
// automatic retrieve if availableStyles are not available or capabilities is not present
// that means you don't have a list and you didn't try to load it.
if (this.props.element && !(this.props.element.capabilities && this.props.element.availableStyles)) {
this.props.retrieveLayerData(this.props.element);
}
}}
promptTextCreator={(value) => {
return <Message msgId="layerProperties.styleCustom" msgParams={{value}} />;
}}
onChange={(selected) => {
this.updateEntry("style", {target: {value: (selected && selected.value) || ""}});
}}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
/**
* Copyright 2015, 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.
*/

var React = require('react/addons');
var ReactDOM = require('react-dom');
var ReactTestUtils = require('react-addons-test-utils');
var WMSStyle = require('../WMSStyle');

var expect = require('expect');

describe('test Layer Properties General module component', () => {
beforeEach((done) => {
document.body.innerHTML = '<div id="container"></div>';
setTimeout(done);
});

afterEach((done) => {
ReactDOM.unmountComponentAtNode(document.getElementById("container"));
document.body.innerHTML = '';
setTimeout(done);
});

it('tests component rendering', () => {
const l = {
name: 'testworkspace:testlayer',
title: 'Layer',
visibility: true,
storeIndex: 9,
type: 'shapefile',
url: 'base/web/client/test-resources/geoserver/wms'
};
const settings = {
options: {opacity: 1}
};

const comp = ReactDOM.render(<WMSStyle element={l} settings={settings} />, document.getElementById("container"));
expect(comp).toExist();
const form = ReactTestUtils.scryRenderedDOMComponentsWithTag( comp, "form" );
expect(form).toExist();

});
it('tests component events', () => {
const l = {
name: 'testworkspace:testlayer',
title: 'Layer',
visibility: true,
storeIndex: 9,
type: 'wms',
url: 'base/web/client/test-resources/geoserver/wms',
availableStyles: [{name: 'style1'}]

};
const settings = {
options: {opacity: 1}
};
const handlers = {
retrieveLayerData: () => {},
updateSettings: () => {}
};
let spyRetrive = expect.spyOn(handlers, "retrieveLayerData");
let spyUpdate = expect.spyOn(handlers, "updateSettings");

const comp = ReactDOM.render(<WMSStyle element={l} settings={settings} retrieveLayerData={handlers.retrieveLayerData} updateSettings={handlers.updateSettings}/>, document.getElementById("container"));
expect(comp).toExist();
// refresh layers list button click
const buttons = ReactTestUtils.scryRenderedDOMComponentsWithTag( comp, "button" );
expect(buttons).toExist();
expect(buttons.length).toBe(1);
ReactTestUtils.Simulate.click(buttons[0]);
expect(spyRetrive.calls.length).toBe(1);

// Simpulate selection
const selectArrow = ReactDOM.findDOMNode(comp).querySelector('.Select-arrow');
const selectControl = ReactDOM.findDOMNode(comp).querySelector('.Select-control');
const inputs = ReactTestUtils.scryRenderedDOMComponentsWithTag( comp, "input" );
ReactTestUtils.Simulate.mouseDown(selectArrow, { button: 0 });
ReactTestUtils.Simulate.keyDown(selectControl, { keyCode: 40, key: 'ArrowDown' });
ReactTestUtils.Simulate.keyDown(inputs[0], { keyCode: 13, key: 'Enter' });
expect(spyUpdate.calls.length).toBe(1);

// click on arrow of the select auto try to retrieve data if not present
const l2 = {
name: 'testworkspace:testlayer',
title: 'Layer',
visibility: true,
storeIndex: 9,
type: 'wms',
url: 'base/web/client/test-resources/geoserver/wms'
};
const comp1 = ReactDOM.render(<WMSStyle element={l2} settings={settings} retrieveLayerData={handlers.retrieveLayerData} updateSettings={handlers.updateSettings}/>, document.getElementById("container"));
const selectArrow1 = ReactDOM.findDOMNode(comp1).querySelector('.Select-arrow');
ReactTestUtils.Simulate.click(selectArrow1);
expect(spyRetrive.calls.length).toBe(2);
});
it('tests rendering error', () => {
const l = {
name: 'testworkspace:testlayer',
title: 'Layer',
visibility: true,
storeIndex: 9,
type: 'shapefile',
url: 'base/web/client/test-resources/geoserver/wms',
capabilities: {
error: "unable to retrieve capabiltiies"
}
};
const settings = {
options: {opacity: 1}
};
const comp = ReactDOM.render(<WMSStyle element={l} settings={settings} />, document.getElementById("container"));
expect(comp).toExist();
const form = ReactTestUtils.scryRenderedDOMComponentsWithTag( comp, "form" );
expect(form).toExist();

});

});
3 changes: 3 additions & 0 deletions web/client/plugins/Save.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ const Save = React.createClass({
opacity: layer.opacity,
provider: layer.provider,
styles: layer.styles,
style: layer.style,
availableStyles: layer.availableStyles,
capabilitiesURL: layer.capabilitiesURL,
title: layer.title,
transparent: layer.transparent,
type: layer.type,
Expand Down
3 changes: 3 additions & 0 deletions web/client/plugins/SaveAs.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ const SaveAs = React.createClass({
opacity: layer.opacity,
provider: layer.provider,
styles: layer.styles,
style: layer.style,
availableStyles: layer.availableStyles,
capabilitiesURL: layer.capabilitiesURL,
title: layer.title,
transparent: layer.transparent,
type: layer.type,
Expand Down
Loading

0 comments on commit 334bc30

Please sign in to comment.