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: