Browse Source

Add formatting

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

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

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

Loading…
Cancel
Save