2021-11-11 12:22:21 +05:00
|
|
|
|
import {Popconfirm, Button, Tooltip, Typography} from 'antd'
|
2021-10-20 16:27:11 +05:00
|
|
|
|
import { FileExcelOutlined } from '@ant-design/icons'
|
|
|
|
|
import { useEffect, useState } from "react"
|
2021-11-11 12:22:21 +05:00
|
|
|
|
import {invokeWebApiWrapperAsync, download, formatBytes} 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-11-09 18:01:00 +05:00
|
|
|
|
import {Mark} from '../../components/Mark'
|
2021-11-11 12:22:21 +05:00
|
|
|
|
import {UserView} from '../../components/UserView'
|
2021-08-31 18:04:04 +05:00
|
|
|
|
|
|
|
|
|
const idFileCategoryDrillingProgramItems = 13;
|
2021-11-11 12:22:21 +05:00
|
|
|
|
const {Text} = Typography
|
2021-08-31 18:04:04 +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-11-09 18:01:00 +05:00
|
|
|
|
const [childKey, setChildKey] = useState();
|
2021-11-11 12:22:21 +05:00
|
|
|
|
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,
|
|
|
|
|
`Не удалось загрузить название скважины "${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()=>{
|
2021-11-09 18:01:00 +05:00
|
|
|
|
const filWebUrl = await DrillingProgramService.getOrCreateSharedUrl(idWell)
|
|
|
|
|
if(filWebUrl && filWebUrl.length > 0)
|
|
|
|
|
window.open(filWebUrl, '_blank');
|
|
|
|
|
else
|
|
|
|
|
throw new Error("Сервер вернул плохую ссылку")
|
2021-10-28 17:00:30 +05:00
|
|
|
|
},
|
|
|
|
|
setShowLoader,
|
2021-10-29 12:56:03 +05:00
|
|
|
|
"Не удалось создать быстрый просмотр программы")
|
2021-10-28 17:00:30 +05:00
|
|
|
|
|
2021-09-01 12:29:44 +05:00
|
|
|
|
const filesUpdated = (files) =>{
|
|
|
|
|
if(!files || files.length === 0){
|
|
|
|
|
setTooltip('Нет файлов для формирования программы')
|
|
|
|
|
selDownloadButtonEnabled(false)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
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))
|
|
|
|
|
|
|
|
|
|
if(isAllFilesAreExcel && isAnyFileMarked){
|
2021-09-01 12:29:44 +05:00
|
|
|
|
setTooltip('Программа доступна для скачивания')
|
|
|
|
|
selDownloadButtonEnabled(true)
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
setTooltip('Список файлов содержит недопустимые типы файлов')
|
|
|
|
|
}
|
2021-11-11 12:22:21 +05:00
|
|
|
|
const last = files.reduce((pre, cur) => pre.uploadDate > cur.uploadDate ? pre : cur)
|
|
|
|
|
setLastUpdatedFile(last);
|
2021-09-01 12:29:44 +05:00
|
|
|
|
}
|
|
|
|
|
|
2021-11-09 18:01:00 +05:00
|
|
|
|
const customColumns = [
|
|
|
|
|
{
|
|
|
|
|
title: "Метки",
|
|
|
|
|
key: "fileMarks",
|
|
|
|
|
render: (_, record) => renderMarksColumn(record?.id, record?.fileMarks)
|
|
|
|
|
},
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
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)}/>)
|
|
|
|
|
|
|
|
|
|
return true &&
|
|
|
|
|
<Popconfirm title="Согласовать файл?" onConfirm={() => addMarkToFile(idFile)}>
|
|
|
|
|
<Button type="link">Согласовать</Button>
|
|
|
|
|
</Popconfirm>
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const addMarkToFile = async (idFile) => {
|
|
|
|
|
const mark = {
|
|
|
|
|
idFile: idFile,
|
|
|
|
|
idMarkType: 1,
|
|
|
|
|
isDeleted:false,
|
|
|
|
|
comment: ''}
|
|
|
|
|
await DrillingProgramService.createFileMark(idWell, mark)
|
|
|
|
|
selDownloadButtonEnabled(true)
|
|
|
|
|
setChildKey(Date.now())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const deleteMark = async (idMark) => {
|
|
|
|
|
await DrillingProgramService.deleteFileMark(idWell, idMark)
|
|
|
|
|
setChildKey(Date.now())
|
|
|
|
|
}
|
|
|
|
|
|
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-11-09 18:01:00 +05:00
|
|
|
|
<Tooltip title="Просмотреть через GoogleDrive">
|
|
|
|
|
<Popconfirm
|
|
|
|
|
title="Загрузить файл на GoogleDrive для просмотра?"
|
|
|
|
|
onConfirm={openProgramPreview}
|
2021-10-20 16:27:11 +05:00
|
|
|
|
disabled={!downloadButtonEnabled}>
|
2021-11-09 18:01:00 +05:00
|
|
|
|
<Button
|
|
|
|
|
type="link"
|
2021-10-28 17:00:30 +05:00
|
|
|
|
disabled={!downloadButtonEnabled}>
|
2021-11-09 18:01:00 +05:00
|
|
|
|
<FileExcelOutlined />
|
|
|
|
|
Программа бурения {wellLabel}.xlsx
|
|
|
|
|
</Button>
|
|
|
|
|
</Popconfirm>
|
2021-10-28 17:00:30 +05:00
|
|
|
|
</Tooltip>
|
2021-10-20 16:27:11 +05:00
|
|
|
|
</Flex>
|
2021-09-01 13:43:14 +05:00
|
|
|
|
</div>
|
|
|
|
|
|
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>
|
|
|
|
|
"{lastUpdatedFile.name}"
|
|
|
|
|
[{formatBytes(lastUpdatedFile.size)}]
|
|
|
|
|
загружен: {new Date(lastUpdatedFile.uploadDate).toLocaleString()}
|
|
|
|
|
автор: <UserView user={lastUpdatedFile.author}/>
|
|
|
|
|
</Text>
|
|
|
|
|
|
2021-08-31 18:04:04 +05:00
|
|
|
|
return(<LoaderPortal show={showLoader}>
|
|
|
|
|
<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-09-01 12:29:44 +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}
|
|
|
|
|
key = {childKey}/>
|
2021-08-31 18:04:04 +05:00
|
|
|
|
</LoaderPortal>)
|
|
|
|
|
}
|