Browse Source

Add formatting

pull/2/head
Wahyu Ramadhan 1 year ago
parent
commit
8151575307
  1. 140
      src/views/SimproV2/CreatedProyek/ImportActivity/index.js

140
src/views/SimproV2/CreatedProyek/ImportActivity/index.js

@ -2,9 +2,9 @@ import React, { useState, useEffect, useMemo } from 'react';
import axios from "../../../../const/interceptorApi" import axios from "../../../../const/interceptorApi"
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 { Button, Table, Form, Upload, Tooltip, Alert, Spin } from 'antd'; import { Button, Table, Form, Upload, Tooltip, Alert, Spin } from 'antd';
import { InboxOutlined, UploadOutlined } from '@ant-design/icons'; import { InboxOutlined, UploadOutlined } from '@ant-design/icons';
import {OutTable, ExcelRenderer} from 'react-excel-renderer'; import { OutTable, ExcelRenderer } from 'react-excel-renderer';
import './table.css'; import './table.css';
import { BASE_OSPRO, ASSIGN_HR_PROJECT_SEARCH } from '../../../../const/ApiConst'; import { BASE_OSPRO, ASSIGN_HR_PROJECT_SEARCH } from '../../../../const/ApiConst';
import { Prompt } from 'react-router-dom'; import { Prompt } from 'react-router-dom';
@ -89,60 +89,60 @@ const ImportActivity = ({ params }) => {
const pageName = params.name; const pageName = params.name;
const [dataTable, setDatatable] = useState([]) const [dataTable, setDatatable] = useState([])
const [dataUserToProject, setdataUserToProject] = useState([]) const [dataUserToProject, setdataUserToProject] = useState([])
// //
const [isMovePage, setIsMovePage] = useState(false); const [isMovePage, setIsMovePage] = useState(false);
const [isPreview, setIsPreview] = useState(false); const [isPreview, setIsPreview] = useState(false);
useEffect(() => { useEffect(() => {
getDataAssignHr(); getDataAssignHr();
}, []) }, [])
const getDataAssignHr = async () => { const getDataAssignHr = async () => {
let url = window.location.href; let url = window.location.href;
let urlSplitted = url.split('/') let urlSplitted = url.split('/')
const payload = { const payload = {
"paging": { "paging": {
"start": 0, "start": 0,
"length": -1 "length": -1
}, },
"columns": [ "columns": [
{ "name": "name", "logic_operator": "ilike", "value": "", "table_name": "m_users" }, { "name": "name", "logic_operator": "ilike", "value": "", "table_name": "m_users" },
{ "name": "proyek_id", "logic_operator": "=", "value": urlSplitted[6] } { "name": "proyek_id", "logic_operator": "=", "value": urlSplitted[6] }
], ],
"joins": [ "joins": [
{ "name": "m_users", "column_join": "user_id", "column_results": ["name", "ktp_number"] }, { "name": "m_users", "column_join": "user_id", "column_results": ["name", "ktp_number"] },
{ "name": "m_role_proyek", "column_join": "project_role", "column_results": ["name"] }, { "name": "m_role_proyek", "column_join": "project_role", "column_results": ["name"] },
], ],
"orders": { "orders": {
"columns": [ "columns": [
"id" "id"
], ],
"ascending": false "ascending": false
} }
} }
const URL = ASSIGN_HR_PROJECT_SEARCH const URL = ASSIGN_HR_PROJECT_SEARCH
const result = await axios const result = await axios
.post(URL, payload, HEADER) .post(URL, 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) {
let dataRes = result.data.data || [] let dataRes = result.data.data || []
setdataUserToProject(dataRes); setdataUserToProject(dataRes);
} else { } else {
NotificationManager.error('Gagal Mengambil Data!!', 'Failed'); NotificationManager.error('Gagal Mengambil Data!!', 'Failed');
} }
} }
const fileHandler = (file) => { const fileHandler = (file) => {
setIsMovePage(true); setIsMovePage(true);
if(file.name.slice(file.name.lastIndexOf('.')+1) === "xlsx"){ if (file.name.slice(file.name.lastIndexOf('.') + 1) === "xlsx") {
// NotificationManager.info('Loading...',' '); // NotificationManager.info('Loading...',' ');
setTimeout(() => { setTimeout(() => {
previewHandler(file); previewHandler(file);
setIsMovePage(false); setIsMovePage(false);
}, 5000); }, 5000);
} else { } else {
NotificationManager.error('file harus dalam format .xlsx', 'Failed'); NotificationManager.error('file harus dalam format .xlsx', 'Failed');
} }
@ -156,7 +156,7 @@ const ImportActivity = ({ params }) => {
let dataMapped = [] let dataMapped = []
ExcelRenderer(fileObj, (err, resp) => { ExcelRenderer(fileObj, (err, resp) => {
if(err){ if (err) {
console.log(err) console.log(err)
errorHandler() errorHandler()
} else { } else {
@ -167,7 +167,7 @@ const ImportActivity = ({ params }) => {
return el.length > 0; return el.length > 0;
}); });
for(let i = 5; i < rows.length; i++){ for (let i = 5; i < rows.length; i++) {
let extractedRow = {} let extractedRow = {}
for (var prop in columnToIndexs) { for (var prop in columnToIndexs) {
@ -175,25 +175,25 @@ const ImportActivity = ({ params }) => {
let columnData = rows[i][columnToIndexs[prop]] let columnData = rows[i][columnToIndexs[prop]]
// remove leading whitespace // remove leading whitespace
if(typeof(columnData) == 'string') { if (typeof (columnData) == 'string') {
columnData = columnData.trim().replace(/&nbsp;/g, '').replace(/<[^\/>][^>]*><\/[^>]+>/g, "") columnData = columnData.trim().replace(/&nbsp;/g, '').replace(/<[^\/>][^>]*><\/[^>]+>/g, "")
} }
if(["nik"].includes(prop)){ if (["nik"].includes(prop)) {
if(columnData){ if (columnData) {
let index = dataUserToProject.findIndex((x) => columnData == x.join_first_ktp_number); let index = dataUserToProject.findIndex((x) => columnData == x.join_first_ktp_number);
if(index >= 0) { if (index >= 0) {
columnData = dataUserToProject[index].join_first_ktp_number; columnData = dataUserToProject[index].join_first_ktp_number;
} else { } else {
columnData = ''; columnData = '';
} }
} }
} }
if(prop == 'weight'){ if (prop == 'weight') {
if (columnData == null) { if (columnData == null) {
columnData = 0; columnData = 0;
} }
columnData = columnData * 100 columnData = columnData * 100
} }
@ -232,13 +232,13 @@ const ImportActivity = ({ params }) => {
console.log(result) console.log(result)
if (result.data.code == 200) { if (result.data.code == 200) {
const timestamp = Date.now(); const timestamp = Date.now();
const newTimestamp = timestamp + 60000; const newTimestamp = timestamp + 60000;
window.location = urlSplitted[0] + '//' + urlSplitted[2] + `/#/projects/` + ganttId + '/' + result.data.projectId + '/' + newTimestamp + '/gantt' window.location = urlSplitted[0] + '//' + urlSplitted[2] + `/#/projects/` + ganttId + '/' + result.data.projectId + '/' + newTimestamp + '/gantt'
} }
setIsMovePage(true); setIsMovePage(true);
setIsPreview(true); setIsPreview(true);
} }
const columns = [ const columns = [
@ -268,7 +268,7 @@ const ImportActivity = ({ params }) => {
key: 'name', key: 'name',
render: (text, record) => { render: (text, record) => {
let prepend = "" let prepend = ""
for(let i = 1; i < record.level; i++) { for (let i = 1; i < record.level; i++) {
prepend = prepend + "--" prepend = prepend + "--"
} }
@ -329,7 +329,7 @@ const ImportActivity = ({ params }) => {
listType="text" listType="text"
accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
maxCount={1} maxCount={1}
beforeUpload={(file)=> fileHandler(file)} beforeUpload={(file) => fileHandler(file)}
showUploadList={false} showUploadList={false}
> >
<Button icon={<UploadOutlined />}>Import Excel</Button> <Button icon={<UploadOutlined />}>Import Excel</Button>
@ -338,11 +338,11 @@ const ImportActivity = ({ params }) => {
</Form.Item> </Form.Item>
</Form> </Form>
</Col> </Col>
<Col span={2} style={{display: 'flex', justifyContent: 'flex-end'}}> <Col span={2} style={{ display: 'flex', justifyContent: 'flex-end' }}>
<Button <Button
style={{ marginLeft: "5px", marginRight: "10px" }} style={{ marginLeft: "5px", marginRight: "10px" }}
disabled={dataTable.length > 0 ? false : true} disabled={dataTable.length > 0 ? false : true}
onClick={(e)=> saveHandler(e)} onClick={(e) => saveHandler(e)}
> >
<i className="fa fa-save" style={{ marginRight: "5px" }}></i> Save <i className="fa fa-save" style={{ marginRight: "5px" }}></i> Save
</Button> </Button>
@ -356,7 +356,7 @@ const ImportActivity = ({ params }) => {
<CardBody> <CardBody>
<Spin tip="Loading..."> <Spin tip="Loading...">
<Table <Table
rowClassName={(record, index) => index % 2 == 0 ? 'table-row-light' : 'table-row-dark'} rowClassName={(record, index) => index % 2 == 0 ? 'table-row-light' : 'table-row-dark'}
dataSource={dataTable} dataSource={dataTable}
columns={columns} columns={columns}
pagination={false} pagination={false}
@ -397,7 +397,7 @@ const ImportActivity = ({ params }) => {
listType="text" listType="text"
accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
maxCount={1} maxCount={1}
beforeUpload={(file)=> fileHandler(file)} beforeUpload={(file) => fileHandler(file)}
showUploadList={false} showUploadList={false}
> >
<Button icon={<UploadOutlined />}>Import Excel</Button> <Button icon={<UploadOutlined />}>Import Excel</Button>
@ -406,11 +406,11 @@ const ImportActivity = ({ params }) => {
</Form.Item> </Form.Item>
</Form> </Form>
</Col> </Col>
<Col span={2} style={{display: 'flex', justifyContent: 'flex-end'}}> <Col span={2} style={{ display: 'flex', justifyContent: 'flex-end' }}>
<Button <Button
style={{ marginLeft: "5px", marginRight: "10px" }} style={{ marginLeft: "5px", marginRight: "10px" }}
disabled={dataTable.length > 0 ? false : true} disabled={dataTable.length > 0 ? false : true}
onClick={(e)=> saveHandler(e)} onClick={(e) => saveHandler(e)}
> >
<i className="fa fa-save" style={{ marginRight: "5px" }}></i> Save <i className="fa fa-save" style={{ marginRight: "5px" }}></i> Save
</Button> </Button>
@ -423,7 +423,7 @@ const ImportActivity = ({ params }) => {
</CardHeader> </CardHeader>
<CardBody> <CardBody>
<Table <Table
rowClassName={(record, index) => index % 2 == 0 ? 'table-row-light' : 'table-row-dark'} rowClassName={(record, index) => index % 2 == 0 ? 'table-row-light' : 'table-row-dark'}
dataSource={dataTable} dataSource={dataTable}
columns={columns} columns={columns}
pagination={false} pagination={false}

Loading…
Cancel
Save