2021-09-01 12:29:44 +05:00
|
|
|
|
import {Button, Tooltip} from 'antd'
|
2021-10-20 16:27:11 +05:00
|
|
|
|
import { FileExcelOutlined } from '@ant-design/icons'
|
|
|
|
|
import { useEffect, useState } from "react"
|
2021-08-31 18:04:04 +05:00
|
|
|
|
import {invokeWebApiWrapperAsync, download} from '../../components/factory'
|
|
|
|
|
import DocumentsTemplate from './DocumentsTemplate'
|
|
|
|
|
import LoaderPortal from '../../components/LoaderPortal'
|
2021-10-20 16:27:11 +05:00
|
|
|
|
import { Flex } from '../../components/Grid'
|
|
|
|
|
import { WellService } from '../../services/api'
|
2021-08-31 18:04:04 +05:00
|
|
|
|
|
|
|
|
|
const idFileCategoryDrillingProgramItems = 13;
|
|
|
|
|
|
|
|
|
|
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}`)
|
|
|
|
|
|
|
|
|
|
useEffect(() => invokeWebApiWrapperAsync(
|
|
|
|
|
async () => {
|
|
|
|
|
const well = await WellService.get(idWell)
|
|
|
|
|
setWellLabel(well.caption ?? `${idWell}`)
|
|
|
|
|
},
|
|
|
|
|
setShowLoader,
|
|
|
|
|
`Не удалось загрузить название скважины "${idWell}"`
|
|
|
|
|
), [idWell])
|
2021-08-31 18:04:04 +05:00
|
|
|
|
|
2021-09-01 10:32:47 +05:00
|
|
|
|
const urlDownloadProgram =`/api/well/${idWell}/drillingProgram`
|
2021-08-31 18:04:04 +05:00
|
|
|
|
|
|
|
|
|
const downloadProgram = () => invokeWebApiWrapperAsync(async()=>{
|
|
|
|
|
await download(urlDownloadProgram)
|
|
|
|
|
},
|
|
|
|
|
setShowLoader,
|
|
|
|
|
"Не удалось загрузить программу бурения")
|
|
|
|
|
|
2021-09-01 12:29:44 +05:00
|
|
|
|
const filesUpdated = (files) =>{
|
|
|
|
|
if(!files || files.length === 0){
|
|
|
|
|
setTooltip('Нет файлов для формирования программы')
|
|
|
|
|
selDownloadButtonEnabled(false)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-01 15:55:23 +05:00
|
|
|
|
if(files.every(fileInfo => fileInfo?.name.toLowerCase().endsWith('.xlsx'))){
|
2021-09-01 12:29:44 +05:00
|
|
|
|
setTooltip('Программа доступна для скачивания')
|
|
|
|
|
selDownloadButtonEnabled(true)
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
setTooltip('Список файлов содержит недопустимые типы файлов')
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-01 13:43:14 +05:00
|
|
|
|
const downloadButton = <div>
|
|
|
|
|
<span>Программа бурения</span>
|
2021-10-20 16:27:11 +05:00
|
|
|
|
<Flex>
|
2021-09-01 13:43:14 +05:00
|
|
|
|
<Tooltip title={tooltip}>
|
|
|
|
|
<Button
|
2021-09-01 15:55:23 +05:00
|
|
|
|
type="primary"
|
2021-09-01 13:43:14 +05:00
|
|
|
|
onClick={downloadProgram}
|
|
|
|
|
disabled={!downloadButtonEnabled}>
|
|
|
|
|
Сформировать и скачать
|
|
|
|
|
</Button>
|
|
|
|
|
</Tooltip>
|
2021-10-20 16:27:11 +05:00
|
|
|
|
<Tooltip title={tooltip}>
|
|
|
|
|
<Button
|
|
|
|
|
type="link"
|
|
|
|
|
onClick={downloadProgram}
|
|
|
|
|
disabled={!downloadButtonEnabled}>
|
|
|
|
|
<FileExcelOutlined />
|
|
|
|
|
Программа бурения {wellLabel}.xlsx
|
|
|
|
|
</Button>
|
|
|
|
|
</Tooltip>
|
|
|
|
|
</Flex>
|
2021-09-01 13:43:14 +05:00
|
|
|
|
</div>
|
|
|
|
|
|
2021-08-31 18:04:04 +05:00
|
|
|
|
return(<LoaderPortal show={showLoader}>
|
|
|
|
|
<DocumentsTemplate
|
|
|
|
|
idWell={idWell}
|
2021-09-01 10:32:47 +05:00
|
|
|
|
idCategory={idFileCategoryDrillingProgramItems}
|
2021-09-01 12:29:44 +05:00
|
|
|
|
accept='.xlsx'
|
2021-09-01 13:43:14 +05:00
|
|
|
|
headerChild={downloadButton}
|
|
|
|
|
onChange={filesUpdated} />
|
2021-08-31 18:04:04 +05:00
|
|
|
|
</LoaderPortal>)
|
|
|
|
|
}
|