Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
kappu72 authored and Tobia Di Pisa committed Sep 8, 2017
1 parent 584f946 commit 60015c8
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 11 deletions.
20 changes: 17 additions & 3 deletions web/client/components/data/download/DownloadDialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const Spinner = require('react-spinkit');
const Dialog = require('../../misc/Dialog');
const Message = require('../../I18N/Message');
const DownloadOptions = require('./DownloadOptions');
const assign = require('object-assign');

class DownloadDialog extends React.Component {
static propTypes = {
Expand All @@ -20,7 +21,9 @@ class DownloadDialog extends React.Component {
onExport: PropTypes.func,
onDownloadOptionChange: PropTypes.func,
downloadOptions: PropTypes.object,
formats: PropTypes.array
formats: PropTypes.array,
srsList: PropTypes.array,
defaultSrs: PropTypes.string
};

static defaultProps = {
Expand All @@ -33,6 +36,10 @@ class DownloadDialog extends React.Component {
formats: [
{name: "csv", label: "csv"},
{name: "shape-zip", label: "shape-zip"}
],
srsList: [
{name: "native", label: "Native"},
{name: "EPSG:4326", label: "WGS84"}
]
};

Expand Down Expand Up @@ -62,19 +69,26 @@ class DownloadDialog extends React.Component {
<DownloadOptions
downloadOptions={this.props.downloadOptions}
onChange={this.props.onDownloadOptionChange}
formats={this.props.formats}/>
formats={this.props.formats}
srsList={this.props.srsList}
defaultSrs={this.props.defaultSrs}/>
</div>
<div role="footer">
<Button
bsStyle="primary"
className="download-button"
disabled={!this.props.downloadOptions.selectedFormat || this.props.loading}
onClick={() => this.props.onExport(this.props.url, this.props.filterObj, this.props.downloadOptions)}>
onClick={this.handelExport}>
{this.renderIcon()} <Message msgId="wfsdownload.export" />
</Button>
</div>
</Dialog>);
}
handelExport = () => {
const {url, filterObj, downloadOptions, defaultSrs, srsList, onExport} = this.props;
const selectedSrs = downloadOptions && downloadOptions.selectedSrs || defaultSrs || (srsList[0] || {}).name;
onExport(url, filterObj, assign({}, downloadOptions, {selectedSrs}));
}
}

module.exports = DownloadDialog;
19 changes: 15 additions & 4 deletions web/client/components/data/download/DownloadOptions.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,23 @@ module.exports = class extends React.Component {
static propTypes = {
downloadOptions: PropTypes.object,
formats: PropTypes.array,
onChange: PropTypes.func
srsList: PropTypes.array,
onChange: PropTypes.func,
defaultSrs: PropTypes.string
};

static defaultProps = {
downloadOptions: {},
formats: []
formats: [],
srsList: []
};

getSelectedFormat = () => {
return get(this.props, "downloadOptions.selectedFormat") || get(head(this.props.formats), "value");
return get(this.props, "downloadOptions.selectedFormat");
};
getSelectedSRS = () => {
return get(this.props, "downloadOptions.selectedSrs") || this.props.defaultSrs || get(head(this.props.srsList), "name");
};

render() {
return (<form>
<label><Message msgId="wfsdownload.format" /></label>
Expand All @@ -45,6 +50,12 @@ module.exports = class extends React.Component {
value={this.getSelectedFormat()}
onChange={(sel) => this.props.onChange("selectedFormat", sel.value)}
options={this.props.formats.map(f => ({value: f.name, label: f.label || f.name}))} />
<label><Message msgId="wfsdownload.srs" /></label>
<Select
clearable={false}
value={this.getSelectedSRS()}
onChange={(sel) => this.props.onChange("selectedSrs", sel.value)}
options={this.props.srsList.map(f => ({value: f.name, label: f.label || f.name}))} />
<Checkbox checked={this.props.downloadOptions.singlePage} onChange={() => this.props.onChange("singlePage", !this.props.downloadOptions.singlePage ) }>
<Message msgId="wfsdownload.downloadonlycurrentpage" />
</Checkbox>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ describe('Test for DownloadOptions component', () => {
expect(cmp).toExist();
expect(TestUtils.scryRenderedDOMComponentsWithClass(cmp, "Select-value-label")).toExist();
});
it('render with srs list element selected', () => {
const cmp = ReactDOM.render(<DownloadOptions downloadOptions={{selectedSrs: "test"}} srsList={[{name: "test"}]}/>, document.getElementById("container"));
expect(cmp).toExist();
expect(TestUtils.scryRenderedDOMComponentsWithClass(cmp, "Select-value-label")).toExist();
});
it('singlePage checkbox events', () => {
const events = {
onChange: () => {}
Expand Down
2 changes: 1 addition & 1 deletion web/client/epics/wfsdownload.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const FilterUtils = require('../utils/FilterUtils');
const {getByOutputFormat} = require('../utils/FileFormatUtils');

const getWFSFeature = ({url, filterObj = {}, downloadOptions= {}} = {}) => {
const data = FilterUtils.toOGCFilter(filterObj.featureTypeName, filterObj, filterObj.ogcVersion, filterObj.sortOptions);
const data = FilterUtils.toOGCFilter(filterObj.featureTypeName, filterObj, filterObj.ogcVersion, filterObj.sortOptions, false, null, null, downloadOptions.selectedSrs);
return Rx.Observable.defer( () =>
axios.post(url + `?service=WFS&outputFormat=${downloadOptions.selectedFormat}`, data, {
timeout: 60000,
Expand Down
9 changes: 8 additions & 1 deletion web/client/plugins/WFSDownload.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ const DownloadDialog = require('../components/data/download/DownloadDialog');
* @name WFSDownload
* @class
* @prop {object[]} formats An array of name-label objects for the allowed formats available.
* @prop {object[]} srsList An array of name-label objects for the allowed srs available. Use name:'native' to omit srsName param in wfs filter
* @prop {string} defaultSrs Deafult selected srs
* @prop {string} closeGlyph The icon to use for close the dialog
* @example
* {
Expand All @@ -30,7 +32,12 @@ const DownloadDialog = require('../components/data/download/DownloadDialog');
* {"name": "excel", "label": "excel"},
* {"name": "excel2007", "label": "excel2007"},
* {"name": "dxf-zip", "label": "dxf-zip"}
* ]
* ],
* "srsList": [
* {"name": "native", "label": "Native"},
* {"name": "EPSG:4326", "label": "WGS84"}
* ],
* "defaultSrs": "native"
* }
* }
*/
Expand Down
1 change: 1 addition & 0 deletions web/client/translations/data.de-DE
Original file line number Diff line number Diff line change
Expand Up @@ -875,6 +875,7 @@
"wfsdownload": {
"title": "Daten exportieren",
"format": "Datei Format",
"srs": "Räumliches Bezugssystem",
"export": "Export",
"downloadonlycurrentpage": "Nur aktuelle Seite herunterladen",
"error": {
Expand Down
1 change: 1 addition & 0 deletions web/client/translations/data.en-US
Original file line number Diff line number Diff line change
Expand Up @@ -874,6 +874,7 @@
"wfsdownload": {
"title": "Export Data",
"format": "File Format",
"srs": "Spatial Reference System",
"export": "Export",
"downloadonlycurrentpage": "Download only current page",
"error": {
Expand Down
1 change: 1 addition & 0 deletions web/client/translations/data.es-ES
Original file line number Diff line number Diff line change
Expand Up @@ -878,6 +878,7 @@
"wfsdownload": {
"title": "Exportar los datos",
"format": "Formato de fichero",
"srs": "Sistema de referencia espacial",
"export": "Exportaciones",
"downloadonlycurrentpage": "Descargar la página actual",
"error": {
Expand Down
1 change: 1 addition & 0 deletions web/client/translations/data.fr-FR
Original file line number Diff line number Diff line change
Expand Up @@ -879,6 +879,7 @@
"wfsdownload": {
"title": "Exporter des données",
"format": "Format de fichier",
"srs": "Système de référence spatiale",
"export": "Exportations",
"downloadonlycurrentpage": "Télécharger uniquement la page actuelle",
"error": {
Expand Down
1 change: 1 addition & 0 deletions web/client/translations/data.it-IT
Original file line number Diff line number Diff line change
Expand Up @@ -875,6 +875,7 @@
"wfsdownload": {
"title": "Esporta Dati",
"format": "Formato file",
"srs": "Sistema di riferimento",
"export": "Esporta",
"downloadonlycurrentpage": "Scarica solo la pagina corrente",
"error": {
Expand Down
5 changes: 3 additions & 2 deletions web/client/utils/FilterUtils.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ const processOGCSimpleFilterField = (field, nsplaceholder) => {
};
const FilterUtils = {

toOGCFilter: function(ftName, json, version, sortOptions = null, hits = false, format = null, propertyNames = null) {
toOGCFilter: function(ftName, json, version, sortOptions = null, hits = false, format = null, propertyNames = null, srsName = "EPSG:4326") {
let objFilter;
try {
objFilter = json instanceof Object ? json : JSON.parse(json);
Expand Down Expand Up @@ -232,8 +232,9 @@ const FilterUtils = {
}

filter += "</" + nsplaceholder + ":Filter>";
// If srsName === native, srsName param is omitted!
ogcFilter += `<wfs:Query ${versionOGC === "2.0" ? "typeNames" : "typeName"}="${ftName}" ${srsName !== 'native' && `srsName="${srsName}"` || ''}>`;

ogcFilter += '<wfs:Query ' + (versionOGC === "2.0" ? "typeNames" : "typeName") + '="' + ftName + '" srsName="EPSG:4326">';
ogcFilter += filter;
if (propertyNames) {
ogcFilter += propertyNames.map( name =>
Expand Down

0 comments on commit 60015c8

Please sign in to comment.