Skip to content

Commit

Permalink
Add ui to configure text search services
Browse files Browse the repository at this point in the history
  • Loading branch information
kappu committed May 18, 2017
1 parent 2a9f77a commit 7425b0d
Show file tree
Hide file tree
Showing 20 changed files with 1,334 additions and 14 deletions.
51 changes: 51 additions & 0 deletions web/client/actions/__tests__/searchconfig-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* Copyright 2017, 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 expect = require('expect');
var {
SET_SEARCH_CONFIG_PROP,
RESET_SEARCH_CONFIG,
UPDATE_SERVICE,
setSearchConfigProp,
restServiceConfig,
updateService
} = require('../searchconfig');

describe('Test correctness of the searchconfig actions', () => {


it('resetServiceConfig', () => {
const testPage = 1;
var retval = restServiceConfig(testPage);

expect(retval).toExist();
expect(retval.type).toBe(RESET_SEARCH_CONFIG);
expect(retval.page).toBe(testPage);
});

it('setSearchConfigProp', () => {
const testProperty = 'prop';
const testValue = 'val';
var retval = setSearchConfigProp(testProperty, testValue);

expect(retval).toExist();
expect(retval.type).toBe(SET_SEARCH_CONFIG_PROP);
expect(retval.property).toBe(testProperty);
expect(retval.value).toBe(testValue);
});

it('updateService', () => {
const testService = "service";
const testIdx = 1;
var retval = updateService(testService, testIdx);
expect(retval).toExist();
expect(retval.type).toBe(UPDATE_SERVICE);
expect(retval.service).toBe(testService);
expect(retval.idx).toBe(testIdx);
});
});
53 changes: 53 additions & 0 deletions web/client/actions/searchconfig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* Copyright 2017, 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 SET_SEARCH_CONFIG_PROP = 'SET_SEARCH_CONFIG_PROP';
const RESET_SEARCH_CONFIG = 'RESET_SEARCH_CONFIG';
const UPDATE_SERVICE = 'UPDATE_SERVICE';

/**
* Sets a property
* @memberof actions.search
* @param {string} property the property to set
* @param {string|number|boolean|object} value the value to set or to check for toggling
* @return {object} of type `SET_SEARCH_CONFIG_PROP` with property and value params
*/
function setSearchConfigProp(property, value) {
return {
type: SET_SEARCH_CONFIG_PROP,
property,
value
};
}

function restServiceConfig(page = 0 ) {
return {
type: RESET_SEARCH_CONFIG,
page
};
}
function updateService(service, idx = -1) {
return {
type: UPDATE_SERVICE,
service,
idx
};
}

/**
* Actions for search
* @name actions.searchconfig
*/
module.exports = {
SET_SEARCH_CONFIG_PROP,
RESET_SEARCH_CONFIG,
UPDATE_SERVICE,
setSearchConfigProp,
restServiceConfig,
updateService
};
3 changes: 2 additions & 1 deletion web/client/api/Nominatim.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ const DEFAULT_REVERSE_URL = 'nominatim.openstreetmap.org/reverse';
const defaultOptions = {
format: 'json',
bounded: 0,
polygon_geojson: 1
polygon_geojson: 1,
priority: 5
};
/**
* API for local config
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/**
* Copyright 2017, 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 {FormGroup, ControlLabel, FormControl, Label} = require('react-bootstrap');
const Message = require('../../I18N/Message');
const Slider = require('react-nouislider');
const assign = require('object-assign');
function validate(service = {}) {
return service.displayName && service.displayName.length > 0;
}
const ResultsProps = React.createClass({
propTypes: {
service: React.PropTypes.object,
onPropertyChange: React.PropTypes.func
},
getDefaultProps() {
return {
service: {},
onPropertyChange: () => {}
};
},
render() {
const {service} = this.props;
return (
<form>
<span className="wfs-required-props-title"><Message msgId="search.s_result_props_label" /></span>
<FormGroup>
<ControlLabel>
<Message msgId="search.s_title" />
</ControlLabel>
<FormControl
value={service.displayName}
key="displayName"
type="text"
placeholder={'e.g. "${properties.name}\"'}
onChange={this.updateProp.bind(null, "displayName")}/>
</FormGroup>
<FormGroup>
<ControlLabel>
<Message msgId="search.s_description" />
</ControlLabel>
<FormControl
value={service.subTitle}
key="subTitle"
type="text"
onChange={this.updateProp.bind(null, "subTitle")}/>
</FormGroup>
<FormGroup>
<ControlLabel>
<Message msgId="search.s_priority" />
<Label key="priority-labeel" className="slider-label">{parseInt(service.priority || 1, 10)}</Label>
</ControlLabel>
<Slider key="priority" start={[service.priority || 1]}
range={{min: 1, max: 10}}
onSlide={this.updatePriority}
/>
<span className="priority-info"><Message msgId="search.s_priority_info" /></span>
</FormGroup>
</form>);
},
updateProp(prop, event) {
const value = event.target.value;
this.props.onPropertyChange("service", assign({}, this.props.service, {[prop]: value}));
},
updatePriority(val) {
this.props.onPropertyChange("service", assign({}, this.props.service, {priority: parseFloat(val[0], 10)}));
}
});

module.exports = { Element: ResultsProps, validate};
Loading

0 comments on commit 7425b0d

Please sign in to comment.