Skip to content

Commit

Permalink
Fixes #1369: avoid array methods and Promise not available on IE
Browse files Browse the repository at this point in the history
  • Loading branch information
mbarto committed Dec 23, 2016
1 parent 03eb0c5 commit 1c72552
Show file tree
Hide file tree
Showing 28 changed files with 90 additions and 51 deletions.
5 changes: 3 additions & 2 deletions web/client/api/GeoStoreDAO.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const _ = require('lodash');
const assign = require('object-assign');

const ConfigUtils = require('../utils/ConfigUtils');
const {findIndex} = require('lodash');

let parseOptions = (opts) => opts;

Expand Down Expand Up @@ -251,9 +252,9 @@ var Api = {
let restUsers = group.users || (group.restUsers && group.restUsers.User) || [];
restUsers = Array.isArray(restUsers) ? restUsers : [restUsers];
// old users not present in the new users list
let toRemove = restUsers.filter( (user) => group.newUsers.findIndex( u => u.id === user.id) < 0);
let toRemove = restUsers.filter( (user) => findIndex(group.newUsers, u => u.id === user.id) < 0);
// new users not present in the old users list
let toAdd = group.newUsers.filter( (user) => restUsers.findIndex( u => u.id === user.id) < 0);
let toAdd = group.newUsers.filter( (user) => findIndex(restUsers, u => u.id === user.id) < 0);

// create callbacks
let removeCallbacks = toRemove.map( (user) => () => this.removeUserFromGroup(user.id, group.id, options) );
Expand Down
3 changes: 2 additions & 1 deletion web/client/components/TOC/fragments/settings/WMSStyle.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ var React = require('react');
const Message = require('../../../I18N/Message');
const Select = require('react-select');
const {Button, Glyphicon, Alert} = require('react-bootstrap');
const {findIndex} = require('lodash');

require('react-select/dist/react-select.css');

Expand Down Expand Up @@ -50,7 +51,7 @@ const WMSStyle = React.createClass({
let options = [{label: "Default Style", value: ""}].concat((this.props.element.availableStyles || []).map((item) => {
return {label: this.renderItemLabel(item), value: item.name};
}));
let currentStyleIndex = this.props.element.style && this.props.element.availableStyles && this.props.element.availableStyles.findIndex( el => el.name === this.props.element.style);
let currentStyleIndex = this.props.element.style && this.props.element.availableStyles && findIndex(this.props.element.availableStyles, el => el.name === this.props.element.style);
if (!(currentStyleIndex >= 0) && this.props.element.style) {
options.push({label: this.props.element.style, value: this.props.element.style });
}
Expand Down
5 changes: 3 additions & 2 deletions web/client/components/data/featuregrid/DockedFeatureGrid.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const FeatureGrid = connect((state) => {
};
}, {})(require('./FeatureGrid'));

const {head} = require('lodash');
const I18N = require('../../../components/I18N/I18N');
const Spinner = require('react-spinkit');
const assign = require('object-assign');
Expand Down Expand Up @@ -156,7 +157,7 @@ const DockedFeatureGrid = React.createClass({
return `${params.startRow}_${params.endRow}_${params.sortModel.map((m) => `${m.colId}_${m.sort}` ).join('_')}`;
},
getSortAttribute(colId) {
let col = this.props.columnsDef.find((c) => colId === `properties.${c.field}`);
let col = head(this.props.columnsDef.filter((c) => colId === `properties.${c.field}`));
return col && col.sortAttribute ? col.sortAttribute : '';
},
getSortOptions(params) {
Expand Down Expand Up @@ -233,7 +234,7 @@ const DockedFeatureGrid = React.createClass({

if (this.sortModel && this.sortModel.length > 0) {
cols = cols.map((c) => {
let model = this.sortModel.find((m) => m.colId === c.field);
let model = head(this.sortModel.filter((m) => m.colId === c.field));
if ( model ) {
c.sort = model.sort;
}
Expand Down
3 changes: 2 additions & 1 deletion web/client/components/data/identify/Identify.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

const React = require('react');
const {Panel, Glyphicon} = require('react-bootstrap');
const {findIndex} = require('lodash');

require('./css/identify.css');

Expand Down Expand Up @@ -234,7 +235,7 @@ const Identify = React.createClass({
}else if (next === "params" && excludeList.length > 0) {
let params = layer[next];
Object.keys(params).forEach((n) => {
if (excludeList.findIndex((el) => {return (el === n); }) === -1) {
if (findIndex(excludeList, (el) => {return (el === n); }) === -1) {
op[n] = params[n];
}
}, {});
Expand Down
10 changes: 5 additions & 5 deletions web/client/components/data/query/SimpleFilterField.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const {Panel, ButtonToolbar, Button, OverlayTrigger, Tooltip} = require('react-b
const ComboField = require('./ComboField');
const NumberField = require('./NumberField');
const TextField = require('./TextField');
const {isEqual} = require('lodash');
const {isEqual, head, findIndex} = require('lodash');

const SimpleFilterField = React.createClass({
propTypes: {
Expand Down Expand Up @@ -122,9 +122,9 @@ const SimpleFilterField = React.createClass({
}, this);
if ( this.props.defaultOptions.length > 0) {
optionsValues = this.props.defaultOptions.reduce((opts, opt) => {
let nOpt = optionsValues.find((v) => {
let nOpt = head(optionsValues.filter((v) => {
return v === opt;
});
}));
if (nOpt) {
opts.push(nOpt);
}
Expand Down Expand Up @@ -156,7 +156,7 @@ const SimpleFilterField = React.createClass({
type="radio"
value={opt}
name={this.props.attribute}
checked={this.props.values.findIndex((val) => { return val === opt; }) !== -1}/>
checked={findIndex(this.props.values, (val) => { return val === opt; }) !== -1}/>
{this.renderLabel(opt)}
</label>);
}, this);
Expand All @@ -176,7 +176,7 @@ const SimpleFilterField = React.createClass({
value={opt}
type="checkbox"
onChange={this.onCheckChange}
checked={this.props.values.findIndex((val) => { return val === opt; }) !== -1}/>
checked={findIndex(this.props.values, (val) => { return val === opt; }) !== -1}/>
{this.renderLabel(opt)}
</label>
);
Expand Down
4 changes: 3 additions & 1 deletion web/client/components/manager/importer/Importer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ const Import = require('./Import');
const Transform = require('./Transform');
const {Grid, Col, Row, Alert} = require('react-bootstrap');
const BreadCrumb = require('./BreadCrumb');
const {head} = require('lodash');

const Importer = React.createClass({
propTypes: {
loading: React.PropTypes.bool,
Expand Down Expand Up @@ -109,7 +111,7 @@ const Importer = React.createClass({
}
};
}
return presets.find((preset) => preset.import );
return head(presets.filter((preset) => preset.import ));
},
getTargetWorkspace(selectedImport) {
let targetWorkspace = selectedImport && selectedImport.targetWorkspace;
Expand Down
3 changes: 2 additions & 1 deletion web/client/components/manager/importer/ImportsGrid.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const Spinner = require('react-spinkit');
const Message = require('../../I18N/Message');
const ImporterUtils = require('../../../utils/ImporterUtils');
const {Table, Glyphicon, Button, Label, OverlayTrigger, Tooltip} = require('react-bootstrap');
const {findIndex} = require('lodash');

const ImportsGrid = React.createClass({
propTypes: {
Expand Down Expand Up @@ -100,7 +101,7 @@ const ImportsGrid = React.createClass({
},
update() {
if (this.props.imports) {
let i = this.props.imports.findIndex((importObj) => importObj.state === "RUNNING");
let i = findIndex(this.props.imports, (importObj) => importObj.state === "RUNNING");
if ( i >= 0 ) {
this.props.loadImports();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
const React = require('react');
const {Input} = require('react-bootstrap');
const assign = require('object-assign');

const {findIndex} = require('lodash');

const {Message, Alert} = require('../../../I18N/I18N');

Expand Down Expand Up @@ -44,8 +44,8 @@ const GdalTranslateTransform = React.createClass({
</form>);
},
isValid(t) {
return t && t.options && t.options.findIndex((e) => e === "") < 0 &&
t.levels && t.levels.findIndex((e) => e === "") < 0;
return t && t.options && findIndex(t.options, (e) => e === "") < 0 &&
t.levels && findIndex(t.levels, (e) => e === "") < 0;
}
});
module.exports = GdalTranslateTransform;
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const {Input, Alert} = require('react-bootstrap');
const assign = require('object-assign');

const {Message} = require('../../../I18N/I18N');
const {findIndex} = require('lodash');

const GdalTranslateTransform = React.createClass({
propTypes: {
Expand Down Expand Up @@ -42,7 +43,7 @@ const GdalTranslateTransform = React.createClass({
</div>);
},
isValid(t) {
return t && t.options && t.options.findIndex((e) => e === "") < 0;
return t && t.options && findIndex(t.options, (e) => e === "") < 0;
}
});
module.exports = GdalTranslateTransform;
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const React = require('react');
const {Panel} = require('react-bootstrap');
const _ = require('lodash');
const Select = require('./RuleAttributeSelect');
const {head} = require('lodash');

const ACCESS_TYPES = [
'ALLOW',
Expand Down Expand Up @@ -125,7 +126,7 @@ const RuleAttributes = React.createClass({
);
},
filterValue(value, values) {
if (value && values.find(existing => existing === value)) {
if (value && head(values.filter(existing => existing === value))) {
return value;
}
return undefined;
Expand Down
6 changes: 4 additions & 2 deletions web/client/components/manager/users/GroupDialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ const assign = require('object-assign');
const Message = require('../../../components/I18N/Message');
const Spinner = require('react-spinkit');
const Select = require("react-select");
const {findIndex} = require('lodash');

require('./style/userdialog.css');
/**
* A Modal window to show password reset form
Expand Down Expand Up @@ -144,7 +146,7 @@ const GroupDialog = React.createClass({
}}/>);
},
renderMembersTab() {
let availableUsers = this.props.availableUsers.filter((user) => this.getCurrentGroupMembers().findIndex( member => member.id === user.id) < 0).map(u => ({value: u.id, label: u.name}));
let availableUsers = this.props.availableUsers.filter((user) => findIndex(this.getCurrentGroupMembers(), member => member.id === user.id) < 0).map(u => ({value: u.id, label: u.name}));
return (<div>
<label key="member-label" className="control-label"><Message msgId="usergroups.groupMembers" /></label>
<div key="member-list" style={
Expand All @@ -163,7 +165,7 @@ const GroupDialog = React.createClass({
onInputChange={this.props.searchUsers}
onChange={(selected) => {
let value = selected.value;
let newMemberIndex = this.props.availableUsers.findIndex(u => u.id === value);
let newMemberIndex = findIndex(this.props.availableUsers, u => u.id === value);
if (newMemberIndex >= 0) {
let newMember = this.props.availableUsers[newMemberIndex];
let newUsers = this.getCurrentGroupMembers();
Expand Down
4 changes: 3 additions & 1 deletion web/client/components/manager/users/UserDialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ const UserGroups = require('./UserGroups');
const assign = require('object-assign');
const Message = require('../../../components/I18N/Message');
const Spinner = require('react-spinkit');
const {findIndex} = require('lodash');

require('./style/userdialog.css');
/**
* A Modal window to show password reset form
Expand Down Expand Up @@ -75,7 +77,7 @@ const UserDialog = React.createClass({
getAttributeValue(name) {
let attrs = this.props.user && this.props.user.attribute;
if (attrs) {
let index = attrs.findIndex( a => a.name === name);
let index = findIndex(attrs, a => a.name === name);
return attrs[index] && attrs[index].value;
}
},
Expand Down
3 changes: 2 additions & 1 deletion web/client/components/manager/users/UserGroups.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const React = require('react');
// const Message = require('../I18N/Message');
const Select = require('react-select');
const Message = require('../../I18N/Message');
const {findIndex} = require('lodash');

require('react-select/dist/react-select.css');

Expand All @@ -36,7 +37,7 @@ const UserCard = React.createClass({
return;
}
this.props.onUserGroupsChange("groups", values.map((group) => {
let index = this.props.groups.findIndex((availableGroup)=>availableGroup.id === group.value);
let index = findIndex(this.props.groups, (availableGroup)=>availableGroup.id === group.value);
return index >= 0 ? this.props.groups[index] : null;
}).filter(group => group));
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

const React = require('react');
const {findIndex} = require('lodash');

const HighlightFeatureSupport = React.createClass({
propTypes: {
Expand Down Expand Up @@ -89,7 +90,7 @@ const HighlightFeatureSupport = React.createClass({
featureClicked(e) {
let layer = e.layer;
if ((e.originalEvent.ctrlKey || e.originalEvent.metaKey) && layer) {
let idx = this._selectedFeatures.findIndex((f) => {
let idx = findIndex(this._selectedFeatures, (f) => {
return f === layer;
});
if (idx !== -1) {
Expand Down
3 changes: 3 additions & 0 deletions web/client/components/map/leaflet/snapshot/GrabMap.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ const ProxyUtils = require('../../../../utils/ProxyUtils');
const {isEqual} = require('lodash');
const html2canvas = require('html2canvas');
const canvg = require('canvg-browser');

const {Promise} = require('es6-promise');

require("./snapshotMapStyle.css");
/**
* GrabMap for Leaflet uses HTML2CANVAS to generate the image for the existing
Expand Down
2 changes: 2 additions & 0 deletions web/client/components/shapefile/ShapefileUploadAndStyle.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ const Combobox = require('react-widgets').DropdownList;

const SelectShape = require('./SelectShape');

const {Promise} = require('es6-promise');

const ShapeFileUploadAndStyle = React.createClass({
propTypes: {
bbox: React.PropTypes.array,
Expand Down
5 changes: 4 additions & 1 deletion web/client/plugins/QueryPanel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ const {connect} = require('react-redux');
const Sidebar = require('react-sidebar').default;
const {createSelector} = require('reselect');
const {changeLayerProperties, changeGroupProperties, toggleNode,
sortNode, showSettings, hideSettings, updateSettings, updateNode, removeNode, getLayerCapabilities} = require('../actions/layers');
sortNode, showSettings, hideSettings, updateSettings, updateNode, removeNode} = require('../actions/layers');

const {getLayerCapabilities} = require('../actions/layerCapabilities');

const {zoomToExtent} = require('../actions/map');
const {toggleControl} = require('../actions/controls');

Expand Down
3 changes: 2 additions & 1 deletion web/client/plugins/TOC.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ const {createSelector} = require('reselect');
const {Button, Glyphicon} = require('react-bootstrap');

const {changeLayerProperties, changeGroupProperties, toggleNode,
sortNode, showSettings, hideSettings, updateSettings, updateNode, removeNode, getLayerCapabilities} = require('../actions/layers');
sortNode, showSettings, hideSettings, updateSettings, updateNode, removeNode} = require('../actions/layers');
const {getLayerCapabilities} = require('../actions/layerCapabilities');
const {zoomToExtent} = require('../actions/map');

const {groupsSelector} = require('../selectors/layers');
Expand Down
3 changes: 2 additions & 1 deletion web/client/plugins/manager/users/GroupDeleteConfirm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const {Alert} = require('react-bootstrap');
const Confirm = require('../../../components/misc/ConfirmDialog');
const GroupCard = require('../../../components/manager/users/GroupCard');
const Message = require('../../../components/I18N/Message');
const {findIndex} = require('lodash');

const GroupDeleteConfirm = React.createClass({
propTypes: {
Expand Down Expand Up @@ -62,7 +63,7 @@ module.exports = connect((state) => {
let groups = groupsstate && groupsstate.groups;
let deleteId = groupsstate.deletingGroup && groupsstate.deletingGroup.id;
if (groups && deleteId) {
let index = groups.findIndex((user) => user.id === deleteId);
let index = findIndex(groups, (user) => user.id === deleteId);
let group = groups[index];
return {
group,
Expand Down
3 changes: 2 additions & 1 deletion web/client/plugins/manager/users/UserDeleteConfirm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const {Alert} = require('react-bootstrap');
const Confirm = require('../../../components/misc/ConfirmDialog');
const UserCard = require('../../../components/manager/users/UserCard');
const Message = require('../../../components/I18N/Message');
const {findIndex} = require('lodash');

const UserDeleteConfirm = React.createClass({
propTypes: {
Expand Down Expand Up @@ -62,7 +63,7 @@ module.exports = connect((state) => {
let users = usersState && usersState.users;
let deleteId = usersState.deletingUser && usersState.deletingUser.id;
if (users && deleteId) {
let index = users.findIndex((user) => user.id === deleteId);
let index = findIndex(users, (user) => user.id === deleteId);
let user = users[index];
return {
user,
Expand Down
Loading

0 comments on commit 1c72552

Please sign in to comment.