Browse Source

Merge branch 'master' of https://git.oslog.id/ibnu/generic-ospro-frontend into Dev-Farhan

pull/1/head
farhantock 10 months ago
parent
commit
3f36182016
  1. 77
      src/views/Master/MasterRoles/DialogMenuRoles.js

77
src/views/Master/MasterRoles/DialogMenuRoles.js

@ -4,10 +4,7 @@ import { Button, Form, FormGroup, Label, Input } from 'reactstrap';
import 'antd/dist/antd.css';
import axios from 'axios';
import { MENU_COMPANY_SEARCH } from '../../../const/ApiConst.js';
const token = window.localStorage.getItem('token');
const config = {
headers:
{
@ -15,7 +12,6 @@ const config = {
"Content-type": `application/json`
}
};
export default class DialogMenuRoles extends Component {
constructor(props) {
super(props)
@ -43,7 +39,6 @@ export default class DialogMenuRoles extends Component {
this.props.showDialog(this.showDialog);
this.getAllMenu();
}
async componentDidUpdate() {
if (this.state.isParentClick === true) {
const { idRoles } = this.props
@ -55,12 +50,9 @@ export default class DialogMenuRoles extends Component {
this.setState({ isParentClick: false, id: idRoles });
}
}
showDialog = () => {
this.setState({ isParentClick: true });
}
getAllMenu = async () => {
const payload = {
"paging": { "start": 0, "length": -1 },
@ -73,9 +65,6 @@ export default class DialogMenuRoles extends Component {
],
"orders": { "columns": ["id"], "ascending": false }
}
const result = await axios
.post(MENU_COMPANY_SEARCH, payload, config)
.then(res => res)
@ -86,11 +75,7 @@ export default class DialogMenuRoles extends Component {
});
} else {
}
}
setStateMenu = edit => {
const stateMenu = [];
this.state.menu.map((val) => {
@ -104,7 +89,6 @@ export default class DialogMenuRoles extends Component {
})
})
}
setStateRead = edit => {
const stateRead = [];
this.state.menu.map((val) => {
@ -118,7 +102,6 @@ export default class DialogMenuRoles extends Component {
})
})
}
setStateCreate = edit => {
const stateCreate = [];
this.state.menu.map((val) => {
@ -132,7 +115,6 @@ export default class DialogMenuRoles extends Component {
})
})
}
setStateUpdate = edit => {
const stateUpdate = [];
this.state.menu.map((val) => {
@ -146,7 +128,6 @@ export default class DialogMenuRoles extends Component {
})
})
}
setStateDelete = edit => {
const stateDelete = [];
this.state.menu.map((val) => {
@ -160,13 +141,10 @@ export default class DialogMenuRoles extends Component {
})
})
}
checkMenuRoles = () => {
let copyStateMenu = [...this.state.stateMenu];
this.props.menuRoles.map((val, indexMenu) => {
let index = this.getIndexDataMenu(val.menu_id);
if (index >= 0 || val.read === true || val.create === true || val.update === true || val.delete === true) {
copyStateMenu[index] = true;
}
@ -180,7 +158,6 @@ export default class DialogMenuRoles extends Component {
}
})
}
checkReadRoles = () => {
let copyStateRead = [...this.state.stateRead];
this.props.menuRoles.map((val) => {
@ -191,7 +168,6 @@ export default class DialogMenuRoles extends Component {
copyStateRead[index] = false;
}
})
this.setState({ stateRead: [] }, () => {
let check = copyStateRead.some(this.checkArray);
if (check === false) {
@ -201,10 +177,8 @@ export default class DialogMenuRoles extends Component {
}
})
}
checkCreateRoles = () => {
let copyStateCreate = [...this.state.stateCreate];
this.props.menuRoles.map((val) => {
let index = this.getIndexDataMenu(val.menu_id);
if (val.create === true) {
@ -213,7 +187,6 @@ export default class DialogMenuRoles extends Component {
copyStateCreate[index] = false;
}
})
this.setState({ stateCreate: [] }, () => {
let check = copyStateCreate.some(this.checkArray);
if (check === false) {
@ -223,10 +196,8 @@ export default class DialogMenuRoles extends Component {
}
})
}
checkUpdateRoles = () => {
let copyStateUpdate = [...this.state.stateUpdate];
this.props.menuRoles.map((val) => {
let index = this.getIndexDataMenu(val.menu_id);
if (val.update === true) {
@ -235,7 +206,6 @@ export default class DialogMenuRoles extends Component {
copyStateUpdate[index] = false;
}
})
this.setState({ stateUpdate: [] }, () => {
let check = copyStateUpdate.some(this.checkArray);
if (check === false) {
@ -245,10 +215,8 @@ export default class DialogMenuRoles extends Component {
}
})
}
checkDeleteRoles = () => {
let copyStateDelete = [...this.state.stateDelete];
this.props.menuRoles.map((val) => {
let index = this.getIndexDataMenu(val.menu_id);
if (val.delete === true) {
@ -257,7 +225,6 @@ export default class DialogMenuRoles extends Component {
copyStateDelete[index] = false;
}
})
this.setState({ stateDelete: [] }, () => {
let check = copyStateDelete.some(this.checkArray);
if (check === false) {
@ -267,32 +234,26 @@ export default class DialogMenuRoles extends Component {
}
})
}
getIndexDataMenu = (id) => {
let index = this.state.menu.findIndex(obj => obj.id === id);
return index
}
getIndexDataCreate = (id) => {
let index = this.state.stateCreate.findIndex(obj => obj.id === id);
return index
}
getIndexDataDelete = (id) => {
let index = this.state.stateDelete.findIndex(obj => obj.id === id);
return index
}
getIndexDataRead = (id) => {
let index = this.state.stateRead.findIndex(obj => obj.id === id);
return index
}
getIndexDataUpdate = (id) => {
let index = this.state.stateUpdate.findIndex(obj => obj.id === id);
return index
}
handleSave = () => {
const {
stateMenu,
@ -303,9 +264,7 @@ export default class DialogMenuRoles extends Component {
menu,
id
} = this.state
const arrayData = [];
menu.map((val, index) => {
let data = {
roles_id: id,
@ -315,27 +274,20 @@ export default class DialogMenuRoles extends Component {
update: stateUpdate[index],
delete: stateDelete[index],
checked: stateMenu[index],
}
arrayData.push(data);
})
this.props.closeDialog('save', arrayData);
this.setState({ id: 0 });
}
handleCancel = () => {
this.props.closeDialog('cancel', 'none')
}
handleChangeCheckbox = (checked, index) => {
let copyStateMenu = [...this.state.stateMenu];
copyStateMenu[index] = checked;
this.setState({ stateMenu: copyStateMenu })
}
handleChangeCheckboxRead = (checked, index, menuItem = null, menuIdxList = []) => {
let copyStateRead = [...this.state.stateRead];
copyStateRead[index] = checked;
@ -358,10 +310,8 @@ export default class DialogMenuRoles extends Component {
stateReadIdx.map((stateRead) => {
copyStateRead[stateRead] = checked
})
this.setState({ stateRead: copyStateRead })
}
handleChangeCheckboxCreate = (checked, index, menuItem = null, menuIdxList = []) => {
let copyStateCreate = [...this.state.stateCreate];
copyStateCreate[index] = checked;
@ -386,7 +336,6 @@ export default class DialogMenuRoles extends Component {
})
this.setState({ stateCreate: copyStateCreate })
}
handleChangeCheckboxEdit = (checked, index, menuItem = null, menuIdxList = []) => {
let copyStateEdit = [...this.state.stateUpdate];
copyStateEdit[index] = checked;
@ -411,7 +360,6 @@ export default class DialogMenuRoles extends Component {
})
this.setState({ stateUpdate: copyStateEdit })
}
handleChangeCheckboxDelete = (checked, index, menuItem = null, menuIdxList = []) => {
let copyStateDelete = [...this.state.stateDelete];
copyStateDelete[index] = checked;
@ -436,7 +384,6 @@ export default class DialogMenuRoles extends Component {
})
this.setState({ stateDelete: copyStateDelete })
}
handleChangeCheckboxReadAll = (checked) => {
let copyStateRead = [...this.state.stateRead];
copyStateRead.map((val, index) => {
@ -444,7 +391,6 @@ export default class DialogMenuRoles extends Component {
})
this.setState({ stateRead: copyStateRead })
}
handleChangeCheckboxCreateAll = (checked, index) => {
let copyStateCreate = [...this.state.stateCreate];
copyStateCreate.map((val, index) => {
@ -452,7 +398,6 @@ export default class DialogMenuRoles extends Component {
})
this.setState({ stateCreate: copyStateCreate })
}
handleChangeCheckboxEditAll = (checked, index) => {
let copyStateEdit = [...this.state.stateUpdate];
copyStateEdit.map((val, index) => {
@ -460,7 +405,6 @@ export default class DialogMenuRoles extends Component {
})
this.setState({ stateUpdate: copyStateEdit })
}
handleChangeCheckboxDeleteAll = (checked, index) => {
let copyStateDelete = [...this.state.stateDelete];
copyStateDelete.map((val, index) => {
@ -468,7 +412,6 @@ export default class DialogMenuRoles extends Component {
})
this.setState({ stateDelete: copyStateDelete })
}
renderForm = () => {
const { menu, stateRead, stateCreate, stateUpdate, stateDelete } = this.state;
let menuIdxList = []
@ -476,16 +419,13 @@ export default class DialogMenuRoles extends Component {
const getChildren = (parentId) => {
return menu.filter(item => item.parent_menu_id === parentId);
};
const renderMenu = (parentId, depth = 0) => {
const children = getChildren(parentId);
return children.map((menuItem, index) => {
const currentIndex = menuIdx;
menuIdxList[currentIndex] = menuItem.menu_id;
menuIdx++
const paddingLeft = depth * 30;
return (
<React.Fragment key={menuIdx - 1}>
<tr >
@ -509,10 +449,7 @@ export default class DialogMenuRoles extends Component {
</React.Fragment>
);
};
renderAll = () => {
return (
<tr>
<td>All</td>
@ -523,45 +460,32 @@ export default class DialogMenuRoles extends Component {
</tr>
)
}
checkArray = (val) => {
return val === false;
}
handleAllChecked = (checked) => {
this.setState({ allChecked: !this.state.allChecked });
if (checked === true) {
let check = this.state.stateMenu.some(this.checkArray);
if (check) {
const stateMenu = [];
this.state.menu.map((val) => {
stateMenu.push(true);
})
this.setState({ stateMenu: [] }, () => {
this.setState({ stateMenu: stateMenu });
})
}
} else {
const stateMenu = [];
this.state.menu.map((val) => {
stateMenu.push(false);
})
this.setState({ stateMenu: [] }, () => {
this.setState({ stateMenu: stateMenu });
})
}
}
render() {
return (
<Modal size="xl" scrollable={true} isOpen={this.props.openDialog} toggle={this.props.toggleDialog}>
@ -584,7 +508,6 @@ export default class DialogMenuRoles extends Component {
<th>
Delete
</th>
</tr>
</thead>
<tbody>

Loading…
Cancel
Save