From 1ebaf3c1851affaaea0bcfa3a7c26401b5f440ce Mon Sep 17 00:00:00 2001 From: goodmice Date: Wed, 17 Nov 2021 13:54:51 +0500 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D1=8B=20=D0=BE=D0=B3=D1=80=D0=B0=D0=BD=D0=B8=D1=87=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D1=8F=20=D0=B2=D1=8B=D0=B1=D0=BE=D1=80=D0=B0=20?= =?UTF-8?q?=D0=B4=D0=B0=D1=82=D1=8B=20=D0=B2=20=D0=B0=D1=80=D1=85=D0=B8?= =?UTF-8?q?=D0=B2=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/Archive/index.jsx | 53 ++++++++++++++++++++++++++++++------- 1 file changed, 43 insertions(+), 10 deletions(-) diff --git a/src/pages/Archive/index.jsx b/src/pages/Archive/index.jsx index 6b19035..7333e0f 100644 --- a/src/pages/Archive/index.jsx +++ b/src/pages/Archive/index.jsx @@ -53,10 +53,18 @@ const getLoadingInterval = (loaded, startDate, interval) => { } } +const range = (start, end) => { + const result = [] + for (let i = start; i < end; i++) + result.push(i) + return result +} + export default function Archive({idWell}) { const [dataSaub, setDataSaub] = useState([]) + const [dateLimit, setDateLimit] = useState({ from: 0, to: new Date() }) const [chartInterval, setChartInterval] = useState(parseInt(defaultPeriod) * 1000) - const [startDate, setStartDate] = useState(new Date(+new Date() - chartInterval)) + const [startDate, setStartDate] = useState(new Date(Date.now() - chartInterval)) const [showLoader, setShowLoader] = useState(false) const [loaded, setLoaded] = useState(null) @@ -64,29 +72,52 @@ export default function Archive({idWell}) { if (loaded) { setStartDate((prevStartDate) => { const offset = e.deltaY * chartInterval * WHEEL_SENSITIVITY - const nextStartDate = new Date(+prevStartDate + offset) - const lastPossibleDate = new Date(Math.min(loaded.end, new Date()) - chartInterval) - return new Date(Math.max(loaded.start, Math.min(nextStartDate, lastPossibleDate))) + const nextStartDate = +prevStartDate + offset + const firstPossibleDate = Math.max(loaded.start, dateLimit.from) + const lastPossibleDate = Math.min(loaded.end, Date.now()) - chartInterval + return new Date(Math.max(firstPossibleDate, Math.min(nextStartDate, lastPossibleDate))) }) } } + const isDateDisabled = (date) => { + if (!date) return false + const dt = new Date(date).setHours(0, 0, 0, 0) + return dt < dateLimit.from || dt > +dateLimit.to - chartInterval + } + const isDateTimeDisabled = (date) => ({ + disabledHours: () => range(0, 24).filter(h => { + if (!date) return false + const dt = +new Date(date).setHours(h) + return dt < dateLimit.from || dt > +dateLimit.to - chartInterval + }), + disabledMinutes: () => range(0, 60).filter(m => { + if (!date) return false + const dt = +new Date(date).setMinutes(m) + return dt < dateLimit.from || dt > +dateLimit.to - chartInterval + }), + disabledSeconds: () => range(0, 60).filter(s => { + if (!date) return false + const dt = +new Date(date).setSeconds(s) + return dt < dateLimit.from || dt > +dateLimit.to - chartInterval + }) + }) + useEffect(() => invokeWebApiWrapperAsync( async () => { const dates = await TelemetryDataSaubService.getDataDatesRange(idWell) - let startDate - if (dates?.from && dates?.to) - startDate = Math.max(new Date(dates.from), +new Date(dates.to) - chartInterval) - else - startDate = +new Date() - chartInterval + dates.from = new Date(dates.from ?? (Date.now() - chartInterval)) + dates.to = new Date(dates.to ?? Date.now()) + const startDate = new Date(Math.max(dates.from, +dates.to - chartInterval)) setStartDate(new Date(startDate)) + setDateLimit(dates) }, setShowLoader, `Не удалось загрузить диапозон телеметрии для скважины "${idWell}"` ), []) useEffect(() => { - setStartDate((startDate) => new Date(Math.min(+new Date() - chartInterval, startDate))) + setStartDate((startDate) => new Date(Math.min(Date.now() - chartInterval, startDate))) setDataSaub([]) }, [chartInterval]) @@ -127,6 +158,8 @@ export default function Archive({idWell}) { allowClear={false} onChange={(startDate) => setStartDate(new Date(startDate))} value={moment(startDate)} + disabledDate={isDateDisabled} + disabledTime={isDateTimeDisabled} />