forked from ddrilling/asb_cloud_front
Добавлены ограничения выбора даты в архиве
This commit is contained in:
parent
91e1abc0fc
commit
1ebaf3c185
@ -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}) {
|
export default function Archive({idWell}) {
|
||||||
const [dataSaub, setDataSaub] = useState([])
|
const [dataSaub, setDataSaub] = useState([])
|
||||||
|
const [dateLimit, setDateLimit] = useState({ from: 0, to: new Date() })
|
||||||
const [chartInterval, setChartInterval] = useState(parseInt(defaultPeriod) * 1000)
|
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 [showLoader, setShowLoader] = useState(false)
|
||||||
const [loaded, setLoaded] = useState(null)
|
const [loaded, setLoaded] = useState(null)
|
||||||
|
|
||||||
@ -64,29 +72,52 @@ export default function Archive({idWell}) {
|
|||||||
if (loaded) {
|
if (loaded) {
|
||||||
setStartDate((prevStartDate) => {
|
setStartDate((prevStartDate) => {
|
||||||
const offset = e.deltaY * chartInterval * WHEEL_SENSITIVITY
|
const offset = e.deltaY * chartInterval * WHEEL_SENSITIVITY
|
||||||
const nextStartDate = new Date(+prevStartDate + offset)
|
const nextStartDate = +prevStartDate + offset
|
||||||
const lastPossibleDate = new Date(Math.min(loaded.end, new Date()) - chartInterval)
|
const firstPossibleDate = Math.max(loaded.start, dateLimit.from)
|
||||||
return new Date(Math.max(loaded.start, Math.min(nextStartDate, lastPossibleDate)))
|
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(
|
useEffect(() => invokeWebApiWrapperAsync(
|
||||||
async () => {
|
async () => {
|
||||||
const dates = await TelemetryDataSaubService.getDataDatesRange(idWell)
|
const dates = await TelemetryDataSaubService.getDataDatesRange(idWell)
|
||||||
let startDate
|
dates.from = new Date(dates.from ?? (Date.now() - chartInterval))
|
||||||
if (dates?.from && dates?.to)
|
dates.to = new Date(dates.to ?? Date.now())
|
||||||
startDate = Math.max(new Date(dates.from), +new Date(dates.to) - chartInterval)
|
const startDate = new Date(Math.max(dates.from, +dates.to - chartInterval))
|
||||||
else
|
|
||||||
startDate = +new Date() - chartInterval
|
|
||||||
setStartDate(new Date(startDate))
|
setStartDate(new Date(startDate))
|
||||||
|
setDateLimit(dates)
|
||||||
},
|
},
|
||||||
setShowLoader,
|
setShowLoader,
|
||||||
`Не удалось загрузить диапозон телеметрии для скважины "${idWell}"`
|
`Не удалось загрузить диапозон телеметрии для скважины "${idWell}"`
|
||||||
), [])
|
), [])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setStartDate((startDate) => new Date(Math.min(+new Date() - chartInterval, startDate)))
|
setStartDate((startDate) => new Date(Math.min(Date.now() - chartInterval, startDate)))
|
||||||
setDataSaub([])
|
setDataSaub([])
|
||||||
}, [chartInterval])
|
}, [chartInterval])
|
||||||
|
|
||||||
@ -127,6 +158,8 @@ export default function Archive({idWell}) {
|
|||||||
allowClear={false}
|
allowClear={false}
|
||||||
onChange={(startDate) => setStartDate(new Date(startDate))}
|
onChange={(startDate) => setStartDate(new Date(startDate))}
|
||||||
value={moment(startDate)}
|
value={moment(startDate)}
|
||||||
|
disabledDate={isDateDisabled}
|
||||||
|
disabledTime={isDateTimeDisabled}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div style={{ marginLeft: '1rem' }}>
|
<div style={{ marginLeft: '1rem' }}>
|
||||||
|
Loading…
Reference in New Issue
Block a user