Skip to content

Commit 3ec6764

Browse files
authored
Merge pull request #92 from opentripplanner/dev
Patch release
2 parents 1998f84 + 9a8b15e commit 3ec6764

File tree

5 files changed

+66
-43
lines changed

5 files changed

+66
-43
lines changed

Diff for: lib/actions/api.js

+24-22
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { rememberPlace } from './map'
1010
import { hasCar } from '../util/itinerary'
1111
import { getTripOptionsFromQuery, getUrlParams } from '../util/query'
1212
import queryParams from '../util/query-params'
13-
import { queryIsValid } from '../util/state'
13+
import { getStopViewerConfig, queryIsValid } from '../util/state'
1414
import { randId } from '../util/storage'
1515
if (typeof (fetch) === 'undefined') require('isomorphic-fetch')
1616

@@ -288,9 +288,6 @@ export function vehicleRentalQuery (params) {
288288
}
289289

290290
// Single stop lookup query
291-
292-
// Stop times for stop query
293-
// TODO: make timeRange and numberOfDepartures configurable
294291
const findStopResponse = createAction('FIND_STOP_RESPONSE')
295292
const findStopError = createAction('FIND_STOP_ERROR')
296293

@@ -303,7 +300,7 @@ export function findStop (params) {
303300
serviceId: 'stops',
304301
postprocess: (payload, dispatch) => {
305302
dispatch(findRoutesAtStop(params.stopId))
306-
dispatch(findStopTimesForStop({ stopId: params.stopId }))
303+
dispatch(findStopTimesForStop(params))
307304
},
308305
noThrottle: true
309306
}
@@ -468,27 +465,32 @@ export function findGeometryForTrip (params) {
468465
)
469466
}
470467

471-
// Stop times for stop query
472-
// TODO: make timeRange and numberOfDepartures configurable
473-
474468
const findStopTimesForStopResponse = createAction('FIND_STOP_TIMES_FOR_STOP_RESPONSE')
475469
const findStopTimesForStopError = createAction('FIND_STOP_TIMES_FOR_STOP_ERROR')
476470

471+
/**
472+
* Stop times for stop query (used in stop viewer).
473+
*/
477474
export function findStopTimesForStop (params) {
478-
return createQueryAction(
479-
`index/stops/${params.stopId}/stoptimes?timeRange=345600&numberOfDepartures=5`,
480-
findStopTimesForStopResponse,
481-
findStopTimesForStopError,
482-
{
483-
rewritePayload: (payload) => {
484-
return {
485-
stopId: params.stopId,
486-
stopTimes: payload
487-
}
488-
},
489-
noThrottle: true
490-
}
491-
)
475+
return function (dispatch, getState) {
476+
let { stopId, ...otherParams } = params
477+
// If other params not provided, fall back on defaults from stop viewer config.
478+
const queryParams = { ...getStopViewerConfig(getState().otp), ...otherParams }
479+
dispatch(createQueryAction(
480+
`index/stops/${stopId}/stoptimes?${qs.stringify(queryParams)}`,
481+
findStopTimesForStopResponse,
482+
findStopTimesForStopError,
483+
{
484+
rewritePayload: (stopTimes) => {
485+
return {
486+
stopId,
487+
stopTimes
488+
}
489+
},
490+
noThrottle: true
491+
}
492+
))
493+
}
492494
}
493495

494496
// Routes lookup query

Diff for: lib/components/map/vehicle-rental-overlay.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ class VehicleRentalOverlay extends MapLayer {
3232
}
3333

3434
componentDidMount () {
35-
if (this.props.visible) this._startRefreshing()
35+
const {companies, mapSymbols, name, visible} = this.props
36+
if (visible) this._startRefreshing()
37+
if (!mapSymbols) console.warn(`No map symbols provided for layer ${name}`, companies)
3638
}
3739

3840
componentWillUnmount () {
@@ -214,8 +216,7 @@ class VehicleRentalOverlay extends MapLayer {
214216
}
215217

216218
render () {
217-
const { mapSymbols, stations, companies } = this.props
218-
if (!mapSymbols) console.warn(`No map symbols provided for layer ${this.props.name}`, companies)
219+
const { stations, companies } = this.props
219220
let filteredStations = stations
220221
if (companies) {
221222
filteredStations = stations.filter(

Diff for: lib/components/viewers/stop-viewer.js

+26-17
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { setMainPanelContent, toggleAutoRefresh } from '../../actions/ui'
1313
import { findStop, findStopTimesForStop } from '../../actions/api'
1414
import { forgetStop, rememberStop, setLocation } from '../../actions/map'
1515
import { routeComparator } from '../../util/itinerary'
16-
import { getShowUserSettings } from '../../util/state'
16+
import { getShowUserSettings, getStopViewerConfig } from '../../util/state'
1717
import { formatDuration, formatStopTime, getTimeFormat } from '../../util/time'
1818

1919
class StopViewer extends Component {
@@ -116,6 +116,7 @@ class StopViewer extends Component {
116116
showUserSettings,
117117
stopData,
118118
stopViewerArriving,
119+
stopViewerConfig,
119120
timeFormat
120121
} = this.props
121122
const { spin } = this.state
@@ -237,6 +238,7 @@ class StopViewer extends Component {
237238
pattern={patternTimes.pattern}
238239
route={patternTimes.route}
239240
stopTimes={patternTimes.times}
241+
stopViewerConfig={stopViewerConfig}
240242
key={patternTimes.id}
241243
stopViewerArriving={stopViewerArriving}
242244
homeTimezone={homeTimezone}
@@ -282,23 +284,28 @@ class PatternRow extends Component {
282284
stopTimes,
283285
homeTimezone,
284286
stopViewerArriving,
287+
stopViewerConfig,
285288
timeFormat
286289
} = this.props
287290
// sort stop times by next departure
288-
let sortedStopTimes = null
289-
if (stopTimes) {
290-
sortedStopTimes = stopTimes.sort((a, b) => {
291-
const aTime = a.serviceDay + a.realtimeDeparture
292-
const bTime = b.serviceDay + b.realtimeDeparture
293-
return aTime - bTime
294-
})
295-
// Cap the number of times shown for any Route at 5. TODO: make configurable
296-
if (sortedStopTimes.length > 0) sortedStopTimes = sortedStopTimes.slice(0, 5)
297-
// Do not show any patterns with no departures happening soon.
298-
const timeIsOverThreshold = sortedStopTimes[0].realtimeDeparture - getHomeTime(homeTimezone) > ONE_HOUR_IN_SECONDS * 3
299-
if (sortedStopTimes[0] && timeIsOverThreshold) {
300-
return null
301-
}
291+
let sortedStopTimes = []
292+
const hasStopTimes = stopTimes && stopTimes.length > 0
293+
if (hasStopTimes) {
294+
sortedStopTimes = stopTimes
295+
.concat()
296+
.sort((a, b) => {
297+
const aTime = a.serviceDay + a.realtimeDeparture
298+
const bTime = b.serviceDay + b.realtimeDeparture
299+
return aTime - bTime
300+
})
301+
// We request only x departures per pattern, but the patterns are merged
302+
// according to shared headsigns, so we need to slice the stop times
303+
// here as well to ensure only x times are shown per route/headsign combo.
304+
// This is applied after the sort, so we're keeping the soonest departures.
305+
.slice(0, stopViewerConfig.numberOfDepartures)
306+
} else {
307+
// Do not include pattern row if it has no stop times.
308+
return null
302309
}
303310
const routeName = route.shortName ? route.shortName : route.longName
304311

@@ -314,7 +321,7 @@ class PatternRow extends Component {
314321
</div>
315322

316323
{/* next departure preview */}
317-
{stopTimes && stopTimes.length > 0 && (
324+
{hasStopTimes && (
318325
<div className='next-trip-preview'>
319326
{getFormattedStopTime(sortedStopTimes[0], homeTimezone, stopViewerArriving, timeFormat)}
320327
</div>
@@ -343,7 +350,7 @@ class PatternRow extends Component {
343350
</div>
344351

345352
{/* list of upcoming trips */}
346-
{stopTimes && (
353+
{hasStopTimes && (
347354
sortedStopTimes.map((stopTime, i) => {
348355
return (
349356
<div
@@ -485,6 +492,7 @@ function getStatusLabel (delay) {
485492

486493
const mapStateToProps = (state, ownProps) => {
487494
const showUserSettings = getShowUserSettings(state.otp)
495+
const stopViewerConfig = getStopViewerConfig(state.otp)
488496
return {
489497
autoRefreshStopTimes: state.otp.user.autoRefreshStopTimes,
490498
favoriteStops: state.otp.user.favoriteStops,
@@ -493,6 +501,7 @@ const mapStateToProps = (state, ownProps) => {
493501
showUserSettings,
494502
stopData: state.otp.transitIndex.stops[state.otp.ui.viewedStop.stopId],
495503
stopViewerArriving: state.otp.config.language.stopViewerArriving,
504+
stopViewerConfig,
496505
timeFormat: getTimeFormat(state.otp.config)
497506
}
498507
}

Diff for: lib/reducers/create-otp-reducer.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,14 @@ const defaultConfig = {
2020
language: {},
2121
operators: [],
2222
realtimeEffectsDisplayThreshold: 120,
23-
routingTypes: []
23+
routingTypes: [],
24+
stopViewer: {
25+
numberOfDepartures: 3, // per pattern
26+
// This is set to 345600 (four days) so that, for example, if it is Friday and
27+
// a route does not begin service again until Monday, we are showing its next
28+
// departure and it is not entirely excluded from display.
29+
timeRange: 345600 // four days in seconds
30+
}
2431
}
2532

2633
// Load user settings from local storage.

Diff for: lib/util/state.js

+4
Original file line numberDiff line numberDiff line change
@@ -172,3 +172,7 @@ export function getRealtimeEffects (otpState) {
172172
export function getShowUserSettings (otpState) {
173173
return otpState.config.persistence && otpState.config.persistence.enabled
174174
}
175+
176+
export function getStopViewerConfig (otpState) {
177+
return otpState.config.stopViewer
178+
}

0 commit comments

Comments
 (0)