Skip to content

Commit

Permalink
Porting of minor fixes (#2076)
Browse files Browse the repository at this point in the history
Porting of minor fixes/improvements:
 - Authkey with custom parameter name (c040)
 - MultiGeom support for search geometry service (c028)
 - Export resilient to natural order errors (040)
 - Disable pinch scale on mobile devices (c040)
  • Loading branch information
offtherailz authored Aug 2, 2017
1 parent dfa6989 commit fc27b58
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 29 deletions.
2 changes: 1 addition & 1 deletion web/client/components/mapcontrols/search/SearchResult.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class SearchResult extends React.Component {
}
let item = this.props.item;
return (
<div key={item.osm_id} className="search-result" onClick={this.onClick}>
<div key={item.osm_id} className="search-result" style={item.resultCssStyle} onClick={this.onClick}>
<div className="icon"> <img src={item.icon} /></div>
<div className="text-result-title">{get(item, this.props.displayName) || generateTemplateString(this.props.displayName || "")(item) }</div>
<small className="text-info">{this.props.subTitle && get(item, this.props.subTitle) || generateTemplateString(this.props.subTitle || "")(item) }</small>
Expand Down
2 changes: 1 addition & 1 deletion web/client/epics/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ const searchItemSelected = action$ =>
// retrieve geometry from geomService or pass the item directly
return Rx.Observable.fromPromise(
API.Utils.getService(item.__SERVICE__.geomService.type)("", assign( {}, item.__SERVICE__.geomService.options, { staticFilter } ))
.then(res => assign({}, item, {geometry: res[0].geometry} ) )
.then(res => assign({}, item, {geometry: CoordinatesUtils.mergeToPolyGeom(res)} ) )
);
}
return Rx.Observable.of(action.item);
Expand Down
30 changes: 28 additions & 2 deletions 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);
const data = FilterUtils.toOGCFilter(filterObj.featureTypeName, filterObj, filterObj.ogcVersion, filterObj.sortOptions);
return Rx.Observable.defer( () =>
axios.post(url + `?service=WFS&outputFormat=${downloadOptions.selectedFormat}`, data, {
timeout: 60000,
Expand All @@ -25,6 +25,12 @@ const getFileName = action => {
}
return name;
};
const getDefaultSortOptions = (attribute) => {
return attribute ? { sortBy: attribute, sortOrder: 'A'} : {};
};
const getFirstAttribute = (state)=> {
return state.query && state.query.featureTypes && state.query.featureTypes[state.query.typeName] && state.query.featureTypes[state.query.typeName].attributes && state.query.featureTypes[state.query.typeName].attributes[0] && state.query.featureTypes[state.query.typeName].attributes[0].attribute || null;
};
/*
const str2bytes = (str) => {
var bytes = new Uint8Array(str.length);
Expand All @@ -35,7 +41,7 @@ const str2bytes = (str) => {
};
*/
module.exports = {
startFeatureExportDownload: action$ =>
startFeatureExportDownload: (action$, store) =>
action$.ofType(DOWNLOAD_FEATURES).switchMap(action =>
getWFSFeature({
url: action.url,
Expand All @@ -52,6 +58,26 @@ module.exports = {
throw xml;
}
}
})
.catch( () => {
return getWFSFeature({
url: action.url,
downloadOptions: action.downloadOptions,
filterObj: {
...action.filterObj,
pagination: get(action, "downloadOptions.singlePage") ? action.filterObj.pagination : null,
sortOptions: getDefaultSortOptions(getFirstAttribute(store.getState()))
}
}).do(({data, headers}) => {
if (headers["content-type"] === "application/xml") { // TODO add expected mimetypes in the case you want application/dxf
let xml = String.fromCharCode.apply(null, new Uint8Array(data));
if (xml.indexOf("<ows:ExceptionReport") === 0 ) {
throw xml;
}
}
saveAs(new Blob([data], {type: headers && headers["content-type"]}), getFileName(action));
});
}).do(({data, headers}) => {
saveAs(new Blob([data], {type: headers && headers["content-type"]}), getFileName(action));
})
.map( () => onDownloadFinished() )
Expand Down
2 changes: 1 addition & 1 deletion web/client/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="UTF-8">
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1.0, user-scalable=no">
<title>MapStore 2 HomePage</title>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Raleway" type='text/css'>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.7/leaflet.css" />
Expand Down
20 changes: 2 additions & 18 deletions web/client/libs/__tests__/ajax-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,8 @@ const authenticationRules = [
},
{
"urlPattern": ".*youhavetouseacustomone.*",
"method": {
"method": "authkey-param",
"param": "mario"
}
"authkeyParamName": "mario",
"method": "authkey"
},
{
"urlPattern": ".*thisismissingtheparam.*",
Expand Down Expand Up @@ -268,20 +266,6 @@ describe('Tests ajax library', () => {
});
});

it('falls back to standard authkey if the custom one is misconfigured', (done) => {
// mocking the authentication rules and user info
expect.spyOn(SecurityUtils, 'isAuthenticationActivated').andReturn(true);
expect.spyOn(SecurityUtils, 'getAuthenticationRules').andReturn(authenticationRules);
expect.spyOn(SecurityUtils, 'getSecurityInfo').andReturn(securityInfoB);
const theExpectedString = 'authkey%3D' + securityInfoB.token;
axios.get('http://non-existent.mapstore2/thisismissingtheparam?parameter1=value1&par2=v2').then(() => {
done("Axios actually reached the fake url");
}).catch((exception) => {
expect(exception.config).toExist().toIncludeKey('url');
expect(exception.config.url.indexOf(theExpectedString)).toBeGreaterThan(-1);
done();
});
});

it('does not add autkeys if the configuration is wrong', (done) => {
// mocking the authentication rules and user info
Expand Down
10 changes: 4 additions & 6 deletions web/client/libs/ajax.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const ConfigUtils = require('../utils/ConfigUtils');

const SecurityUtils = require('../utils/SecurityUtils');
const assign = require('object-assign');
const {has, isObject} = require('lodash');
const {isObject} = require('lodash');
const urlUtil = require('url');

/**
Expand All @@ -38,17 +38,15 @@ function addAuthenticationToAxios(axiosConfig) {
return axiosConfig;
}
const rule = SecurityUtils.getAuthenticationRule(axiosConfig.url);
const method = rule && (has(rule, "method.method") ? rule.method : assign({}, {method: rule.method}));
const methodType = rule && (has(rule, "method.method") ? rule.method.method : rule.method);
switch (methodType) {

switch (rule && rule.method) {
case 'authkey':
case 'authkey-param':
{
const token = SecurityUtils.getToken();
if (!token) {
return axiosConfig;
}
addParameterToAxiosConfig(axiosConfig, method.param || 'authkey', token);
addParameterToAxiosConfig(axiosConfig, rule.authkeyParamName || 'authkey', token);
return axiosConfig;
}
case 'basic':
Expand Down
9 changes: 9 additions & 0 deletions web/client/utils/CoordinatesUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,15 @@ const CoordinatesUtils = {
}
default: return [];
}
},
mergeToPolyGeom(features) {
if (features.length === 1) {
return features[0].geometry;
}
return {
type: "GeometryCollection",
geometries: features.map( ({geometry}) => geometry)
};
}
};

Expand Down

0 comments on commit fc27b58

Please sign in to comment.