From 30b5ac8eb39206007df4654fa3eda1dd4bd6ea5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A4=D1=80=D0=BE=D0=BB=D0=BE=D0=B2?= Date: Mon, 30 Aug 2021 16:40:56 +0500 Subject: [PATCH] Add Measure Editor --- src/pages/Measure/Editor.jsx | 95 +++++++++++++++++++++++ src/pages/Measure/MeasureTable.jsx | 39 ++++++++-- src/pages/Measure/_old_LastData.__ | 68 ---------------- src/pages/Measure/columnsCommon.js | 31 ++++++++ src/pages/Measure/columnsDrillingFluid.js | 69 +++++++--------- src/pages/Measure/columnsMudDiagram.js | 49 ++++++------ src/pages/Measure/columnsNnb.js | 35 +++++---- src/pages/Measure/index.jsx | 12 +-- 8 files changed, 236 insertions(+), 162 deletions(-) create mode 100644 src/pages/Measure/Editor.jsx delete mode 100644 src/pages/Measure/_old_LastData.__ create mode 100644 src/pages/Measure/columnsCommon.js diff --git a/src/pages/Measure/Editor.jsx b/src/pages/Measure/Editor.jsx new file mode 100644 index 0000000..de9cca6 --- /dev/null +++ b/src/pages/Measure/Editor.jsx @@ -0,0 +1,95 @@ +import { useState, useEffect } from 'react' +import moment from 'moment' +import { EditableTable, DatePickerWrapper } from '../../components/Table' +import LoaderPortal from '../../components/LoaderPortal' +import { invokeWebApiWrapperAsync } from '../../components/factory' +import { MeasureService } from '../../services/api' + +const format='YYYY.MM.DD HH:mm' + +const columnTimestamp = { + editable: true, + title: 'Время', + key:'timestamp', + dataindex:'timestamp', + input: , + width:'12em', + render: (text, record, idx) => record['timestamp'], +} + +export const Editor = ({idWell, idCategory, columns, onUpdate}) => { + const [showLoader, setShowLoader] = useState(false) + const [history, setHistory] = useState([]) + + const update = () => invokeWebApiWrapperAsync(async()=>{ + const data = await MeasureService.getHisory(idWell, idCategory) + const story = data?.map( i=> ({ + id: i.id, + idWell: i.idWell, + idCategory: i.idCategory, + timestamp: moment.utc(i.timestamp).local().format(format), + ...i.data})) + setHistory(story??[]) + } + , setShowLoader + , "не удалось загрузить") + + useEffect(update, [idWell, idCategory]) + + const onAdd = async (row) => { + const {id, idCategory: _idCategory, idWell : _idWell, timestamp, key, ...data} = row + const measure = { + id:0, + idWell: idWell, + idCategory: idCategory, + timestamp: timestamp?? moment(), + data, + } + await MeasureService.insert(idWell, measure) + if(onUpdate) + onUpdate() + else + update() + } + + const onEdit = async (row) => { + if(!row?.id) + return + const {id, idCategory: _idCategory, idWell : _idWell, timestamp, ...data} = row + const measure = { + id: id, + idWell: idWell, + idCategory: idCategory, + timestamp: timestamp?? moment(), + data, + } + await MeasureService.update(idWell, measure) + if(onUpdate) + onUpdate() + else + update() + } + + const onDelete = async (row) => { + if(!row?.id) + return + await MeasureService.markAsDelete(idWell, row.id) + if(onUpdate) + onUpdate() + else + update() + } + + return + + +} \ No newline at end of file diff --git a/src/pages/Measure/MeasureTable.jsx b/src/pages/Measure/MeasureTable.jsx index f276599..7aab0f0 100644 --- a/src/pages/Measure/MeasureTable.jsx +++ b/src/pages/Measure/MeasureTable.jsx @@ -1,27 +1,54 @@ import { useState, useEffect } from 'react' -import { Table } from 'antd' +import { Table, Button, Modal } from 'antd' +import { HourglassOutlined } from '@ant-design/icons' import LoaderPortal from '../../components/LoaderPortal' import { invokeWebApiWrapperAsync } from '../../components/factory' import { MeasureService } from '../../services/api' +import { Editor } from './Editor' export const MeasureTable = ({idWell, idCategory, title, columns}) => { const [showLoader, setShowLoader] = useState(false) - const [lastData, setLastData] = useState([]) + const [showEditor, setShowEditor] = useState(false) + const [lastData, setLastData] = useState({}) - useEffect(()=>invokeWebApiWrapperAsync(async()=>{ + const update = ()=>invokeWebApiWrapperAsync(async()=>{ const data = await MeasureService.getLast(idWell, idCategory) setLastData(data) } , setShowLoader , "не удалось загрузить") - , [idWell, idCategory]) + + useEffect(update, [idWell, idCategory]) + + const timestamp = lastData ? new Date(lastData?.timestamp).toLocaleString() : '-' return

{title}

- дата: {lastData?.timestamp} + Дата: {timestamp} +   + + scroll={{ x: 400, y: 600 }}/> + setShowEditor(false)} + onCancel={() => setShowEditor(false)} + width="95%" + footer={null} + > + + } \ No newline at end of file diff --git a/src/pages/Measure/_old_LastData.__ b/src/pages/Measure/_old_LastData.__ deleted file mode 100644 index d86ba31..0000000 --- a/src/pages/Measure/_old_LastData.__ +++ /dev/null @@ -1,68 +0,0 @@ -import {Button, Modal } from "antd"; -import {DrillingFluid} from "../../components/modalWindows/DrillingFluid"; -import {useState} from "react"; -import {SludgeDiagram} from "../../components/modalWindows/MudDiagram"; -import {Nnb} from "../../components/modalWindows/Nnb" - -export default function LastData(/*{idWell}*/) { - - const [tableVisible, setCementTableVisible] = useState(false) - const [tableSludgeVisible, setTableSludgeVisible] = useState(false) - const [tableNNBVisible, setTableNNBVisible] = useState(false) - - return ( - <> -
 
- - setCementTableVisible(false)} - width={2000} - footer={[ - - ]} - > - - - - setTableSludgeVisible(false)} - width={2000} - footer={[ - - ]} - > - - - - setTableNNBVisible(false)} - width={2000} - footer={[ - - ]} - > - - - ) -} \ No newline at end of file diff --git a/src/pages/Measure/columnsCommon.js b/src/pages/Measure/columnsCommon.js new file mode 100644 index 0000000..e5f5bbf --- /dev/null +++ b/src/pages/Measure/columnsCommon.js @@ -0,0 +1,31 @@ +import {RegExpIsFloat} from '../../components/Table' +import {Input} from 'antd' + +const {TextArea} = Input + +export const v = (text) =>
+ {text} +
+ +export const numericColumnOptions = { + editable: true, + initialValue: 0, + width:'5em', + formItemRules: [ + { + required: true, + message: `Введите число`, + pattern: RegExpIsFloat, + }, + ], +}; + +export const textColumnOptions = { + editable:true, + input: