2021-12-20 12:44:07 +05:00
|
|
|
|
import { useEffect, useState } from 'react'
|
2021-10-20 16:27:11 +05:00
|
|
|
|
import { FileExcelOutlined } from '@ant-design/icons'
|
2021-12-20 12:44:07 +05:00
|
|
|
|
import { Popconfirm, Button, Tooltip, Typography } from 'antd'
|
2021-10-20 16:27:11 +05:00
|
|
|
|
import { Flex } from '../../components/Grid'
|
2021-12-20 12:44:07 +05:00
|
|
|
|
import { Mark } from '../../components/Mark'
|
|
|
|
|
import { UserView } from '../../components/UserView'
|
|
|
|
|
import LoaderPortal from '../../components/LoaderPortal'
|
|
|
|
|
import { invokeWebApiWrapperAsync, download, formatBytes } from '../../components/factory'
|
2021-10-28 15:46:18 +05:00
|
|
|
|
import {DrillingProgramService, WellService} from '../../services/api'
|
2021-12-20 12:44:07 +05:00
|
|
|
|
import DocumentsTemplate from './DocumentsTemplate'
|
2021-08-31 18:04:04 +05:00
|
|
|
|
|
2021-12-20 12:44:07 +05:00
|
|
|
|
const idFileCategoryDrillingProgramItems = 13
|
2021-11-11 12:22:21 +05:00
|
|
|
|
const {Text} = Typography
|
2021-08-31 18:04:04 +05:00
|
|
|
|
|
2021-12-20 12:44:07 +05:00
|
|
|
|
export default function DrillingProgram({ idWell }) {
|
2021-09-01 12:29:44 +05:00
|
|
|
|
const [downloadButtonEnabled, selDownloadButtonEnabled] = useState(false)
|
2021-08-31 18:04:04 +05:00
|
|
|
|
const [showLoader, setShowLoader] = useState(false)
|
2021-09-01 12:29:44 +05:00
|
|
|
|
const [tooltip, setTooltip] = useState('нет файлов для формирования')
|
2021-10-20 16:27:11 +05:00
|
|
|
|
const [wellLabel, setWellLabel] = useState(`${idWell}`)
|
2021-12-20 12:44:07 +05:00
|
|
|
|
const [childKey, setChildKey] = useState()
|
|
|
|
|
const [lastUpdatedFile, setLastUpdatedFile] = useState()
|
2021-10-20 16:27:11 +05:00
|
|
|
|
|
|
|
|
|
useEffect(() => invokeWebApiWrapperAsync(
|
|
|
|
|
async () => {
|
|
|
|
|
const well = await WellService.get(idWell)
|
|
|
|
|
setWellLabel(well.caption ?? `${idWell}`)
|
|
|
|
|
},
|
|
|
|
|
setShowLoader,
|
2021-12-20 12:44:07 +05:00
|
|
|
|
`Не удалось загрузить название скважины '${idWell}'`
|
2021-10-20 16:27:11 +05:00
|
|
|
|
), [idWell])
|
2021-08-31 18:04:04 +05:00
|
|
|
|
|
2021-12-20 12:44:07 +05:00
|
|
|
|
const urlDownloadProgram = `/api/well/${idWell}/drillingProgram`
|
|
|
|
|
|
|
|
|
|
const downloadProgram = () => invokeWebApiWrapperAsync(
|
|
|
|
|
async () => await download(urlDownloadProgram),
|
|
|
|
|
setShowLoader,
|
|
|
|
|
'Не удалось загрузить программу бурения'
|
|
|
|
|
)
|
2021-08-31 18:04:04 +05:00
|
|
|
|
|
2021-12-20 12:44:07 +05:00
|
|
|
|
const openProgramPreview = () => invokeWebApiWrapperAsync(
|
|
|
|
|
async() => {
|
2021-11-09 18:01:00 +05:00
|
|
|
|
const filWebUrl = await DrillingProgramService.getOrCreateSharedUrl(idWell)
|
|
|
|
|
if(filWebUrl && filWebUrl.length > 0)
|
2021-12-20 12:44:07 +05:00
|
|
|
|
window.open(filWebUrl, '_blank')
|
2021-11-09 18:01:00 +05:00
|
|
|
|
else
|
2021-12-20 12:44:07 +05:00
|
|
|
|
throw new Error('Сервер вернул плохую ссылку')
|
|
|
|
|
},
|
|
|
|
|
setShowLoader,
|
|
|
|
|
'Не удалось создать быстрый просмотр программы'
|
|
|
|
|
)
|
2021-10-28 17:00:30 +05:00
|
|
|
|
|
2021-12-20 12:44:07 +05:00
|
|
|
|
const filesUpdated = (files) => {
|
|
|
|
|
if (!files || files.length === 0) {
|
2021-09-01 12:29:44 +05:00
|
|
|
|
setTooltip('Нет файлов для формирования программы')
|
|
|
|
|
selDownloadButtonEnabled(false)
|
|
|
|
|
return
|
|
|
|
|
}
|
2021-12-20 12:44:07 +05:00
|
|
|
|
|
2021-11-09 18:01:00 +05:00
|
|
|
|
const isAllFilesAreExcel = files.every(fileInfo => fileInfo?.name.toLowerCase().endsWith('.xlsx'))
|
|
|
|
|
const isAnyFileMarked = files.some(file => file?.fileMarks.some(m => m?.idMarkType === 1 && !m?.isDeleted))
|
|
|
|
|
|
2021-12-20 12:44:07 +05:00
|
|
|
|
if (isAllFilesAreExcel && isAnyFileMarked) {
|
2021-09-01 12:29:44 +05:00
|
|
|
|
setTooltip('Программа доступна для скачивания')
|
|
|
|
|
selDownloadButtonEnabled(true)
|
2021-12-20 12:44:07 +05:00
|
|
|
|
} else {
|
2021-09-01 12:29:44 +05:00
|
|
|
|
setTooltip('Список файлов содержит недопустимые типы файлов')
|
|
|
|
|
}
|
2021-11-11 12:22:21 +05:00
|
|
|
|
const last = files.reduce((pre, cur) => pre.uploadDate > cur.uploadDate ? pre : cur)
|
2021-12-20 12:44:07 +05:00
|
|
|
|
setLastUpdatedFile(last)
|
2021-09-01 12:29:44 +05:00
|
|
|
|
}
|
|
|
|
|
|
2021-11-09 18:01:00 +05:00
|
|
|
|
const customColumns = [
|
|
|
|
|
{
|
2021-12-20 12:44:07 +05:00
|
|
|
|
title: 'Метки',
|
|
|
|
|
key: 'fileMarks',
|
2021-11-09 18:01:00 +05:00
|
|
|
|
render: (_, record) => renderMarksColumn(record?.id, record?.fileMarks)
|
|
|
|
|
},
|
|
|
|
|
]
|
2021-12-20 12:44:07 +05:00
|
|
|
|
|
2021-11-09 18:01:00 +05:00
|
|
|
|
const renderMarksColumn=(idFile, marks)=>{
|
|
|
|
|
const validMarks = marks?.filter(m => !(m?.isDeleted))
|
|
|
|
|
if(validMarks?.length)
|
|
|
|
|
return validMarks.map(mark => <Mark mark = {mark} onDelete={() => deleteMark(mark.id)}/>)
|
|
|
|
|
|
2021-12-20 12:44:07 +05:00
|
|
|
|
return (
|
|
|
|
|
<Popconfirm title={'Согласовать файл?'} onConfirm={() => addMarkToFile(idFile)}>
|
|
|
|
|
<Button type={'link'}>Согласовать</Button>
|
2021-11-09 18:01:00 +05:00
|
|
|
|
</Popconfirm>
|
2021-12-20 12:44:07 +05:00
|
|
|
|
)
|
2021-11-09 18:01:00 +05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const addMarkToFile = async (idFile) => {
|
|
|
|
|
const mark = {
|
|
|
|
|
idFile: idFile,
|
|
|
|
|
idMarkType: 1,
|
2021-12-20 12:44:07 +05:00
|
|
|
|
isDeleted: false,
|
|
|
|
|
comment: '',
|
|
|
|
|
}
|
2021-11-09 18:01:00 +05:00
|
|
|
|
await DrillingProgramService.createFileMark(idWell, mark)
|
|
|
|
|
selDownloadButtonEnabled(true)
|
|
|
|
|
setChildKey(Date.now())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const deleteMark = async (idMark) => {
|
|
|
|
|
await DrillingProgramService.deleteFileMark(idWell, idMark)
|
|
|
|
|
setChildKey(Date.now())
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-20 12:44:07 +05:00
|
|
|
|
const downloadButton = (
|
|
|
|
|
<div>
|
|
|
|
|
<span>Программа бурения</span>
|
|
|
|
|
<Flex>
|
|
|
|
|
<Tooltip title={tooltip}>
|
|
|
|
|
<Button
|
|
|
|
|
type={'primary'}
|
|
|
|
|
onClick={downloadProgram}
|
|
|
|
|
disabled={!downloadButtonEnabled}
|
|
|
|
|
>
|
|
|
|
|
Сформировать и скачать
|
2021-11-09 18:01:00 +05:00
|
|
|
|
</Button>
|
2021-12-20 12:44:07 +05:00
|
|
|
|
</Tooltip>
|
|
|
|
|
<Tooltip title={'Просмотреть через GoogleDrive'}>
|
|
|
|
|
<Popconfirm
|
|
|
|
|
title={'Загрузить файл на GoogleDrive для просмотра?'}
|
|
|
|
|
onConfirm={openProgramPreview}
|
|
|
|
|
disabled={!downloadButtonEnabled}
|
|
|
|
|
>
|
|
|
|
|
<Button
|
|
|
|
|
type={'link'}
|
|
|
|
|
disabled={!downloadButtonEnabled}
|
|
|
|
|
>
|
|
|
|
|
<FileExcelOutlined />
|
|
|
|
|
Программа бурения {wellLabel}.xlsx
|
|
|
|
|
</Button>
|
|
|
|
|
</Popconfirm>
|
|
|
|
|
</Tooltip>
|
|
|
|
|
</Flex>
|
|
|
|
|
</div>
|
|
|
|
|
)
|
2021-09-01 13:43:14 +05:00
|
|
|
|
|
2021-11-11 12:22:21 +05:00
|
|
|
|
const lastUpdatedFileView = lastUpdatedFile &&
|
2021-11-18 13:40:08 +05:00
|
|
|
|
<Text>
|
2021-11-11 12:22:21 +05:00
|
|
|
|
<b>Последнее изменние:</b>
|
2021-12-20 12:44:07 +05:00
|
|
|
|
'{lastUpdatedFile.name}'
|
2021-11-11 12:22:21 +05:00
|
|
|
|
[{formatBytes(lastUpdatedFile.size)}]
|
|
|
|
|
загружен: {new Date(lastUpdatedFile.uploadDate).toLocaleString()}
|
|
|
|
|
автор: <UserView user={lastUpdatedFile.author}/>
|
2021-12-20 12:44:07 +05:00
|
|
|
|
</Text>
|
2021-11-11 12:22:21 +05:00
|
|
|
|
|
2021-12-20 12:44:07 +05:00
|
|
|
|
return (
|
|
|
|
|
<LoaderPortal show={showLoader}>
|
2021-08-31 18:04:04 +05:00
|
|
|
|
<DocumentsTemplate
|
2021-11-11 12:22:21 +05:00
|
|
|
|
beforeTable={lastUpdatedFileView}
|
2021-08-31 18:04:04 +05:00
|
|
|
|
idWell={idWell}
|
2021-09-01 10:32:47 +05:00
|
|
|
|
idCategory={idFileCategoryDrillingProgramItems}
|
2021-12-20 12:44:07 +05:00
|
|
|
|
accept={'.xlsx'}
|
2021-09-01 13:43:14 +05:00
|
|
|
|
headerChild={downloadButton}
|
2021-11-09 18:01:00 +05:00
|
|
|
|
onChange={filesUpdated}
|
|
|
|
|
customColumns = {customColumns}
|
2021-12-20 12:44:07 +05:00
|
|
|
|
key = {childKey}
|
|
|
|
|
/>
|
|
|
|
|
</LoaderPortal>
|
|
|
|
|
)
|
|
|
|
|
}
|