From 6a2fa499df9ee3fc832a98d6e56d16b36cd2d5bc Mon Sep 17 00:00:00 2001 From: KharchenkoVV Date: Mon, 7 Jun 2021 16:03:50 +0500 Subject: [PATCH] =?UTF-8?q?CF2-8:=20=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=BE=20=D0=BF=D0=BE=D0=BB=D1=83=D1=87=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=BE=D1=82=D1=87=D0=B5=D1=82=D0=BE=D0=B2=20?= =?UTF-8?q?=D1=81=20=D1=81=D0=B5=D1=80=D0=B2=D0=B5=D1=80=D0=B0=20=D0=B8=20?= =?UTF-8?q?=D0=BE=D0=BF=D0=BE=D0=B2=D0=B5=D1=89=D0=B5=D0=BD=D0=B8=D0=B5=20?= =?UTF-8?q?=D0=BE=20=D0=BF=D1=80=D0=BE=D0=B3=D1=80=D0=B5=D1=81=D1=81=D0=B5?= =?UTF-8?q?=20=D0=BF=D0=BE=D0=BB=D1=83=D1=87=D0=B5=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/Report.jsx | 223 +++++++++++++++++++++++++------------------ src/styles/App.less | 8 ++ src/styles/index.css | 31 ++++++ 3 files changed, 167 insertions(+), 95 deletions(-) diff --git a/src/pages/Report.jsx b/src/pages/Report.jsx index bc3e481..dd5d287 100644 --- a/src/pages/Report.jsx +++ b/src/pages/Report.jsx @@ -1,4 +1,4 @@ -import React, { useState, useEffect } from "react"; +import { useState, useEffect } from "react"; import { useParams } from 'react-router-dom'; import { Form, @@ -6,7 +6,9 @@ import { Radio, Button, Select, - Table + Table, + Progress, + notification } from 'antd'; import 'moment/locale/ru'; import locale from 'antd/lib/locale/ru_RU'; @@ -42,10 +44,11 @@ export default function Report(props) { const [rangeDate, setRangeDate] = useState([moment().subtract(1,'days'), moment()]) const [step, setStep] = useState(600) const [format, setFormat] = useState(0) - const [reportProgress, setReportProgress] = useState(0.0) const [approxPages, setPagesCount] = useState(0) const [suitableReports, setSuitableReports] = useState([]) const [loader, setLoader] = useState(false) + + let wellId = useParams().id; const columns = [ @@ -64,41 +67,73 @@ export default function Report(props) { title: 'Название отчета', dataIndex: 'reportName', key: 'reportName', - render: name => {name} + render: name => getReportFile(event, name)} download={name}>{name} }, ]; + + const ReportCreationNotify = ({progressData}) => { + progressData = progressData ?? {progress: 0.0, operation: 'Создание отчета', reportName: ''} - const handleReportProgress = (data) => { - console.log('data: ' + data) - if(data) { - setReportProgress(data) + return ( + <> + +
+ { progressData.operation } +
+ {getReportFile(event, progressData.reportName)}} + download={progressData.reportName}> + { progressData.reportName } + + + ) + } + + const getReportFile = async (event, reportFileName) => { + try { + const element = event.target + let reportFile = await ReportService.getReport(wellId, reportFileName) + let reportUrl = URL.createObjectURL(reportFile) + element.href = reportUrl + } catch (error) { + notify(`Не удалось скачать отчет по скважине (${wellId}) c + ${rangeDate[0].format("DD.MM.YYYY hh:mm:ss")} по + ${rangeDate[1].format("DD.MM.YYYY hh:mm:ss")}`, 'error') + console.log(error) } - - console.log('reportProgress: ' + reportProgress) - //console.log(data) } const handleReportCreation = async (values) => { let begin = rangeDate[0].toISOString() let end = rangeDate[1].toISOString() - let taskId = null; - ReportService.createReport(wellId, values.step, values.format, begin, end) - .then((data) => { - if(data) { - taskId = data - let unSubscribeReportHub = Subscribe('hubs/reports', 'GetReportProgress', `Report_${taskId}`, handleReportProgress) - //unSubscribeReportHub() - } - }) - .catch(error => { - notify(`Не удалось создать отчет по скважине (${wellId}) c - ${rangeDate[0].format("DD.MM.YYYY hh:mm:ss")} по - ${rangeDate[1].format("DD.MM.YYYY hh:mm:ss")}`, 'error') - console.error(error) - }) + try { + const taskId = await ReportService.createReport(wellId, values.step, values.format, begin, end) + if(!taskId) + return - }; + const handleReportProgress = (progressData) => { + if(progressData) { + notification.open({ + key: taskId, + message: 'Создание отчета:', + description: , + duration: 0 + }); + + if (progressData.reportName.length) + unSubscribeReportHub() + } + } + + const unSubscribeReportHub = Subscribe('hubs/reports', 'GetReportProgress', `Report_${taskId}`, handleReportProgress) + } + catch(error) { + notify(`Не удалось создать отчет по скважине (${wellId}) c + ${rangeDate[0].format("DD.MM.YYYY hh:mm:ss")} по + ${rangeDate[1].format("DD.MM.YYYY hh:mm:ss")}`, 'error') + console.log(error) + } + } function disabledDate(current) { return reportDatesRange.From >= current || reportDatesRange.To <= current; @@ -115,7 +150,7 @@ export default function Report(props) { notify(`Не удалось получить предварительный размер отчета c ${rangeDate[0].format("DD.MM.YYYY hh:mm:ss")} по ${rangeDate[1].format("DD.MM.YYYY hh:mm:ss")}`, 'error') - console.error(error) + console.log(error) } finally { setLoader(false) } @@ -147,7 +182,7 @@ export default function Report(props) { notify(`Не удалось получить подходящие по параметрам отчеты c ${rangeDate[0].format("DD.MM.YYYY hh:mm:ss")} по ${rangeDate[1].format("DD.MM.YYYY hh:mm:ss")}`, 'error') - console.error(error) + console.log(error) } finally { setLoader(false) } @@ -164,76 +199,74 @@ export default function Report(props) { } getDatesRange() - //return ()=>{uns && uns()} },[]) return (<> -
-
- - { - setRangeDate([moment(dateStrings[0]), moment(dateStrings[1])]) - } - } - locale={locale} - showTime - /> - - - - - setFormat(e.target.value)} - style={{marginLeft: '30px'}} - > - - PDF - LAS - - - -
-
+ { + setRangeDate([moment(dateStrings[0]), moment(dateStrings[1])]) + } + } + locale={locale} + showTime + /> + + + + + setFormat(e.target.value)} + className="ml-30px" + > + + PDF + LAS + + + + + +

Отчеты с аналогичными параметрами, доступные для скачивания: diff --git a/src/styles/App.less b/src/styles/App.less index d2ef1e5..89df32a 100644 --- a/src/styles/App.less +++ b/src/styles/App.less @@ -16,6 +16,14 @@ html { height: 100%; } +.mt-30px { + margin-top: 30px; +} + +.ml-30px { + margin-left: 30px; +} + .login_page{ position: absolute; height:100%; diff --git a/src/styles/index.css b/src/styles/index.css index 087d9c3..8d31ab7 100644 --- a/src/styles/index.css +++ b/src/styles/index.css @@ -11,6 +11,37 @@ body { -moz-osx-font-smoothing: grayscale; } +.d-flex { + display: flex; +} + +.d-inline { + display: inline; +} + +.d-none { + display: none; +} + +.w-100 { + width: 100% +} + +.mt-20px { + margin-top: 20px; +} + +.ml-5px { + margin-left: 5px; +} + +.ml-30px { + margin-left: 30px; +} + +.vertical-align-center { + vertical-align: center; +} code { font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',