CF2-49: Fixed Measures appearence. Added switch values by history.

This commit is contained in:
KharchenkoVV 2021-10-05 14:57:56 +05:00
parent 5755b41abc
commit fa78376c2a
5 changed files with 91 additions and 122 deletions

View File

@ -1,83 +1,59 @@
import { useState, useEffect } from 'react' import { useState, useEffect } from "react"
import { Button, Modal, Timeline } from 'antd' import { Button, Timeline } from 'antd'
import moment from 'moment' import moment from 'moment'
import { HourglassOutlined } from '@ant-design/icons' import { ClockCircleOutlined } from '@ant-design/icons'
import LoaderPortal from '../../components/LoaderPortal'
import { invokeWebApiWrapperAsync } from '../../components/factory'
import { MeasureService } from '../../services/api'
import { Editor } from './Editor'
import TimelineItem from 'antd/lib/timeline/TimelineItem'
import { View } from './View' import { View } from './View'
import '../../styles/index.css'
import '../../styles/measure.css' import '../../styles/measure.css'
const format='YYYY.MM.DD HH:mm' const format='YYYY.MM.DD HH:mm'
export const MeasureTable2 = ({idWell, idCategory, title, columns, currentValues}) => { export const MeasureTable2 = ({title, columns, values}) => {
const [showLoader, setShowLoader] = useState(false) var defaultDisplay = values && values.length > 1
const [showEditor, setShowEditor] = useState(false) ? values[values.length-1]
const [history, setHistory] = useState([]) : []
const updateHistory = () => invokeWebApiWrapperAsync(async()=>{ const [displayedValues, setDisplayedValues] = useState([]);
const data = await MeasureService.getHisory(idWell, idCategory)
const story = data?.map( i=> ({
id: i.id,
idWell: i.idWell,
idCategory: i.idCategory,
timestamp: moment.utc(i.timestamp).local().format(format),
...i.data}))
setHistory(story??[])
}
, setShowLoader
, `Не удалось загрузить последние данные по скважине ${idWell}`)
useEffect(updateHistory, [idWell, idCategory]) useEffect(() => {
setDisplayedValues(defaultDisplay)
const lastHistoryIndex = history.length }, [defaultDisplay])
return <> return <>
<LoaderPortal show={showLoader}> &nbsp;
&nbsp; <h3>{title}</h3>
<h3>{title}</h3> &nbsp;
&nbsp; <div className='d-flex'>
<div className='d-flex'> <div className='fd-column'>
<div className='measure-dates'> <div className='mt-8px'>
<Timeline> <Button className='w-100'>Добавить</Button>
{history.map((item, index)=> <Button className='w-100'>Редактировать</Button>
<Timeline.Item <Button className='w-100'>Удалить</Button>
key={item.id} </div>
className={index === lastHistoryIndex - 1 <div className='measure-dates mt-20px'>
? 'last-measure-button' <Timeline className='mt-8px ml-10px'>
: 'measure-button'} {values.map((item, index) =>
onClick={() => setShowEditor(true)} <Timeline.Item
value={item} key={item.id}
> className='measure-button'
<p>{item.timestamp}</p> onClick={() => setDisplayedValues(values.find(el => el.id === item.id))}
</Timeline.Item>)} dot={index === values.length - 1
? <ClockCircleOutlined className="timeline-clock-icon" />
: null}
value={moment.utc(item.timestamp).local().format(format)}
>
{moment.utc(item.timestamp).local().format(format)}
</Timeline.Item>
)}
</Timeline> </Timeline>
</div> </div>
<div className='w-100'>
<View
item = {currentValues.data}
columns = {columns}
/>
</div>
</div> </div>
<Modal <div className='w-100'>
title={title} <View
centered item={displayedValues.data}
visible={showEditor} columns={columns}
onOk={() => setShowEditor(false)}
onCancel={() => setShowEditor(false)}
width="95%"
footer={null}
>
<Editor
idWell={idWell}
idCategory={idCategory}
columns = {columns}
onUpdate={updateHistory}
/> />
</Modal> </div>
</LoaderPortal> </div>
</> </>
} }

View File

@ -12,23 +12,23 @@ export const View = ({columns, item}) => {
return <> return <>
<GridItem <GridItem
//style={{width:'100%', border:'1px solid red'}}
row={row} row={row}
col={colb*2 + 1} col={colb*2 + 1}
background='#00000005' style={{background:'#00000005',
border='1px solid #FFFE' border:'1px solid black'
}}
> >
{column.title} {column.title}
</GridItem> </GridItem>
<GridItem <GridItem
//style={{width:'50%', border:'1px solid blue'}}
row={row} row={row}
col={colb*2 + 2} col={colb*2 + 2}
border='1px solid rgba(0, 0, 0, 0.05)' style={{background:'#00000005',
justifycontent='right' border:'1px solid black',
marginright='16px' justifyContent:'right',
fontWeight='bold' marginRight:'16px',
textalign='right' fontWeight:'bold',
textAlign:'right'}}
> >
{column.render ? column.render(item[column.dataIndex]) : item[column.dataIndex]} {column.render ? column.render(item[column.dataIndex]) : item[column.dataIndex]}
</GridItem> </GridItem>

View File

@ -9,23 +9,27 @@ import LoaderPortal from '../../components/LoaderPortal'
//import { MeasureTable } from './MeasureTable' //import { MeasureTable } from './MeasureTable'
import { MeasureTable2 } from './MeasureTable2' import { MeasureTable2 } from './MeasureTable2'
const format='YYYY.MM.DD HH:mm'
export default function Measure({idWell}){ export default function Measure({idWell}){
const [showLoader, setShowLoader] = useState(false) const [showLoader, setShowLoader] = useState(false)
const [currentFluidValues, setCurrentFluidValues] = useState([]) const [fluidValues, setFluidValues] = useState([])
const [currentMudValues, setCurrentMudValues] = useState([]) const [mudValues, setMudValues] = useState([])
const [currentNnbValues, setCurrentNnbValues] = useState([]) const [nnbValues, setNnbValues] = useState([])
const updateCurrentValues = () => invokeWebApiWrapperAsync(async()=>{ const updateCurrentValues = () => invokeWebApiWrapperAsync(async()=>{
const data = await MeasureService.getAllLast(idWell) // const data = await MeasureService.getAllLast(idWell)
const fluidValues = data?.find(value => value.idCategory === 1) // const fluids = data?.filter(value => value.idCategory === 1)
setCurrentFluidValues(fluidValues ?? []) // setFluidValues(fluids ?? [])
const mudValues = data?.find(value => value.idCategory === 2) // const muds = data?.filter(value => value.idCategory === 2)
setCurrentMudValues(mudValues ?? []) // setMudValues(muds ?? [])
const nnbValues = data?.find(value => value.idCategory === 3) // const nnbs = data?.filter(value => value.idCategory === 3)
setCurrentNnbValues(nnbValues ?? []) // setNnbValues(nnbs ?? [])
const fluids = await MeasureService.getHisory(idWell, 1)
setFluidValues(fluids ?? [])
const muds = await MeasureService.getHisory(idWell, 2)
setMudValues(muds ?? [])
const nnbs = await MeasureService.getHisory(idWell, 3)
setNnbValues(nnbs ?? [])
} }
,setShowLoader ,setShowLoader
,`Не удалось загрузить последние данные по скважине ${idWell}`) ,`Не удалось загрузить последние данные по скважине ${idWell}`)
@ -35,25 +39,19 @@ export default function Measure({idWell}){
return <> return <>
<LoaderPortal show={showLoader}> <LoaderPortal show={showLoader}>
<MeasureTable2 <MeasureTable2
idWell={idWell}
idCategory={1}
title='Замер бурового раствора' title='Замер бурового раствора'
columns={columnsDrillingFluid} columns={columnsDrillingFluid}
currentValues={currentFluidValues} values={fluidValues}
/> />
<MeasureTable2 <MeasureTable2
idWell={idWell} title='Шламограмма'
idCategory={2} columns={columnsMudDiagram}
title='Шламограмма' values={mudValues}
columns={columnsMudDiagram}
currentValues={currentMudValues}
/> />
<MeasureTable2 <MeasureTable2
idWell={idWell}
idCategory={3}
title='ННБ' title='ННБ'
columns={columnsNnb} columns={columnsNnb}
currentValues={currentNnbValues} values={nnbValues}
/> />
</LoaderPortal> </LoaderPortal>
</> </>

View File

@ -11,6 +11,10 @@ body {
display: flex; display: flex;
} }
.fd-column {
flex-direction: column;
}
.d-inline { .d-inline {
display: inline; display: inline;
} }
@ -27,6 +31,10 @@ body {
width: 100% width: 100%
} }
.mt-8px {
margin-top: 8px;
}
.mt-20px { .mt-20px {
margin-top: 20px; margin-top: 20px;
} }
@ -39,6 +47,10 @@ body {
margin-left: 5px; margin-left: 5px;
} }
.ml-10px {
margin-left: 10px;
}
.ml-30px { .ml-30px {
margin-left: 30px; margin-left: 30px;
} }

View File

@ -1,32 +1,15 @@
.measure-dates { .measure-dates {
width: 15%;
overflow-y: scroll; overflow-y: scroll;
} }
.measure-button {
display: flex;
margin-top: 8px;
width: 95%;
height: 30px;
border: 1px solid black;
border-radius: 5px;
}
.measure-button:hover { .measure-button:hover {
cursor: pointer; cursor: pointer;
} }
.last-measure-button { .mt-8px {
display: flex;
margin-top: 8px; margin-top: 8px;
background-color: #DCDCDC;
width: 95%;
height: 30px;
border: 1px solid black;
border-radius: 5px;
} }
.last-measure-button:hover { .ml-10px {
cursor: pointer; margin-left: 10px;
background-color: #D3D3D3; }
}