forked from ddrilling/asb_cloud_front
Add marks and action_confirms to drilling program page.
This commit is contained in:
parent
a6d330e276
commit
497d106a9d
25
src/components/Mark.jsx
Normal file
25
src/components/Mark.jsx
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
import {Tooltip, Tag, Typography, Popconfirm, Button } from 'antd'
|
||||||
|
import {UserView} from './UserView'
|
||||||
|
|
||||||
|
const markTypes = {
|
||||||
|
0 : {color:"orange", text : "неизвестно"},
|
||||||
|
1 : {color:"green", text : "согласовано"},
|
||||||
|
}
|
||||||
|
|
||||||
|
const {Text} = Typography
|
||||||
|
|
||||||
|
export const Mark = ({mark, onDelete}) => {
|
||||||
|
const markType = markTypes[mark.idMarkType]??markTypes[0]
|
||||||
|
return <Tooltip title={<UserView user={mark.user}/>}>
|
||||||
|
<Tag color={markType.color}>
|
||||||
|
<Text delete={mark?.isDeleted}>
|
||||||
|
{`${markType.text} ${new Date(mark.dateCreated).toLocaleString()}`}
|
||||||
|
</Text>
|
||||||
|
{(!mark?.isDeleted)&&
|
||||||
|
<Popconfirm title="Отозвать согласование?" onConfirm={onDelete}>
|
||||||
|
<Button type="link">x</Button>
|
||||||
|
</Popconfirm>
|
||||||
|
}
|
||||||
|
</Tag >
|
||||||
|
</Tooltip>
|
||||||
|
}
|
@ -17,7 +17,7 @@ const pageSize = 12
|
|||||||
const { RangePicker } = DatePicker
|
const { RangePicker } = DatePicker
|
||||||
const { Search } = Input
|
const { Search } = Input
|
||||||
|
|
||||||
export default function DocumentsTemplate({ idCategory, idWell, accept, headerChild, onChange }) {
|
export default function DocumentsTemplate({ idCategory, idWell, accept, headerChild, customColumns, onChange}) {
|
||||||
const [page, setPage] = useState(1)
|
const [page, setPage] = useState(1)
|
||||||
const [filterDataRange, setFilterDataRange] = useState([])
|
const [filterDataRange, setFilterDataRange] = useState([])
|
||||||
const [filterCompanyName, setFilterCompanyName] = useState([])
|
const [filterCompanyName, setFilterCompanyName] = useState([])
|
||||||
@ -79,6 +79,7 @@ export default function DocumentsTemplate({ idCategory, idWell, accept, headerCh
|
|||||||
key: "company",
|
key: "company",
|
||||||
render: (_, record) => <CompanyView company={record?.author?.company}/>
|
render: (_, record) => <CompanyView company={record?.author?.company}/>
|
||||||
},
|
},
|
||||||
|
...(customColumns??[])
|
||||||
]
|
]
|
||||||
|
|
||||||
const update = () => {
|
const update = () => {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import {Button, Tooltip} from 'antd'
|
import {Popconfirm, Button, Tooltip} from 'antd'
|
||||||
import { FileExcelOutlined } from '@ant-design/icons'
|
import { FileExcelOutlined } from '@ant-design/icons'
|
||||||
import { useEffect, useState } from "react"
|
import { useEffect, useState } from "react"
|
||||||
import {invokeWebApiWrapperAsync, download} from '../../components/factory'
|
import {invokeWebApiWrapperAsync, download} from '../../components/factory'
|
||||||
@ -6,6 +6,7 @@ import DocumentsTemplate from './DocumentsTemplate'
|
|||||||
import LoaderPortal from '../../components/LoaderPortal'
|
import LoaderPortal from '../../components/LoaderPortal'
|
||||||
import { Flex } from '../../components/Grid'
|
import { Flex } from '../../components/Grid'
|
||||||
import {DrillingProgramService, WellService} from '../../services/api'
|
import {DrillingProgramService, WellService} from '../../services/api'
|
||||||
|
import {Mark} from '../../components/Mark'
|
||||||
|
|
||||||
const idFileCategoryDrillingProgramItems = 13;
|
const idFileCategoryDrillingProgramItems = 13;
|
||||||
|
|
||||||
@ -14,6 +15,7 @@ export default function DrillingProgram({idWell}) {
|
|||||||
const [showLoader, setShowLoader] = useState(false)
|
const [showLoader, setShowLoader] = useState(false)
|
||||||
const [tooltip, setTooltip] = useState('нет файлов для формирования')
|
const [tooltip, setTooltip] = useState('нет файлов для формирования')
|
||||||
const [wellLabel, setWellLabel] = useState(`${idWell}`)
|
const [wellLabel, setWellLabel] = useState(`${idWell}`)
|
||||||
|
const [childKey, setChildKey] = useState();
|
||||||
|
|
||||||
useEffect(() => invokeWebApiWrapperAsync(
|
useEffect(() => invokeWebApiWrapperAsync(
|
||||||
async () => {
|
async () => {
|
||||||
@ -33,8 +35,11 @@ export default function DrillingProgram({idWell}) {
|
|||||||
"Не удалось загрузить программу бурения")
|
"Не удалось загрузить программу бурения")
|
||||||
|
|
||||||
const openProgramPreview = () => invokeWebApiWrapperAsync(async()=>{
|
const openProgramPreview = () => invokeWebApiWrapperAsync(async()=>{
|
||||||
const filWebUrl = await DrillingProgramService.getFileWebLink(idWell)
|
const filWebUrl = await DrillingProgramService.getOrCreateSharedUrl(idWell)
|
||||||
window.open(filWebUrl, '_blank')
|
if(filWebUrl && filWebUrl.length > 0)
|
||||||
|
window.open(filWebUrl, '_blank');
|
||||||
|
else
|
||||||
|
throw new Error("Сервер вернул плохую ссылку")
|
||||||
},
|
},
|
||||||
setShowLoader,
|
setShowLoader,
|
||||||
"Не удалось создать быстрый просмотр программы")
|
"Не удалось создать быстрый просмотр программы")
|
||||||
@ -46,7 +51,10 @@ export default function DrillingProgram({idWell}) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if(files.every(fileInfo => fileInfo?.name.toLowerCase().endsWith('.xlsx'))){
|
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){
|
||||||
setTooltip('Программа доступна для скачивания')
|
setTooltip('Программа доступна для скачивания')
|
||||||
selDownloadButtonEnabled(true)
|
selDownloadButtonEnabled(true)
|
||||||
}
|
}
|
||||||
@ -55,6 +63,41 @@ export default function DrillingProgram({idWell}) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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())
|
||||||
|
}
|
||||||
|
|
||||||
const downloadButton = <div>
|
const downloadButton = <div>
|
||||||
<span>Программа бурения</span>
|
<span>Программа бурения</span>
|
||||||
<Flex>
|
<Flex>
|
||||||
@ -66,22 +109,18 @@ export default function DrillingProgram({idWell}) {
|
|||||||
Сформировать и скачать
|
Сформировать и скачать
|
||||||
</Button>
|
</Button>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
<Tooltip title={tooltip}>
|
<Tooltip title="Просмотреть через GoogleDrive">
|
||||||
<Button
|
<Popconfirm
|
||||||
type="link"
|
title="Загрузить файл на GoogleDrive для просмотра?"
|
||||||
onClick={downloadProgram}
|
onConfirm={openProgramPreview}
|
||||||
disabled={!downloadButtonEnabled}>
|
disabled={!downloadButtonEnabled}>
|
||||||
<FileExcelOutlined />
|
<Button
|
||||||
Программа бурения {wellLabel}.xlsx
|
type="link"
|
||||||
</Button>
|
|
||||||
</Tooltip>
|
|
||||||
<Tooltip title="Перед просмотром программы бурения сначала сформируйте ее.">
|
|
||||||
<Button
|
|
||||||
type="primary"
|
|
||||||
onClick={openProgramPreview}
|
|
||||||
disabled={!downloadButtonEnabled}>
|
disabled={!downloadButtonEnabled}>
|
||||||
Сформировать и просмотреть
|
<FileExcelOutlined />
|
||||||
</Button>
|
Программа бурения {wellLabel}.xlsx
|
||||||
|
</Button>
|
||||||
|
</Popconfirm>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
</Flex>
|
</Flex>
|
||||||
</div>
|
</div>
|
||||||
@ -92,6 +131,8 @@ export default function DrillingProgram({idWell}) {
|
|||||||
idCategory={idFileCategoryDrillingProgramItems}
|
idCategory={idFileCategoryDrillingProgramItems}
|
||||||
accept='.xlsx'
|
accept='.xlsx'
|
||||||
headerChild={downloadButton}
|
headerChild={downloadButton}
|
||||||
onChange={filesUpdated} />
|
onChange={filesUpdated}
|
||||||
|
customColumns = {customColumns}
|
||||||
|
key = {childKey}/>
|
||||||
</LoaderPortal>)
|
</LoaderPortal>)
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user