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-10-28 17:00:30 +05:00
|
|
|
|
import {invokeWebApiWrapperAsync, download} from '../../components/factory'
|
2021-08-31 18:04:04 +05:00
|
|
|
|
import DocumentsTemplate from './DocumentsTemplate'
|
|
|
|
|
import LoaderPortal from '../../components/LoaderPortal'
|
2021-10-20 16:27:11 +05:00
|
|
|
|
import { Flex } from '../../components/Grid'
|
2021-10-28 15:46:18 +05:00
|
|
|
|
import {DrillingProgramService, 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-10-28 17:00:30 +05:00
|
|
|
|
const urlDownloadProgram =`/api/well/${idWell}/drillingProgram`
|
2021-08-31 18:04:04 +05:00
|
|
|
|
|
|
|
|
|
const downloadProgram = () => invokeWebApiWrapperAsync(async()=>{
|
2021-10-28 17:00:30 +05:00
|
|
|
|
await download(urlDownloadProgram)
|
2021-10-28 15:46:18 +05:00
|
|
|
|
},
|
2021-08-31 18:04:04 +05:00
|
|
|
|
setShowLoader,
|
|
|
|
|
"Не удалось загрузить программу бурения")
|
|
|
|
|
|
2021-10-28 17:00:30 +05:00
|
|
|
|
const openProgramPreview = () => invokeWebApiWrapperAsync(async()=>{
|
|
|
|
|
var filWebUrl = await DrillingProgramService.getFileWebLink(idWell)
|
|
|
|
|
if(filWebUrl && filWebUrl.length)
|
|
|
|
|
window.open(filWebUrl, '_blank')
|
|
|
|
|
else
|
|
|
|
|
throw new Error()
|
|
|
|
|
},
|
|
|
|
|
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}>
|
2021-10-28 17:00:30 +05:00
|
|
|
|
Сформировать и скачать
|
2021-09-01 13:43:14 +05:00
|
|
|
|
</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>
|
2021-10-28 17:00:30 +05:00
|
|
|
|
<Tooltip title="Перед просмотром программы бурения сначала сформируйте ее.">
|
|
|
|
|
<Button
|
|
|
|
|
type="primary"
|
|
|
|
|
onClick={openProgramPreview}
|
|
|
|
|
disabled={!downloadButtonEnabled}>
|
|
|
|
|
Просмотреть программу бурения
|
|
|
|
|
</Button>
|
|
|
|
|
</Tooltip>
|
2021-10-20 16:27:11 +05:00
|
|
|
|
</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>)
|
|
|
|
|
}
|