2021-09-01 12:29:44 +05:00
|
|
|
|
import {Button, Tooltip} from 'antd'
|
2021-08-31 18:04:04 +05:00
|
|
|
|
import { useState } from "react"
|
|
|
|
|
import {invokeWebApiWrapperAsync, download} from '../../components/factory'
|
|
|
|
|
import DocumentsTemplate from './DocumentsTemplate'
|
|
|
|
|
import LoaderPortal from '../../components/LoaderPortal'
|
|
|
|
|
|
|
|
|
|
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-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
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(files.every(fileInfo => fileInfo?.name.endsWith('.xlsx'))){
|
|
|
|
|
setTooltip('Программа доступна для скачивания')
|
|
|
|
|
selDownloadButtonEnabled(true)
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
setTooltip('Список файлов содержит недопустимые типы файлов')
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-31 18:04:04 +05:00
|
|
|
|
return(<LoaderPortal show={showLoader}>
|
2021-09-01 12:29:44 +05:00
|
|
|
|
<Tooltip title={tooltip}>
|
|
|
|
|
<Button
|
|
|
|
|
onClick={downloadProgram}
|
|
|
|
|
disabled={!downloadButtonEnabled}>
|
|
|
|
|
Сформировать программу бурения
|
|
|
|
|
</Button>
|
|
|
|
|
</Tooltip>
|
2021-08-31 18:04:04 +05:00
|
|
|
|
<DocumentsTemplate
|
|
|
|
|
idWell={idWell}
|
2021-09-01 10:32:47 +05:00
|
|
|
|
idCategory={idFileCategoryDrillingProgramItems}
|
2021-09-01 12:29:44 +05:00
|
|
|
|
accept='.xlsx'
|
|
|
|
|
onChange={filesUpdated}/>
|
2021-08-31 18:04:04 +05:00
|
|
|
|
</LoaderPortal>)
|
|
|
|
|
}
|