Browse Source

Merge pull request 'Dev-Farhan' (#11) from Dev-Farhan into staging

Reviewed-on: ibnu/generic-ospro-frontend#11
pull/1/head
farhantock 12 months ago
parent
commit
eaf181e036
  1. 80
      src/views/Master/MasterRoles/DialogForm.js
  2. 84
      src/views/Master/MasterRoles/DialogMenuRoles.js
  3. 10
      src/views/Master/MasterRoles/index.js
  4. 5
      src/views/SimproV2/CreatedProyek/index.js

80
src/views/Master/MasterRoles/DialogForm.js

@ -5,7 +5,7 @@ import 'antd/dist/antd.css';
import { withTranslation } from 'react-i18next'; import { withTranslation } from 'react-i18next';
import axios from 'axios'; import axios from 'axios';
import { Select } from 'antd'; import { Select } from 'antd';
import { MENU_SEARCH } from '../../../const/ApiConst.js'; import { MENU_COMPANY_SEARCH, MENU_SEARCH } from '../../../const/ApiConst.js';
const { Option } = Select const { Option } = Select
const token = window.localStorage.getItem('token'); const token = window.localStorage.getItem('token');
@ -18,6 +18,7 @@ const config = {
} }
}; };
class DialogForm extends Component { class DialogForm extends Component {
constructor(props) { constructor(props) {
super(props) super(props)
@ -29,7 +30,6 @@ class DialogForm extends Component {
isParentClick: false, isParentClick: false,
menu: [], menu: [],
selectedMenu: null, selectedMenu: null,
company_id
} }
} }
@ -61,21 +61,60 @@ class DialogForm extends Component {
} }
getAllMenu = async () => { getAllMenu = async () => {
const payload = { const { companyID } = this.props;
"paging": { "start": 0, "length": -1 }, const { roleName } = this.props;
"columns": [ if (roleName !== "Super Admin") {
{ "name": "name", "logic_operator": "ilike", "value": "", "operator": "AND" } const payload = {
], "paging": {
"joins": [], "start": 0,
"orders": { "columns": ["id"], "ascending": false } "length": -1
} },
const result = await axios "columns": [{
.post(MENU_SEARCH, payload, config) "name": "company_id",
.then(res => res) "logic_operator": "=",
.catch((error) => error.response); "value": companyID,
if (result && result.data && result.data.code == 200) { "operator": "AND"
this.setState({ menu: result.data.data }); }],
"joins": [{
"name": "m_menu",
"column_join": "menu_id",
"column_results": [
"name"
]
}],
"orders": { "columns": ["id"], "ascending": false }
}
const result = await axios
.post(MENU_COMPANY_SEARCH, payload, config)
.then(res => res)
.catch((error) => error.response);
if (result && result.data && result.data.code == 200) {
this.setState({ menu: result.data.data });
}
} else {
const payload = {
"paging": {
"start": 0,
"length": -1
},
"columns": [{
"name": "name",
"logic_operator": "ilike",
"value": "",
"operator": "AND"
}],
"orders": { "columns": ["id"], "ascending": false }
}
const result = await axios
.post(MENU_SEARCH, payload, config)
.then(res => res)
.catch((error) => error.response);
if (result && result.data && result.data.code == 200) {
this.setState({ menu: result.data.data });
}
} }
} }
showDialog = () => { showDialog = () => {
@ -94,12 +133,13 @@ class DialogForm extends Component {
} }
handleSave = () => { handleSave = () => {
const { companyID } = this.props;
const { const {
id, id,
name, name,
description, description,
selectedMenu, selectedMenu,
company_id
} = this.state } = this.state
let data = ''; let data = '';
@ -111,7 +151,7 @@ class DialogForm extends Component {
name, name,
description, description,
selectedMenu, selectedMenu,
company_id company_id: companyID
} }
// console.log('data', data); // console.log('data', data);
this.props.closeDialog('save', data); this.props.closeDialog('save', data);
@ -121,7 +161,7 @@ class DialogForm extends Component {
name, name,
description, description,
selectedMenu, selectedMenu,
company_id company_id: companyID
} }
this.props.closeDialog('edit', data); this.props.closeDialog('edit', data);
} }
@ -166,7 +206,7 @@ class DialogForm extends Component {
}}> }}>
{this.state.menu.map((item) => ( {this.state.menu.map((item) => (
<option key={item.id} value={item.id}> <option key={item.id} value={item.id}>
{item.name} {item.name ?? item.join_first_name}
</option> </option>
))} ))}
</Input> </Input>

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

@ -3,9 +3,8 @@ import { Modal, ModalHeader, ModalBody, ModalFooter, Row, Col, Table } from 'rea
import { Button, Form, FormGroup, Label, Input } from 'reactstrap'; import { Button, Form, FormGroup, Label, Input } from 'reactstrap';
import 'antd/dist/antd.css'; import 'antd/dist/antd.css';
import axios from 'axios'; import axios from 'axios';
import { MENU_SEARCH } from '../../../const/ApiConst.js'; import { MENU_COMPANY_SEARCH, MENU_SEARCH } from '../../../const/ApiConst.js';
import { withTranslation, WithTranslation } from 'react-i18next'; import { withTranslation, WithTranslation } from 'react-i18next';
const BASE_URL = "http://siopas.co.id/custom-php/api/geohr/";
const token = window.localStorage.getItem('token'); const token = window.localStorage.getItem('token');
@ -52,30 +51,61 @@ class DialogMenuRoles extends Component {
} }
getAllMenu = async () => { getAllMenu = async () => {
const payload = { const { companyID } = this.props;
"paging": { "start": 0, "length": -1 }, const { roleName } = this.props;
"columns": [ if (roleName !== "Super Admin") {
{ "name": "name", "logic_operator": "ilike", "value": "", "operator": "AND" } const payload = {
], "paging": {
"joins": [], "start": 0,
"orders": { "columns": ["id"], "ascending": false } "length": -1
} },
"columns": [{
"name": "company_id",
"logic_operator": "=",
const result = await axios "value": companyID,
.post(MENU_SEARCH, payload, config) "operator": "AND"
.then(res => res) }],
.catch((error) => error.response); "joins": [{
"name": "m_menu",
"column_join": "menu_id",
if (result && result.data && result.data.code == 200) { "column_results": [
this.setState({ menu: result.data.data }, () => { "name"
this.setStateMenu(false); ]
}); }],
"orders": { "columns": ["id"], "ascending": false }
}
const result = await axios
.post(MENU_COMPANY_SEARCH, payload, config)
.then(res => res)
.catch((error) => error.response);
if (result && result.data && result.data.code == 200) {
this.setState({ menu: result.data.data }, () => {
this.setStateMenu(false);
});
} else {
}
} else { } else {
const payload = {
"paging": {
"start": 0,
"length": -1
},
"columns": [{
"name": "name",
"logic_operator": "ilike",
"value": "",
"operator": "AND"
}],
"orders": { "columns": ["id"], "ascending": false }
}
const result = await axios
.post(MENU_SEARCH, payload, config)
.then(res => res)
.catch((error) => error.response);
if (result && result.data && result.data.code == 200) {
this.setState({ menu: result.data.data });
}
} }
} }
setStateMenu = edit => { setStateMenu = edit => {
@ -96,13 +126,14 @@ class DialogMenuRoles extends Component {
let copyStateMenu = [...this.state.stateMenu]; let copyStateMenu = [...this.state.stateMenu];
this.props.menuRoles.map((val, indexMenu) => { this.props.menuRoles.map((val, indexMenu) => {
let index = this.getIndexDataMenu(val.menu_id); let index = this.getIndexDataMenu(val.menu_id);
console.log("index true", val.menu_id); console.log('index true', index);
if (index >= 0) { if (index >= 0) {
copyStateMenu[index] = true; copyStateMenu[index] = true;
} }
}) })
this.setState({ stateMenu: [] }, () => { this.setState({ stateMenu: [] }, () => {
let check = copyStateMenu.some(this.checkArray); let check = copyStateMenu.some(this.checkArray);
console.log('icheck', check);
if (check === false) { if (check === false) {
this.setState({ allChecked: true, stateMenu: copyStateMenu }) this.setState({ allChecked: true, stateMenu: copyStateMenu })
} else { } else {
@ -151,11 +182,12 @@ class DialogMenuRoles extends Component {
renderForm = () => { renderForm = () => {
const { menu, stateMenu } = this.state const { menu, stateMenu } = this.state
console.log('stateMenu', stateMenu);
return ( return (
menu.map((val, index) => { menu.map((val, index) => {
return ( return (
<tr key={index}> <tr key={index}>
<td>{val.name}</td> <td>{val.join_first_name ?? val.name}</td>
<td><input type="checkbox" onClick={(e) => this.handleChangeCheckbox(e.target.checked, index)} defaultChecked={stateMenu[index]} /></td> <td><input type="checkbox" onClick={(e) => this.handleChangeCheckbox(e.target.checked, index)} defaultChecked={stateMenu[index]} /></td>
</tr> </tr>
) )

10
src/views/Master/MasterRoles/index.js

@ -198,7 +198,7 @@ class index extends Component {
name: data.name, name: data.name,
description: data.description, description: data.description,
default_page: data.selectedMenu, default_page: data.selectedMenu,
company_id: this.company_id company_id: data.company_id
} }
const result = await axios.post(ROLE_ADD, formData, this.config) const result = await axios.post(ROLE_ADD, formData, this.config)
@ -218,7 +218,8 @@ class index extends Component {
const formData = { const formData = {
name: data.name, name: data.name,
description: data.description, description: data.description,
default_page: data.selectedMenu default_page: data.selectedMenu,
company_id: data.company_id
} }
const url = ROLE_EDIT(data.id) const url = ROLE_EDIT(data.id)
const result = await axios.put(url, formData, this.config) const result = await axios.put(url, formData, this.config)
@ -426,6 +427,9 @@ class index extends Component {
dataEdit={this.state.dataEdit} dataEdit={this.state.dataEdit}
showDialog={showDialog => this.showChildDialog = showDialog} showDialog={showDialog => this.showChildDialog = showDialog}
dataHs={this.state.dataIdHo} dataHs={this.state.dataIdHo}
companyID={this.state.company_id}
roleName={this.state.role_name}
/> />
<DialogMenuRoles <DialogMenuRoles
openDialog={dialogMenuForm} openDialog={dialogMenuForm}
@ -433,6 +437,8 @@ class index extends Component {
idRoles={this.state.idRoles} idRoles={this.state.idRoles}
showDialog={showDialog => this.showMenuRolesDialog = showDialog} showDialog={showDialog => this.showMenuRolesDialog = showDialog}
menuRoles={this.state.menuRoles} menuRoles={this.state.menuRoles}
companyID={this.state.company_id}
roleName={this.state.role_name}
/> />
<Card> <Card>
<CardHeader style={{ display: "flex", justifyContent: "space-between" }}> <CardHeader style={{ display: "flex", justifyContent: "space-between" }}>

5
src/views/SimproV2/CreatedProyek/index.js

@ -306,7 +306,7 @@ const CreatedProyek = ({ params, ...props }) => {
const getDataProyek = async () => { const getDataProyek = async () => {
let start = 0; let start = 0;
let hierarchy = []; let hierarchy = [];
//hierarchy.push(JSON.parse(localStorage.getItem("hierarchy"))); hierarchy.push(JSON.parse(localStorage.getItem("hierarchy")));
if (currentPage !== 1 && currentPage > 1) { if (currentPage !== 1 && currentPage > 1) {
start = currentPage * rowsPerPage - rowsPerPage; start = currentPage * rowsPerPage - rowsPerPage;
} }
@ -346,9 +346,8 @@ const CreatedProyek = ({ params, ...props }) => {
paging: { start: start, length: rowsPerPage }, paging: { start: start, length: rowsPerPage },
}; };
if (parseInt(role_id) !== 1) { if (parseInt(role_id) !== 70) {
payload["columns"] = [ payload["columns"] = [
{ name: "id", logic_operator: "=", value: proyek_id, operator: "AND" },
{ name: "created_by_id", logic_operator: "IN", value: hierarchy, operator: "AND" } { name: "created_by_id", logic_operator: "IN", value: hierarchy, operator: "AND" }
]; ];
} }

Loading…
Cancel
Save