|
|
|
@ -43,7 +43,6 @@ class index extends Component {
|
|
|
|
|
tooltipTambah: false, |
|
|
|
|
totalPage: 0, |
|
|
|
|
typeDialog: 'Save', |
|
|
|
|
company_id: props.company_id || 0, |
|
|
|
|
role_name: props.role_name || '', |
|
|
|
|
role_id: props.role_id || 0, |
|
|
|
|
user_id: props.user_id || 0, |
|
|
|
@ -68,29 +67,27 @@ class index extends Component {
|
|
|
|
|
render: (text, record) => <> |
|
|
|
|
<Tooltip title={this.props.t('menuRoles')}> |
|
|
|
|
{ |
|
|
|
|
checkActMenup('/roles', 'update') ? |
|
|
|
|
<i className="cil-menu fa-lg" style={{ color: 'green', marginRight: 10, cursor: "pointer" }} onClick={() => this.handleMenuRoles(text.id)}></i> |
|
|
|
|
: |
|
|
|
|
null |
|
|
|
|
} |
|
|
|
|
checkActMenup('/roles', 'update') ? |
|
|
|
|
<i className="cil-menu fa-lg" style={{ color: 'green', marginRight: 10, cursor: "pointer" }} onClick={() => this.handleMenuRoles(text)}></i> |
|
|
|
|
: |
|
|
|
|
null |
|
|
|
|
} |
|
|
|
|
</Tooltip> |
|
|
|
|
|
|
|
|
|
<Tooltip title={this.props.t('delete')}> |
|
|
|
|
{ |
|
|
|
|
checkActMenup('/roles', 'delete') ? |
|
|
|
|
<i className="fa fa-trash" style={{ color: 'red', marginRight: 10, cursor: "pointer" }} onClick={() => this.handleDelete(text.id)}></i> |
|
|
|
|
: |
|
|
|
|
null |
|
|
|
|
} |
|
|
|
|
checkActMenup('/roles', 'delete') ? |
|
|
|
|
<i className="fa fa-trash" style={{ color: 'red', marginRight: 10, cursor: "pointer" }} onClick={() => this.handleDelete(text)}></i> |
|
|
|
|
: |
|
|
|
|
null |
|
|
|
|
} |
|
|
|
|
</Tooltip> |
|
|
|
|
|
|
|
|
|
<Tooltip title={this.props.t('edit')}> |
|
|
|
|
{ |
|
|
|
|
checkActMenup('/roles', 'update') ? |
|
|
|
|
<i className="fa fa-edit" style={{ color: 'green', cursor: "pointer" }} onClick={() => this.handleEdit(text)}></i> |
|
|
|
|
: |
|
|
|
|
null |
|
|
|
|
} |
|
|
|
|
checkActMenup('/roles', 'update') ? |
|
|
|
|
<i className="fa fa-edit" style={{ color: 'green', cursor: "pointer" }} onClick={() => this.handleEdit(text)}></i> |
|
|
|
|
: |
|
|
|
|
null |
|
|
|
|
} |
|
|
|
|
</Tooltip> |
|
|
|
|
</>, |
|
|
|
|
}, |
|
|
|
@ -133,7 +130,6 @@ class index extends Component {
|
|
|
|
|
if (this.state.currentPage !== 1 && this.state.currentPage > 1) { |
|
|
|
|
start = (this.state.currentPage * this.state.rowsPerPage) - this.state.rowsPerPage |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const formData = { |
|
|
|
|
"paging": { "start": start, "length": this.state.rowsPerPage }, |
|
|
|
|
"columns": [], |
|
|
|
@ -153,12 +149,9 @@ class index extends Component {
|
|
|
|
|
} |
|
|
|
|
if (this.state.role_name !== "Super Admin") { |
|
|
|
|
formData.columns.push( |
|
|
|
|
{ "name": "company_id", "logic_operator": "=", "value": this.state.company_id, "operator": "AND" }, |
|
|
|
|
{ "name": "company_id", "logic_operator": "=", "value": this.props.company_id, "operator": "AND" }, |
|
|
|
|
) |
|
|
|
|
} else { |
|
|
|
|
// formData.columns.push(
|
|
|
|
|
// { "name": "company_id", "logic_operator": "is null", "value": "", "operator": "AND" },
|
|
|
|
|
// )
|
|
|
|
|
formData.joins.push( |
|
|
|
|
{ "name": "m_company", "column_join": "company_id", "column_results": ["company_name"] } |
|
|
|
|
) |
|
|
|
@ -228,7 +221,6 @@ class index extends Component {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
saveRole = async (data) => { |
|
|
|
|
|
|
|
|
|
const formData = { |
|
|
|
|
name: data.name, |
|
|
|
|
description: data.description, |
|
|
|
@ -247,7 +239,6 @@ class index extends Component {
|
|
|
|
|
} else { |
|
|
|
|
NotificationManager.error(`Data role gagal ditambahkan`, 'Failed!!'); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
editRole = async (data) => { |
|
|
|
@ -272,13 +263,13 @@ class index extends Component {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
handleEdit = (data) => { |
|
|
|
|
this.setState({ dataEdit: data }); |
|
|
|
|
this.setState({ dataEdit: data, company_id: data.company_id }); |
|
|
|
|
this.handleOpenDialog('Edit'); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
handleDelete = (id) => { |
|
|
|
|
id == '1' ? this.setState({ alertNotDelete: true }) : |
|
|
|
|
this.setState({ alertDelete: true, idDelete: id }); |
|
|
|
|
handleDelete = (data) => { |
|
|
|
|
data.id == '1' ? this.setState({ alertNotDelete: true }) : |
|
|
|
|
this.setState({ alertDelete: true, idDelete: data.id }); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
onShowSizeChange = (current, pageSize) => { |
|
|
|
@ -317,29 +308,24 @@ class index extends Component {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
handleMenuRoles = async (id) => { |
|
|
|
|
handleMenuRoles = async (data) => { |
|
|
|
|
const formData = { |
|
|
|
|
"paging": { "start": 0, "length": -1 }, |
|
|
|
|
"columns": [], |
|
|
|
|
"joins": [{ "name": "m_menu", "column_join": "menu_id", "column_results": ["parent_id", "name"] }], |
|
|
|
|
"orders": { "columns": ["id"], "ascending": false } |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (this.state.role_name !== "Super Admin") { |
|
|
|
|
formData.columns.push( |
|
|
|
|
{ "name": "role_id", "logic_operator": "=", "value": `${id}`, "operator": "AND" } |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
formData.columns.push( |
|
|
|
|
{ "name": "role_id", "logic_operator": "=", "value": parseInt(data.id), "operator": "AND" } |
|
|
|
|
) |
|
|
|
|
const result = await axios |
|
|
|
|
.post(ROLEMENU_SEARCH, formData, this.state.config) |
|
|
|
|
.then(res => res) |
|
|
|
|
.catch((error) => error.response); |
|
|
|
|
if (result && result.data && result.data.code == 200) { |
|
|
|
|
this.setState({ menuRoles: result.data.data, idRoles: id }, () => { |
|
|
|
|
this.setState({ menuRoles: result.data.data, idRoles: data.id, company_id: data.company_id }, () => { |
|
|
|
|
this.handleOpenDialogMr(); |
|
|
|
|
}); |
|
|
|
|
} else { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -348,8 +334,7 @@ class index extends Component {
|
|
|
|
|
if (payloadArray.length > 0) { |
|
|
|
|
await this.deleteCurrentRoleMenu(payloadArray[0].roles_id) |
|
|
|
|
} |
|
|
|
|
let promises = [] |
|
|
|
|
let result = [] |
|
|
|
|
let dataArr = [] |
|
|
|
|
dataArray.map((val, index) => { |
|
|
|
|
if (val.read === true) { |
|
|
|
|
const formData = { |
|
|
|
@ -359,24 +344,22 @@ class index extends Component {
|
|
|
|
|
read: val.read, |
|
|
|
|
update: val.update, |
|
|
|
|
delete: val.delete |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
promises.push(axios.post(ROLEMENU_ADD, formData, this.state.config) |
|
|
|
|
.then(res => result.push(res))) |
|
|
|
|
dataArr.push(formData); |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
await Promise.all(promises); |
|
|
|
|
if (result) { |
|
|
|
|
if (result.length > 0) { |
|
|
|
|
if (result[0].data.code === 200) { |
|
|
|
|
this.getDataRoles(); |
|
|
|
|
NotificationManager.success('Data roles berhasil ditambahkan!!', 'Success!!'); |
|
|
|
|
} else { |
|
|
|
|
NotificationManager.error(`${result[0].data.message}`, 'Failed!!'); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
const result = await axios |
|
|
|
|
.post(ROLEMENU_ADD, dataArr, this.state.config) |
|
|
|
|
.then((res) => res) |
|
|
|
|
.catch((err) => err.response); |
|
|
|
|
|
|
|
|
|
if (result && result.data && result.data.code == 200) { |
|
|
|
|
this.getDataRoles(); |
|
|
|
|
NotificationManager.success('Data roles berhasil ditambahkan!!', 'Success!!'); |
|
|
|
|
} else { |
|
|
|
|
NotificationManager.error(`${result.data.message}`, 'Failed!!'); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
deleteCurrentRoleMenu = async (id) => { |
|
|
|
@ -413,12 +396,9 @@ class index extends Component {
|
|
|
|
|
|
|
|
|
|
if (this.state.role_name !== "Super Admin") { |
|
|
|
|
formData.columns.push( |
|
|
|
|
{ "name": "company_id", "logic_operator": "=", "value": this.state.company_id, "operator": "AND" }, |
|
|
|
|
{ "name": "company_id", "logic_operator": "=", "value": this.props.company_id, "operator": "AND" }, |
|
|
|
|
) |
|
|
|
|
} else { |
|
|
|
|
// formData.columns.push(
|
|
|
|
|
// { "name": "company_id", "logic_operator": "is null", "value": "", "operator": "AND" },
|
|
|
|
|
// )
|
|
|
|
|
formData.joins.push( |
|
|
|
|
{ "name": "m_company", "column_join": "company_id", "column_results": ["company_name"] } |
|
|
|
|
) |
|
|
|
@ -462,9 +442,7 @@ class index extends Component {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
render() { |
|
|
|
|
const { t } = this.props; |
|
|
|
|
const { tooltipTambah, tooltipExport, dialogMenuForm, dataTable, openDialog, currentPage, rowsPerPage, totalPage, search, tooltipEdit, tooltipDelete, tooltipMenu } = this.state |
|
|
|
|
let noSeq = 0; |
|
|
|
|
const { dialogMenuForm, dataTable, openDialog, currentPage, rowsPerPage, totalPage, search } = this.state |
|
|
|
|
return ( |
|
|
|
|
<div> |
|
|
|
|
<NotificationContainer /> |
|
|
|
@ -524,16 +502,15 @@ class index extends Component {
|
|
|
|
|
<Col> |
|
|
|
|
<Tooltip title={this.props.t('rolesAdd')}> |
|
|
|
|
{ |
|
|
|
|
checkActMenup('/roles', 'create') ? |
|
|
|
|
<Button Button id="TooltipTambah" color="success" onClick={() => this.handleOpenDialog('Save')}><i className="fa fa-plus"></i> |
|
|
|
|
</Button> |
|
|
|
|
|
|
|
|
|
: |
|
|
|
|
null |
|
|
|
|
} |
|
|
|
|
checkActMenup('/roles', 'create') ? |
|
|
|
|
<Button Button id="TooltipTambah" color="success" onClick={() => this.handleOpenDialog('Save')}><i className="fa fa-plus"></i> |
|
|
|
|
</Button> |
|
|
|
|
: |
|
|
|
|
null |
|
|
|
|
} |
|
|
|
|
</Tooltip> |
|
|
|
|
<Tooltip title={this.props.t('exportExcel')}> |
|
|
|
|
<Button style={{ marginLeft: "5px" }} id="TooltipExport" color="primary" onClick={() => this.handleExportExcel()}><i className="fa fa-print"></i></Button> |
|
|
|
|
<Button style={{ marginLeft: "5px" }} id="TooltipExport" color="primary" onClick={() => this.handleExportExcel()}><i className="fa fa-print"></i></Button> |
|
|
|
|
</Tooltip> |
|
|
|
|
</Col> |
|
|
|
|
</Row> |
|
|
|
|