|
|
|
@ -9,46 +9,10 @@ import { NotificationContainer, NotificationManager } from 'react-notifications'
|
|
|
|
|
import { PROJECT_ROLE_ADD, PROJECT_ROLE_SEARCH, PROJECT_ROLE_EDIT, PROJECT_ROLE_DELETE, ROLEMENU_ADD, ROLEMENU_SEARCH, ROLEMENU_DELETE_ROLE } from '../../../const/ApiConst.js'; |
|
|
|
|
import { Pagination, Tooltip, Table } from 'antd'; |
|
|
|
|
import { withTranslation } from 'react-i18next'; |
|
|
|
|
const token = window.localStorage.getItem('token'); |
|
|
|
|
const company_id = localStorage.getItem("company_id") |
|
|
|
|
const role_name = window.localStorage.getItem('role_name'); |
|
|
|
|
const BASE_URL = "http://siopas.co.id/custom-php/api/geohr/"; |
|
|
|
|
|
|
|
|
|
const config = { |
|
|
|
|
headers: |
|
|
|
|
{ |
|
|
|
|
Authorization: `Bearer ${token}`, |
|
|
|
|
"Content-type": `application/json` |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const momentFormat = 'HH:mm'; |
|
|
|
|
|
|
|
|
|
const column = [ |
|
|
|
|
{ name: "Nama" }, |
|
|
|
|
{ name: "Deskripsi" }, |
|
|
|
|
] |
|
|
|
|
|
|
|
|
|
const LENGTH_DATA = 10 |
|
|
|
|
|
|
|
|
|
class index extends Component { |
|
|
|
|
constructor(props) { |
|
|
|
|
let role_id = 0, user_id = 0, isLogin = false, token = '', company_id = 0, all_project = null, role_name='', hierarchy=[], user_name=''; |
|
|
|
|
if (props && props.role_id && props.user_id) { |
|
|
|
|
role_id = props.role_id; |
|
|
|
|
user_id = props.user_id; |
|
|
|
|
token = props.token; |
|
|
|
|
isLogin = props.isLogin; |
|
|
|
|
company_id = props.company_id; |
|
|
|
|
all_project = props.all_project; |
|
|
|
|
role_name = props.role_name; |
|
|
|
|
isLogin = props.isLogin; |
|
|
|
|
hierarchy = props.hierarchy; |
|
|
|
|
user_name = props.user_name; |
|
|
|
|
} |
|
|
|
|
super(props) |
|
|
|
|
super(props); |
|
|
|
|
this.state = { |
|
|
|
|
alertDelete: false, |
|
|
|
|
alertNotDelete: false, |
|
|
|
@ -74,9 +38,23 @@ class index extends Component {
|
|
|
|
|
tooltipTambah: false, |
|
|
|
|
totalPage: 0, |
|
|
|
|
typeDialog: 'Save', |
|
|
|
|
company_id: company_id, |
|
|
|
|
role_name: role_name |
|
|
|
|
} |
|
|
|
|
company_id: props.company_id || 0, |
|
|
|
|
role_name: props.role_name || '', |
|
|
|
|
role_id: props.role_id || 0, |
|
|
|
|
user_id: props.user_id || 0, |
|
|
|
|
isLogin: props.isLogin || false, |
|
|
|
|
token: props.token || '', |
|
|
|
|
all_project: props.all_project || null, |
|
|
|
|
hierarchy: props.hierarchy || [], |
|
|
|
|
user_name: props.user_name || '', |
|
|
|
|
config: { |
|
|
|
|
headers: { |
|
|
|
|
Authorization: `Bearer ${props.token || ''}`, |
|
|
|
|
"Content-type": "application/json", |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
this.columns = [ |
|
|
|
|
{ |
|
|
|
|
title: this.props.t('action'), |
|
|
|
@ -86,21 +64,27 @@ class index extends Component {
|
|
|
|
|
render: (text, record) => <> |
|
|
|
|
<Tooltip title={this.props.t('delete')}> |
|
|
|
|
<i className="fa fa-trash" style={{ color: 'red', marginRight: 10, cursor: "pointer" }} onClick={() => this.handleDelete(text.id)}></i> |
|
|
|
|
|
|
|
|
|
</Tooltip> |
|
|
|
|
|
|
|
|
|
<Tooltip title={this.props.t('edit')}> |
|
|
|
|
<i className="fa fa-edit" style={{ color: 'green', cursor: "pointer" }} onClick={() => this.handleEdit(text)}></i> |
|
|
|
|
</Tooltip> |
|
|
|
|
</>, |
|
|
|
|
}, |
|
|
|
|
{ |
|
|
|
|
title: this.state.role_name === 'Super Admin' ? "Company Name" : null, |
|
|
|
|
dataIndex: "join_first_company_name", |
|
|
|
|
key: "join_first_company_name", |
|
|
|
|
render: (text, record) => { |
|
|
|
|
return this.state.role_name === 'Super Admin' ? ( |
|
|
|
|
<span>{record.join_first_company_name}</span> |
|
|
|
|
) : null; |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
{ title: this.props.t('name'), dataIndex: 'name', key: 'name', className: "nowrap" }, |
|
|
|
|
{ title: this.props.t('description'), dataIndex: 'description', key: 'description' }, |
|
|
|
|
]; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async componentDidMount() { |
|
|
|
|
this.getDataRoles(); |
|
|
|
|
} |
|
|
|
@ -123,9 +107,18 @@ class index extends Component {
|
|
|
|
|
|
|
|
|
|
const formData = { |
|
|
|
|
"paging": { "start": start, "length": this.state.rowsPerPage }, |
|
|
|
|
"columns": [ |
|
|
|
|
{ "name": "name", "logic_operator": "ilike", "value": this.state.search, "operator": "AND" }, |
|
|
|
|
], |
|
|
|
|
"columns": [], |
|
|
|
|
group_column: { |
|
|
|
|
"operator": "AND", |
|
|
|
|
"group_operator": "OR", |
|
|
|
|
"where": [ |
|
|
|
|
{ |
|
|
|
|
"name": "name", |
|
|
|
|
"logic_operator": "~*", |
|
|
|
|
"value": this.state.search, |
|
|
|
|
} |
|
|
|
|
] |
|
|
|
|
}, |
|
|
|
|
"joins": [], |
|
|
|
|
"orders": { "columns": ["id"], "ascending": false } |
|
|
|
|
} |
|
|
|
@ -137,9 +130,15 @@ class index extends Component {
|
|
|
|
|
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"] } |
|
|
|
|
) |
|
|
|
|
formData.group_column.where.push( |
|
|
|
|
{ name: "company_name", logic_operator: "~*", value: this.state.search, table_name: "m_company" } |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
const result = await axios |
|
|
|
|
.post(PROJECT_ROLE_SEARCH, formData, config) |
|
|
|
|
.post(PROJECT_ROLE_SEARCH, formData, this.state.config) |
|
|
|
|
.then(res => res) |
|
|
|
|
.catch((error) => error.response); |
|
|
|
|
|
|
|
|
@ -184,7 +183,7 @@ class index extends Component {
|
|
|
|
|
const { idDelete } = this.state |
|
|
|
|
const url = PROJECT_ROLE_DELETE(idDelete) |
|
|
|
|
|
|
|
|
|
const result = await axios.delete(url, config) |
|
|
|
|
const result = await axios.delete(url, this.state.config) |
|
|
|
|
.then(res => res) |
|
|
|
|
.catch((error) => error.response); |
|
|
|
|
|
|
|
|
@ -203,10 +202,10 @@ class index extends Component {
|
|
|
|
|
const formData = { |
|
|
|
|
name: data.name, |
|
|
|
|
description: data.description, |
|
|
|
|
company_id |
|
|
|
|
company_id: this.state.company_id |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const result = await axios.post(PROJECT_ROLE_ADD, formData, config) |
|
|
|
|
const result = await axios.post(PROJECT_ROLE_ADD, formData, this.state.config) |
|
|
|
|
.then(res => res) |
|
|
|
|
.catch((error) => error.response); |
|
|
|
|
|
|
|
|
@ -224,10 +223,10 @@ class index extends Component {
|
|
|
|
|
const formData = { |
|
|
|
|
name: data.name, |
|
|
|
|
description: data.description, |
|
|
|
|
company_id |
|
|
|
|
company_id : this.state.company_id |
|
|
|
|
} |
|
|
|
|
const url = PROJECT_ROLE_EDIT(data.id) |
|
|
|
|
const result = await axios.put(url, formData, config) |
|
|
|
|
const result = await axios.put(url, formData, this.state.config) |
|
|
|
|
.then(res => res) |
|
|
|
|
.catch((error) => error.response); |
|
|
|
|
|
|
|
|
@ -290,24 +289,50 @@ class index extends Component {
|
|
|
|
|
handleExportExcel = async () => { |
|
|
|
|
const payload = { |
|
|
|
|
"paging": { "start": 0, "length": -1 }, |
|
|
|
|
"columns": [ |
|
|
|
|
{ "name": "name", "logic_operator": "ilike", "value": this.state.search, "operator": "AND" } |
|
|
|
|
], |
|
|
|
|
"columns": [], |
|
|
|
|
"group_column": { |
|
|
|
|
"operator": "AND", |
|
|
|
|
"group_operator": "OR", |
|
|
|
|
"where": [ |
|
|
|
|
{ |
|
|
|
|
"name": "name", |
|
|
|
|
"logic_operator": "~*", |
|
|
|
|
"value": this.state.search, |
|
|
|
|
} |
|
|
|
|
] |
|
|
|
|
}, |
|
|
|
|
"joins": [], |
|
|
|
|
"orders": { "columns": ["id"], "ascending": false } |
|
|
|
|
} |
|
|
|
|
if (this.state.role_name !== "Super Admin") { |
|
|
|
|
payload.columns.push( |
|
|
|
|
{ "name": "company_id", "logic_operator": "=", "value": this.state.company_id, "operator": "AND" }, |
|
|
|
|
) |
|
|
|
|
} else { |
|
|
|
|
payload.columns.push( |
|
|
|
|
{ "name": "company_id", "logic_operator": "is null", "value": "", "operator": "AND" }, |
|
|
|
|
) |
|
|
|
|
payload.joins.push( |
|
|
|
|
{ "name": "m_company", "column_join": "company_id", "column_results": ["company_name"] } |
|
|
|
|
) |
|
|
|
|
payload.group_column.where.push( |
|
|
|
|
{ name: "company_name", logic_operator: "~*", value: this.state.search, table_name: "m_company" } |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
const result = await axios |
|
|
|
|
.post(PROJECT_ROLE_SEARCH, payload, config) |
|
|
|
|
.post(PROJECT_ROLE_SEARCH, payload, this.state.config) |
|
|
|
|
.then(res => res) |
|
|
|
|
.catch((error) => error.response); |
|
|
|
|
if (result && result.data && result.statusText == "OK") { |
|
|
|
|
const dataRes = result.data.data || []; |
|
|
|
|
const dataExport = []; |
|
|
|
|
dataRes.map((val, index) => { |
|
|
|
|
let row = { |
|
|
|
|
Nama: val.name, |
|
|
|
|
Deskripsi: val.description |
|
|
|
|
let row = {}; |
|
|
|
|
if (this.state.role_name === 'Super Admin') { |
|
|
|
|
row.Company = val.join_first_company_name; |
|
|
|
|
} |
|
|
|
|
row.Nama = val.name; |
|
|
|
|
row.Deskripsi = val.description; |
|
|
|
|
dataExport.push(row); |
|
|
|
|
}) |
|
|
|
|
this.setState({ dataExport: dataExport }, () => { |
|
|
|
@ -371,7 +396,7 @@ class index extends Component {
|
|
|
|
|
<h4>{this.props.params.name}</h4> |
|
|
|
|
<Row> |
|
|
|
|
<Col> |
|
|
|
|
<Input onChange={this.handleSearch} value={search} type="text" name="search" id="search" placeholder={this.props.t('searchProjectRoles')} /> |
|
|
|
|
<Input onChange={this.handleSearch} value={search} type="text" name="search" id="search" placeholder={this.props.t('search')} /> |
|
|
|
|
</Col> |
|
|
|
|
<Col> |
|
|
|
|
<Tooltip title={this.props.t('rolesAdd')}> |
|
|
|
|