2022-09-12 12:30:27 +05:00
|
|
|
|
import { memo, useCallback, useEffect, useMemo, useState } from 'react'
|
2022-09-13 16:46:02 +05:00
|
|
|
|
import { Alert, Button, Typography } from 'antd'
|
2022-09-12 12:30:27 +05:00
|
|
|
|
|
|
|
|
|
import { useWell } from '@asb/context'
|
|
|
|
|
import { UserView } from '@components/views'
|
2022-09-13 16:46:02 +05:00
|
|
|
|
import UploadForm from '@components/UploadForm'
|
2022-09-12 12:30:27 +05:00
|
|
|
|
import DownloadLink from '@components/DownloadLink'
|
|
|
|
|
import LoaderPortal from '@components/LoaderPortal'
|
|
|
|
|
import { invokeWebApiWrapperAsync } from '@components/factory'
|
|
|
|
|
import { makeColumn, makeDateColumn, makeTextColumn, Table } from '@components/Table'
|
2022-09-13 16:21:57 +05:00
|
|
|
|
import { WellFinalDocumentsService } from '@api'
|
2022-09-13 16:46:02 +05:00
|
|
|
|
import { wrapPrivateComponent } from '@utils'
|
2022-09-12 12:30:27 +05:00
|
|
|
|
|
|
|
|
|
import WellCaseEditor from './WellCaseEditor'
|
|
|
|
|
import { HistoryTable } from './HistoryTable'
|
2022-09-13 16:46:02 +05:00
|
|
|
|
|
|
|
|
|
import '@styles/well_case.less'
|
2022-09-12 12:30:27 +05:00
|
|
|
|
|
2022-09-13 16:21:57 +05:00
|
|
|
|
const expandable = {
|
2022-09-13 16:46:02 +05:00
|
|
|
|
expandedRowRender: (category) => <HistoryTable category={category} />,
|
2022-09-13 16:21:57 +05:00
|
|
|
|
}
|
2022-09-12 12:30:27 +05:00
|
|
|
|
|
|
|
|
|
const WellCase = memo(() => {
|
|
|
|
|
const [isLoading, setIsLoading] = useState(false)
|
|
|
|
|
const [categories, setCategories] = useState([])
|
|
|
|
|
const [canEdit, setCanEdit] = useState(false)
|
|
|
|
|
const [showEdit, setShowEdit] = useState(false)
|
|
|
|
|
|
|
|
|
|
const [well] = useWell()
|
|
|
|
|
|
|
|
|
|
const updateTable = useCallback(() => {
|
|
|
|
|
invokeWebApiWrapperAsync(
|
|
|
|
|
async () => {
|
2022-09-13 16:21:57 +05:00
|
|
|
|
const { permissionToSetPubliher, wellFinalDocuments } = await WellFinalDocumentsService.get(well.id)
|
2022-09-12 12:30:27 +05:00
|
|
|
|
|
2022-09-13 16:21:57 +05:00
|
|
|
|
setCategories(wellFinalDocuments.map((cat) => ({ ...cat, uploadDate: cat.file?.uploadDate })))
|
|
|
|
|
setCanEdit(permissionToSetPubliher)
|
2022-09-12 12:30:27 +05:00
|
|
|
|
},
|
|
|
|
|
setIsLoading,
|
|
|
|
|
'Не удалось загрузить список категорий',
|
2022-09-13 16:21:57 +05:00
|
|
|
|
{ actionName: 'Загрузка списка категорий', well }
|
2022-09-12 12:30:27 +05:00
|
|
|
|
)
|
|
|
|
|
}, [well])
|
|
|
|
|
|
2022-09-13 16:21:57 +05:00
|
|
|
|
const columns = useMemo(() => [
|
|
|
|
|
makeTextColumn('Категория', 'nameCategory'),
|
|
|
|
|
makeColumn('Файл', 'file', {
|
|
|
|
|
render: (file, category) => (
|
2022-09-13 16:46:02 +05:00
|
|
|
|
<div className={'file-cell'}>
|
|
|
|
|
{file ? <DownloadLink file={file} /> : <span style={{ marginLeft: 15 }}>Файл не загружен</span>}
|
|
|
|
|
|
2022-09-13 16:21:57 +05:00
|
|
|
|
{category.permissionToUpload && (
|
|
|
|
|
<UploadForm
|
|
|
|
|
url={`/api/WellFinalDocuments/${well.id}?idCategory=${category.idCategory}`}
|
|
|
|
|
onUploadStart={() => setIsLoading(true)}
|
|
|
|
|
onUploadComplete={updateTable}
|
|
|
|
|
onUploadError={() => setIsLoading(false)}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
),
|
|
|
|
|
}),
|
|
|
|
|
makeDateColumn('Дата загрузки', 'uploadDate'),
|
|
|
|
|
makeColumn('Ответственные', 'publishers', {
|
2022-09-13 16:46:02 +05:00
|
|
|
|
render: (publishers) => publishers?.map((user) => <UserView user={user} style={{ marginLeft: 10 }} />),
|
2022-09-13 16:21:57 +05:00
|
|
|
|
}),
|
|
|
|
|
], [well, updateTable])
|
|
|
|
|
|
2022-09-12 12:30:27 +05:00
|
|
|
|
const onEditClose = useCallback((changed = false) => {
|
|
|
|
|
setShowEdit(false)
|
|
|
|
|
if (changed) updateTable()
|
|
|
|
|
}, [updateTable])
|
|
|
|
|
|
2022-09-13 16:21:57 +05:00
|
|
|
|
useEffect(updateTable, [updateTable])
|
2022-09-12 12:30:27 +05:00
|
|
|
|
|
|
|
|
|
return (
|
2022-09-13 16:46:02 +05:00
|
|
|
|
<div className={'well-case-page'}>
|
2022-09-12 12:30:27 +05:00
|
|
|
|
<LoaderPortal show={isLoading}>
|
|
|
|
|
{canEdit && (
|
2022-09-13 16:46:02 +05:00
|
|
|
|
<Alert
|
|
|
|
|
type={'info'}
|
|
|
|
|
className={'customer-block'}
|
|
|
|
|
showIcon
|
2022-09-13 16:53:12 +05:00
|
|
|
|
message={'Вам доступно редактирование ответственных.'}
|
2022-09-13 16:46:02 +05:00
|
|
|
|
action={<Button onClick={() => setShowEdit(true)}>Редактировать</Button>}
|
|
|
|
|
/>
|
2022-09-12 12:30:27 +05:00
|
|
|
|
)}
|
2022-09-13 16:53:12 +05:00
|
|
|
|
<Table
|
|
|
|
|
bordered
|
|
|
|
|
size={'small'}
|
|
|
|
|
columns={columns}
|
|
|
|
|
pagination={false}
|
|
|
|
|
dataSource={categories}
|
|
|
|
|
expandable={expandable}
|
|
|
|
|
/>
|
2022-09-12 12:30:27 +05:00
|
|
|
|
</LoaderPortal>
|
2022-09-13 16:21:57 +05:00
|
|
|
|
<WellCaseEditor categories={categories} show={showEdit} onClose={onEditClose} />
|
2022-09-13 16:46:02 +05:00
|
|
|
|
</div>
|
2022-09-12 12:30:27 +05:00
|
|
|
|
)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
export default wrapPrivateComponent(WellCase, {
|
|
|
|
|
title: 'Дело скважины',
|
|
|
|
|
route: 'well_case',
|
|
|
|
|
requirements: [],
|
2022-09-13 16:21:57 +05:00
|
|
|
|
// requirements: ['WellFinalDocuments.get'],
|
2022-09-12 12:30:27 +05:00
|
|
|
|
})
|