2022-02-25 16:57:08 +05:00
|
|
|
|
import { Button, Layout } from 'antd'
|
2022-02-24 17:40:17 +05:00
|
|
|
|
import {
|
2022-03-02 21:17:27 +05:00
|
|
|
|
AuditOutlined,
|
2022-02-24 17:59:45 +05:00
|
|
|
|
CheckOutlined,
|
2022-02-24 17:40:17 +05:00
|
|
|
|
CloseOutlined,
|
|
|
|
|
FileWordOutlined,
|
|
|
|
|
LoadingOutlined,
|
|
|
|
|
ReloadOutlined,
|
2022-03-02 21:17:27 +05:00
|
|
|
|
WarningOutlined,
|
2022-02-24 17:40:17 +05:00
|
|
|
|
} from '@ant-design/icons'
|
2022-02-22 15:30:20 +05:00
|
|
|
|
import { memo, useCallback, useEffect, useState } from 'react'
|
|
|
|
|
|
|
|
|
|
import LoaderPortal from '@components/LoaderPortal'
|
2022-02-28 15:53:48 +05:00
|
|
|
|
import { downloadFile, formatBytes, invokeWebApiWrapperAsync } from '@components/factory'
|
2022-02-22 15:30:20 +05:00
|
|
|
|
import { arrayOrDefault, formatDate } from '@utils'
|
|
|
|
|
import { DrillingProgramService } from '@api'
|
|
|
|
|
|
|
|
|
|
import CategoryAdder from './CategoryAdder'
|
|
|
|
|
import CategoryRender from './CategoryRender'
|
|
|
|
|
import CategoryEditor from './CategoryEditor'
|
|
|
|
|
import CategoryHistory from './CategoryHistory'
|
|
|
|
|
|
|
|
|
|
import '@styles/drilling_program.less'
|
|
|
|
|
|
2022-02-24 17:40:17 +05:00
|
|
|
|
const idStateNotInitialized = 0
|
|
|
|
|
const idStateApproving = 1
|
|
|
|
|
const idStateCreating = 2
|
|
|
|
|
const idStateReady = 3
|
|
|
|
|
const idStateError = 4
|
|
|
|
|
const idStateUnknown = -1
|
|
|
|
|
|
2022-02-24 15:22:03 +05:00
|
|
|
|
const stateString = {
|
2022-02-24 17:40:17 +05:00
|
|
|
|
[idStateNotInitialized]: { icon: CloseOutlined, text: 'Не настроена' },
|
2022-03-02 21:17:27 +05:00
|
|
|
|
[idStateApproving]: { icon: AuditOutlined, text: 'Согласовывается' },
|
2022-02-24 17:40:17 +05:00
|
|
|
|
[idStateCreating]: { icon: LoadingOutlined, text: 'Формируется' },
|
2022-02-24 17:59:45 +05:00
|
|
|
|
[idStateReady]: { icon: CheckOutlined, text: 'Сформирована' },
|
2022-02-24 17:40:17 +05:00
|
|
|
|
[idStateError]: { icon: WarningOutlined, text: 'Ошибка формирования' },
|
|
|
|
|
[idStateUnknown]: { icon: WarningOutlined, text: 'Неизвестно' },
|
2022-02-24 15:22:03 +05:00
|
|
|
|
}
|
|
|
|
|
|
2022-02-22 15:30:20 +05:00
|
|
|
|
export const DrillingProgram = memo(({ idWell }) => {
|
|
|
|
|
const [selectedCategory, setSelectedCategory] = useState()
|
|
|
|
|
const [historyVisible, setHistoryVisible] = useState(false)
|
|
|
|
|
const [editorVisible, setEditorVisible] = useState(false)
|
|
|
|
|
const [showLoader, setShowLoader] = useState(false)
|
|
|
|
|
const [categories, setCategories] = useState([])
|
|
|
|
|
const [data, setData] = useState({})
|
|
|
|
|
|
2022-02-24 17:40:17 +05:00
|
|
|
|
const {
|
|
|
|
|
idState,
|
|
|
|
|
permissionToEdit,
|
|
|
|
|
parts,
|
|
|
|
|
program,
|
|
|
|
|
error,
|
|
|
|
|
} = data
|
|
|
|
|
|
|
|
|
|
const stateId = idState ?? idStateUnknown
|
|
|
|
|
const state = stateString[stateId]
|
|
|
|
|
const StateIcon = state.icon
|
|
|
|
|
|
2022-02-22 15:30:20 +05:00
|
|
|
|
const updateData = useCallback(async () => await invokeWebApiWrapperAsync(
|
|
|
|
|
async () => {
|
|
|
|
|
const data = await DrillingProgramService.getState(idWell)
|
|
|
|
|
const categories = arrayOrDefault(await DrillingProgramService.getCategories(idWell))
|
|
|
|
|
setData(data)
|
|
|
|
|
setCategories(categories.filter(cat => {
|
|
|
|
|
if (cat?.id && (cat.name || cat.shortName))
|
2022-02-24 17:41:45 +05:00
|
|
|
|
if (data.parts?.findIndex((val) => val.idFileCategory === cat.id) < 0)
|
2022-02-22 15:30:20 +05:00
|
|
|
|
return true
|
|
|
|
|
return false
|
|
|
|
|
}))
|
|
|
|
|
},
|
|
|
|
|
setShowLoader,
|
|
|
|
|
`Не удалось загрузить название скважины "${idWell}"`
|
|
|
|
|
), [idWell])
|
|
|
|
|
|
|
|
|
|
useEffect(() => updateData(), [updateData])
|
|
|
|
|
|
|
|
|
|
const onCategoryEdit = (catId) => {
|
|
|
|
|
setSelectedCategory(catId)
|
|
|
|
|
setEditorVisible(!!catId)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const onCategoryHistory = (catId) => {
|
|
|
|
|
setSelectedCategory(catId)
|
|
|
|
|
setHistoryVisible(!!catId)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const onEditorClosed = useCallback(() => {
|
|
|
|
|
setEditorVisible(false)
|
|
|
|
|
updateData()
|
|
|
|
|
}, [updateData])
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<LoaderPortal show={showLoader}>
|
2022-02-24 15:41:51 +05:00
|
|
|
|
<Layout style={{ backgroundColor: 'white' }}>
|
2022-02-24 17:40:17 +05:00
|
|
|
|
<div className={'drilling_program'}>
|
|
|
|
|
<div className={'program_header'}>
|
|
|
|
|
<h3>Программа бурения</h3>
|
|
|
|
|
{permissionToEdit && (
|
|
|
|
|
<div>
|
2022-02-24 18:53:06 +05:00
|
|
|
|
<CategoryAdder
|
|
|
|
|
idWell={idWell}
|
|
|
|
|
categories={categories}
|
|
|
|
|
onUpdate={updateData}
|
|
|
|
|
/>
|
2022-02-24 17:40:17 +05:00
|
|
|
|
</div>
|
|
|
|
|
)}
|
2022-02-22 15:30:20 +05:00
|
|
|
|
</div>
|
2022-02-24 17:40:17 +05:00
|
|
|
|
<div className={'program_content'}>
|
|
|
|
|
{stateId === idStateReady ? (
|
|
|
|
|
<>
|
2022-02-25 18:02:41 +05:00
|
|
|
|
<Button
|
|
|
|
|
type={'link'}
|
|
|
|
|
icon={<FileWordOutlined />}
|
|
|
|
|
style={{ marginLeft: '10px' }}
|
|
|
|
|
onClick={() => downloadFile(program)}
|
|
|
|
|
>
|
|
|
|
|
{program?.name}
|
|
|
|
|
</Button>
|
2022-02-28 15:53:48 +05:00
|
|
|
|
<div className={'m-10'}>Размер: {formatBytes(program?.size)}</div>
|
|
|
|
|
<div className={'m-10'}>Сформирован: {formatDate(program?.uploadDate)}</div>
|
2022-02-24 17:40:17 +05:00
|
|
|
|
</>
|
2022-02-24 18:53:06 +05:00
|
|
|
|
) : stateId === idStateError ? (
|
|
|
|
|
<>
|
|
|
|
|
<h3 className={'program_status error'}>
|
|
|
|
|
<StateIcon className={'m-10'} />
|
|
|
|
|
{error?.message ?? state.text}
|
|
|
|
|
</h3>
|
|
|
|
|
<Button icon={<ReloadOutlined />}>
|
|
|
|
|
Сбросить статус ошибки
|
|
|
|
|
</Button>
|
|
|
|
|
</>
|
2022-02-24 17:40:17 +05:00
|
|
|
|
) : (
|
2022-02-24 18:53:06 +05:00
|
|
|
|
<h3 className={'program_status'}>
|
2022-02-24 17:40:17 +05:00
|
|
|
|
<StateIcon className={'m-10'} />
|
2022-02-24 18:53:06 +05:00
|
|
|
|
{state.text}
|
2022-02-24 17:40:17 +05:00
|
|
|
|
</h3>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2022-02-22 15:30:20 +05:00
|
|
|
|
|
2022-02-24 17:40:17 +05:00
|
|
|
|
{parts?.map?.((part, idx) => part && (
|
2022-02-22 15:30:20 +05:00
|
|
|
|
<CategoryRender
|
|
|
|
|
key={`${idx}`}
|
|
|
|
|
idWell={idWell}
|
|
|
|
|
partData={part}
|
2022-02-24 17:40:17 +05:00
|
|
|
|
onEdit={permissionToEdit && onCategoryEdit}
|
2022-02-22 15:30:20 +05:00
|
|
|
|
onUpdate={updateData}
|
|
|
|
|
onHistory={onCategoryHistory}
|
|
|
|
|
/>
|
|
|
|
|
))}
|
|
|
|
|
|
2022-02-24 17:40:17 +05:00
|
|
|
|
{permissionToEdit && (
|
|
|
|
|
<>
|
|
|
|
|
<CategoryEditor
|
|
|
|
|
idWell={idWell}
|
|
|
|
|
visible={editorVisible}
|
|
|
|
|
onClosed={onEditorClosed}
|
|
|
|
|
category={parts?.find((part) => part.idFileCategory === selectedCategory) ?? {}}
|
|
|
|
|
/>
|
|
|
|
|
</>
|
|
|
|
|
)}
|
2022-02-22 15:30:20 +05:00
|
|
|
|
|
|
|
|
|
<CategoryHistory
|
|
|
|
|
idWell={idWell}
|
|
|
|
|
idCategory={selectedCategory}
|
|
|
|
|
onClose={() => setHistoryVisible(false)}
|
|
|
|
|
visible={historyVisible}
|
|
|
|
|
/>
|
|
|
|
|
</Layout>
|
|
|
|
|
</LoaderPortal>
|
|
|
|
|
)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
export default DrillingProgram
|