From ad8f01b1860fd131224ea6b903bd96a3eb1c5157 Mon Sep 17 00:00:00 2001 From: goodm2ice Date: Fri, 17 Dec 2021 10:12:19 +0500 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B5=D1=80=D0=B0=D0=B1?= =?UTF-8?q?=D0=BE=D1=82=D0=B0=D0=BD=D0=B0=20=D1=80=D0=B5=D0=BA=D0=BE=D0=BC?= =?UTF-8?q?=D0=B5=D0=BD=D0=B4=D0=B0=D1=86=D0=B8=D0=B8=20=D1=83=D1=81=D1=82?= =?UTF-8?q?=D0=B0=D0=B2=D0=BE=D0=BA:=20*=20=D0=94=D0=BE=D0=B1=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=B0=20=D1=82=D0=B0=D0=B1=D0=BB=D0=B8=D1=86?= =?UTF-8?q?=D0=B0=20=D1=81=20=D0=B8=D1=81=D1=82=D0=BE=D1=80=D0=B8=D0=B5?= =?UTF-8?q?=D0=B9=20=D1=83=D1=81=D1=82=D0=B0=D0=B2=D0=BE=D0=BA=20*=20?= =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=BE=20=D0=BE?= =?UTF-8?q?=D0=BA=D0=BD=D0=BE=20=D0=BF=D1=80=D0=BE=D1=81=D0=BC=D0=BE=D1=82?= =?UTF-8?q?=D1=80=D0=B0=20=D1=83=D1=81=D1=82=D0=B0=D0=B2=D0=BA=D0=B8=20*?= =?UTF-8?q?=20=D0=9F=D0=B5=D1=80=D0=B5=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0?= =?UTF-8?q?=D0=BD=20=D1=81=D1=82=D0=B8=D0=BB=D1=8C=20=D0=B4=D0=BE=D0=B1?= =?UTF-8?q?=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F=20=D1=83=D1=81=D1=82?= =?UTF-8?q?=D0=B0=D0=B2=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/TelemetryView/SetpointSender.jsx | 113 +++++++++++++++ src/pages/TelemetryView/SetpointViewer.jsx | 77 ++++++++++ src/pages/TelemetryView/Setpoints.jsx | 161 +++++++++------------ 3 files changed, 260 insertions(+), 91 deletions(-) create mode 100644 src/pages/TelemetryView/SetpointSender.jsx create mode 100644 src/pages/TelemetryView/SetpointViewer.jsx diff --git a/src/pages/TelemetryView/SetpointSender.jsx b/src/pages/TelemetryView/SetpointSender.jsx new file mode 100644 index 0000000..6ad3b2e --- /dev/null +++ b/src/pages/TelemetryView/SetpointSender.jsx @@ -0,0 +1,113 @@ +import { useState } from 'react' +import { Select, Modal, Input, InputNumber } from 'antd' +import { SetpointsService } from '../../services/api' +import LoaderPortal from '../../components/LoaderPortal' +import { invokeWebApiWrapperAsync } from '../../components/factory' +import { makeNumericRender, EditableTable, makeNumericInput } from '../../components/Table' +import { PeriodPicker, defaultPeriod } from '../../components/PeriodPicker' +import { Grid, GridItem } from '../../components/Grid' + +export const SetpointSender = ({ idWell, onClose, visible, setpointNames }) => { + const [expirePeriod, setExpirePeriod] = useState(defaultPeriod) + const [comment, setComment] = useState('') + const [setpoints, setSetpoints] = useState([]) + const [isLoading, setIsLoading] = useState(false) + + const addingColumns = [ + { + title: 'Наименование уставки', + dataIndex: 'name', + editable: true, + isRequired: true, + width: 200, + input: , - render: (val) => setpointNames.find((name) => name.value === val)?.label - }, { - title: 'Значение', - dataIndex: 'value', - editable: true, - isRequired: true, - width: 125, - render: makeNumericRender(7), - align: 'right' - } - ] - - const onOpenClick = () => invokeWebApiWrapperAsync( + useEffect(() => invokeWebApiWrapperAsync( async () => { const names = await SetpointsService.getSetpointsNamesByIdWell(idWell) if (!names) throw Error('Setpoints not found') @@ -44,84 +28,79 @@ export const Setpoints = ({ idWell, ...other }) => { value: spn.name, tooltip: spn.comment }))) - setIsModalShown(true) + }, + setIsLoading, + `Не удалось загрузить список имёт уставок по скважине "${idWell}"` + ), [idWell]) + + const showMore = (id) => { + const selected = setpoints.find((sp) => sp.id === id) + setSelected(selected ?? {}) + setIsViewerVisible(true) + } + + const historyColumns = [ + { title: 'Дата', dataIndex: 'uploadDate', render: item => moment(item).format('DD MMM YYYY, HH:mm:ss') }, + { title: 'Автор', dataIndex: 'author', render: (user) => }, + { title: 'Комментарий', dataIndex: 'comment', render: makeStringCutter() }, + { title: 'Статус', dataIndex: 'idState', render: (id) => getSetpointStatus(parseInt(id)) }, + { dataIndex: 'id', render: (id) => }, + ] + + const updateTable = () => invokeWebApiWrapperAsync( + async () => { + const setpoints = await SetpointsService.getByIdWell(idWell) + setSetpoints(setpoints) }, setIsLoading, `Не удалось загрузить список для скважины "${idWell}"` ) - const onModalOk = () => invokeWebApiWrapperAsync( - async () => { - // eslint-disable-next-line no-sequences - const setpointsObject = setpoints.reduce((obj, sp) => (obj[sp.name] = sp.value, obj), {}) - const request = { - uploadDate: new Date(), - obsolescenceSec: expirePeriod, - setpoints: setpointsObject, - comment: comment - } - await SetpointsService.insert(idWell, request) - setIsModalShown(false) - }, - setIsUploading, - `Не удалось отправить рекомендации по скважине "${idWell}"` - ) + useEffect(updateTable, [idWell]) - const onAdd = async (setpoint) => setSetpoints((prevSetpoints) => { - setpoint.key = Date.now() - prevSetpoints.push(setpoint) - return prevSetpoints - }) - - const onEdit = async (setpoint) => setSetpoints((prevSetpoints) => { - const idx = prevSetpoints.findIndex((val) => val.key === setpoint.key) - prevSetpoints[idx] = setpoint - return prevSetpoints - }) - - const onDelete = async (setpoint) => setSetpoints((prevSetpoints) => { - const idx = prevSetpoints.findIndex((val) => val.key === setpoint.key) - prevSetpoints.splice(idx, 1) - return prevSetpoints - }) + const onSenderClose = (pushed) => { + if (pushed) updateTable() + setIsSenderVisible(false) + } return (
- setIsModalShown(false)} - onOk={onModalOk} - okText={'Отправить'} + width={1200} + title={'Рекомендованные уставки'} + visible={isModalVisible} + onCancel={() => setIsModalVisible(false)} + footer={ + + } > - -
- Период актуальности рекомендаций: - -
- + - Комментарий: - setComment(e.value)} - value={comment} - required /> + + setIsViewerVisible(false)} + /> ) }