|
|
@ -4,14 +4,15 @@ import { Menu, Icon, Tooltip } from 'antd'; |
|
|
|
const Item = Menu.Item; |
|
|
|
const Item = Menu.Item; |
|
|
|
const SubMenu = Menu.SubMenu; |
|
|
|
const SubMenu = Menu.SubMenu; |
|
|
|
import { connect } from 'react-redux' |
|
|
|
import { connect } from 'react-redux' |
|
|
|
import { setLogSelectedIds } from '../../actions'; |
|
|
|
import { setLogSelectedIds, getLogs, banIp, deleteIp } from '../../actions'; |
|
|
|
import _ from 'lodash' |
|
|
|
import _ from 'lodash' |
|
|
|
import { genTree, getPermissionCheck } from '../../../../lib/helper'; |
|
|
|
import { genTree, getPermissionCheck } from '../../../../lib/helper'; |
|
|
|
import moment from 'moment' |
|
|
|
import moment from 'moment' |
|
|
|
import './style.scss' |
|
|
|
import './style.scss' |
|
|
|
import Modal from '../../../../components/Modal' |
|
|
|
import Modal from '../../../../components/Modal' |
|
|
|
import { Button, ButtonToolbar } from 'reactstrap'; |
|
|
|
import { Button, ButtonToolbar } from 'reactstrap'; |
|
|
|
setLogSelectedIds |
|
|
|
import { updateUser } from '../../../User/actions'; |
|
|
|
|
|
|
|
import { logoutUser } from '../../../Profile/actions'; |
|
|
|
|
|
|
|
|
|
|
|
class Contexmenu extends Component { |
|
|
|
class Contexmenu extends Component { |
|
|
|
constructor(props) { |
|
|
|
constructor(props) { |
|
|
@ -84,27 +85,44 @@ class Contexmenu extends Component { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
handleMenuClick = (e) => { |
|
|
|
handleMenuClick = (e) => { |
|
|
|
let {item, profile, selectedUserIds, mode} = this.props; |
|
|
|
let {data, item} = this.props; |
|
|
|
let user = {}; |
|
|
|
console.log("TCL: Contexmenu -> handleMenuClick -> item", item) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let log = {}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
data.some(log_item => { |
|
|
|
|
|
|
|
if(log_item.id == item){ |
|
|
|
|
|
|
|
log = _.cloneDeep(log_item); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
switch (e.key) { |
|
|
|
switch (e.key) { |
|
|
|
case 'update': |
|
|
|
case 'isban': |
|
|
|
|
|
|
|
if(log.user_id){ |
|
|
|
|
|
|
|
this.props.updateUser(log.user_id.id, {is_ban: true}); |
|
|
|
|
|
|
|
this.props.logoutUser(log.user_id.id); |
|
|
|
|
|
|
|
this.props.getLogs({populate: 'user_id'}); |
|
|
|
|
|
|
|
} |
|
|
|
this.props.handleMenuClick(); |
|
|
|
this.props.handleMenuClick(); |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
case 'notban': |
|
|
|
case 'delete': |
|
|
|
if(log.user_id){ |
|
|
|
// this.props.deleteUser(selectedUserIds) |
|
|
|
this.props.updateUser(log.user_id.id, {is_ban: false}); |
|
|
|
this.setState({warningDelete: true}) |
|
|
|
this.props.getLogs({populate: 'user_id'}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
this.props.handleMenuClick(); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case 'new': |
|
|
|
case 'isban_ip': |
|
|
|
|
|
|
|
this.props.banIp({ip: log.ip}); |
|
|
|
|
|
|
|
this.props.getLogs({populate: 'user_id'}); |
|
|
|
|
|
|
|
this.props.handleMenuClick(); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case 'notban_ip': |
|
|
|
|
|
|
|
this.props.deleteIp({ip: log.ip}); |
|
|
|
|
|
|
|
this.props.getLogs({populate: 'user_id'}); |
|
|
|
this.props.handleMenuClick(); |
|
|
|
this.props.handleMenuClick(); |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
default: |
|
|
|
default: |
|
|
|
this.props.handleMenuClick(); |
|
|
|
this.props.handleMenuClick(); |
|
|
|
break; |
|
|
|
break; |
|
|
@ -112,13 +130,22 @@ class Contexmenu extends Component { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
render() { |
|
|
|
render() { |
|
|
|
let {item, users, profile, selectedUserIds, mode} = this.props; |
|
|
|
let {item, users, profile, selectedUserIds, mode, data, ban_ip} = this.props; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(!mode){ |
|
|
|
if(!mode){ |
|
|
|
mode = "vertical"; |
|
|
|
mode = "vertical"; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let log = {}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
data.some(log_item => { |
|
|
|
|
|
|
|
if(log_item.id == item){ |
|
|
|
|
|
|
|
log = _.cloneDeep(log_item); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let find_index = _.findIndex(ban_ip, ['ip', log.ip]) |
|
|
|
|
|
|
|
console.log("TCL: Contexmenu -> render -> find_index", find_index) |
|
|
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
return ( |
|
|
|
<div style={{visibility: this.state.visible ? 'visible' : 'hidden'}} id={mode == "vertical" ? "menu1" : "menu2"} ref={this.menuRef}> |
|
|
|
<div style={{visibility: this.state.visible ? 'visible' : 'hidden'}} id={mode == "vertical" ? "menu1" : "menu2"} ref={this.menuRef}> |
|
|
@ -126,7 +153,7 @@ class Contexmenu extends Component { |
|
|
|
|
|
|
|
|
|
|
|
<Menu onClick={this.handleMenuClick} selectable={false} mode={mode || "vertical"}> |
|
|
|
<Menu onClick={this.handleMenuClick} selectable={false} mode={mode || "vertical"}> |
|
|
|
|
|
|
|
|
|
|
|
{getPermissionCheck('user', 'update', profile) && selectedUserIds.length == 1 ? |
|
|
|
{getPermissionCheck('user', 'update', profile) && selectedUserIds.length == 1 && log.user_id && !log.user_id.is_ban ? |
|
|
|
<Item key='isban'> |
|
|
|
<Item key='isban'> |
|
|
|
<Tooltip placement="bottom" title={mode != "vertical" ? ' Заблокувати користувача' : null}> |
|
|
|
<Tooltip placement="bottom" title={mode != "vertical" ? ' Заблокувати користувача' : null}> |
|
|
|
<i className="fal fa-lock-alt"></i>{mode == "vertical" ? ' Заблокувати користувача' : null} |
|
|
|
<i className="fal fa-lock-alt"></i>{mode == "vertical" ? ' Заблокувати користувача' : null} |
|
|
@ -134,13 +161,29 @@ class Contexmenu extends Component { |
|
|
|
</Item> |
|
|
|
</Item> |
|
|
|
: null} |
|
|
|
: null} |
|
|
|
|
|
|
|
|
|
|
|
{getPermissionCheck('user', 'update', profile) ? |
|
|
|
{getPermissionCheck('user', 'update', profile) && selectedUserIds.length == 1 && log.user_id && log.user_id.is_ban ? |
|
|
|
<Item key='notban'> |
|
|
|
<Item key='notban'> |
|
|
|
<Tooltip placement="bottom" title={mode != "vertical" ? ' Розблокувати користувача' : null}> |
|
|
|
<Tooltip placement="bottom" title={mode != "vertical" ? ' Розблокувати користувача' : null}> |
|
|
|
<i className="fal fa-lock-open-alt"></i>{mode == "vertical" ? ' Розблокувати користувача' : null} |
|
|
|
<i className="fal fa-lock-open-alt"></i>{mode == "vertical" ? ' Розблокувати користувача' : null} |
|
|
|
</Tooltip> |
|
|
|
</Tooltip> |
|
|
|
</Item> |
|
|
|
</Item> |
|
|
|
: null} |
|
|
|
: null} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{getPermissionCheck('user', 'update', profile) && selectedUserIds.length == 1 && find_index < 0 ? |
|
|
|
|
|
|
|
<Item key='isban_ip'> |
|
|
|
|
|
|
|
<Tooltip placement="bottom" title={mode != "vertical" ? ' Заблокувати ip' : null}> |
|
|
|
|
|
|
|
<i className="fal fa-lock-alt"></i>{mode == "vertical" ? ' Заблокувати ip' : null} |
|
|
|
|
|
|
|
</Tooltip> |
|
|
|
|
|
|
|
</Item> |
|
|
|
|
|
|
|
: null} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{getPermissionCheck('user', 'update', profile) && selectedUserIds.length == 1 && find_index > -1 ? |
|
|
|
|
|
|
|
<Item key='notban_ip'> |
|
|
|
|
|
|
|
<Tooltip placement="bottom" title={mode != "vertical" ? ' Розблокувати ip' : null}> |
|
|
|
|
|
|
|
<i className="fal fa-lock-open-alt"></i>{mode == "vertical" ? ' Розблокувати ip' : null} |
|
|
|
|
|
|
|
</Tooltip> |
|
|
|
|
|
|
|
</Item> |
|
|
|
|
|
|
|
: null} |
|
|
|
|
|
|
|
|
|
|
|
</Menu> |
|
|
|
</Menu> |
|
|
|
</div> |
|
|
|
</div> |
|
|
@ -155,11 +198,18 @@ Contexmenu.propTypes = { |
|
|
|
|
|
|
|
|
|
|
|
const mapStateToProps = (state, ownProps) => ({ |
|
|
|
const mapStateToProps = (state, ownProps) => ({ |
|
|
|
selectedUserIds: state.logs.log_selected_ids, |
|
|
|
selectedUserIds: state.logs.log_selected_ids, |
|
|
|
|
|
|
|
data: state.logs.data, |
|
|
|
|
|
|
|
ban_ip: state.logs.ban_ip, |
|
|
|
profile: state.auth.profile, |
|
|
|
profile: state.auth.profile, |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
const mapDispatchToProps = { |
|
|
|
const mapDispatchToProps = { |
|
|
|
setLogSelectedIds |
|
|
|
setLogSelectedIds, |
|
|
|
|
|
|
|
getLogs, |
|
|
|
|
|
|
|
logoutUser, |
|
|
|
|
|
|
|
updateUser, |
|
|
|
|
|
|
|
banIp, |
|
|
|
|
|
|
|
deleteIp, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(Contexmenu) |
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(Contexmenu) |