From 497d106a9de5a15f38e2c26cbf0b83ee711832df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A4=D1=80=D0=BE=D0=BB=D0=BE=D0=B2?= Date: Tue, 9 Nov 2021 18:01:00 +0500 Subject: [PATCH] Add marks and action_confirms to drilling program page. --- src/components/Mark.jsx | 25 +++++++ src/pages/Documents/DocumentsTemplate.jsx | 3 +- src/pages/Documents/DrillingProgram.jsx | 79 +++++++++++++++++------ 3 files changed, 87 insertions(+), 20 deletions(-) create mode 100644 src/components/Mark.jsx diff --git a/src/components/Mark.jsx b/src/components/Mark.jsx new file mode 100644 index 0000000..c865eda --- /dev/null +++ b/src/components/Mark.jsx @@ -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 }> + + + {`${markType.text} ${new Date(mark.dateCreated).toLocaleString()}`} + + {(!mark?.isDeleted)&& + + + + } + + +} \ No newline at end of file diff --git a/src/pages/Documents/DocumentsTemplate.jsx b/src/pages/Documents/DocumentsTemplate.jsx index 6409392..497dd05 100644 --- a/src/pages/Documents/DocumentsTemplate.jsx +++ b/src/pages/Documents/DocumentsTemplate.jsx @@ -17,7 +17,7 @@ const pageSize = 12 const { RangePicker } = DatePicker 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 [filterDataRange, setFilterDataRange] = useState([]) const [filterCompanyName, setFilterCompanyName] = useState([]) @@ -79,6 +79,7 @@ export default function DocumentsTemplate({ idCategory, idWell, accept, headerCh key: "company", render: (_, record) => }, + ...(customColumns??[]) ] const update = () => { diff --git a/src/pages/Documents/DrillingProgram.jsx b/src/pages/Documents/DrillingProgram.jsx index 09adc6c..4fd7062 100644 --- a/src/pages/Documents/DrillingProgram.jsx +++ b/src/pages/Documents/DrillingProgram.jsx @@ -1,4 +1,4 @@ -import {Button, Tooltip} from 'antd' +import {Popconfirm, Button, Tooltip} from 'antd' import { FileExcelOutlined } from '@ant-design/icons' import { useEffect, useState } from "react" import {invokeWebApiWrapperAsync, download} from '../../components/factory' @@ -6,6 +6,7 @@ import DocumentsTemplate from './DocumentsTemplate' import LoaderPortal from '../../components/LoaderPortal' import { Flex } from '../../components/Grid' import {DrillingProgramService, WellService} from '../../services/api' +import {Mark} from '../../components/Mark' const idFileCategoryDrillingProgramItems = 13; @@ -14,6 +15,7 @@ export default function DrillingProgram({idWell}) { const [showLoader, setShowLoader] = useState(false) const [tooltip, setTooltip] = useState('нет файлов для формирования') const [wellLabel, setWellLabel] = useState(`${idWell}`) + const [childKey, setChildKey] = useState(); useEffect(() => invokeWebApiWrapperAsync( async () => { @@ -33,8 +35,11 @@ export default function DrillingProgram({idWell}) { "Не удалось загрузить программу бурения") const openProgramPreview = () => invokeWebApiWrapperAsync(async()=>{ - const filWebUrl = await DrillingProgramService.getFileWebLink(idWell) - window.open(filWebUrl, '_blank') + const filWebUrl = await DrillingProgramService.getOrCreateSharedUrl(idWell) + if(filWebUrl && filWebUrl.length > 0) + window.open(filWebUrl, '_blank'); + else + throw new Error("Сервер вернул плохую ссылку") }, setShowLoader, "Не удалось создать быстрый просмотр программы") @@ -46,7 +51,10 @@ export default function DrillingProgram({idWell}) { 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('Программа доступна для скачивания') 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 => deleteMark(mark.id)}/>) + + return true && + addMarkToFile(idFile)}> + + + } + + 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 =
Программа бурения @@ -66,22 +109,18 @@ export default function DrillingProgram({idWell}) { Сформировать и скачать - - - - - + + Программа бурения {wellLabel}.xlsx + +
@@ -92,6 +131,8 @@ export default function DrillingProgram({idWell}) { idCategory={idFileCategoryDrillingProgramItems} accept='.xlsx' headerChild={downloadButton} - onChange={filesUpdated} /> + onChange={filesUpdated} + customColumns = {customColumns} + key = {childKey}/> ) } \ No newline at end of file