Skip to content

Commit

Permalink
feat(TripSeriesModal): add auto block IDs
Browse files Browse the repository at this point in the history
  • Loading branch information
philip-cline committed Oct 26, 2023
1 parent 5ef96bd commit 8f0965a
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 31 deletions.
5 changes: 5 additions & 0 deletions i18n/english.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1352,12 +1352,17 @@ components:
tableDeleted: Table Deleted
transformationsTitle: Transformations
TripSeriesModal:
alternateEvery: "Alternate every: "
automaticallyUpdateBlockIds: Automatically assign Block IDs for trips created in series?
automaticallyUpdateTripIds: Automatically update Trip IDs for trips created in series?
blockIdPrefixPlaceholder: Auto block ID prefix
blockIncrementPlaceholder: inc. by
close: Close
createTripSeriesBody: Enter the start and end time for the trip series (24 hour time) and headway between trips. Click generate to create the series of trips.
createTripSeriesQuestion: Create a series of trips
disabledTooltip: There is an issue with the input data
endTime: "End Time:"
formatExplanation: "* Block IDs will be formatted as {prefix}-{alternating number}, e.g. 'WEEKDAY-1' then 'WEEKDAY-2', etc.'"
generateTrips: Generate Trips
headway: "Headway:"
incrementAmountPlaceholder: Increment amount
Expand Down
8 changes: 6 additions & 2 deletions i18n/german.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1551,13 +1551,17 @@ components:
pickupDropOffDefault: (Default - Available)
pickupTitle: Define the pickup method/availability at this stop.
TripSeriesModal:
alternateEvery: "Alternate every: "
automaticallyUpdateBlockIds: Automatically assign Block IDs for trips created in series?
automaticallyUpdateTripIds: Automatically update Trip IDs for trips created in series?
blockIdPrefixPlaceholder: Auto block ID prefix
blockIncrementPlaceholder: inc. by
close: Close
createTripSeriesBody: Enter the start and end time for the trip series (24 hour
time) and headway between trips. Click generate to create the series of trips.
createTripSeriesBody: Enter the start and end time for the trip series (24 hour time) and headway between trips. Click generate to create the series of trips.
createTripSeriesQuestion: Create a series of trips
disabledTooltip: There is an issue with the input data
endTime: "End Time:"
formatExplanation: "* Block IDs will be formatted as {prefix}-{alternating number}, e.g. 'WEEKDAY-1' then 'WEEKDAY-2', etc.'"
generateTrips: Generate Trips
headway: "Headway:"
incrementAmountPlaceholder: Increment amount
Expand Down
8 changes: 6 additions & 2 deletions i18n/polish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1522,13 +1522,17 @@ components:
pickupDropOffDefault: (Default - Available)
pickupTitle: Define the pickup method/availability at this stop.
TripSeriesModal:
alternateEvery: "Alternate every: "
automaticallyUpdateBlockIds: Automatically assign Block IDs for trips created in series?
automaticallyUpdateTripIds: Automatically update Trip IDs for trips created in series?
blockIdPrefixPlaceholder: Auto block ID prefix
blockIncrementPlaceholder: inc. by
close: Close
createTripSeriesBody: Enter the start and end time for the trip series (24 hour
time) and headway between trips. Click generate to create the series of trips.
createTripSeriesBody: Enter the start and end time for the trip series (24 hour time) and headway between trips. Click generate to create the series of trips.
createTripSeriesQuestion: Create a series of trips
disabledTooltip: There is an issue with the input data
endTime: "End Time:"
formatExplanation: "* Block IDs will be formatted as {prefix}-{alternating number}, e.g. 'WEEKDAY-1' then 'WEEKDAY-2', etc.'"
generateTrips: Generate Trips
headway: "Headway:"
incrementAmountPlaceholder: Increment amount
Expand Down
3 changes: 2 additions & 1 deletion lib/editor/components/timetable/TimetableEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export default class TimetableEditor extends Component<Props, State> {

cloneSelectedTrips = () => this.duplicateRows(this._getSelectedRowIndexes())

constructNewRow = (toClone: ?Trip = null, tripSeriesStartTime: ?number, autoTripId: ?string): ?Trip => {
constructNewRow = (toClone: ?Trip = null, tripSeriesStartTime: ?number, autoTripId: ?string, autoBlockId: ?string): ?Trip => {
const {activePatternId, route} = this.props
const activePattern = route && route.tripPatterns
? route.tripPatterns.find(p => p.id === activePatternId)
Expand Down Expand Up @@ -230,6 +230,7 @@ export default class TimetableEditor extends Component<Props, State> {
// IMPORTANT: set id to NEW_ID
objectPath.set(newRow, 'id', ENTITY.NEW_ID)
objectPath.set(newRow, 'tripId', autoTripId || null)
objectPath.set(newRow, 'blockId', autoBlockId || null)
objectPath.set(newRow, 'useFrequency', activePattern.useFrequency)
if (activePattern.useFrequency) {
// If a frequency-based trip, never use exact times. NOTE: there is no
Expand Down
99 changes: 73 additions & 26 deletions lib/editor/components/timetable/TripSeriesModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,32 @@ type Props = {
}

const TripSeriesModal = (props: Props) => {
// Trip series timing state variables
const [startTime, setStartTime] = useState(null)
const [headway, setHeadway] = useState(null)
const [endTime, setEndTime] = useState(null)

// Automatic block and trip ID state variables
const [useAutoTripIds, setUseAutoTripIds] = useState(false)
const [useAutoBlockIds, setUseAutoBlockIds] = useState(false)

const [autoTripIdStart, setAutoTripIdStart] = useState(0)

const [autoTripIdIncrement, setAutoTripIdIncrement] = useState(1)
const [autoBlockIdIncrement, setAutoBlockIdIncrement] = useState(1)

const [autoTripIdPrefix, setAutoTripIdPrefix] = useState('')
const [autoBlockIdPrefix, setAutoBlockIdPrefix] = useState('')

const messages = getComponentMessages('TripSeriesModal')

const handleIncrementStartUpdate = (evt: SyntheticInputEvent<HTMLInputElement>) => setAutoTripIdStart(+evt.target.value)
const handleTripPrefixUpdate = (evt: SyntheticInputEvent<HTMLInputElement>) => setAutoTripIdPrefix(evt.target.value)
const handleBlockPrefixUpdate = (evt: SyntheticInputEvent<HTMLInputElement>) => setAutoBlockIdPrefix(evt.target.value)
const handleTripIncrementUpdate = (evt: SyntheticInputEvent<HTMLInputElement>) => setAutoTripIdIncrement(+evt.target.value)
const handleCheckBox = () => setUseAutoTripIds(!useAutoTripIds)
const handleBlockIncrementUpdate = (evt: SyntheticInputEvent<HTMLInputElement>) => setAutoBlockIdIncrement(+evt.target.value)
const handleAutoTripIDCheckBox = () => setUseAutoTripIds(!useAutoTripIds)
const handleAutoBlockIDCheckBox = () => setUseAutoBlockIds(!useAutoBlockIds)

const onClickGenerate = useCallback(() => {
const {addNewTrip, constructNewRow, onClose} = props
Expand All @@ -39,16 +51,25 @@ const TripSeriesModal = (props: Props) => {
const adjustedEndTime = startTime < endTime ? endTime : endTime + 24 * 60 * 60

let tripId = autoTripIdStart
let currentBlockIdSuffix = 1
for (let time = startTime; time <= adjustedEndTime; time += headway) {
const autoTripId = useAutoTripIds ? `${autoTripIdPrefix}-${tripId}` : null
const autoBlockId = useAutoBlockIds ? `${autoBlockIdPrefix}-${currentBlockIdSuffix}` : null
addNewTrip(constructNewRow(null, time, autoTripId, autoBlockId))
// If we're upating the trip IDs automatically, increment the trip ID:
addNewTrip(constructNewRow(null, time, useAutoTripIds ? `${autoTripIdPrefix}-${tripId}` : null))
if (useAutoTripIds) tripId += autoTripIdIncrement
// If we're updating the Block IDs automatically, alternate according to input number
if (useAutoBlockIds) {
currentBlockIdSuffix += 1
// If we increase past the alternating number, use the modulus to reset
if (currentBlockIdSuffix > autoBlockIdIncrement) currentBlockIdSuffix = currentBlockIdSuffix % autoBlockIdIncrement
}
}
setStartTime(null)
setEndTime(null)
setHeadway(null)
onClose()
}, [endTime, startTime, headway, autoTripIdStart, autoTripIdIncrement, autoTripIdPrefix])
}, [endTime, startTime, headway, autoTripIdStart, autoTripIdIncrement, autoTripIdPrefix, autoBlockIdPrefix, autoBlockIdIncrement])

const {Body, Footer, Header, Title} = Modal
const {onClose, show, useSecondsInOffset} = props
Expand All @@ -75,38 +96,64 @@ const TripSeriesModal = (props: Props) => {
<HourMinuteInput onChange={setEndTime} seconds={endTime} showSeconds={useSecondsInOffset} standaloneInput />
</div>
</div>
<hr />
<div>
<Checkbox checked={useAutoTripIds} onChange={handleAutoTripIDCheckBox}>{messages('automaticallyUpdateTripIds')}</Checkbox>
{useAutoTripIds &&
<>
<div style={{alignItems: 'center', display: 'flex'}}>
<>
<FormControl
onChange={handleTripPrefixUpdate}
placeholder={messages('prefixPlaceholder')}
style={{width: '30%', marginRight: '5px'}}
type='text'
/>
-
<FormControl
onChange={handleIncrementStartUpdate}
placeholder={messages('incrementStartPlaceholder')}
style={{width: '40%', marginLeft: '5px', marginRight: '5px'}}
type='number'
/>
{messages('incrementBy')}
<FormControl
onChange={handleTripIncrementUpdate}
placeholder={messages('incrementAmountPlaceholder')}
style={{width: '15%', marginLeft: '5px'}}
type='number'
value={autoTripIdIncrement}
/>
</>
</div>
<hr />
</>
}
</div>
<div>
<Checkbox checked={useAutoTripIds} onChange={handleCheckBox}>{messages('automaticallyUpdateTripIds')}</Checkbox>
<div style={{
alignItems: 'center',
display: 'flex'
}}>
{useAutoTripIds &&
<>
<Checkbox checked={useAutoBlockIds} onChange={handleAutoBlockIDCheckBox}>{messages('automaticallyUpdateBlockIds')} </Checkbox>
{useAutoBlockIds &&
<>
<div style={{alignItems: 'center', display: 'flex'}}>
<FormControl
onChange={handleTripPrefixUpdate}
placeholder={messages('prefixPlaceholder')}
onChange={handleBlockPrefixUpdate}
placeholder={messages('blockIdPrefixPlaceholder')}
style={{width: '30%', marginRight: '5px'}}
type='text'
value={autoBlockIdPrefix} // Remove me??
/>
-
<FormControl
onChange={handleIncrementStartUpdate}
placeholder={messages('incrementStartPlaceholder')}
style={{width: '40%', marginLeft: '5px', marginRight: '5px'}}
type='number'
/>
{messages('incrementBy')}
{messages('alternateEvery')}
<FormControl
onChange={handleTripIncrementUpdate}
placeholder={messages('incrementAmountPlaceholder')}
onChange={handleBlockIncrementUpdate}
placeholder={messages('blockIncrementPlaceholder')}
style={{width: '15%', marginLeft: '5px'}}
type='number'
value={autoTripIdIncrement}
value={autoBlockIdIncrement}
/>
</>
}
</div>
</div>
<span style={{fontSize: 'smaller'}}>{messages('formatExplanation')}</span>
</>
}
</div>

</Body>
Expand Down

0 comments on commit 8f0965a

Please sign in to comment.