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}) {
|
||||
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}
|
||||
/>
|
||||
</div>
|
||||
<div style={{ marginLeft: '1rem' }}>
|
||||
|
Loading…
Reference in New Issue
Block a user