From c9a82975beea0ecf4422ba5c4a89f80b8a1b3286 Mon Sep 17 00:00:00 2001 From: saidaipparla Date: Fri, 16 Dec 2016 14:22:45 +0100 Subject: [PATCH] Fix #1291. Add Group manager plugin (#1352) Fixes #1291 introducing GroupManager Plugin. Makes GroupManager and UserManager two independent plugins --- web/client/localConfig.json | 8 +- web/client/plugins/manager/GroupManager.jsx | 117 ++++++++++++++++++ web/client/plugins/manager/UserManager.jsx | 102 +++++++++++---- .../plugins/manager/users/SearchBar.jsx | 70 ----------- .../plugins/manager/users/TopButtons.jsx | 75 ----------- web/client/product/plugins.js | 1 + 6 files changed, 205 insertions(+), 168 deletions(-) create mode 100644 web/client/plugins/manager/GroupManager.jsx delete mode 100644 web/client/plugins/manager/users/SearchBar.jsx delete mode 100644 web/client/plugins/manager/users/TopButtons.jsx diff --git a/web/client/localConfig.json b/web/client/localConfig.json index ac3d160af1..4fa3a2544d 100644 --- a/web/client/localConfig.json +++ b/web/client/localConfig.json @@ -835,6 +835,12 @@ "cfg": { "id": "usermanager" } - }] + },{ + "name": "GroupManager", + "hide": true, + "cfg": { + "id": "GroupManager" + } + }] } } diff --git a/web/client/plugins/manager/GroupManager.jsx b/web/client/plugins/manager/GroupManager.jsx new file mode 100644 index 0000000000..6f741f302a --- /dev/null +++ b/web/client/plugins/manager/GroupManager.jsx @@ -0,0 +1,117 @@ +/** + * 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 React = require('react'); +const {connect} = require('react-redux'); +const {Button, Grid, Glyphicon} = require('react-bootstrap'); +const {editGroup} = require('../../actions/usergroups'); +const {getUserGroups, groupSearchTextChanged} = require('../../actions/usergroups'); +const SearchBar = require("../../components/mapcontrols/search/SearchBar"); +const GroupsGrid = require('./users/GroupGrid'); +const GroupDialog = require('./users/GroupDialog'); +const GroupDeleteConfirm = require('./users/GroupDeleteConfirm'); +const Message = require('../../components/I18N/Message'); +const assign = require('object-assign'); +const {trim} = require('lodash'); +const GroupManager = React.createClass({ + propTypes: { + onNewGroup: React.PropTypes.func, + className: React.PropTypes.string, + hideOnBlur: React.PropTypes.bool, + placeholderMsgId: React.PropTypes.string, + typeAhead: React.PropTypes.bool, + searchText: React.PropTypes.string, + onSearch: React.PropTypes.func, + onSearchReset: React.PropTypes.func, + onSearchTextChange: React.PropTypes.func, + start: React.PropTypes.number, + limit: React.PropTypes.number + }, + getDefaultProps() { + return { + className: "user-search", + hideOnBlur: false, + placeholderMsgId: "usergroups.searchGroups", + typeAhead: false, + searchText: "", + start: 0, + limit: 20, + onNewGroup: () => {}, + onSearch: () => {}, + onSearchReset: () => {}, + onSearchTextChange: () => {} + }; + }, + onNew() { + this.props.onNewGroup(); + }, + render() { + return (
+ + +

+ +
+ + + +
); + } +}); +module.exports = { + GroupManagerPlugin: assign( + connect((state) => { + let searchState = state && state.usergroups; + return { + start: searchState && searchState.start, + limit: searchState && searchState.limit, + searchText: (searchState && searchState.searchText && trim(searchState.searchText, '*')) || "" + }; + }, { + onNewGroup: editGroup.bind(null, {}), + onSearchTextChange: groupSearchTextChanged, + onSearch: getUserGroups + }, (stateProps, dispatchProps) => { + return { + ...stateProps, + ...dispatchProps, + onSearchReset: (text) => { + let limit = stateProps.limit; + let searchText = (text && text !== "") ? ("*" + text + "*") : "*"; + dispatchProps.onSearch(searchText, {params: {start: 0, limit}}); + }, + onSearch: (text) => { + let limit = stateProps.limit; + let searchText = (text && text !== "") ? ("*" + text + "*") : "*"; + dispatchProps.onSearch(searchText, {params: {start: 0, limit}}); + } + }; + })(GroupManager), { + hide: true, + Manager: { + id: "groupmanager", + name: 'groupmanager', + position: 1, + title: , + glyph: "1-group-mod" + }}), + reducers: { + usergroups: require('../../reducers/usergroups') + } +}; diff --git a/web/client/plugins/manager/UserManager.jsx b/web/client/plugins/manager/UserManager.jsx index 88e0b78856..433dcf0c10 100644 --- a/web/client/plugins/manager/UserManager.jsx +++ b/web/client/plugins/manager/UserManager.jsx @@ -7,52 +7,110 @@ */ const React = require('react'); const {connect} = require('react-redux'); -const SearchBar = require('./users/SearchBar'); +const {Button, Grid, Glyphicon} = require('react-bootstrap'); +const {editUser} = require('../../actions/users'); +const {getUsers, usersSearchTextChanged} = require('../../actions/users'); +const SearchBar = require("../../components/mapcontrols/search/SearchBar"); const UserGrid = require('./users/UserGrid'); -const GroupsGrid = require('./users/GroupGrid'); const UserDialog = require('./users/UserDialog'); -const GroupDialog = require('./users/GroupDialog'); -const TopButtons = require('./users/TopButtons'); const UserDeleteConfirm = require('./users/UserDeleteConfirm'); -const GroupDeleteConfirm = require('./users/GroupDeleteConfirm'); const Message = require('../../components/I18N/Message'); const assign = require('object-assign'); - +const {trim} = require('lodash'); const UserManager = React.createClass({ propTypes: { - selectedTool: React.PropTypes.string + onNewUser: React.PropTypes.func, + className: React.PropTypes.string, + hideOnBlur: React.PropTypes.bool, + placeholderMsgId: React.PropTypes.string, + typeAhead: React.PropTypes.bool, + searchText: React.PropTypes.string, + onSearch: React.PropTypes.func, + onSearchReset: React.PropTypes.func, + onSearchTextChange: React.PropTypes.func, + start: React.PropTypes.number, + limit: React.PropTypes.number }, getDefaultProps() { return { - selectedTool: "users" + className: "user-search", + hideOnBlur: false, + placeholderMsgId: "users.searchUsers", + typeAhead: false, + searchText: "", + start: 0, + limit: 20, + onSearch: () => {}, + onSearchReset: () => {}, + onSearchTextChange: () => {}, + onNewUser: () => {} }; }, + onNew() { + this.props.onNewUser(); + }, render() { return (
- - - {this.props.selectedTool === "users" ? : } - - - - -
); + + +

+ +
+ + + + ); } }); module.exports = { UserManagerPlugin: assign( - connect((state) => ({ selectedTool: state && state.controls && state.controls.usermanager && state.controls.usermanager.selectedTool}))(UserManager), { + connect((state) => { + let searchState = state && state.users; + return { + start: searchState && searchState.start, + limit: searchState && searchState.limit, + searchText: (searchState && searchState.searchText && trim(searchState.searchText, '*')) || "" + }; + }, + { + onNewUser: editUser.bind(null, {role: "USER", "enabled": true}), + onSearchTextChange: usersSearchTextChanged, + onSearch: getUsers + }, (stateProps, dispatchProps) => { + return { + ...stateProps, + ...dispatchProps, + onSearchReset: (text) => { + let limit = stateProps.limit; + let searchText = (text && text !== "") ? ("*" + text + "*") : "*"; + dispatchProps.onSearch(searchText, {params: {start: 0, limit}}); + }, + onSearch: (text) => { + let limit = stateProps.limit; + let searchText = (text && text !== "") ? ("*" + text + "*") : "*"; + dispatchProps.onSearch(searchText, {params: {start: 0, limit}}); + } + }; + })(UserManager), { hide: true, Manager: { id: "usermanager", name: 'usermanager', position: 1, - title: , - glyph: "1-group-mod" + title: , + glyph: "1-user-mod" }}), reducers: { - users: require('../../reducers/users'), - usergroups: require('../../reducers/usergroups'), - controls: require('../../reducers/controls') + users: require('../../reducers/users') } }; diff --git a/web/client/plugins/manager/users/SearchBar.jsx b/web/client/plugins/manager/users/SearchBar.jsx deleted file mode 100644 index 2ce39026e9..0000000000 --- a/web/client/plugins/manager/users/SearchBar.jsx +++ /dev/null @@ -1,70 +0,0 @@ - -/** - * 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 {connect} = require('react-redux'); - - -const {getUsers, usersSearchTextChanged} = require('../../../actions/users'); -const {getUserGroups, groupSearchTextChanged} = require('../../../actions/usergroups'); - -const {trim} = require('lodash'); -const USERS = "users"; -// const GROUPS = "groups"; -const SearchBar = connect((state) => { - let tool = state && state.controls && state.controls.usermanager && state.controls.usermanager && state.controls.usermanager.selectedTool; - let searchState = tool === USERS ? (state && state.users) : (state && state.usergroups); - return { - tool, - className: "user-search", - hideOnBlur: false, - placeholderMsgId: tool === USERS ? "users.searchUsers" : "usergroups.searchGroups", - typeAhead: false, - start: searchState && searchState.start, - limit: searchState && searchState.limit, - searchText: (searchState && searchState.searchText && trim(searchState.searchText, '*')) || "" - }; -}, { - usersSearchTextChanged, groupSearchTextChanged, - onSearchUser: (text, options) => { - let searchText = (text && text !== "") ? ("*" + text + "*") : "*"; - return getUsers(searchText, options); - }, - onSearchGroup: (text, options) => { - let searchText = (text && text !== "") ? ("*" + text + "*") : "*"; - return getUserGroups(searchText, options); - } -}, (stateProps, dispatchProps) => { - return { - ...stateProps, - onSearch: (text) => { - let limit = stateProps.limit; - if (stateProps.tool === "USER") { - dispatchProps.onSearchUser(text, {params: {start: 0, limit}}); - } else { - dispatchProps.onSearchGroup(text, {params: {start: 0, limit}}); - } - }, - onSearchReset: () => { - if (stateProps.tool === "USER") { - dispatchProps.onSearchUser(); - } else { - dispatchProps.onSearchGroup(); - } - dispatchProps.onSearchReset({params: {start: 0, limit: stateProps.limit}}); - }, - onSearchTextChange: (text) => { - if (stateProps.tool === "USER") { - dispatchProps.usersSearchTextChanged(text); - } else { - dispatchProps.groupSearchTextChanged(text); - } - } - }; -})(require("../../../components/mapcontrols/search/SearchBar")); - -module.exports = SearchBar; diff --git a/web/client/plugins/manager/users/TopButtons.jsx b/web/client/plugins/manager/users/TopButtons.jsx deleted file mode 100644 index c70020d036..0000000000 --- a/web/client/plugins/manager/users/TopButtons.jsx +++ /dev/null @@ -1,75 +0,0 @@ -/** - * 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 React = require('react'); -const {connect} = require('react-redux'); -const {Button, Grid, Glyphicon} = require('react-bootstrap'); -const {editUser} = require('../../../actions/users'); -const {editGroup} = require('../../../actions/usergroups'); -const {setControlProperty} = require('../../../actions/controls'); -const Message = require('../../../components/I18N/Message'); -const USERS = "users"; -const GROUPS = "groups"; -const Bar = React.createClass({ - propTypes: { - selectedTool: React.PropTypes.string, - onNewUser: React.PropTypes.func, - onNewGroup: React.PropTypes.func, - onToggleUsersGroups: React.PropTypes.func - }, - getDefaultProps() { - return { - selectedTool: "users", - onNewUser: () => {}, - onNewGroup: () => {}, - onToggleUsersGroups: () => {} - }; - }, - onNew() { - if (this.props.selectedTool === "users") { - this.props.onNewUser(); - } else if (this.props.selectedTool === "groups") { - this.props.onNewGroup(); - } - }, - renderNewButton() { - if (this.props.selectedTool === USERS) { - return ; - } else if (this.props.selectedTool === GROUPS) { - return ; - } - }, - renderToggle() { - if (this.props.selectedTool === (USERS)) { - return ; - } else if (this.props.selectedTool === GROUPS) { - return ; - } - }, - renderTitle() { - return

; - }, - render() { - return ( - {this.renderTitle()} - - - ); - }, - toogleTools() { - this.props.onToggleUsersGroups(this.props.selectedTool === USERS ? GROUPS : USERS ); - } -}); -const TopButtons = connect((state) => ({ - selectedTool: state && state.controls && state.controls.usermanager && state.controls.usermanager && state.controls.usermanager.selectedTool -}), { - onNewUser: editUser.bind(null, {role: "USER", "enabled": true}), - onNewGroup: editGroup.bind(null, {}), - onToggleUsersGroups: setControlProperty.bind(null, "usermanager", "selectedTool") -})(Bar); - -module.exports = TopButtons; diff --git a/web/client/product/plugins.js b/web/client/product/plugins.js index ef9f8287c9..6c0ec8efc1 100644 --- a/web/client/product/plugins.js +++ b/web/client/product/plugins.js @@ -51,6 +51,7 @@ module.exports = { FooterPlugin: require('./plugins/Footer'), ManagerPlugin: require('../plugins/manager/Manager'), UserManagerPlugin: require('../plugins/manager/UserManager'), + GroupManagerPlugin: require('../plugins/manager/GroupManager'), RulesManagerPlugin: require('../plugins/manager/RulesManager'), ManagerMenuPlugin: require('../plugins/manager/ManagerMenu'), RedirectPlugin: require('../plugins/Redirect'),