Skip to content

Commit

Permalink
Merge pull request #194 from kappu72/GetFeatureInfoSpinner#172
Browse files Browse the repository at this point in the history
Close#172
  • Loading branch information
mbarto committed Oct 2, 2015
2 parents 6d405d4 + bbd49e9 commit 1b2b68f
Show file tree
Hide file tree
Showing 10 changed files with 343 additions and 124 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"keymirror": "~0.1.1",
"leaflet": "^0.7.3",
"leaflet-plugins": "https://github.com/Polyconseil/leaflet-plugins/tarball/master",
"node-uuid": "^1.4.3",
"object-assign": "^3.0.0",
"openlayers": "^3.8.2",
"proj4": "~2.3.6",
Expand Down
130 changes: 94 additions & 36 deletions web/client/actions/__tests__/mapInfo-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,49 +23,103 @@ var {
describe('Test correctness of the map actions', () => {

it('get feature info data', (done) => {
/*eslint-disable */
let reqId;
/*eslint-enable */
getFeatureInfo('base/web/client/test-resources/featureInfo-response.json', {p: "p"}, "meta")((e) => {
try {
expect(e).toExist();
expect(e.type).toBe(LOAD_FEATURE_INFO);
expect(e.data).toExist();
expect(e.requestParams).toExist();
expect(e.requestParams.p).toBe("p");
expect(e.layerMetadata).toBe("meta");
done();
} catch(ex) {
done(ex);
if (e.type === NEW_MAPINFO_REQUEST) {
reqId = e.reqId;
try {
expect(e).toExist();
expect(e.type).toBe(NEW_MAPINFO_REQUEST);
expect(e.reqId).toExist();
expect(e.request).toExist();
expect(e.request.p).toBe("p");
} catch(ex) {
done(ex);
}
} else if (e.type === LOAD_FEATURE_INFO) {
try {
expect(e).toExist();
expect(e.type).toBe(LOAD_FEATURE_INFO);
expect(e.data).toExist();
expect(e.requestParams).toExist();
expect(e.reqId).toExist();
expect(e.reqId).toBe(reqId);
expect(e.requestParams.p).toBe("p");
expect(e.layerMetadata).toBe("meta");
done();
} catch(ex) {
done(ex);
}
}
});
});

it('get feature info exception', (done) => {
/*eslint-disable */
let reqId;
/*eslint-enable */
getFeatureInfo('base/web/client/test-resources/featureInfo-exception.json', {p: "p"}, "meta")((e) => {
try {
expect(e).toExist();
expect(e.type).toBe(EXCEPTIONS_FEATURE_INFO);
expect(e.exceptions).toExist();
expect(e.requestParams).toExist();
expect(e.requestParams.p).toBe("p");
expect(e.layerMetadata).toBe("meta");
done();
} catch(ex) {
done(ex);
if (e.type === NEW_MAPINFO_REQUEST) {
reqId = e.reqId;
try {
expect(e).toExist();
expect(e.type).toBe(NEW_MAPINFO_REQUEST);
expect(e.reqId).toExist();
expect(e.request).toExist();
expect(e.request.p).toBe("p");
} catch(ex) {
done(ex);
}
} else if (e.type === EXCEPTIONS_FEATURE_INFO) {
try {
expect(e).toExist();
expect(e.type).toBe(EXCEPTIONS_FEATURE_INFO);
expect(e.exceptions).toExist();
expect(e.reqId).toExist();
expect(e.reqId).toBe(reqId);
expect(e.requestParams).toExist();
expect(e.requestParams.p).toBe("p");
expect(e.layerMetadata).toBe("meta");
done();
} catch(ex) {
done(ex);
}
}
});
});

it('get feature info error', (done) => {
/*eslint-disable */
let reqId;
/*eslint-enable */
getFeatureInfo('requestError.json', {p: "p"}, "meta")((e) => {
try {
expect(e).toExist();
expect(e.type).toBe(ERROR_FEATURE_INFO);
expect(e.error).toExist();
expect(e.requestParams).toExist();
expect(e.requestParams.p).toBe("p");
expect(e.layerMetadata).toBe("meta");
done();
} catch(ex) {
done(ex);
if (e.type === NEW_MAPINFO_REQUEST) {
reqId = e.reqId;
try {
expect(e).toExist();
expect(e.type).toBe(NEW_MAPINFO_REQUEST);
expect(e.reqId).toExist();
expect(e.request).toExist();
expect(e.request.p).toBe("p");
} catch(ex) {
done(ex);
}
} else if (e.type === ERROR_FEATURE_INFO) {
try {
expect(e).toExist();
expect(e.type).toBe(ERROR_FEATURE_INFO);
expect(e.error).toExist();
expect(e.reqId).toExist();
expect(e.reqId).toBe(reqId);
expect(e.requestParams).toExist();
expect(e.requestParams.p).toBe("p");
expect(e.layerMetadata).toBe("meta");
done();
} catch(ex) {
done(ex);
}
}
});
});
Expand All @@ -80,12 +134,16 @@ describe('Test correctness of the map actions', () => {
});

it('add new info request', () => {
const testVal = "val";
const retval = newMapInfoRequest(testVal);

expect(retval.type).toBe(NEW_MAPINFO_REQUEST);
expect(retval.request).toExist();
expect(retval.request).toBe(testVal);
const reqIdVal = 100;
const requestVal = {p: "p"};
const e = newMapInfoRequest(reqIdVal, requestVal);
expect(e).toExist();
expect(e.type).toBe(NEW_MAPINFO_REQUEST);
expect(e.reqId).toExist();
expect(e.reqId).toBeA('number');
expect(e.reqId).toBe(100);
expect(e.request).toExist();
expect(e.request.p).toBe("p");
});

it('delete all results', () => {
Expand Down
35 changes: 21 additions & 14 deletions web/client/actions/mapInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

const assign = require('object-assign');
const axios = require('axios');
const uuid = require('node-uuid');

const LOAD_FEATURE_INFO = 'LOAD_FEATURE_INFO';
const ERROR_FEATURE_INFO = 'ERROR_FEATURE_INFO';
Expand All @@ -20,10 +21,11 @@ const PURGE_MAPINFO_RESULTS = 'PURGE_MAPINFO_RESULTS';
* Private
* @return a LOAD_FEATURE_INFO action with the response data to a wms GetFeatureInfo
*/
function loadFeatureInfo(data, rParams, lMetaData) {
function loadFeatureInfo(reqId, data, rParams, lMetaData) {
return {
type: LOAD_FEATURE_INFO,
data: data,
reqId: reqId,
requestParams: rParams,
layerMetadata: lMetaData
};
Expand All @@ -33,10 +35,11 @@ function loadFeatureInfo(data, rParams, lMetaData) {
* Private
* @return a ERROR_FEATURE_INFO action with the error occured
*/
function errorFeatureInfo(e, rParams, lMetaData) {
function errorFeatureInfo(reqId, e, rParams, lMetaData) {
return {
type: ERROR_FEATURE_INFO,
error: e,
reqId: reqId,
requestParams: rParams,
layerMetadata: lMetaData
};
Expand All @@ -47,15 +50,24 @@ function errorFeatureInfo(e, rParams, lMetaData) {
* @return a EXCEPTIONS_FEATURE_INFO action with the wms exception occured
* during a GetFeatureInfo request.
*/
function exceptionsFeatureInfo(exceptions, rParams, lMetaData) {
function exceptionsFeatureInfo(reqId, exceptions, rParams, lMetaData) {
return {
type: EXCEPTIONS_FEATURE_INFO,
reqId: reqId,
exceptions: exceptions,
requestParams: rParams,
layerMetadata: lMetaData
};
}

function newMapInfoRequest(reqId, reqConfig) {
return {
type: NEW_MAPINFO_REQUEST,
reqId: reqId,
request: reqConfig
};
}

/**
* Sends a wms GetFeatureInfo request and dispatches the right action
* in case of success, error or exceptions.
Expand All @@ -75,15 +87,17 @@ function getFeatureInfo(wmsBasePath, requestParams, lMetaData) {
exceptions: 'application/json'
};
const param = assign({}, defaultParams, requestParams);
const reqId = uuid.v1();
return (dispatch) => {
return axios.get(wmsBasePath, {params: param}).then((response) => {
dispatch(newMapInfoRequest(reqId, param));
axios.get(wmsBasePath, {params: param}).then((response) => {
if (response.data.exceptions) {
dispatch(exceptionsFeatureInfo(response.data.exceptions, requestParams, lMetaData));
dispatch(exceptionsFeatureInfo(reqId, response.data.exceptions, requestParams, lMetaData));
} else {
dispatch(loadFeatureInfo(response.data, requestParams, lMetaData));
dispatch(loadFeatureInfo(reqId, response.data, requestParams, lMetaData));
}
}).catch((e) => {
dispatch(errorFeatureInfo(e, requestParams, lMetaData));
dispatch(errorFeatureInfo(reqId, e, requestParams, lMetaData));
});
};
}
Expand All @@ -95,13 +109,6 @@ function changeMapInfoState(enabled) {
};
}

function newMapInfoRequest(reqConfig) {
return {
type: NEW_MAPINFO_REQUEST,
request: reqConfig
};
}

function purgeMapInfoResults() {
return {
type: PURGE_MAPINFO_RESULTS
Expand Down
37 changes: 37 additions & 0 deletions web/client/components/misc/BasicSpinner.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
* 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');
require("./basicSpinner.css");

let BasicSpinner = React.createClass({
propTypes: {
id: React.PropTypes.string,
value: React.PropTypes.number,
sSize: React.PropTypes.string
},
getDefaultProps() {
return {
id: "mapstore-basicspinner",
value: null,
sSize: null
};
},
render() {
return (
<div className="spinner">
<div className={ "spinner-card " + this.props.sSize}>
<div className="spinner-bg whirly-loader" >Loadin..</div>
<div className="spinner-fg">{this.props.value}</div>
</div>
</div>
);
}

});

module.exports = BasicSpinner;
Loading

0 comments on commit 1b2b68f

Please sign in to comment.