|
|
@ -54,14 +54,23 @@ const ProjectType = ({ params }) => { |
|
|
|
const [typeDialog, setTypeDialog] = useState('Save') |
|
|
|
const [typeDialog, setTypeDialog] = useState('Save') |
|
|
|
const [dataDivisions, setDataDivisions] = useState([]) |
|
|
|
const [dataDivisions, setDataDivisions] = useState([]) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
|
|
|
getListDivision() |
|
|
|
|
|
|
|
}, []) |
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
useEffect(() => { |
|
|
|
getDataProjectType() |
|
|
|
getDataProjectType() |
|
|
|
}, [currentPage, rowsPerPage, search]) |
|
|
|
}, [currentPage, rowsPerPage, search]) |
|
|
|
|
|
|
|
|
|
|
|
const getDataProjectType = async () => { |
|
|
|
useEffect(() => { |
|
|
|
|
|
|
|
const cekData = dataExport || [] |
|
|
|
let start = 0; |
|
|
|
if (cekData.length > 0) { |
|
|
|
|
|
|
|
exportExcel() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}, [dataExport]) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const getListDivision = async () => { |
|
|
|
const listDivions = await axios |
|
|
|
const listDivions = await axios |
|
|
|
.get(DIVISI_LIST, HEADER) |
|
|
|
.get(DIVISI_LIST, HEADER) |
|
|
|
.then(res => res) |
|
|
|
.then(res => res) |
|
|
@ -76,11 +85,12 @@ const ProjectType = ({ params }) => { |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
NotificationManager.error('Gagal Mengambil Data!!', 'Failed'); |
|
|
|
NotificationManager.error('Gagal Mengambil Data!!', 'Failed'); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
const getDataProjectType = async () => { |
|
|
|
|
|
|
|
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": [ |
|
|
|
{ |
|
|
|
{ |
|
|
@ -101,19 +111,78 @@ const ProjectType = ({ params }) => { |
|
|
|
"start": start |
|
|
|
"start": start |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const result = await axios |
|
|
|
const result = await axios |
|
|
|
.post(DIVISI_SEARCH, payload, config) |
|
|
|
.post(DIVISI_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) { |
|
|
|
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 { |
|
|
|
NotificationManager.error('Gagal Mengambil Data!!', 'Failed'); |
|
|
|
NotificationManager.error('Gagal Mengambil Data!!', 'Failed'); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
const handleExportExcel = async () => { |
|
|
|
|
|
|
|
let start = 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (currentPage !== 1 && currentPage > 1) { |
|
|
|
|
|
|
|
start = (currentPage * rowsPerPage) - rowsPerPage |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const payload = { |
|
|
|
|
|
|
|
"columns": [ |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
"name": "name", |
|
|
|
|
|
|
|
"logic_operator": "like", |
|
|
|
|
|
|
|
"value": search, |
|
|
|
|
|
|
|
"operator": "AND" |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
"orders": { |
|
|
|
|
|
|
|
"ascending": true, |
|
|
|
|
|
|
|
"columns": [ |
|
|
|
|
|
|
|
'id' |
|
|
|
|
|
|
|
] |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
"paging": { |
|
|
|
|
|
|
|
"length": rowsPerPage, |
|
|
|
|
|
|
|
"start": start |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const result = await axios |
|
|
|
|
|
|
|
.post(DIVISI_SEARCH, payload, HEADER) |
|
|
|
|
|
|
|
.then(res => res) |
|
|
|
|
|
|
|
.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 Divisi": val.name, |
|
|
|
|
|
|
|
"Deskripsi": val.description, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
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 handleSearch = e => { |
|
|
|
const handleSearch = e => { |
|
|
|
const value = e.target.value |
|
|
|
const value = e.target.value |
|
|
@ -248,10 +317,16 @@ const ProjectType = ({ 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 Divisi`} /> |
|
|
|
|
|
|
|
</Col> |
|
|
|
<Col> |
|
|
|
<Col> |
|
|
|
<Tooltip title="Add Data"> |
|
|
|
<Tooltip title="Add 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> |
|
|
@ -280,7 +355,7 @@ const ProjectType = ({ params }) => { |
|
|
|
<i id="TooltipEdit" className="fa fa-edit" style={{ color: 'green', cursor: "pointer" }} onClick={() => handleEdit(n)}></i> |
|
|
|
<i id="TooltipEdit" className="fa fa-edit" style={{ color: 'green', cursor: "pointer" }} onClick={() => handleEdit(n)}></i> |
|
|
|
</Tooltip> |
|
|
|
</Tooltip> |
|
|
|
</td> |
|
|
|
</td> |
|
|
|
<td>{n.displayName}</td> |
|
|
|
<td>{n.name}</td> |
|
|
|
<td>{n.description}</td> |
|
|
|
<td>{n.description}</td> |
|
|
|
</tr> |
|
|
|
</tr> |
|
|
|
) |
|
|
|
) |
|
|
|