Browse Source

fix user table

merge-requests/1/merge
Listat.an 5 years ago
parent
commit
51dd879ef1
  1. 0
      public/css/font.css
  2. BIN
      public/fonts/Roboto-Black.ttf
  3. BIN
      public/fonts/Roboto-BlackItalic.ttf
  4. BIN
      public/fonts/Roboto-Bold.ttf
  5. BIN
      public/fonts/Roboto-BoldItalic.ttf
  6. BIN
      public/fonts/Roboto-Light.ttf
  7. BIN
      public/fonts/Roboto-LightItalic.ttf
  8. BIN
      public/fonts/Roboto-Medium.ttf
  9. BIN
      public/fonts/Roboto-MediumItalic.ttf
  10. BIN
      public/fonts/Roboto-Regular.ttf
  11. BIN
      public/fonts/Roboto-RegularItalic.ttf
  12. BIN
      public/fonts/Roboto-Thin.ttf
  13. BIN
      public/fonts/Roboto-ThinItalic.ttf
  14. 1
      public/index.html
  15. 26
      src/components/Modal/index.jsx
  16. 3
      src/config/index.js
  17. 62
      src/containers/Task/components/Contexmenu/index.jsx
  18. 29
      src/containers/Task/components/Data/index.jsx
  19. 14
      src/containers/Task/components/Data/style.scss
  20. 4
      src/containers/Task/components/Menu/index.jsx
  21. 20
      src/containers/User/actions.js
  22. 213
      src/containers/User/components/Contexmenu/index.jsx
  23. 14
      src/containers/User/components/Contexmenu/style.scss
  24. 70
      src/containers/User/components/DataUser/Row.jsx
  25. 135
      src/containers/User/components/DataUser/index.jsx
  26. 3
      src/containers/User/components/DataUser/style.scss
  27. 27
      src/containers/User/index.jsx
  28. 7
      src/containers/User/reducer.js
  29. 1
      src/scss/app.scss

0
public/css/font.css

BIN
public/fonts/Roboto-Black.ttf

Binary file not shown.

BIN
public/fonts/Roboto-BlackItalic.ttf

Binary file not shown.

BIN
public/fonts/Roboto-Bold.ttf

Binary file not shown.

BIN
public/fonts/Roboto-BoldItalic.ttf

Binary file not shown.

BIN
public/fonts/Roboto-Light.ttf

Binary file not shown.

BIN
public/fonts/Roboto-LightItalic.ttf

Binary file not shown.

BIN
public/fonts/Roboto-Medium.ttf

Binary file not shown.

BIN
public/fonts/Roboto-MediumItalic.ttf

Binary file not shown.

BIN
public/fonts/Roboto-Regular.ttf

Binary file not shown.

BIN
public/fonts/Roboto-RegularItalic.ttf

Binary file not shown.

BIN
public/fonts/Roboto-Thin.ttf

Binary file not shown.

BIN
public/fonts/Roboto-ThinItalic.ttf

Binary file not shown.

1
public/index.html

@ -10,7 +10,6 @@ @@ -10,7 +10,6 @@
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json">
<link rel="shortcut icon" href="%PUBLIC_URL%/fav.ico">
<link href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900" rel="stylesheet">
<link rel="stylesheet" href="https://cdn.linearicons.com/free/1.0.0/icon-font.min.css">
<script src="https://kit.fontawesome.com/fa03d58b56.js"></script>
<link rel="stylesheet" href="%PUBLIC_URL%/load.css">

26
src/components/Modal/index.jsx

@ -1,8 +1,17 @@ @@ -1,8 +1,17 @@
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import { Button, Modal, ModalHeader, ModalBody, ModalFooter } from 'reactstrap';
import classNames from 'classnames'
class ModalComponent extends Component {
static defaultProps = {
title: '',
colored: false,
header: true,
color: 'primary',
full: false,
};
constructor(props) {
super(props)
@ -29,21 +38,28 @@ class ModalComponent extends Component { @@ -29,21 +38,28 @@ class ModalComponent extends Component {
}
render() {
let {show, title} = this.props;
let color = 'primary';
const {
color, show, title, colored, header, full
} = this.props;
const modalClass = classNames({
'modal-dialog--colored': colored,
'modal-dialog--header': header,
});
return (
<Modal
isOpen={show}
toggle={this.toggle}
className={`modal-dialog--${color} modal-dialog--header`}
className={`modal-dialog--${color} ${modalClass}`}
>
<div className="modal__header">
<button className="lnr lnr-cross modal__close-btn" type="button" onClick={this.toggle} />
<h4 className="bold-text modal__title" style={{color: 'white'}}>{title}</h4>
</div>
<div className="modal__body">
{full ? this.props.children : <div className="modal__body">
{this.props.children}
</div>
</div>}
</Modal>
)
}

3
src/config/index.js

@ -1,5 +1,6 @@ @@ -1,5 +1,6 @@
export default {
// apiUrl: 'http://c3ac9e7a.ngrok.io',
apiUrl: 'http://127.0.0.1:1337',
// apiUrl: 'http://localhost:1337',
// apiUrl: 'https://api-tasks.ubg.ua',
apiUrl: 'http://api.ls',
};

62
src/containers/Task/components/Contexmenu/index.jsx

@ -11,6 +11,9 @@ import moment from 'moment' @@ -11,6 +11,9 @@ import moment from 'moment'
import ReactToPrint from "react-to-print";
import PrintComponet from '../PrintComponent';
import './style.scss'
import Modal from '../../../../components/Modal'
import { Button, ButtonToolbar } from 'reactstrap';
class Contexmenu extends Component {
constructor(props) {
@ -22,7 +25,8 @@ class Contexmenu extends Component { @@ -22,7 +25,8 @@ class Contexmenu extends Component {
this.myRef4 = React.createRef();
this.myRef5 = React.createRef();
this.state = {
visible: false
visible: false,
warningDelete: false,
}
}
@ -129,6 +133,7 @@ class Contexmenu extends Component { @@ -129,6 +133,7 @@ class Contexmenu extends Component {
case 'update':
this.props.setItemTask(task);
this.props.showModal(true);
this.props.handleMenuClick();
break;
case 'copy':
delete task.comments;
@ -137,23 +142,30 @@ class Contexmenu extends Component { @@ -137,23 +142,30 @@ class Contexmenu extends Component {
task.is_copy = true;
this.props.setItemTask(task);
this.props.showModal(true);
this.props.handleMenuClick();
break;
case 'mark_performance':
this.props.setItemTask({status: 'finished', done_date: moment()});
this.props.showModalPerformance(true);
this.props.showModalPerformance(true);
this.props.handleMenuClick();
break;
case 'reassign_task':
this.props.setItemTask({user_done: task.user_done});
this.props.showModalReassign(true);
this.props.showModalReassign(true);
this.props.handleMenuClick();
break;
case 'favorite':
this.props.favoriteTask(selectedTaskIds);
this.props.handleMenuClick();
break;
case 'unfavorite':
this.props.unfavoriteTask(selectedTaskIds)
this.props.handleMenuClick();
break;
case 'delete':
this.props.deleteTask(selectedTaskIds)
// this.props.deleteTask(selectedTaskIds)
this.setState({warningDelete: true});
break;
case 'new':
this.props.setItemTask({
@ -166,13 +178,18 @@ class Contexmenu extends Component { @@ -166,13 +178,18 @@ class Contexmenu extends Component {
type: tmp_types && tmp_types[0] ? tmp_types[0].id : null
});
this.props.showModal(true);
this.props.handleMenuClick();
break;
default:
this.props.handleMenuClick();
break;
}
// this.props.handleMenuClick();
}
delete = () =>{
this.props.deleteTask(this.props.selectedTaskIds);
this.props.handleMenuClick();
}
@ -192,39 +209,54 @@ class Contexmenu extends Component { @@ -192,39 +209,54 @@ class Contexmenu extends Component {
}
});
let isFavorite = selectedTaskIds.some(item => {
return profile.favorites.indexOf(item) > -1;
});
// let isFavorite = selectedTaskIds.some(item => {
// return profile && profile.favorites ? profile.favorites.indexOf(item) > -1 : false;
// });
return (
<div style={{visibility: this.state.visible ? 'visible' : 'hidden'}} id={mode == "vertical" ? "menu1" : "menu2"} ref={this.menuRef}>
<Modal
show={this.state.warningDelete}
toggle={() => {this.setState({warningDelete: false})}}
colored
header={false}
color="primary"
>
<div className="modal__body">
<h4 style={{color: 'white'}}>Ви справді бажаєте видалити?</h4>
</div>
<ButtonToolbar className="modal__footer">
<Button onClick={() => {this.setState({warningDelete: false})}}>Ні</Button>{' '}
<Button outline={true} color={"primary"} onClick={this.delete}>Так</Button>
</ButtonToolbar>
</Modal>
<Menu onClick={this.handleMenuClick} selectable={false} mode={mode || "vertical"}>
{selectedTaskIds.length == 1 && !isFavorite ?
{/* {selectedTaskIds.length == 1 && !isFavorite ?
<Item key='favorite'>
<Tooltip placement="bottom" title={mode != "vertical" ? ' Відмітити зірочкою' : null}><i className="far fa-star"></i></Tooltip>
{mode == "vertical" ? ' Відмітити зірочкою' : null}
</Item>
: null}
: null} */}
{selectedTaskIds.length > 1 ?
{/* {selectedTaskIds.length > 1 ?
<Item key='favorite'>
<Tooltip placement="bottom" title={mode != "vertical" ? ' Відмітити зірочкою' : null}><i className="far fa-star"></i></Tooltip>
{mode == "vertical" ? ' Відмітити зірочкою' : null}
</Item>
: null}
: null} */}
{isFavorite ?
{/* {isFavorite ?
<Item key='unfavorite'>
<Tooltip placement="bottom" title={mode != "vertical" ? ' Відмінити відмітку зірочкою' : null}>
<i className="far fa-star"></i>{mode == "vertical" ? ' Відмінити відмітку зірочкою' : null}
</Tooltip>
</Item>
: null}
: null} */}
{this.getCheckPermissionsTask('update', task) && !task.done_date && selectedTaskIds.length == 1 ?
<Item key='mark_performance'>

29
src/containers/Task/components/Data/index.jsx

@ -3,7 +3,7 @@ import PropTypes from 'prop-types' @@ -3,7 +3,7 @@ import PropTypes from 'prop-types'
import { connect } from 'react-redux'
import { Table, Popconfirm, Dropdown } from 'antd';
import _ from 'lodash';
import { showModal, setItemTask, deleteTask, getTasks, showModalView, setTaskSelectedIds } from '../../actions';
import { showModal, setItemTask, deleteTask, getTasks, showModalView, setTaskSelectedIds, unfavoriteTask, favoriteTask } from '../../actions';
import history from '../../../../lib/histoty'
import { getPermissionCheck } from '../../../../lib/helper';
import moment from 'moment'
@ -153,7 +153,7 @@ class Data extends Component { @@ -153,7 +153,7 @@ class Data extends Component {
return item;
});
let maxWidth = this.props.containerWidth ? Math.floor((this.props.containerWidth - 551)/3) : 240;
let maxWidth = this.props.containerWidth ? Math.floor((this.props.containerWidth - 547)/3) : 240;
if(maxWidth < 55){
maxWidth = 55;
@ -162,6 +162,23 @@ class Data extends Component { @@ -162,6 +162,23 @@ class Data extends Component {
maxWidth = maxWidth.toString() + 'px';
let columns = [
{
title: '',
key: 'favorite',
width: 18,
className: "favorite",
// fixed: 'right',
render: (text, record) => (
<span>
{profile && profile.favorites && profile.favorites.indexOf(record.id) > -1 ?
<i className="fas fa-star" onClick={() => {
this.props.unfavoriteTask(record.id)
}}></i> : <i style={{color: '#ddd'}} className="fas fa-star" onClick={() => {
this.props.favoriteTask(record.id)
}}></i>}
</span>
),
},
{
title: '№',
dataIndex: 'id',
@ -335,15 +352,15 @@ class Data extends Component { @@ -335,15 +352,15 @@ class Data extends Component {
{
title: '',
key: 'action',
width: 102,
width: 80,
// fixed: 'right',
render: (text, record) => (
<span>
{record.documents && record.documents.length ? <i className="fas fa-paperclip"></i> : null}
{record.documents && record.documents.length ? <span style={{padding: '2px'}}> </span> : null}
{record.comments && record.comments.length ? <i className="far fa-comment"></i> : null}
{record.comments && record.comments.length ? <span style={{padding: '2px'}}> </span> : null}
{profile.favorites && profile.favorites.indexOf(record.id) > -1 ? <i className="fas fa-star"></i> : null}
{/* {record.comments && record.comments.length ? <span style={{padding: '2px'}}> </span> : null} */}
{/* {profile && profile.favorites && profile.favorites.indexOf(record.id) > -1 ? <i className="fas fa-star"></i> : null} */}
</span>
// <span>
// {this.getCheckPermissionsTask('update', record) ? <a className="lnr lnr-pencil" href='javascript:;' onClick={() => {
@ -515,6 +532,8 @@ const mapDispatchToProps = { @@ -515,6 +532,8 @@ const mapDispatchToProps = {
deleteTask,
showModalView,
setTaskSelectedIds,
unfavoriteTask,
favoriteTask,
}
export default Dimensions()(connect(mapStateToProps, mapDispatchToProps)(Data))

14
src/containers/Task/components/Data/style.scss

@ -2,6 +2,17 @@ @@ -2,6 +2,17 @@
// white-space: nowrap;
}
.table-task{
tr{
td:nth-child(2){
padding: 0;
}
th:nth-child(2){
padding: 0;
}
}
}
.table-task tbody tr td:first-child{
text-align: center;
}
@ -16,7 +27,8 @@ @@ -16,7 +27,8 @@
.table-task tbody tr td .fa-star{
// color: black;
color: #e6c04d;
color: #f6da6e;
cursor: pointer;
}
.table-row-red{

4
src/containers/Task/components/Menu/index.jsx

@ -135,10 +135,6 @@ class MenuTask extends Component { @@ -135,10 +135,6 @@ class MenuTask extends Component {
task = _.cloneDeep(task_item);
}
});
let isFavorite = selectedTaskIds.some(item => {
return profile.favorites.indexOf(item) > -1;
});
return (
<div className="menu-task">

20
src/containers/User/actions.js

@ -87,10 +87,18 @@ export function clearData() { @@ -87,10 +87,18 @@ export function clearData() {
};
}
export function deleteUser(id) {
export function deleteUser(ids) {
if(!Array.isArray(ids)){
ids = [ids]
}
return (dispatch) => {
return restClient.delete('user', id).then((result) => {
dispatch({ type: 'DELETE_USER', id });
return Promise.all(ids.map(id => restClient.delete('user', id))) .then((result) => {
ids.forEach(id => {
dispatch({ type: 'DELETE_USER', id });
})
return null;
}).catch(err => {
return processError(err, dispatch);
@ -157,4 +165,10 @@ export function updateUser(id, data, image, login_id) { @@ -157,4 +165,10 @@ export function updateUser(id, data, image, login_id) {
return processError(err, dispatch);
});
};
}
export function setUserSelectedIds(data) {
return (dispatch) => {
dispatch({ type: 'SET_USER_SELECTED_IDS', data });
};
}

213
src/containers/User/components/Contexmenu/index.jsx

@ -0,0 +1,213 @@ @@ -0,0 +1,213 @@
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import { Menu, Icon, Tooltip } from 'antd';
const Item = Menu.Item;
const SubMenu = Menu.SubMenu;
import { connect } from 'react-redux'
import { setUserSelectedIds, setItemUser, showModalPermission, showModal, deleteUser } from '../../actions';
import _ from 'lodash'
import { genTree, getPermissionCheck } from '../../../../lib/helper';
import moment from 'moment'
import './style.scss'
import Modal from '../../../../components/Modal'
import { Button, ButtonToolbar } from 'reactstrap';
class Contexmenu extends Component {
constructor(props) {
super(props)
this.state = {
visible: false,
warningDelete: false
}
}
componentWillMount() {
if(this.props.mode == 'horizontal'){
return null;
}
if(this.props.selectedUserIds.indexOf(this.props.item) == -1)
this.props.setUserSelectedIds([this.props.item])
}
delete = () =>{
this.props.deleteUser(this.props.selectedUserIds);
this.props.handleMenuClick();
}
componentDidMount() {
if(this.props.mode == 'horizontal'){
this.setState({visible: true})
return null;
}
var elem = document.getElementById('menu1').parentElement;
var menu = document.getElementById('menu1')
setTimeout(() => {
// console.log("TCL: Contexmenu -> componentDidMount -> menu", menu.clientHeight)
// console.log("TCL: Contexmenu -> componentDidMount -> menu", menu.clientWidth)
// console.log("TCL: Contexmenu -> componentDidMount -> this.menuRef", this.menuRef.current.clientHeight)
// console.log("TCL: Contexmenu -> componentDidMount -> this.menuRef", this.menuRef.current.clientWidth)
let left = this.props.popup.left;
let top = this.props.popup.top;
let clientHeight = document.body.clientHeight;
let clientWidth = document.body.clientWidth;
let menuW = 184;
let menuH = 385;
if(menu.clientHeight > 0){
menuH = menu.clientHeight;
}
if(menu.clientWidth > 0){
menuW = menu.clientWidth;
}
if((clientHeight - top) < menuH){
top = top - menuH;
}
if((clientWidth - left) < menuW){
left = left - menuW;
}
elem.style.left = `${left}px`;
elem.style.top = `${top}px`;
this.setState({visible: true})
}, 100);
}
componentWillReceiveProps(nextProps) {
}
componentWillUnmount() {
}
handleMenuClick = (e) => {
let {item, users, profile, selectedUserIds, mode} = this.props;
let user = {};
users.some(user_item => {
if(user_item.id == item){
user = _.cloneDeep(user_item);
}
});
switch (e.key) {
case 'update':
this.props.setItemUser(user);
this.props.showModal(true);
this.props.handleMenuClick();
break;
case 'delete':
// this.props.deleteUser(selectedUserIds)
this.setState({warningDelete: true})
break;
case 'new':
this.props.setItemUser({factories: [], role: 'user'});
this.props.showModal(true);
this.props.handleMenuClick();
break;
default:
this.props.handleMenuClick();
break;
}
}
render() {
let {item, users, profile, selectedUserIds, mode} = this.props;
if(!mode){
mode = "vertical";
}
// let isFavorite = selectedUserIds.some(item => {
// return profile && profile.favorites ? profile.favorites.indexOf(item) > -1 : false;
// });
return (
<div style={{visibility: this.state.visible ? 'visible' : 'hidden'}} id={mode == "vertical" ? "menu1" : "menu2"} ref={this.menuRef}>
<Modal
show={this.state.warningDelete}
toggle={() => {this.setState({warningDelete: false})}}
colored
header={false}
color="primary"
>
<div className="modal__body">
<h4 style={{color: 'white'}}>Ви справді бажаєте видалити?</h4>
</div>
<ButtonToolbar className="modal__footer">
<Button onClick={() => {this.setState({warningDelete: false})}}>Ні</Button>{' '}
<Button outline={true} color={"primary"} onClick={this.delete}>Так</Button>
</ButtonToolbar>
</Modal>
<Menu onClick={this.handleMenuClick} selectable={false} mode={mode || "vertical"}>
{getPermissionCheck('user', 'update', profile) && selectedUserIds.length == 1 ?
<Item key='update'>
<Tooltip placement="bottom" title={mode != "vertical" ? ' Редагувати' : null}>
<i className="far fa-edit"></i>{mode == "vertical" ? ' Редагувати' : null}
</Tooltip>
</Item>
: null}
<Item key='new'>
<Tooltip placement="bottom" title={mode != "vertical" ? ' Створити' : null}>
<i className="far fa-plus-square"></i>{mode == "vertical" ? ' Створити' : null}
</Tooltip>
</Item>
{getPermissionCheck('user', 'destroy', profile) ?
<Item key='delete'>
<Tooltip placement="bottom" title={mode != "vertical" ? ' Видалити' : null}>
<i className="far fa-trash-alt"></i>{mode == "vertical" ? ' Видалити' : null}
</Tooltip>
</Item>
: null}
</Menu>
</div>
)
}
}
Contexmenu.propTypes = {
}
const mapStateToProps = (state, ownProps) => ({
selectedUserIds: state.user.user_selected_ids,
profile: state.auth.profile,
users: state.user.data,
})
const mapDispatchToProps = {
setUserSelectedIds,
setItemUser,
showModalPermission,
showModal,
deleteUser,
}
export default connect(mapStateToProps, mapDispatchToProps)(Contexmenu)

14
src/containers/User/components/Contexmenu/style.scss

@ -0,0 +1,14 @@ @@ -0,0 +1,14 @@
#menu1{
.ant-menu{
// min-height: 184px;
border: 1px solid #e8e8e8;
// .ant-menu-item, .ant-menu-submenu-title{
// margin-bottom: 4px;
// height: 20px !important;
// line-height: 20px !important;
// }
// .ant-menu-submenu-title{
// margin-bottom: 8px;
// }
}
}

70
src/containers/User/components/DataUser/Row.jsx

@ -0,0 +1,70 @@ @@ -0,0 +1,70 @@
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import Contexmenu from '../Contexmenu';
import { Dropdown } from 'antd';
class Row extends Component {
constructor(props) {
super(props)
this.state = {
visible: false
}
this.myRef = React.createRef()
}
componentWillMount() {
}
componentDidMount() {
}
handleVisibleChange = (flag) => {
// this.setState({ visible: flag });
this.props.setContentMenu(this.props['data-row-key'], flag)
}
componentWillReceiveProps(nextProps) {
}
componentWillUnmount() {
}
handleMenuClick = (e) => {
// this.setState({ visible: false });
this.props.setContentMenu(this.props['data-row-key'], false)
}
menu = (item) => {
return <Contexmenu
handleMenuClick={this.handleMenuClick}
popup={this.props.popup}
item={item}
/>
}
render() {
let {contentMenu} = this.props;
return (
<Dropdown
overlay={this.menu(this.props['data-row-key'])}
trigger={[`contextMenu`]}
onVisibleChange={this.handleVisibleChange}
visible={contentMenu[this.props['data-row-key']]}
ref={this.myRef}
// visible={this.state.visible}
>
<tr {...this.props} />
</Dropdown>
)
}
}
Row.propTypes = {
}
export default Row

135
src/containers/User/components/DataUser/index.jsx

@ -3,15 +3,20 @@ import PropTypes from 'prop-types' @@ -3,15 +3,20 @@ import PropTypes from 'prop-types'
import { connect } from 'react-redux'
import { Table, Popconfirm } from 'antd';
import _ from 'lodash';
import { showModal, setItemUser, deleteUser, showModalPermission, getUsers } from '../../actions';
import { showModal, setItemUser, deleteUser, showModalPermission, getUsers, setUserSelectedIds } from '../../actions';
import history from '../../../../lib/histoty'
import { getPermissionCheck } from '../../../../lib/helper';
import Row from './Row'
import './style.scss'
class DataUser extends Component {
constructor(props) {
super(props)
this.state = {
sortedInfo: {},
contentMenu: {},
popup: {}
}
}
componentWillMount() {
@ -31,6 +36,15 @@ class DataUser extends Component { @@ -31,6 +36,15 @@ class DataUser extends Component {
}
sortString = (a, b) => {
var nameA=a.toLowerCase(), nameB=b.toLowerCase();
if (nameA < nameB)
return -1;
if (nameA > nameB)
return 1;
return 0;
}
getTitleFactory = (id) => {
let {factory} = this.props;
@ -54,34 +68,49 @@ class DataUser extends Component { @@ -54,34 +68,49 @@ class DataUser extends Component {
}
onChange = (pagination, filters, sorter) => {
let filter = _.cloneDeep(this.props.filter)
// let filter = _.cloneDeep(this.props.filter)
const skip = parseFloat(pagination.current) * parseFloat(filter.limit) - filter.limit;
filter.skip = skip;
// const skip = parseFloat(pagination.current) * parseFloat(filter.limit) - filter.limit;
// filter.skip = skip;
this.props.getUsers(filter);
// this.props.getUsers(filter);
this.setState({
sortedInfo: sorter,
});
}
setContentMenu = (key, status) => {
this.setState({contentMenu: {[key]: status}})
}
render() {
let {users, factory, profile, is_load, filter, totalCount} = this.props;
let {users, factory, user_selected_ids, profile, is_load, filter, totalCount} = this.props;
let permissions = profile.permissions || {};
let {sortedInfo} = this.state;
const columns = [
{
title: 'ПІБ',
dataIndex: 'name',
key: 'name',
sortOrder: sortedInfo.columnKey === 'name' && sortedInfo.order,
sorter: (a, b) => this.sortString(a.name, b.name),
},
{
title: 'Логін',
dataIndex: 'login',
key: 'login',
sortOrder: sortedInfo.columnKey === 'login' && sortedInfo.order,
sorter: (a, b) => this.sortString(a.login, b.login),
},
{
title: 'Email',
dataIndex: 'email',
key: 'email',
sortOrder: sortedInfo.columnKey === 'email' && sortedInfo.order,
sorter: (a, b) => this.sortString(a.email, b.email),
},
{
title: 'Підприємство',
@ -103,35 +132,48 @@ class DataUser extends Component { @@ -103,35 +132,48 @@ class DataUser extends Component {
// dataIndex: 'name',
// key: 'name',
// },
{
title: 'Дії',
key: 'action',
render: (text, record) => (
<span>
{getPermissionCheck('user', 'update', profile) ? <a className="lnr lnr-pencil" href='javascript:;' onClick={() => {
this.props.setItemUser(record);
this.props.showModal(true);
}}></a> : null}
{/* <span style={{padding: '10px'}}> </span> */}
{/* {getPermissionCheck('user', 'update', permissions) ? <a className="lnr lnr-cog" href='javascript:;' onClick={() => {
this.props.setItemUser(record);
this.props.showModalPermission(true);
}}></a> : null} */}
<span style={{padding: '10px'}}> </span>
// {
// title: 'Дії',
// key: 'action',
// render: (text, record) => (
// <span>
// {getPermissionCheck('user', 'update', profile) ? <a className="lnr lnr-pencil" href='javascript:;' onClick={() => {
// this.props.setItemUser(record);
// this.props.showModal(true);
// }}></a> : null}
// {/* <span style={{padding: '10px'}}> </span> */}
// {/* {getPermissionCheck('user', 'update', permissions) ? <a className="lnr lnr-cog" href='javascript:;' onClick={() => {
// this.props.setItemUser(record);
// this.props.showModalPermission(true);
// }}></a> : null} */}
// <span style={{padding: '10px'}}> </span>
{profile.id == record.id || !getPermissionCheck('user', 'destroy', profile) ? null : <Popconfirm
title="Ви справді хочете видалити користувача?"
onConfirm={() => {
this.props.deleteUser(record.id)
}}
>
<a className="lnr lnr-trash" href="javascript:;"></a>
</Popconfirm>}
</span>
),
}
// {profile.id == record.id || !getPermissionCheck('user', 'destroy', profile) ? null : <Popconfirm
// title="Ви справді хочете видалити користувача?"
// onConfirm={() => {
// this.props.deleteUser(record.id)
// }}
// >
// <a className="lnr lnr-trash" href="javascript:;"></a>
// </Popconfirm>}
// </span>
// ),
// }
];
const components = {
body: {
row: (props) => (<Row
{...props}
popup={this.state.popup}
setContentMenu={this.setContentMenu}
contentMenu={this.state.contentMenu}
setUserSelectedIds={this.props.setUserSelectedIds}
/>),
cell: ({children}) => (<td>{children}</td>),
},
};
return (
<div>
<Table
@ -139,28 +181,41 @@ class DataUser extends Component { @@ -139,28 +181,41 @@ class DataUser extends Component {
// bordered
onChange={this.onChange}
loading={!is_load}
components={components}
columns={columns}
className='table-user'
onRow={(record, rowIndex) => {
return {
onClick: (event) => {}, // click row
onDoubleClick: (event) => {
// history.push('/profile/' + record.id)
if(getPermissionCheck('user', 'update', profile)){
this.props.setItemUser(record);
this.props.showModal(true);
// this.props.setItemUser(record);
// this.props.showModal(true);
} else {
history.push('/profile/' + record.id)
}
}, // double click row
onContextMenu: (event) => {}, // right button click row
onContextMenu: (event) => {
let top = event.pageY;
let left = event.clientX;
this.setState({popup: {left, top}})
}, // right button click row
onMouseEnter: (event) => {}, // mouse enter row
onMouseLeave: (event) => {}, // mouse leave row
};
}}
rowKey={(record) => record.id}
rowSelection={{
selectedRowKeys: user_selected_ids,
onChange: (selectedRowKeys, selectedRows) => {
console.log(`selectedRowKeys: ${selectedRowKeys}`, 'selectedRows: ', selectedRows);
this.props.setUserSelectedIds(selectedRows.map(item => item.id))
}
}}
pagination={{
total: totalCount,
pageSize: filter.limit,
total: users.length,
pageSize: 10,
}}
/>
</div>
@ -179,6 +234,7 @@ const mapStateToProps = (state, ownProps) => ({ @@ -179,6 +234,7 @@ const mapStateToProps = (state, ownProps) => ({
filter: state.user.filter,
totalCount: state.user.totalCount,
factory: state.user.factory,
user_selected_ids: state.user.user_selected_ids,
profile: state.auth.profile
})
@ -188,6 +244,7 @@ const mapDispatchToProps = { @@ -188,6 +244,7 @@ const mapDispatchToProps = {
getUsers,
deleteUser,
showModalPermission,
setUserSelectedIds
}
export default connect(mapStateToProps, mapDispatchToProps)(DataUser)

3
src/containers/User/components/DataUser/style.scss

@ -0,0 +1,3 @@ @@ -0,0 +1,3 @@
.table-user tbody tr td:first-child{
text-align: center;
}

27
src/containers/User/index.jsx

@ -9,6 +9,7 @@ import FormUser from './components/FormUser'; @@ -9,6 +9,7 @@ import FormUser from './components/FormUser';
import FormPermissions from './components/FormPermissions';
import { getPermissionCheck } from '../../lib/helper';
import SearchUser from './components/Search'
import Contexmenu from './components/Contexmenu';
class User extends Component {
constructor(props) {
@ -36,7 +37,7 @@ class User extends Component { @@ -36,7 +37,7 @@ class User extends Component {
}
render() {
let {show_modal, show_modal_permission, profile} = this.props;
let {show_modal, show_modal_permission, profile, selectedUserIds} = this.props;
let permissions = profile.permissions || {};
return (
<Container className="factory">
@ -52,15 +53,20 @@ class User extends Component { @@ -52,15 +53,20 @@ class User extends Component {
<FormPermissions/>
</Modal>
{getPermissionCheck('user', 'create', profile) ? <Row>
<div className='col-md-12 justify-content-end flex'>
<SearchUser/>
<Button color="primary" size='sm' onClick={() => {
this.props.setItemUser({factories: [], role: 'user'});
this.props.showModal(true);
}}>Створити</Button>
</div>
</Row> : null}
<div className='col-md-12 flex' style={{justifyContent: 'space-between'}}>
{selectedUserIds.length ? <Contexmenu mode="horizontal" item={selectedUserIds[0]} handleMenuClick={() => {} }/> : <div/>}
{getPermissionCheck('user', 'create', profile) ? <div className='flex'>
<div className='col-md-12 justify-content-end flex'>
<SearchUser/>
<Button color="primary" size='sm' onClick={() => {
this.props.setItemUser({factories: [], role: 'user'});
this.props.showModal(true);
}}>Створити</Button>
</div>
</div> : null}
</div>
<DataUser/>
</CardBody>
</Card>
@ -79,6 +85,7 @@ User.propTypes = { @@ -79,6 +85,7 @@ User.propTypes = {
const mapStateToProps = (state, ownProps) => ({
show_modal: state.user.show_modal,
filter: state.user.filter,
selectedUserIds: state.user.user_selected_ids,
show_modal_permission: state.user.show_modal_permission,
profile: state.auth.profile,
})

7
src/containers/User/reducer.js

@ -10,11 +10,12 @@ const initialState = { @@ -10,11 +10,12 @@ const initialState = {
factories: []
},
filter: {
skip: 0,
limit: 10
// skip: 0,
// limit: 10
},
totalCount: 0,
users: [],
user_selected_ids: [],
};
export default function (state = initialState, action) {
@ -24,6 +25,8 @@ export default function (state = initialState, action) { @@ -24,6 +25,8 @@ export default function (state = initialState, action) {
return {...state, data: action.data, is_load: true, filter: action.filter, totalCount: action.count }
case 'GET_USER_FACTORY':
return {...state, factory: action.data}
case 'SET_USER_SELECTED_IDS':
return {...state, user_selected_ids: action.data}
case 'CLEAR_USER_DATA':
return {...state, is_load: false, filter: initialState.filter};
case 'GET_USER_USERS':

1
src/scss/app.scss

@ -1,3 +1,4 @@ @@ -1,3 +1,4 @@
@import url('https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900&display=swap');
@import 'settings/variable'; //themes' colors
//vendor...

Loading…
Cancel
Save