Skip to content

Commit

Permalink
Merge pull request #958 from linea-it/938-ativar-desativar-solar-time
Browse files Browse the repository at this point in the history
added a switch to enable and disable the show events filter
  • Loading branch information
jandsonrj authored Apr 1, 2024
2 parents a877c1b + 5d18957 commit efad37e
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 32 deletions.
4 changes: 2 additions & 2 deletions frontend/src/components/GeoFilter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ function GeoFilter({ value, onChange }) {
required
disabled={!enabled}
value={value.longitude === undefined ? '' : value.longitude}
min={0}
max={360}
min={-180}
max={180}
onChange={(event) => {
handleChange({
...value,
Expand Down
22 changes: 16 additions & 6 deletions frontend/src/components/PredictionEventsFilter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,26 +102,36 @@ function PredictionEventsFilter() {
}}
/>
</Grid>
<Grid item xs={12} md={6} lg={4}>
<Grid item xs={12}>
<Divider />
</Grid>
<Grid item xs={12}>
<SolarTimeFilter
value={[queryOptions.filters.solar_time_after, queryOptions.filters.solar_time_before]}
value={{
solar_time_enabled: queryOptions.filters.solar_time_enabled,
solar_time_after: queryOptions.filters.solar_time_after,
solar_time_before: queryOptions.filters.solar_time_before
}}
onChange={(value) => {
setQueryOptions((prev) => {
return {
...prev,
filters: {
...prev.filters,
solar_time_after: value[0],
solar_time_before: value[1]
...value
}
}
})
}}
></SolarTimeFilter>
</Grid>
<Grid item xs={12} md={6} lg={4}>
<Grid item xs={12}>
<Divider />
</Grid>
{/* <Grid item xs={12} md={3} container justifyContent='flex-end'> */}
<Grid item xs={12} container>
<FormControlLabel
label='Nighttime Only'
label='Hide Diurn Events'
control={
<Switch
checked={queryOptions.filters.nightside}
Expand Down
79 changes: 59 additions & 20 deletions frontend/src/components/SolarTimeFilter/index.js
Original file line number Diff line number Diff line change
@@ -1,44 +1,83 @@
import React from 'react'
import PropTypes from 'prop-types'
import dayjs from 'dayjs'
import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs'
import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider'
import { TimeField } from '@mui/x-date-pickers/TimeField'
import Grid from '@mui/material/Grid'
import FormControlLabel from '@mui/material/FormControlLabel'
import Switch from '@mui/material/Switch'

function SolarTimeFilter({ value, onChange }) {
return (
<LocalizationProvider dateAdapter={AdapterDayjs}>
<Grid container spacing={2}>
<Grid item xs={12} sm={6}>
<TimeField
label='Local Solar Time After'
slotProps={{ textField: { fullWidth: true } }}
// shouldDisableTime={(value, view) =>
// view === 'hours' && value.hour() > 0 && value.hour() < 12}
value={value[0]}
onChange={(newValue) => onChange([newValue, value[1]])}
<Grid container spacing={2} alignItems='center'>
<Grid item xs={12}>
<FormControlLabel
control={
<Switch
checked={value.solar_time_enabled}
onChange={(e) => {
onChange({
solar_time_enabled: e.target.checked,
solar_time_after: value.solar_time_after,
solar_time_before: value.solar_time_before
})
}}
/>
}
label={'Local Solar Time'}
/>
</Grid>
<Grid item xs={12} sm={6}>
<TimeField
label='Local Solar Time Before'
slotProps={{ textField: { fullWidth: true } }}
// shouldDisableTime={(value, view) =>
// view === 'hours' && value.hour() > 12 && value.hour() < 24}
value={value[1]}
onChange={(newValue) => onChange([value[0], newValue])}
/>
<Grid item xs={12}>
<Grid container spacing={2} alignItems='center'>
<Grid item xs={12} sm={4}>
<TimeField
label='Show Events After'
slotProps={{ textField: { fullWidth: true } }}
value={value.solar_time_after}
onChange={(newValue) =>
onChange({
solar_time_enabled: value.solar_time_enabled,
solar_time_after: newValue,
solar_time_before: value.solar_time_before
})
}
disabled={!value.solar_time_enabled}
/>
</Grid>
<Grid item xs={12} sm={4}>
<TimeField
label='Local Solar Time'
slotProps={{ textField: { fullWidth: true } }}
value={value.solar_time_before}
onChange={(newValue) =>
onChange({
solar_time_enabled: value.solar_time_enabled,
solar_time_after: value.solar_time_after,
solar_time_before: newValue
})
}
disabled={!value.solar_time_enabled}
/>
</Grid>
</Grid>
</Grid>
</Grid>
</LocalizationProvider>
)
}

SolarTimeFilter.defaultProps = {
value: [dayjs('2024-01-01T18:00'), dayjs('2024-01-02T06:00')]
value: {
solar_time_enabled: true,
solar_time_after: dayjs('2024-01-01T18:00'),
solar_time_before: dayjs('2024-01-02T06:00')
}
}

SolarTimeFilter.propTypes = {
value: PropTypes.array.isRequired,
value: PropTypes.object.isRequired,
onChange: PropTypes.func.isRequired
}

Expand Down
1 change: 1 addition & 0 deletions frontend/src/contexts/PredictionContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export function PredictionEventsProvider({ children }) {
filterType: '',
filterValue: undefined,
maginitudeMax: 15,
solar_time_enabled: true,
solar_time_after: dayjs().set('hour', 18).startOf('hour'),
solar_time_before: dayjs().set('hour', 6).startOf('hour'),
nightside: true,
Expand Down
10 changes: 6 additions & 4 deletions frontend/src/services/api/Occultation.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,12 @@ const parsePredictEventsFilters = (params) => {
newFilters.mag_g_max = filters.maginitudeMax

// Filtro por Local Solar Time
if (filters.solar_time_after !== undefined && filters.solar_time_before !== '') {
if (filters.solar_time_after.isValid() && filters.solar_time_before.isValid()) {
newFilters.local_solar_time_after = filters.solar_time_after.format('HH:mm:ss')
newFilters.local_solar_time_before = filters.solar_time_before.format('HH:mm:ss')
if (filters.solar_time_enabled === true) {
if (filters.solar_time_after !== undefined && filters.solar_time_before !== '') {
if (filters.solar_time_after.isValid() && filters.solar_time_before.isValid()) {
newFilters.local_solar_time_after = filters.solar_time_after.format('HH:mm:ss')
newFilters.local_solar_time_before = filters.solar_time_before.format('HH:mm:ss')
}
}
}

Expand Down

0 comments on commit efad37e

Please sign in to comment.