From 1c7255218cb4d2354516b830fbd9d27f6a684129 Mon Sep 17 00:00:00 2001 From: Mauro Bartolomeoli Date: Fri, 23 Dec 2016 12:19:11 +0100 Subject: [PATCH] Fixes #1369: avoid array methods and Promise not available on IE --- web/client/api/GeoStoreDAO.js | 5 +++-- .../TOC/fragments/settings/WMSStyle.jsx | 3 ++- .../data/featuregrid/DockedFeatureGrid.jsx | 5 +++-- .../components/data/identify/Identify.jsx | 3 ++- .../components/data/query/SimpleFilterField.jsx | 10 +++++----- .../components/manager/importer/Importer.jsx | 4 +++- .../components/manager/importer/ImportsGrid.jsx | 3 ++- .../importer/transforms/GdalAddoTransform.jsx | 6 +++--- .../transforms/GdalTranslateTransform.jsx | 3 ++- .../manager/rulesmanager/RuleAttributes.jsx | 3 ++- .../components/manager/users/GroupDialog.jsx | 6 ++++-- .../components/manager/users/UserDialog.jsx | 4 +++- .../components/manager/users/UserGroups.jsx | 3 ++- .../map/leaflet/HighlightFeatureSupport.jsx | 3 ++- .../components/map/leaflet/snapshot/GrabMap.jsx | 3 +++ .../shapefile/ShapefileUploadAndStyle.jsx | 2 ++ web/client/plugins/QueryPanel.jsx | 5 ++++- web/client/plugins/TOC.jsx | 3 ++- .../manager/users/GroupDeleteConfirm.jsx | 3 ++- .../plugins/manager/users/UserDeleteConfirm.jsx | 3 ++- web/client/reducers/importer.js | 17 +++++++++-------- web/client/reducers/layers.js | 8 ++++---- web/client/reducers/rulesmanager.js | 2 +- web/client/reducers/security.js | 4 ++-- web/client/reducers/users.js | 5 ++++- web/client/reducers/vectorstyler.js | 4 ++-- web/client/selectors/vectorstyler.js | 12 ++++++++++-- web/client/utils/SecurityUtils.js | 9 +++++---- 28 files changed, 90 insertions(+), 51 deletions(-) diff --git a/web/client/api/GeoStoreDAO.js b/web/client/api/GeoStoreDAO.js index d3149b9721..91fb28a956 100644 --- a/web/client/api/GeoStoreDAO.js +++ b/web/client/api/GeoStoreDAO.js @@ -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; @@ -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) ); diff --git a/web/client/components/TOC/fragments/settings/WMSStyle.jsx b/web/client/components/TOC/fragments/settings/WMSStyle.jsx index 10a6d02cd2..237528e6e4 100644 --- a/web/client/components/TOC/fragments/settings/WMSStyle.jsx +++ b/web/client/components/TOC/fragments/settings/WMSStyle.jsx @@ -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'); @@ -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 }); } diff --git a/web/client/components/data/featuregrid/DockedFeatureGrid.jsx b/web/client/components/data/featuregrid/DockedFeatureGrid.jsx index 960f201de8..684afae256 100644 --- a/web/client/components/data/featuregrid/DockedFeatureGrid.jsx +++ b/web/client/components/data/featuregrid/DockedFeatureGrid.jsx @@ -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'); @@ -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) { @@ -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; } diff --git a/web/client/components/data/identify/Identify.jsx b/web/client/components/data/identify/Identify.jsx index 618af5b805..27cfe77c5a 100644 --- a/web/client/components/data/identify/Identify.jsx +++ b/web/client/components/data/identify/Identify.jsx @@ -8,6 +8,7 @@ const React = require('react'); const {Panel, Glyphicon} = require('react-bootstrap'); +const {findIndex} = require('lodash'); require('./css/identify.css'); @@ -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]; } }, {}); diff --git a/web/client/components/data/query/SimpleFilterField.jsx b/web/client/components/data/query/SimpleFilterField.jsx index 088d4a11f1..350f49cbd1 100644 --- a/web/client/components/data/query/SimpleFilterField.jsx +++ b/web/client/components/data/query/SimpleFilterField.jsx @@ -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: { @@ -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); } @@ -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)} ); }, this); @@ -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)} ); diff --git a/web/client/components/manager/importer/Importer.jsx b/web/client/components/manager/importer/Importer.jsx index 1645e177e2..020457c82f 100644 --- a/web/client/components/manager/importer/Importer.jsx +++ b/web/client/components/manager/importer/Importer.jsx @@ -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, @@ -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; diff --git a/web/client/components/manager/importer/ImportsGrid.jsx b/web/client/components/manager/importer/ImportsGrid.jsx index 1a46d00731..73b53ddc04 100644 --- a/web/client/components/manager/importer/ImportsGrid.jsx +++ b/web/client/components/manager/importer/ImportsGrid.jsx @@ -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: { @@ -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(); } diff --git a/web/client/components/manager/importer/transforms/GdalAddoTransform.jsx b/web/client/components/manager/importer/transforms/GdalAddoTransform.jsx index 5d1437ec5d..83c4a92fa1 100644 --- a/web/client/components/manager/importer/transforms/GdalAddoTransform.jsx +++ b/web/client/components/manager/importer/transforms/GdalAddoTransform.jsx @@ -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'); @@ -44,8 +44,8 @@ const GdalTranslateTransform = React.createClass({ ); }, 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; diff --git a/web/client/components/manager/importer/transforms/GdalTranslateTransform.jsx b/web/client/components/manager/importer/transforms/GdalTranslateTransform.jsx index 3878445dbd..fe0bd56765 100644 --- a/web/client/components/manager/importer/transforms/GdalTranslateTransform.jsx +++ b/web/client/components/manager/importer/transforms/GdalTranslateTransform.jsx @@ -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: { @@ -42,7 +43,7 @@ const GdalTranslateTransform = React.createClass({ ); }, 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; diff --git a/web/client/components/manager/rulesmanager/RuleAttributes.jsx b/web/client/components/manager/rulesmanager/RuleAttributes.jsx index a3937acede..a677ddd623 100644 --- a/web/client/components/manager/rulesmanager/RuleAttributes.jsx +++ b/web/client/components/manager/rulesmanager/RuleAttributes.jsx @@ -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', @@ -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; diff --git a/web/client/components/manager/users/GroupDialog.jsx b/web/client/components/manager/users/GroupDialog.jsx index 1db428c68f..291b50eaa8 100644 --- a/web/client/components/manager/users/GroupDialog.jsx +++ b/web/client/components/manager/users/GroupDialog.jsx @@ -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 @@ -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 (
{ 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(); diff --git a/web/client/components/manager/users/UserDialog.jsx b/web/client/components/manager/users/UserDialog.jsx index 914fbeaa31..0f111425e7 100644 --- a/web/client/components/manager/users/UserDialog.jsx +++ b/web/client/components/manager/users/UserDialog.jsx @@ -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 @@ -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; } }, diff --git a/web/client/components/manager/users/UserGroups.jsx b/web/client/components/manager/users/UserGroups.jsx index cea0a522e1..e47d75dc2a 100644 --- a/web/client/components/manager/users/UserGroups.jsx +++ b/web/client/components/manager/users/UserGroups.jsx @@ -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'); @@ -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)); }, diff --git a/web/client/components/map/leaflet/HighlightFeatureSupport.jsx b/web/client/components/map/leaflet/HighlightFeatureSupport.jsx index ed81627768..3c1b4445ff 100644 --- a/web/client/components/map/leaflet/HighlightFeatureSupport.jsx +++ b/web/client/components/map/leaflet/HighlightFeatureSupport.jsx @@ -7,6 +7,7 @@ */ const React = require('react'); +const {findIndex} = require('lodash'); const HighlightFeatureSupport = React.createClass({ propTypes: { @@ -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) { diff --git a/web/client/components/map/leaflet/snapshot/GrabMap.jsx b/web/client/components/map/leaflet/snapshot/GrabMap.jsx index 790a1a7688..179cfcf82b 100644 --- a/web/client/components/map/leaflet/snapshot/GrabMap.jsx +++ b/web/client/components/map/leaflet/snapshot/GrabMap.jsx @@ -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 diff --git a/web/client/components/shapefile/ShapefileUploadAndStyle.jsx b/web/client/components/shapefile/ShapefileUploadAndStyle.jsx index a45e5e65cd..76d0169584 100644 --- a/web/client/components/shapefile/ShapefileUploadAndStyle.jsx +++ b/web/client/components/shapefile/ShapefileUploadAndStyle.jsx @@ -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, diff --git a/web/client/plugins/QueryPanel.jsx b/web/client/plugins/QueryPanel.jsx index 2a26e19972..82c797fc26 100644 --- a/web/client/plugins/QueryPanel.jsx +++ b/web/client/plugins/QueryPanel.jsx @@ -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'); diff --git a/web/client/plugins/TOC.jsx b/web/client/plugins/TOC.jsx index c4a5d1370f..2acd841bc2 100644 --- a/web/client/plugins/TOC.jsx +++ b/web/client/plugins/TOC.jsx @@ -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'); diff --git a/web/client/plugins/manager/users/GroupDeleteConfirm.jsx b/web/client/plugins/manager/users/GroupDeleteConfirm.jsx index 8a4e5ce43c..2ac59a6059 100644 --- a/web/client/plugins/manager/users/GroupDeleteConfirm.jsx +++ b/web/client/plugins/manager/users/GroupDeleteConfirm.jsx @@ -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: { @@ -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, diff --git a/web/client/plugins/manager/users/UserDeleteConfirm.jsx b/web/client/plugins/manager/users/UserDeleteConfirm.jsx index 49617dc9f8..bc63c718ab 100644 --- a/web/client/plugins/manager/users/UserDeleteConfirm.jsx +++ b/web/client/plugins/manager/users/UserDeleteConfirm.jsx @@ -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: { @@ -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, diff --git a/web/client/reducers/importer.js b/web/client/reducers/importer.js index a5b7d52a1b..32051d92a8 100644 --- a/web/client/reducers/importer.js +++ b/web/client/reducers/importer.js @@ -41,6 +41,7 @@ const { } = require('../actions/manager'); const assign = require('object-assign'); +const {head, findIndex} = require('lodash'); // constant used to reset the state only if the importer tool is passed to the reducer // see case: MANAGER_ITEM_SELECTED @@ -54,7 +55,7 @@ function updateArray(tasks, newTask) { if (!newTask || !tasks) { return tasks; } - let taskIndex = tasks.findIndex( (task) => task.id === newTask.id ); + let taskIndex = findIndex(tasks, (task) => task.id === newTask.id ); if (taskIndex >= 0 && newTask !== tasks[taskIndex]) { let newTasks = tasks.slice(); newTasks[taskIndex] = newTask; @@ -72,7 +73,7 @@ function updateImportLoadingStatus(state, action, loading = true) { selectedImport = assign({}, selectedImport, {loading: loading}); } // update imports list - imports = updateArray(imports, assign({}, imports.find((imp) => imp.id === importId), {loading: loading})); + imports = updateArray(imports, assign({}, head(imports.filter((imp) => imp.id === importId), {loading: loading}))); return assign({}, state, { uploading: action.details && action.details.uploadingFiles !== undefined || state.uploading, loading: loading, @@ -96,7 +97,7 @@ function updateImportTaskLoadingStatus(state, action, loading = true) { element: action.details && action.details.element }); } - let newTask = assign({}, selectedImport.tasks.find((task) => task.id === taskId), { + let newTask = assign({}, head(selectedImport.tasks.filter((task) => task.id === taskId)), { loading: loading, message: action.details && action.details.message, element: action.details && action.details.element @@ -108,11 +109,11 @@ function updateImportTaskLoadingStatus(state, action, loading = true) { } } // update imports list's task - let impIndex = imports && imports.findIndex((imp) => imp.id === importId); + let impIndex = imports && findIndex(imports, (imp) => imp.id === importId); if ( imports && impIndex >= 0 ) { imports = imports.concat(); let imp = imports[impIndex]; - let taskIndex = imp && imp.tasks && imp.tasks.findIndex((task) => task.id === taskId); + let taskIndex = imp && imp.tasks && findIndex(imp.tasks, (task) => task.id === taskId); if ( imp && imp.tasks && taskIndex >= 0 ) { let task = assign({}, task, { loading: loading, @@ -197,7 +198,7 @@ function importer(state = {}, action) { } let tasks = state.tasks; if (tasks && action.task) { - let index = tasks.findIndex((task) => task.id === action.task.id); + let index = findIndex(tasks, (task) => task.id === action.task.id); if (index >= 0) { tasks = tasks.concat(); tasks[index] = action.task; @@ -223,7 +224,7 @@ function importer(state = {}, action) { } if (selectedImport && (selectedImport.id === action.importId)) { - let index = tasks.findIndex((task) => task.id === action.taskId); + let index = findIndex(tasks, (task) => task.id === action.taskId); if (index >= 0) { tasks = tasks.concat(); tasks[index] = assign({}, tasks[index], action.info); @@ -330,7 +331,7 @@ function importer(state = {}, action) { } case IMPORT_DELETE: { let imports = state && state.imports; - let importIndex = imports && imports.findIndex((imp) => imp.id === action.id); + let importIndex = imports && findIndex(imports, (imp) => imp.id === action.id); if (importIndex >= 0) { imports = state.imports.filter((imp) => imp.id !== action.id); } diff --git a/web/client/reducers/layers.js b/web/client/reducers/layers.js index 7d6a596c42..01ea66f450 100644 --- a/web/client/reducers/layers.js +++ b/web/client/reducers/layers.js @@ -12,7 +12,7 @@ var {LAYER_LOADING, LAYER_LOAD, LAYER_ERROR, CHANGE_LAYER_PROPERTIES, CHANGE_GRO } = require('../actions/layers'); var assign = require('object-assign'); -var {isObject, isArray, head} = require('lodash'); +var {isObject, isArray, head, findIndex} = require('lodash'); const LayersUtils = require('../utils/LayersUtils'); @@ -59,9 +59,9 @@ const removeNode = (groups, nodeId) => { // add the newGroup to the list if it does not already exists const addGroup = (groups, newGroup) => { - return groups.find( + return head(groups.filter( (group) => group.id === newGroup - ) ? + )) ? groups : groups.concat({ id: newGroup, @@ -270,7 +270,7 @@ function layers(state = [], action) { let groupName = layer && layer.group ? layer.group : 'Default'; let newLayers = (state.flat || []).filter(lyr => lyr.id !== action.layerId); let newGroups = (state.groups || []).concat(); - let gidx = newGroups.findIndex(entry => entry.id === groupName); + let gidx = findIndex(newGroups, entry => entry.id === groupName); if (gidx >= 0) { let newGroup = assign({}, newGroups[gidx]); let nidx = newGroup.nodes.indexOf(action.layerId); diff --git a/web/client/reducers/rulesmanager.js b/web/client/reducers/rulesmanager.js index 3ea1ca3f0b..a82b65c109 100644 --- a/web/client/reducers/rulesmanager.js +++ b/web/client/reducers/rulesmanager.js @@ -25,7 +25,7 @@ function rulesmanager(state = {}, action) { if (action.unselect) { return assign({}, state, { selectedRules: _(existingRules).filter( - rule => !newRules.find(unselected => unselected.id === rule.id)).value() + rule => !_.head(newRules.filter(unselected => unselected.id === rule.id))).value() }); } return assign({}, state, { diff --git a/web/client/reducers/security.js b/web/client/reducers/security.js index 901756deb3..9045ac2961 100644 --- a/web/client/reducers/security.js +++ b/web/client/reducers/security.js @@ -12,7 +12,7 @@ const { USERMANAGER_UPDATE_USER } = require('../actions/users'); const SecurityUtils = require('../utils/SecurityUtils'); const assign = require('object-assign'); -const {cloneDeep} = require('lodash'); +const {cloneDeep, head} = require('lodash'); function security(state = {user: null, errorCause: null}, action) { switch (action.type) { @@ -25,7 +25,7 @@ function security(state = {user: null, errorCause: null}, action) { return state; case LOGIN_SUCCESS: const userAttributes = SecurityUtils.getUserAttributes(action.userDetails.User); - const userUuid = userAttributes.find(attribute => attribute.name.toLowerCase() === 'uuid'); + const userUuid = head(userAttributes.filter(attribute => attribute.name.toLowerCase() === 'uuid')); return assign({}, state, { user: action.userDetails.User, token: userUuid && userUuid.value || '', diff --git a/web/client/reducers/users.js b/web/client/reducers/users.js index 1889753895..65b9212d8a 100644 --- a/web/client/reducers/users.js +++ b/web/client/reducers/users.js @@ -11,6 +11,9 @@ const { USERMANAGER_GETGROUPS, USERS_SEARCH_TEXT_CHANGED } = require('../actions/users'); const assign = require('object-assign'); + +const {findIndex} = require('lodash'); + function users(state = { start: 0, limit: 12 @@ -57,7 +60,7 @@ function users(state = { if ( k.indexOf("attribute") === 0) { let attrs = (currentUser.attribute || []).concat(); let attrName = k.split(".")[1]; - let attrIndex = attrs.findIndex((att) => att.name === attrName); + let attrIndex = findIndex(attrs, (att) => att.name === attrName); if (attrIndex >= 0) { attrs[attrIndex] = {name: attrName, value: action.newValue}; } else { diff --git a/web/client/reducers/vectorstyler.js b/web/client/reducers/vectorstyler.js index 87bf5d1c84..9075f81177 100644 --- a/web/client/reducers/vectorstyler.js +++ b/web/client/reducers/vectorstyler.js @@ -16,7 +16,7 @@ const { } = require('../actions/vectorstyler'); const { STYLER_RESET } = require('../actions/styler'); const assign = require('object-assign'); -const {isObject} = require('lodash'); +const {isObject, findIndex} = require('lodash'); const baseStyle = { Point: { type: "Point", @@ -75,7 +75,7 @@ function getBaseSymbol(type = "Polygon") { } function getRuleIdx(rules, id) { - return rules.findIndex((r) => {return r.id === id; }); + return findIndex(rules, (r) => {return r.id === id; }); } function vectorstyler(state = initialSpec, action) { diff --git a/web/client/selectors/vectorstyler.js b/web/client/selectors/vectorstyler.js index 4db3c2bbe8..917469bd1d 100644 --- a/web/client/selectors/vectorstyler.js +++ b/web/client/selectors/vectorstyler.js @@ -1,7 +1,15 @@ -const {createSelector} = require('reselect'); +/** + * 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 {createSelector} = require('reselect'); +const {head} = require('lodash'); -const ruleselctor = (state) => state.vectorstyler && state.vectorstyler.rule && state.vectorstyler.rules.find((r) => {return r.id === state.vectorstyler.rule; }); +const ruleselctor = (state) => state.vectorstyler && state.vectorstyler.rule && head(state.vectorstyler.rules.filter((r) => {return r.id === state.vectorstyler.rule; })); const symbolselector = createSelector([ruleselctor], (rule) => ({ diff --git a/web/client/utils/SecurityUtils.js b/web/client/utils/SecurityUtils.js index b58356f755..87c915df96 100644 --- a/web/client/utils/SecurityUtils.js +++ b/web/client/utils/SecurityUtils.js @@ -9,6 +9,7 @@ const ConfigUtils = require('./ConfigUtils'); const URL = require('url'); const assign = require('object-assign'); +const {head} = require('lodash'); /** * This utility class will get information about the current logged user directly from the store. @@ -80,8 +81,8 @@ const SecurityUtils = { // the user as no attributes or the provided attribute name is undefined return undefined; } - return userAttributes.find(attribute => attribute.name - && attribute.name.toLowerCase() === attributeName.toLowerCase()); + return head(userAttributes.filter(attribute => attribute.name + && attribute.name.toLowerCase() === attributeName.toLowerCase())); }, /** @@ -116,8 +117,8 @@ const SecurityUtils = { * the provided URL, if no rule matchs the provided URL undefined is returned. */ getAuthenticationMethod: function(url) { - const foundRule = this.getAuthenticationRules().find( - rule => rule && rule.urlPattern && url.match(new RegExp(rule.urlPattern, "i"))); + const foundRule = head(this.getAuthenticationRules().filter( + rule => rule && rule.urlPattern && url.match(new RegExp(rule.urlPattern, "i")))); return foundRule ? foundRule.method : undefined; },