import { useState, useEffect } from "react";
import { useParams } from 'react-router-dom';
import {
Form,
DatePicker,
Radio,
Button,
Select,
Table,
Progress,
notification
} from 'antd';
import 'moment/locale/ru';
import locale from 'antd/lib/locale/ru_RU';
import moment from "moment";
import {Subscribe} from '../services/signalr';
import notify from '../components/notify';
import LoaderPortal from '../components/LoaderPortal';
import { ReportService } from '../services/api';
const { RangePicker } = DatePicker;
const { Option } = Select;
let reportDatesRange = {
from: moment("0001-01-01T00:00:00"),
to: moment("9999-12-31T23:59:59.9999999")
}
const timePeriodNames = [
{label: '1 секунда', value: 1},
{label: '10 секунд', value: 10},
{label: '1 минута', value: 60},
{label: '5 минут', value: 300},
{label: '30 минут', value: 1800},
{label: '1 час', value: 3600},
{label: '6 часов', value: 21600},
{label: '12 часов', value: 43200},
{label: '1 день', value: 86400},
{label: '1 неделя', value: 604800}
]
const firstStep = timePeriodNames[2]["value"]
const imgPaths = {
'.pdf': '/images/pdf.png',
'.las': '/images/las.png'
}
// Экспорт рендера
export default function Report(props) {
const [rangeDate, setRangeDate] = useState([moment().subtract(1,'days'), moment()])
const [step, setStep] = useState(firstStep)
const [format, setFormat] = useState(0)
const [approxPages, setPagesCount] = useState(0)
const [suitableReports, setSuitableReports] = useState([])
const [loader, setLoader] = useState(false)
let wellId = useParams().id;
const periods = timePeriodNames.map((line) => )
const columns = [
{
title: '',
dataIndex: 'reportFormat',
key: 'reportFormat',
render: format =>
},
{
title: 'Параметры отчета',
dataIndex: 'reportParams',
key: 'reportParams',
},
{
title: 'Название отчета',
dataIndex: 'reportName',
key: 'reportName',
render: name =>
},
];
const ReportCreationNotify = ({progressData}) => {
progressData = progressData ?? {progress: 0.0, operation: 'Создание отчета', reportName: ''}
return (
<>
{ progressData.operation }
>
)
}
const getReportFile = async (event, reportFileName) => {
const element = event.target
if(!element.href.length) {
try {
await fetch(`/api/report/${wellId}/${reportFileName}`, {
headers: {
Authorization: 'Bearer ' + localStorage['token']
}
})
.then(async (response) => {
const blob = await response.blob();
let reader = new FileReader();
reader.readAsDataURL(blob);
reader.onload = function (e) {
element.href = e.target.result
element.click()
};
});
} 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)
}
}
}
const handleReportCreation = async (values) => {
let begin = rangeDate[0].toISOString()
let end = rangeDate[1].toISOString()
try {
const idUser = localStorage['userId'];
const taskId = await ReportService.createReport(wellId,
idUser, values.step, values.format, begin, end)
if(!taskId)
return
const handleReportProgress = (progressData) => {
if(progressData) {
notification.open({
key: taskId,
message: 'Создание отчета:',
description: