2021-08-04 14:19:22 +05:00
import { useState , useEffect } from 'react'
2021-08-02 18:30:47 +05:00
import { useParams } from "react-router-dom" ;
2021-08-11 17:39:27 +05:00
import { Table , InputNumber , Form , Popconfirm , Typography , Button } from 'antd'
import LoaderPortal from '../LoaderPortal'
2021-08-03 17:47:46 +05:00
import { makeColumn } from '../factory'
import { NnbDataService } from '../../services/api/services/NnbDataService' ;
2021-08-04 14:19:22 +05:00
import notify from "../notify"
2021-07-28 17:59:16 +05:00
2021-07-29 17:17:28 +05:00
const EditableCell = ( {
editing ,
dataIndex ,
title ,
inputType ,
record ,
index ,
children ,
... restProps
} ) => {
return (
< td { ...restProps } style = { { paddingLeft : 2 , paddingRight : 2 } } >
< div style = { { width : '100%' , display : 'flex' , justifyContent : 'center' } } >
{ editing ? (
< Form.Item
name = { dataIndex }
style = { { margin : 0 } }
rules = { [
{
required : true ,
2021-08-04 14:19:22 +05:00
message : ''
2021-07-29 17:17:28 +05:00
} ,
] }
>
2021-08-04 14:19:22 +05:00
< InputNumber size = "small" style = { { width : "auto" } } / >
2021-07-29 17:17:28 +05:00
< / Form.Item >
) : (
children
) }
< / div >
< / td >
) ;
} ;
2021-07-28 17:59:16 +05:00
export function Nnb ( ) {
2021-08-02 18:30:47 +05:00
let { id } = useParams ( )
2021-07-29 17:17:28 +05:00
const [ form ] = Form . useForm ( ) ;
const [ editingKey , setEditingKey ] = useState ( '' ) ;
2021-08-04 14:19:22 +05:00
const [ data , setData ] = useState ( { } )
2021-08-03 17:47:46 +05:00
const [ isUpdatingData , setIsUpdatingData ] = useState ( false )
2021-08-11 17:39:27 +05:00
const [ showLoader , setShowLoader ] = useState ( false )
2021-07-29 17:17:28 +05:00
const isEditing = ( row ) => row . key === editingKey ;
const columns = [
2021-07-30 12:26:52 +05:00
makeColumn ( 'Глубина по стволу, м' , 'depth' , { dataIndex : 'depth' , align : 'center' , editable : true } ) ,
makeColumn ( 'Зенитный угол, град' , 'zenithAngle' , { dataIndex : 'zenithAngle' , align : 'center' , editable : true } ) ,
2021-08-02 18:30:47 +05:00
makeColumn ( 'Азимут магнитный, град' , 'magneticAzimuth' , { dataIndex : 'magneticAzimuth' , align : 'center' , editable : true } ) ,
makeColumn ( 'Азимут истинный, град' , 'trueAzimuth' , { dataIndex : 'trueAzimuth' , align : 'center' , editable : true } ) ,
2021-07-30 12:26:52 +05:00
makeColumn ( 'Азимут дирекц., град' , 'directAzimuth' , { dataIndex : 'directAzimuth' , align : 'center' , editable : true } ) ,
makeColumn ( 'Глубина по вертикали, м' , 'verticalDepth' , { dataIndex : 'verticalDepth' , align : 'center' , editable : true } ) ,
makeColumn ( 'Абсолютная отметка, м' , 'absoluteMark' , { dataIndex : 'absoluteMark' , align : 'center' , editable : true } ) ,
makeColumn ( 'Лок. смещение к северу, м' , 'localNorthOffset' , { dataIndex : 'localNorthOffset' , align : 'center' , editable : true } ) ,
makeColumn ( 'Лок. смещение к востоку, м' , 'localEastOffset' , { dataIndex : 'localEastOffset' , align : 'center' , editable : true } ) ,
makeColumn ( 'Отклонение от устья, м' , 'outFallOffset' , { dataIndex : 'outFallOffset' , align : 'center' , editable : true } ) ,
makeColumn ( 'Азимут смещения, град' , 'offsetAzimuth' , { dataIndex : 'offsetAzimuth' , align : 'center' , editable : true } ) ,
makeColumn ( 'Пространст. интенсивность, град/10 м' , 'areaIntensity' , { dataIndex : 'areaIntensity' , align : 'center' , editable : true } ) ,
makeColumn ( 'Угол установки отклон., град' , 'offsetStopAngle' , { dataIndex : 'offsetStopAngle' , align : 'center' , editable : true } ) ,
makeColumn ( 'Интенсив. по зениту, град/10 м' , 'zenithIntensity' , { dataIndex : 'zenithIntensity' , align : 'center' , editable : true } ) ,
makeColumn ( 'Комментарий' , 'comment' , { dataIndex : 'comment' , align : 'comment' , editable : true } ) ,
makeColumn ( 'Разница вертикальных глубин между Х Х Х (план) и Х Х Х (факт)' , 'depthPlanFactDifference' , { dataIndex : 'depthPlanFactDifference' , align : 'center' , editable : true } ) ,
makeColumn ( 'Расстояние в пространстве между Х Х Х (план) и Х Х Х (факт)' , 'distancePlanFactDifference' , { dataIndex : 'distancePlanFactDifference' , align : 'center' , editable : true } ) ,
2021-07-29 17:17:28 +05:00
{
title : 'Действие' ,
dataIndex : 'action' ,
align : 'center' ,
width : 150 ,
className : 'small-font' ,
render : ( _ , row ) => {
const editable = isEditing ( row ) ;
return editable ? (
< span >
2021-08-11 17:39:27 +05:00
< Button
2021-07-29 17:17:28 +05:00
onClick = { ( ) => save ( row . key ) }
style = { { marginRight : 8 } }
>
Сохранить
2021-08-11 17:39:27 +05:00
< / Button >
2021-07-29 17:17:28 +05:00
< Popconfirm style = { { width : '100px' } } title = { < span > Отменить < br / > редактирование ? < / span > } onConfirm = { cancel } >
2021-08-11 17:39:27 +05:00
< Button > Отменить < / Button >
2021-07-29 17:17:28 +05:00
< / Popconfirm >
< / span >
) : (
< Typography.Link disabled = { editingKey !== '' } onClick = { ( ) => edit ( row ) } >
Редактировать
< / Typography.Link >
) ;
} ,
}
] ;
2021-08-04 14:19:22 +05:00
useEffect ( ( ) => {
const update = async ( ) => {
2021-08-11 17:39:27 +05:00
setShowLoader ( true )
2021-08-04 14:19:22 +05:00
try {
let response = await NnbDataService . get ( id , 11 )
response . key = 11
setData ( response )
}
catch ( ex ) {
notify ( ` Н е удалось загрузить данные ННБ по скважине "${ id } " ` , 'error' )
console . log ( ex )
}
setIsUpdatingData ( false )
2021-08-11 17:39:27 +05:00
setShowLoader ( false )
2021-08-04 14:19:22 +05:00
}
update ( )
2021-08-11 17:39:27 +05:00
} , [ id , isUpdatingData ] )
2021-08-04 14:19:22 +05:00
2021-07-29 17:17:28 +05:00
const mergedColumns = columns . map ( ( col ) => {
if ( ! col . editable ) {
return col ;
}
return {
... col ,
onCell : ( row ) => ( {
row ,
dataIndex : col . dataIndex ,
title : col . title ,
editing : isEditing ( row ) ,
} ) ,
} ;
} ) ;
const edit = ( row ) => {
form . setFieldsValue ( {
... row ,
} ) ;
setEditingKey ( row . key ) ;
} ;
const cancel = ( ) => {
setEditingKey ( '' ) ;
} ;
2021-08-02 18:30:47 +05:00
const save = async ( formData ) => {
const params = {
2021-08-04 14:19:22 +05:00
key : 11 ,
2021-08-02 18:30:47 +05:00
depth : form . getFieldValue ( 'depth' ) ,
zenithAngle : form . getFieldValue ( 'zenithAngle' ) ,
magneticAzimuth : form . getFieldValue ( 'magneticAzimuth' ) ,
trueAzimuth : form . getFieldValue ( 'trueAzimuth' ) ,
directAzimuth : form . getFieldValue ( 'directAzimuth' ) ,
verticalDepth : form . getFieldValue ( 'verticalDepth' ) ,
absoluteMark : form . getFieldValue ( 'absoluteMark' ) ,
localNorthOffset : form . getFieldValue ( 'localNorthOffset' ) ,
localEastOffset : form . getFieldValue ( 'localEastOffset' ) ,
outFallOffset : form . getFieldValue ( 'outFallOffset' ) ,
offsetAzimuth : form . getFieldValue ( 'offsetAzimuth' ) ,
areaIntensity : form . getFieldValue ( 'areaIntensity' ) ,
offsetStopAngle : form . getFieldValue ( 'offsetStopAngle' ) ,
zenithIntensity : form . getFieldValue ( 'zenithIntensity' ) ,
comment : form . getFieldValue ( 'comment' ) ,
depthPlanFactDifference : form . getFieldValue ( 'depthPlanFactDifference' ) ,
distancePlanFactDifference : form . getFieldValue ( 'distancePlanFactDifference' )
}
2021-07-29 17:17:28 +05:00
try {
2021-08-11 17:39:27 +05:00
setShowLoader ( true )
2021-08-02 18:30:47 +05:00
await NnbDataService . put ( ` ${ id } ` , 11 , params )
2021-08-04 14:19:22 +05:00
setIsUpdatingData ( true )
2021-08-11 17:39:27 +05:00
setShowLoader ( false )
2021-08-02 18:30:47 +05:00
setEditingKey ( '' )
2021-07-29 17:17:28 +05:00
} catch ( errInfo ) {
console . log ( 'Validate Failed:' , errInfo ) ;
}
} ;
2021-08-02 18:30:47 +05:00
2021-08-11 17:39:27 +05:00
return ( < LoaderPortal show = { showLoader } >
2021-08-02 18:30:47 +05:00
< Form form = { form } component = { false } onFinish = { save } >
2021-07-29 17:17:28 +05:00
< Table
components = { {
body : {
cell : EditableCell ,
} ,
} }
columns = { mergedColumns }
2021-08-04 14:19:22 +05:00
dataSource = { [ data ] }
2021-07-29 17:17:28 +05:00
size = { 'small' }
bordered = { true }
pagination = { false }
/ >
< / Form >
2021-08-04 14:19:22 +05:00
< div > & nbsp ; < / div >
< p style = { { textAlign : "right" } } >
Дата последнего обновления : < b > { new Date ( data ? . lastUpdate ) . toLocaleString ( ) } < / b >
< / p >
2021-08-11 17:39:27 +05:00
< / LoaderPortal > )
2021-07-28 17:59:16 +05:00
}