|
|
@ -6,7 +6,7 @@ import axios from "../../../const/interceptorApi" |
|
|
|
import moment from 'moment' |
|
|
|
import moment from 'moment' |
|
|
|
import { Card, CardBody, CardHeader, Col, Row, Input } from 'reactstrap'; |
|
|
|
import { Card, CardBody, CardHeader, Col, Row, Input } from 'reactstrap'; |
|
|
|
import { NotificationContainer, NotificationManager } from 'react-notifications'; |
|
|
|
import { NotificationContainer, NotificationManager } from 'react-notifications'; |
|
|
|
import { PROJECT_PHASE_ADD, PROJECT_PHASE_EDIT, PROJECT_PHASE_DELETE, PROJECT_PHASE_SEARCH, BASE_OSPRO } from '../../../const/ApiConst'; |
|
|
|
import { PROJECT_PHASE_ADD, PROJECT_PHASE_EDIT, PROJECT_PHASE_DELETE, PROJECT_PHASE_SEARCH, PROJECT_PHASE_LIST, BASE_OSPRO } from '../../../const/ApiConst'; |
|
|
|
import { Pagination, Button, Tooltip, Table } from 'antd'; |
|
|
|
import { Pagination, Button, Tooltip, Table } from 'antd'; |
|
|
|
|
|
|
|
|
|
|
|
const token = window.localStorage.getItem('token'); |
|
|
|
const token = window.localStorage.getItem('token'); |
|
|
@ -40,6 +40,7 @@ const ProjectPhase = ({ params }) => { |
|
|
|
const [clickOpenModal, setClickOpenModal] = useState(false) |
|
|
|
const [clickOpenModal, setClickOpenModal] = useState(false) |
|
|
|
const [currentPage, setCurrentPage] = useState(1) |
|
|
|
const [currentPage, setCurrentPage] = useState(1) |
|
|
|
const [dataEdit, setDataEdit] = useState([]) |
|
|
|
const [dataEdit, setDataEdit] = useState([]) |
|
|
|
|
|
|
|
const [dataExport, setDataExport] = useState([]) |
|
|
|
const [dataTable, setDatatable] = useState([]) |
|
|
|
const [dataTable, setDatatable] = useState([]) |
|
|
|
const [idDelete, setIdDelete] = useState(0) |
|
|
|
const [idDelete, setIdDelete] = useState(0) |
|
|
|
const [idPhaseProject, setIdPhaseProject] = useState(0) |
|
|
|
const [idPhaseProject, setIdPhaseProject] = useState(0) |
|
|
@ -54,17 +55,23 @@ const ProjectPhase = ({ params }) => { |
|
|
|
getDataProjectPhase() |
|
|
|
getDataProjectPhase() |
|
|
|
}, [currentPage, rowsPerPage, search]) |
|
|
|
}, [currentPage, rowsPerPage, search]) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
|
|
|
const cekData = dataExport || [] |
|
|
|
|
|
|
|
if (cekData.length > 0) { |
|
|
|
|
|
|
|
exportExcel() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}, [dataExport]) |
|
|
|
|
|
|
|
|
|
|
|
const getDataProjectPhase = async () => { |
|
|
|
const getDataProjectPhase = async () => { |
|
|
|
let start = 0; |
|
|
|
let start = 0; |
|
|
|
if (currentPage !== 1 && currentPage > 1) { |
|
|
|
if (currentPage !== 1 && currentPage > 1) { |
|
|
|
start = (currentPage * rowsPerPage) - rowsPerPage |
|
|
|
start = (currentPage * rowsPerPage) - rowsPerPage |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const payload = { |
|
|
|
const payload = { |
|
|
|
"columns": [ |
|
|
|
"columns": [ |
|
|
|
{ |
|
|
|
{ |
|
|
|
"name": "name", |
|
|
|
"name": "name", |
|
|
|
"logic_operator": "like", |
|
|
|
"logic_operator": "ilike", |
|
|
|
"value": search, |
|
|
|
"value": search, |
|
|
|
"operator": "AND" |
|
|
|
"operator": "AND" |
|
|
|
} |
|
|
|
} |
|
|
@ -80,18 +87,16 @@ const ProjectPhase = ({ params }) => { |
|
|
|
"start": start |
|
|
|
"start": start |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// let url = `${BASE_OSPRO}/api/project-phase/list?start=${start}&length=${rowsPerPage}&orderby=id&asc=false&column=name&logic=ilike&value=${search}`
|
|
|
|
/*const result = await axios |
|
|
|
const result = await axios |
|
|
|
.post(PROJECT_PHASE_SEARCH, payload, config) |
|
|
|
.post(PROJECT_PHASE_SEARCH, payload, HEADER) |
|
|
|
.then(res => res) |
|
|
|
.then((res) => res) |
|
|
|
.catch((error) => error.response);*/ |
|
|
|
.catch((err) => err.response); |
|
|
|
//const result = await axios.post(PROJECT_PHASE_SEARCH, payload, HEADER).then(res => res).catch(err => err.response)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const URL = `${BASE_OSPRO}/api/project-phase/list` |
|
|
|
|
|
|
|
const result = await axios.get(URL, HEADER).then(res => res).catch(err => err.response) |
|
|
|
|
|
|
|
console.log(result) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (result && result.data && result.data.code == 200) { |
|
|
|
if (result && result.data && result.data.code == 200) { |
|
|
|
|
|
|
|
result.data.data.map((res) => { |
|
|
|
|
|
|
|
res.key = res.id.toString() |
|
|
|
|
|
|
|
}); |
|
|
|
setDatatable(result.data.data); |
|
|
|
setDatatable(result.data.data); |
|
|
|
setTotalPage(result.data.totalRecord); |
|
|
|
setTotalPage(result.data.totalRecord); |
|
|
|
} else { |
|
|
|
} else { |
|
|
@ -104,7 +109,6 @@ const ProjectPhase = ({ params }) => { |
|
|
|
setSearch(value); |
|
|
|
setSearch(value); |
|
|
|
setCurrentPage(1) |
|
|
|
setCurrentPage(1) |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
const handleOpenDialog = (type) => { |
|
|
|
const handleOpenDialog = (type) => { |
|
|
|
setOpenDialog(true) |
|
|
|
setOpenDialog(true) |
|
|
|
setTypeDialog(type) |
|
|
|
setTypeDialog(type) |
|
|
@ -113,19 +117,59 @@ const ProjectPhase = ({ params }) => { |
|
|
|
const handleExportExcel = async () => { |
|
|
|
const handleExportExcel = async () => { |
|
|
|
let start = 0; |
|
|
|
let start = 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (currentPage !== 1 && currentPage > 1) { |
|
|
|
|
|
|
|
start = (currentPage * rowsPerPage) - rowsPerPage |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const payload = { |
|
|
|
const payload = { |
|
|
|
"paging": { "start": start, "length": -1 }, |
|
|
|
|
|
|
|
"columns": [ |
|
|
|
"columns": [ |
|
|
|
{ "name": "name", "logic_operator": "ilike", "value": search, "operator": "AND" } |
|
|
|
{ |
|
|
|
|
|
|
|
"name": "name", |
|
|
|
|
|
|
|
"logic_operator": "like", |
|
|
|
|
|
|
|
"value": search, |
|
|
|
|
|
|
|
"operator": "AND" |
|
|
|
|
|
|
|
} |
|
|
|
], |
|
|
|
], |
|
|
|
"joins": [], |
|
|
|
"orders": { |
|
|
|
"orders": { "columns": ["id"], "ascending": false } |
|
|
|
"ascending": true, |
|
|
|
|
|
|
|
"columns": [ |
|
|
|
|
|
|
|
'id' |
|
|
|
|
|
|
|
] |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
"paging": { |
|
|
|
|
|
|
|
"length": rowsPerPage, |
|
|
|
|
|
|
|
"start": start |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const result = await axios |
|
|
|
const result = await axios |
|
|
|
.post(PROJECT_PHASE_SEARCH, payload) |
|
|
|
.post(PROJECT_PHASE_SEARCH, payload, HEADER) |
|
|
|
.then(res => res) |
|
|
|
.then(res => res) |
|
|
|
.catch((error) => error.response); |
|
|
|
.catch((error) => error.response); |
|
|
|
|
|
|
|
if (result && result.data && result.data.code == 200) { |
|
|
|
|
|
|
|
let resData = result.data.data; |
|
|
|
|
|
|
|
const excelData = []; |
|
|
|
|
|
|
|
resData.map((val, index) => { |
|
|
|
|
|
|
|
let dataRow = { |
|
|
|
|
|
|
|
"Nama": val.name, |
|
|
|
|
|
|
|
"Color": val.color, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
excelData.push(dataRow) |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
await setDataExport(excelData) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
NotificationManager.error('Gagal Export Data!!', 'Failed'); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const exportExcel = () => { |
|
|
|
|
|
|
|
const dataExcel = dataExport || []; |
|
|
|
|
|
|
|
const fileName = `Data ${pageName}.xlsx`; |
|
|
|
|
|
|
|
const ws = XLSX.utils.json_to_sheet(dataExcel); |
|
|
|
|
|
|
|
const wb = XLSX.utils.book_new(); |
|
|
|
|
|
|
|
XLSX.utils.book_append_sheet(wb, ws, `Data ${pageName}`); |
|
|
|
|
|
|
|
XLSX.writeFile(wb, fileName); |
|
|
|
|
|
|
|
setDataExport([]) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const handleEdit = (data) => { |
|
|
|
const handleEdit = (data) => { |
|
|
@ -309,10 +353,16 @@ const ProjectPhase = ({ params }) => { |
|
|
|
<CardHeader style={{ display: "flex", justifyContent: "space-between" }}> |
|
|
|
<CardHeader style={{ display: "flex", justifyContent: "space-between" }}> |
|
|
|
<h4 className="capitalize">{pageName}</h4> |
|
|
|
<h4 className="capitalize">{pageName}</h4> |
|
|
|
<Row> |
|
|
|
<Row> |
|
|
|
|
|
|
|
<Col> |
|
|
|
|
|
|
|
<Input onChange={handleSearch} value={search} type="text" name="search" id="search" placeholder={`Cari Fase`} /> |
|
|
|
|
|
|
|
</Col> |
|
|
|
<Col> |
|
|
|
<Col> |
|
|
|
<Tooltip title="Add new data"> |
|
|
|
<Tooltip title="Add new data"> |
|
|
|
<Button style={{ background: "#4caf50", color: "#fff" }} onClick={() => handleOpenDialog('Save')}><i className="fa fa-plus"></i></Button> |
|
|
|
<Button style={{ background: "#4caf50", color: "#fff" }} onClick={() => handleOpenDialog('Save')}><i className="fa fa-plus"></i></Button> |
|
|
|
</Tooltip> |
|
|
|
</Tooltip> |
|
|
|
|
|
|
|
<Tooltip title="Export Excel"> |
|
|
|
|
|
|
|
<Button style={{ marginLeft: "5px" }} onClick={() => handleExportExcel()}><i className="fa fa-print"></i></Button> |
|
|
|
|
|
|
|
</Tooltip> |
|
|
|
</Col> |
|
|
|
</Col> |
|
|
|
</Row> |
|
|
|
</Row> |
|
|
|
</CardHeader> |
|
|
|
</CardHeader> |
|
|
|