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-05-18 17:18:35 +05:00
|
|
|
|
import { memo, useCallback, useEffect, useMemo, useState } from 'react'
|
2022-02-22 15:30:20 +05:00
|
|
|
|
|
2022-08-16 10:58:22 +05:00
|
|
|
|
import { useWell } from '@asb/context'
|
2022-02-22 15:30:20 +05:00
|
|
|
|
import LoaderPortal from '@components/LoaderPortal'
|
2022-02-28 15:53:48 +05:00
|
|
|
|
import { downloadFile, formatBytes, invokeWebApiWrapperAsync } from '@components/factory'
|
2022-06-09 17:51:41 +05:00
|
|
|
|
import { arrayOrDefault, formatDate, wrapPrivateComponent } from '@utils'
|
2022-02-22 15:30:20 +05:00
|
|
|
|
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-05-18 17:18:35 +05:00
|
|
|
|
const ID_STATE = {
|
|
|
|
|
NotInitialized: 0,
|
|
|
|
|
Approving: 1,
|
|
|
|
|
Creating: 2,
|
|
|
|
|
Ready: 3,
|
|
|
|
|
Error: 4,
|
|
|
|
|
Unknown: -1,
|
|
|
|
|
}
|
2022-02-24 17:40:17 +05:00
|
|
|
|
|
2022-05-18 17:18:35 +05:00
|
|
|
|
const STATE_STRING = {
|
|
|
|
|
[ID_STATE.NotInitialized]: { icon: CloseOutlined, text: 'Не настроена' },
|
|
|
|
|
[ID_STATE.Approving]: { icon: AuditOutlined, text: 'Согласовывается' },
|
|
|
|
|
[ID_STATE.Creating]: { icon: LoadingOutlined, text: 'Формируется' },
|
|
|
|
|
[ID_STATE.Ready]: { icon: CheckOutlined, text: 'Сформирована' },
|
|
|
|
|
[ID_STATE.Error]: { icon: WarningOutlined, text: 'Ошибка формирования' },
|
|
|
|
|
[ID_STATE.Unknown]: { icon: WarningOutlined, text: 'Неизвестно' },
|
2022-02-24 15:22:03 +05:00
|
|
|
|
}
|
|
|
|
|
|
2022-06-09 17:51:41 +05:00
|
|
|
|
const DrillingProgram = memo(() => {
|
2022-02-22 15:30:20 +05:00
|
|
|
|
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-08-16 10:58:22 +05:00
|
|
|
|
const [well] = useWell()
|
2022-04-19 15:38:53 +05:00
|
|
|
|
|
2022-02-24 17:40:17 +05:00
|
|
|
|
const {
|
|
|
|
|
idState,
|
|
|
|
|
permissionToEdit,
|
|
|
|
|
parts,
|
|
|
|
|
program,
|
|
|
|
|
error,
|
2022-03-18 19:40:52 +05:00
|
|
|
|
} = useMemo(() => data, [data])
|
2022-02-24 17:40:17 +05:00
|
|
|
|
|
2022-05-18 17:18:35 +05:00
|
|
|
|
const stateId = useMemo(() => idState ?? ID_STATE.Unknown, [idState])
|
|
|
|
|
const state = useMemo(() => STATE_STRING[stateId], [stateId])
|
2022-03-18 19:40:52 +05:00
|
|
|
|
const StateIcon = useMemo(() => state.icon, [state?.icon])
|
2022-02-24 17:40:17 +05:00
|
|
|
|
|
2022-02-22 15:30:20 +05:00
|
|
|
|
const updateData = useCallback(async () => await invokeWebApiWrapperAsync(
|
|
|
|
|
async () => {
|
2022-08-16 10:58:22 +05:00
|
|
|
|
const data = await DrillingProgramService.getState(well.id)
|
|
|
|
|
const categories = arrayOrDefault(await DrillingProgramService.getCategories(well.id))
|
2022-02-22 15:30:20 +05:00
|
|
|
|
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,
|
2022-08-18 11:49:10 +05:00
|
|
|
|
`Не удалось загрузить категории программы бурения`,
|
|
|
|
|
{ actionName: 'Загрузка категорий программы бурения', well }
|
2022-08-16 10:58:22 +05:00
|
|
|
|
), [well])
|
2022-02-22 15:30:20 +05:00
|
|
|
|
|
2022-06-09 17:51:41 +05:00
|
|
|
|
useEffect(() => {
|
|
|
|
|
updateData()
|
|
|
|
|
}, [updateData])
|
2022-02-22 15:30:20 +05:00
|
|
|
|
|
2022-03-18 19:40:52 +05:00
|
|
|
|
const onCategoryEdit = useCallback((catId) => {
|
2022-02-22 15:30:20 +05:00
|
|
|
|
setSelectedCategory(catId)
|
|
|
|
|
setEditorVisible(!!catId)
|
2022-03-18 19:40:52 +05:00
|
|
|
|
}, [])
|
2022-02-22 15:30:20 +05:00
|
|
|
|
|
2022-03-18 19:40:52 +05:00
|
|
|
|
const onCategoryHistory = useCallback((catId) => {
|
2022-02-22 15:30:20 +05:00
|
|
|
|
setSelectedCategory(catId)
|
|
|
|
|
setHistoryVisible(!!catId)
|
2022-03-18 19:40:52 +05:00
|
|
|
|
}, [])
|
2022-02-22 15:30:20 +05:00
|
|
|
|
|
2022-05-18 17:18:35 +05:00
|
|
|
|
const onEditorClosed = useCallback((needUpdate) => {
|
2022-02-22 15:30:20 +05:00
|
|
|
|
setEditorVisible(false)
|
2022-05-18 17:18:35 +05:00
|
|
|
|
if (needUpdate)
|
|
|
|
|
updateData()
|
2022-02-22 15:30:20 +05:00
|
|
|
|
}, [updateData])
|
|
|
|
|
|
2022-07-18 12:03:11 +05:00
|
|
|
|
const clearError = useCallback(() => invokeWebApiWrapperAsync(
|
|
|
|
|
async () => {
|
2022-08-16 10:58:22 +05:00
|
|
|
|
await DrillingProgramService.clearError(well.id)
|
2022-07-18 12:03:11 +05:00
|
|
|
|
await updateData()
|
|
|
|
|
},
|
|
|
|
|
setShowLoader,
|
2022-08-18 11:49:10 +05:00
|
|
|
|
`Не удалось сбросить ошибку формирования программы бурения`,
|
|
|
|
|
{ actionName: 'Сброс ошибки форматирования программы бурения', well }
|
2022-08-16 10:58:22 +05:00
|
|
|
|
), [well])
|
2022-07-18 12:03:11 +05:00
|
|
|
|
|
2022-02-22 15:30:20 +05:00
|
|
|
|
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-04-19 15:38:53 +05:00
|
|
|
|
<CategoryAdder 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'}>
|
2022-05-18 17:18:35 +05:00
|
|
|
|
{stateId === ID_STATE.Ready ? (
|
2022-02-24 17:40:17 +05:00
|
|
|
|
<>
|
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-05-18 17:18:35 +05:00
|
|
|
|
) : stateId === ID_STATE.Error ? (
|
2022-02-24 18:53:06 +05:00
|
|
|
|
<>
|
|
|
|
|
<h3 className={'program_status error'}>
|
|
|
|
|
<StateIcon className={'m-10'} />
|
|
|
|
|
{error?.message ?? state.text}
|
|
|
|
|
</h3>
|
2022-07-18 12:03:11 +05:00
|
|
|
|
<Button onClick={clearError} icon={<ReloadOutlined />}>
|
2022-02-24 18:53:06 +05:00
|
|
|
|
Сбросить статус ошибки
|
|
|
|
|
</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}`}
|
|
|
|
|
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
|
|
|
|
|
visible={editorVisible}
|
|
|
|
|
onClosed={onEditorClosed}
|
|
|
|
|
category={parts?.find((part) => part.idFileCategory === selectedCategory) ?? {}}
|
|
|
|
|
/>
|
|
|
|
|
</>
|
|
|
|
|
)}
|
2022-02-22 15:30:20 +05:00
|
|
|
|
|
|
|
|
|
<CategoryHistory
|
|
|
|
|
idCategory={selectedCategory}
|
|
|
|
|
onClose={() => setHistoryVisible(false)}
|
|
|
|
|
visible={historyVisible}
|
|
|
|
|
/>
|
|
|
|
|
</Layout>
|
|
|
|
|
</LoaderPortal>
|
|
|
|
|
)
|
|
|
|
|
})
|
|
|
|
|
|
2022-06-09 17:51:41 +05:00
|
|
|
|
export default wrapPrivateComponent(DrillingProgram, {
|
|
|
|
|
requirements: [ 'DrillingProgram.get' ],
|
|
|
|
|
title: 'Программа бурения',
|
|
|
|
|
route: 'drillingProgram',
|
|
|
|
|
})
|