-
Notifications
You must be signed in to change notification settings - Fork 410
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Query panel code base to kickoff development (#1332)
* import query panel in main product * Fix tests and increase coverage * Split turf dependencies
- Loading branch information
1 parent
2f0b144
commit 5b03ce0
Showing
20 changed files
with
1,826 additions
and
712 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
/** | ||
* Copyright 2016, 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 FEATURE_TYPE_SELECTED = 'FEATURE_TYPE_SELECTED'; | ||
const FEATURE_TYPE_LOADED = 'FEATURE_TYPE_LOADED'; | ||
const FEATURE_LOADED = 'FEATURE_LOADED'; | ||
const FEATURE_TYPE_ERROR = 'FEATURE_TYPE_ERROR'; | ||
const FEATURE_ERROR = 'FEATURE_ERROR'; | ||
const QUERY_RESULT = 'QUERY_RESULT'; | ||
const QUERY_ERROR = 'QUERY_ERROR'; | ||
const RESET_QUERY = 'RESET_QUERY'; | ||
|
||
const axios = require('../libs/ajax'); | ||
function featureTypeSelected(url, typeName) { | ||
return { | ||
type: FEATURE_TYPE_SELECTED, | ||
url, | ||
typeName | ||
}; | ||
} | ||
function featureTypeLoaded(typeName, featureType) { | ||
return { | ||
type: FEATURE_TYPE_LOADED, | ||
typeName, | ||
featureType | ||
}; | ||
} | ||
|
||
function featureTypeError(typeName, error) { | ||
return { | ||
type: FEATURE_TYPE_ERROR, | ||
typeName, | ||
error | ||
}; | ||
} | ||
|
||
function featureLoaded(typeName, feature) { | ||
return { | ||
type: FEATURE_LOADED, | ||
typeName, | ||
feature | ||
}; | ||
} | ||
|
||
function featureError(typeName, error) { | ||
return { | ||
type: FEATURE_ERROR, | ||
typeName, | ||
error | ||
}; | ||
} | ||
|
||
function querySearchResponse(result) { | ||
return { | ||
type: QUERY_RESULT, | ||
result | ||
}; | ||
} | ||
|
||
function queryError(error) { | ||
return { | ||
type: QUERY_ERROR, | ||
error | ||
}; | ||
} | ||
|
||
function describeFeatureType(baseUrl, typeName) { | ||
return (dispatch) => { | ||
return axios.get(baseUrl + '?service=WFS&version=1.1.0&request=DescribeFeatureType&typeName=' + typeName + '&outputFormat=application/json').then((response) => { | ||
if (typeof response.data === 'object') { | ||
dispatch(featureTypeLoaded(typeName, response.data)); | ||
} else { | ||
try { | ||
JSON.parse(response.data); | ||
} catch(e) { | ||
dispatch(featureTypeError(typeName, 'Error from WFS: ' + e.message)); | ||
} | ||
|
||
} | ||
|
||
}).catch((e) => { | ||
dispatch(featureTypeError(typeName, e)); | ||
}); | ||
}; | ||
} | ||
|
||
function loadFeature(baseUrl, typeName) { | ||
return (dispatch) => { | ||
return axios.get(baseUrl + '?service=WFS&version=1.1.0&request=GetFeature&typeName=' + typeName + '&outputFormat=application/json').then((response) => { | ||
if (typeof response.data === 'object') { | ||
dispatch(featureLoaded(typeName, response.data)); | ||
} else { | ||
try { | ||
JSON.parse(response.data); | ||
} catch(e) { | ||
dispatch(featureError(typeName, 'Error from WFS: ' + e.message)); | ||
} | ||
|
||
} | ||
|
||
}).catch((e) => { | ||
dispatch(featureError(typeName, e)); | ||
}); | ||
}; | ||
} | ||
|
||
function query(seachURL, data) { | ||
return (dispatch) => { | ||
return axios.post(seachURL + '?service=WFS&&outputFormat=json', data, { | ||
timeout: 60000, | ||
headers: {'Accept': 'application/json', 'Content-Type': 'application/json'} | ||
}).then((response) => { | ||
dispatch(querySearchResponse(response.data)); | ||
}).catch((e) => { | ||
dispatch(queryError(e)); | ||
}); | ||
}; | ||
} | ||
|
||
function resetQuery() { | ||
return { | ||
type: RESET_QUERY | ||
}; | ||
} | ||
|
||
module.exports = { | ||
FEATURE_TYPE_SELECTED, | ||
FEATURE_TYPE_LOADED, | ||
FEATURE_LOADED, | ||
FEATURE_TYPE_ERROR, | ||
FEATURE_ERROR, | ||
QUERY_RESULT, | ||
QUERY_ERROR, | ||
RESET_QUERY, | ||
featureTypeSelected, | ||
describeFeatureType, | ||
loadFeature, | ||
query, | ||
resetQuery | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.