Skip to content

Commit

Permalink
Modified wfsquery epic structure
Browse files Browse the repository at this point in the history
  • Loading branch information
allyoucanmap committed Apr 28, 2017
1 parent fef5734 commit c90c628
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
12 changes: 6 additions & 6 deletions web/client/epics/wfsquery.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
*/

const Rx = require('rxjs');
const axios = require('../libs/ajax');
const {changeSpatialAttribute} = require('../actions/queryform');
const {FEATURE_TYPE_SELECTED, featureTypeLoaded, featureTypeError} = require('../actions/wfsquery');
const axios = require('../libs/ajax');

const types = {
'xsd:string': 'string',
Expand Down Expand Up @@ -51,27 +51,27 @@ const extractInfo = (data) => {
};
};

const addGeometryFieldEpic = action$ =>
const featureTypeSelectedEpic = action$ =>
action$.ofType(FEATURE_TYPE_SELECTED).switchMap(action => {
return Rx.Observable.defer( () =>
axios.get(action.url + '?service=WFS&version=1.1.0&request=DescribeFeatureType&typeName=' + action.typeName + '&outputFormat=application/json'))
.map((response) => {
if (typeof response.data === 'object' && response.data.featureTypes && response.data.featureTypes[0]) {
const info = extractInfo(response.data);
const geometry = info.geometry[0] && info.geometry[0].attribute ? info.geometry[0].attribute : 'the_geom';
return [featureTypeLoaded(action.typeName, info), changeSpatialAttribute(geometry)];
return Rx.Observable.from([featureTypeLoaded(action.typeName, info), changeSpatialAttribute(geometry)]);
}
try {
JSON.parse(response.data);
} catch(e) {
return [featureTypeError(action.typeName, 'Error from WFS: ' + e.message)];
return Rx.Observable.from([featureTypeError(action.typeName, 'Error from WFS: ' + e.message)]);
}
return [featureTypeError(action.typeName, 'Error: feature types are empty')];
return Rx.Observable.from([featureTypeError(action.typeName, 'Error: feature types are empty')]);
})
.mergeAll()
.catch(e => Rx.Observable.of(featureTypeError(action.typeName, e.message)));
});

module.exports = {
addGeometryFieldEpic
featureTypeSelectedEpic
};
4 changes: 2 additions & 2 deletions web/client/plugins/QueryPanel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const LayersUtils = require('../utils/LayersUtils');
// include application component
const QueryBuilder = require('../components/data/query/QueryBuilder');

const {addGeometryFieldEpic} = require('../epics/wfsquery');
const {featureTypeSelectedEpic} = require('../epics/wfsquery');

const {bindActionCreators} = require('redux');
const {
Expand Down Expand Up @@ -237,5 +237,5 @@ module.exports = {
queryform: require('../reducers/queryform'),
query: require('../reducers/query')
},
epics: {addGeometryFieldEpic}
epics: {featureTypeSelectedEpic}
};

0 comments on commit c90c628

Please sign in to comment.