From cf7323ba5abbb6aaee0e003fd5dcaed734199a0b Mon Sep 17 00:00:00 2001 From: goodm2ice Date: Fri, 17 Dec 2021 10:02:12 +0500 Subject: [PATCH 1/8] =?UTF-8?q?PeriodPicker=20=D0=B4=D0=BE=D0=B1=D0=B0?= =?UTF-8?q?=D0=B2=D0=BB=D0=B5=D0=BD=D0=B0=20=D0=B2=D0=BE=D0=B7=D0=BC=D0=BE?= =?UTF-8?q?=D0=B6=D0=BD=D0=BE=D1=81=D1=82=D1=8C=20=D1=83=D0=BA=D0=B0=D0=B7?= =?UTF-8?q?=D1=8B=D0=B2=D0=B0=D1=82=D1=8C=20=D0=B4=D0=BE=D0=BF=20=D0=B0?= =?UTF-8?q?=D1=82=D1=80=D0=B8=D0=B1=D0=B1=D1=83=D1=82=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/PeriodPicker.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/components/PeriodPicker.tsx b/src/components/PeriodPicker.tsx index 88bbe6a..90ff7d6 100644 --- a/src/components/PeriodPicker.tsx +++ b/src/components/PeriodPicker.tsx @@ -16,10 +16,12 @@ const timePeriodCollection = [ type PeriodPickerProps = { defaultValue?: number onChange?: (value: number) => void + [other: string]: any } -export const PeriodPicker = ({ defaultValue = defaultPeriod, onChange }: PeriodPickerProps) => ( +export const PeriodPicker = ({ defaultValue = defaultPeriod, onChange, ...other }: PeriodPickerProps) => ( , + render: (val) => setpointNames.find((name) => name.value === val)?.label + }, { + title: 'Значение', + dataIndex: 'value', + editable: true, + isRequired: true, + width: 125, + input: `${value}`.replace(',', '.')}/>, + render: makeNumericRender(1), + align: 'right' + } + ] + + const onAdd = async (sp) => setSetpoints((prevSp) => { + sp.key = Date.now() + prevSp.push(sp) + return prevSp + }) + + const onEdit = async (sp) => setSetpoints((prevSp) => { + const idx = prevSp.findIndex((val) => val.key === sp.key) + prevSp[idx] = sp + return prevSp + }) + + const onDelete = async (sp) => setSetpoints((prevSp) => { + const idx = prevSp.findIndex((val) => val.key === sp.key) + prevSp.splice(idx, 1) + return prevSp + }) + + const onModalOk = () => invokeWebApiWrapperAsync( + async () => { + 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) + onClose(true) + }, + setIsLoading, + `Не удалось отправить уставки по скважине "${idWell}"` + ) + + return ( + + + + Период актуальности рекомендаций: + + + + + Комментарий: + + setComment(e.target.value)} + value={comment} + required + /> + + + + + + + + + ) +} diff --git a/src/pages/TelemetryView/SetpointViewer.jsx b/src/pages/TelemetryView/SetpointViewer.jsx new file mode 100644 index 0000000..feb2240 --- /dev/null +++ b/src/pages/TelemetryView/SetpointViewer.jsx @@ -0,0 +1,77 @@ +import moment from 'moment' +import { memo } from 'react' +import { Modal, Input } from 'antd' +import { Table } from '../../components/Table' +import { UserView } from '../../components/UserView' +import { Grid, GridItem } from '../../components/Grid' +import { periodToString } from '../../utils/datetime' + +export const setpointStatus = { + 0: 'Неизвестно', + 1: 'Ожидает отправки', + 2: 'Отправлено', + 3: 'Принято оператором', + 4: 'Отклонено оператором', + 5: 'Устарело', +} + +export const getSetpointStatus = (id) => { + if (!id || Object.keys(setpointStatus).every((idx) => Number(idx) !== id)) + return setpointStatus[0] + return setpointStatus[id] +} + +const columns = [ + { title: 'Название', dataIndex: 'name' }, + { title: 'Значение', dataIndex: 'value' }, +] + +export const SetpointViewer = memo(({ setpoint, visible, onClose, setpointNames }) => { + let date = moment(setpoint?.uploadDate).format('DD MMM YYYY, HH:mm:ss') + let setpoints = [] + if (setpoint) { + setpoints = Object.keys(setpoint?.setpoints).map((name) => ({ + name: setpointNames.find(spName => spName.value === name)?.label, + value: setpoint.setpoints[name] + })) + } + + return ( + + + Дата рекомендаций: + {date} + + Автор: + + + Статус: + {getSetpointStatus(setpoint?.idState)} + + Период актуальности рекомендаций: + {periodToString(setpoint?.obsolescenceSec)} + + Комментарий: + + + + + + + + + + ) +}) diff --git a/src/pages/TelemetryView/Setpoints.jsx b/src/pages/TelemetryView/Setpoints.jsx index ad2701e..1f6846a 100644 --- a/src/pages/TelemetryView/Setpoints.jsx +++ b/src/pages/TelemetryView/Setpoints.jsx @@ -1,41 +1,25 @@ -import { Button, Input, Modal, Select } from 'antd' -import { useState } from 'react' -import { invokeWebApiWrapperAsync } from '../../components/factory' +import moment from 'moment' +import { Button, Modal } from 'antd' +import { useState, useEffect } from 'react' +import { Table } from '../../components/Table' +import { UserView } from '../../components/UserView' import LoaderPortal from '../../components/LoaderPortal' -import PeriodPicker, { defaultPeriod } from '../../components/PeriodPicker' -import { EditableTable, makeNumericRender } from '../../components/Table' +import { invokeWebApiWrapperAsync } from '../../components/factory' +import { makeStringCutter } from '../../utils/string' import { SetpointsService } from '../../services/api' +import { SetpointSender } from './SetpointSender' +import { SetpointViewer, getSetpointStatus } from './SetpointViewer' export const Setpoints = ({ idWell, ...other }) => { - const [isModalShown, setIsModalShown] = useState(false) + const [isModalVisible, setIsModalVisible] = useState(false) + const [isSenderVisible, setIsSenderVisible] = useState(false) + const [isViewerVisible, setIsViewerVisible] = useState(false) const [isLoading, setIsLoading] = useState(false) - const [isUploading, setIsUploading] = useState(false) - const [setpointNames, setSetpointNames] = useState([]) const [setpoints, setSetpoints] = useState([]) - const [comment, setComment] = useState('') - const [expirePeriod, setExpirePeriod] = useState(defaultPeriod) + const [selected, setSelected] = useState(null) + const [setpointNames, setSetpointNames] = useState([]) - const columns = [ - { - title: 'Наименование установки', - dataIndex: 'name', - editable: true, - isRequired: true, - width: 200, - input:
- Комментарий: - setComment(e.value)} - value={comment} - required /> + + setIsViewerVisible(false)} + /> ) }