Skip to content

Commit

Permalink
Merge pull request #451 from opentripplanner/dev
Browse files Browse the repository at this point in the history
Patch Release: September 8, 2021
  • Loading branch information
landonreed authored Sep 8, 2021
2 parents c37ac4d + bdd8951 commit 1d881bd
Show file tree
Hide file tree
Showing 14 changed files with 107 additions and 88 deletions.
4 changes: 4 additions & 0 deletions example-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ api:
persistence:
enabled: true
strategy: localStorage
### This variable hides the "more info" link when accepting the terms of storage.
### If no terms of storage page content is set, this removes an otherwise dead link
### False is default in that if the value isn't set, the link isn't shown
# terms_of_storage: true

### If using the OTP Middleware to store user profiles
### with Auth0 as the authentication mechanism,
Expand Down
40 changes: 27 additions & 13 deletions lib/actions/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -723,18 +723,7 @@ function createQueryAction (endpoint, responseAction, errorAction, options = {})
return async function (dispatch, getState) {
const state = getState()
const { config } = state.otp
let url
if (
options.serviceId &&
config.alternateTransitIndex &&
config.alternateTransitIndex.services.includes(options.serviceId)
) {
console.log('Using alt service for ' + options.serviceId)
url = config.alternateTransitIndex.apiRoot + endpoint
} else {
const api = config.api
url = `${api.host}${api.port ? ':' + api.port : ''}${api.path}/${endpoint}`
}
const url = makeApiUrl(config, endpoint, options)

if (!options.noThrottle) {
// don't make a request to a URL that has already seen the same request
Expand All @@ -750,9 +739,10 @@ function createQueryAction (endpoint, responseAction, errorAction, options = {})
throttledUrls[throttleKey] = now()
}
}

let payload
try {
const response = await fetch(url, options.fetchOptions)
const response = await fetch(url, getOtpFetchOptions(state))
if (response.status >= 400) {
const error = new Error('Received error from server')
error.response = response
Expand All @@ -775,6 +765,30 @@ function createQueryAction (endpoint, responseAction, errorAction, options = {})
}
}

/**
* Creates the URL to use for making an API request.
*
* @param {Object} config The app-wide config
* @param {string} endpoint The API endpoint path
* @param {Object} options The options object for the API request
* @return {string} The URL to use for making the http request
*/
function makeApiUrl (config, endpoint, options) {
let url
if (
options.serviceId &&
config.alternateTransitIndex &&
config.alternateTransitIndex.services.includes(options.serviceId)
) {
console.log('Using alt service for ' + options.serviceId)
url = config.alternateTransitIndex.apiRoot + endpoint
} else {
const api = config.api
url = `${api.host}${api.port ? ':' + api.port : ''}${api.path}/${endpoint}`
}
return url
}

// TODO: Determine how we might be able to use GraphQL with the alternative
// transit index. Currently this is not easily possible because the alternative
// transit index does not have support for GraphQL and handling both Rest and
Expand Down
11 changes: 11 additions & 0 deletions lib/components/admin/call-taker.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,14 @@
.otp .advanced-search-options {
box-shadow: 0px 5px 3px 0px rgba(0,0,0,0.32157);
}

.otp .search-options {
display: flex;
justify-content: space-between;
flex-flow: row wrap;
}

.otp .search-options > * {
margin-bottom: 5px;
height: 24px;
}
9 changes: 3 additions & 6 deletions lib/components/admin/field-trip-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Loading from '../narrative/loading'
import {getVisibleRequests, TABS} from '../../util/call-taker'
import {FETCH_STATUS} from '../../util/constants'

import FieldTripStatusIcon from './field-trip-status-icon'
import {FieldTripRecordButton, WindowHeader} from './styled'
import DraggableWindow from './draggable-window'

Expand Down Expand Up @@ -186,10 +187,6 @@ class FieldTripRequestRecord extends Component {
onClick(request)
}

_getStatusIcon = (status) => status
? <Icon className='text-success' type='check' />
: <Icon className='text-warning' type='exclamation-circle' />

render () {
const {active, request} = this.props
const style = {
Expand Down Expand Up @@ -223,10 +220,10 @@ class FieldTripRequestRecord extends Component {
</span>
<span style={{display: 'inline-block', width: '50%'}}>
<span style={{marginLeft: '10px'}}>
{this._getStatusIcon(inboundTripStatus)} Inbound
<FieldTripStatusIcon ok={Boolean(outboundTripStatus)} /> Outbound
</span>
<span style={{marginLeft: '10px'}}>
{this._getStatusIcon(outboundTripStatus)} Outbound
<FieldTripStatusIcon ok={Boolean(inboundTripStatus)} /> Inbound
</span>
</span>
<span style={{display: 'block', fontSize: '.9em'}}>
Expand Down
11 changes: 11 additions & 0 deletions lib/components/admin/field-trip-status-icon.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React from 'react'

import Icon from '../narrative/icon'

const FieldTripStatusIcon = ({ ok }) => (
ok
? <Icon className='text-success' type='check' />
: <Icon className='text-warning' type='exclamation-circle' />
)

export default FieldTripStatusIcon
12 changes: 5 additions & 7 deletions lib/components/admin/trip-status.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import { connect } from 'react-redux'

import * as fieldTripActions from '../../actions/field-trip'
import * as formActions from '../../actions/form'
import Icon from '../narrative/icon'
import { getTripFromRequest } from '../../util/call-taker'

import FieldTripStatusIcon from './field-trip-status-icon'
import {
Bold,
Button,
Expand Down Expand Up @@ -47,13 +47,11 @@ class TripStatus extends Component {
viewRequestTripItineraries(request, outbound)
}

_renderStatusIcon = () => this.props.status
? <Icon className='text-success' type='check' />
: <Icon className='text-warning' type='exclamation-circle' />
_tripIsPlanned = () => Boolean(this.props.status && this.props.trip)

_renderTripStatus = () => {
const { status, trip } = this.props
if (!status || !trip) {
const { trip } = this.props
if (!this._tripIsPlanned()) {
return (
<Para>
No itineraries planned! Click Plan to plan trip.
Expand Down Expand Up @@ -92,7 +90,7 @@ class TripStatus extends Component {
return (
<Full>
<Header>
{this._renderStatusIcon()}
<FieldTripStatusIcon ok={this._tripIsPlanned()} />
{outbound ? 'Outbound' : 'Inbound'} trip
<Button bsSize='xs' onClick={this._onPlanTrip}>Plan</Button>
<Button
Expand Down
8 changes: 3 additions & 5 deletions lib/components/app/call-taker-panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ class CallTakerPanel extends Component {
onClick={this._addPlace}
to={to}
/>
<div className='search-options' style={{height: '30px'}}>
<div className='search-options'>
<DateTimeOptions
date={date}
departArrive={departArrive}
Expand All @@ -208,9 +208,7 @@ class CallTakerPanel extends Component {
onClick={this._planTrip}
style={{
fontSize: '13px',
padding: '0px 10px',
position: 'absolute',
right: '6px'
padding: '1px 10px'
}} >
Plan
</Button>
Expand Down Expand Up @@ -261,7 +259,7 @@ class CallTakerPanel extends Component {
right: '0',
// FIXME: This top pixel value can be variable dependent on
// height of the form above. It may need to be specified differently
top: 193 + intermediatePlaces.length * 45
top: 210 + intermediatePlaces.length * 45
}}
/>
</div>
Expand Down
51 changes: 22 additions & 29 deletions lib/components/form/call-taker/date-time-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,44 +186,37 @@ export default class DateTimeOptions extends Component {
onKeyDown={onKeyDown}
value={departArrive}
>
{departureOptions.map(o => (
<option key={o.value} {...o} />
))}
{departureOptions.map(o => <option key={o.value} {...o} />)}
</select>
<span style={{display: 'inline-flex'}}>
<OverlayTrigger
overlay={<Tooltip id='time-tooltip'>{cleanTime}</Tooltip>}
placement='bottom'
trigger={['focus', 'hover']}
>
<input
className='datetime-slim'
onChange={this.handleTimeChange}
onFocus={this.handleTimeFocus}
onKeyDown={onKeyDown}
style={{
fontSize: 'inherit',
lineHeight: '.8em',
marginLeft: '3px',
padding: '0px',
width: '50px'
}}
value={timeInput || dateTime.format('H:mm')}
/>
</OverlayTrigger>
</span>
<OverlayTrigger
overlay={<Tooltip id='time-tooltip'>{cleanTime}</Tooltip>}
placement='bottom'
trigger={['focus', 'hover']}
>
<input
className='datetime-slim'
onChange={this.handleTimeChange}
onFocus={this.handleTimeFocus}
onKeyDown={onKeyDown}
style={{
fontSize: 'inherit',
lineHeight: '.8em',
marginLeft: '3px',
padding: '0px',
width: '50px'
}}
value={timeInput || dateTime.format('H:mm')}
/>
</OverlayTrigger>
<input
className='datetime-slim'
onChange={this.handleDateChange}
onKeyDown={onKeyDown}
style={{
border: 'none',
fontSize: '14px',
left: '146px',
lineHeight: '1em',
outline: 'none',
position: 'absolute',
width: '101px'
width: '109px'
}}
type='date'
value={dateTime.format('YYYY-MM-DD')}
Expand Down
1 change: 0 additions & 1 deletion lib/components/form/call-taker/mode-dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ export default class ModeDropdown extends Component {
onBlur={this._setMode}
onChange={this._onChange}
onKeyDown={onKeyDown}
style={{position: 'absolute', right: '60px'}}
value={this.modeToOptionValue(mode)}
>
{this._getModeOptions().map(o => (
Expand Down
10 changes: 6 additions & 4 deletions lib/components/narrative/default/default-itinerary.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ import FieldTripGroupSize from '../../admin/field-trip-itinerary-group-size'
import NarrativeItinerary from '../narrative-itinerary'
import ItineraryBody from '../line-itin/connected-itinerary-body'
import SimpleRealtimeAnnotation from '../simple-realtime-annotation'
import { getTotalFare } from '../../../util/state'

import ItinerarySummary from './itinerary-summary'

const { calculateFares, isBicycle, isMicromobility, isTransit } = coreUtils.itinerary
const { isBicycle, isMicromobility, isTransit } = coreUtils.itinerary

/**
* Obtains the description of an itinerary in the given locale.
Expand Down Expand Up @@ -125,14 +126,12 @@ const ITINERARY_ATTRIBUTES = [
id: 'cost',
order: 2,
render: (itinerary, options) => {
// Get unformatted transit fare portion only (in cents).
const { transitFare } = calculateFares(itinerary)
return (
<FormattedNumber
currency={options.currency}
currencyDisplay='narrowSymbol'
style='currency'
value={transitFare / 100}
value={getTotalFare(itinerary, options.configCosts) / 100}
/>
)
}
Expand Down Expand Up @@ -194,6 +193,7 @@ class DefaultItinerary extends NarrativeItinerary {
render () {
const {
active,
configCosts,
currency,
expanded,
itinerary,
Expand Down Expand Up @@ -246,6 +246,7 @@ class DefaultItinerary extends NarrativeItinerary {
}
options.LegIcon = LegIcon
options.timeFormat = use24HourFormat ? 'H:mm' : 'h:mm a'
options.configCosts = configCosts
options.currency = currency
return (
<li className={`${attribute.id}${isSelected ? ' main' : ''}`} key={attribute.id}>
Expand Down Expand Up @@ -276,6 +277,7 @@ class DefaultItinerary extends NarrativeItinerary {

const mapStateToProps = (state, ownProps) => {
return {
configCosts: state.otp.config.itinerary?.costs,
// The configured (ambient) currency is needed for rendering the cost
// of itineraries whether they include a fare or not, in which case
// we show $0.00 or its equivalent in the configured currency and selected locale.
Expand Down
2 changes: 1 addition & 1 deletion lib/components/narrative/narrative-itineraries-header.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export default function NarrativeItinerariesHeader ({
<select
onBlur={onSortChange}
onChange={onSortChange}
value={sort.value}
value={sort.type}
>
<option value='BEST'>Best option</option>
<option value='DURATION'>Duration</option>
Expand Down
12 changes: 9 additions & 3 deletions lib/components/user/terms-of-use-pane.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react'
import { connect } from 'react-redux'
import { Checkbox, ControlLabel, FormGroup } from 'react-bootstrap'

import { TERMS_OF_SERVICE_PATH, TERMS_OF_STORAGE_PATH } from '../../util/constants'
Expand All @@ -10,6 +11,7 @@ const TermsOfUsePane = ({
disableCheckTerms,
handleBlur,
handleChange,
termsOfStorageSet,
values: userData
}) => {
const {
Expand Down Expand Up @@ -46,11 +48,15 @@ const TermsOfUsePane = ({
>
{/* TODO: Implement the link */}
Optional: I consent to the Trip Planner storing my historical planned trips in order to
improve transit services in my area. <a href={`/#${TERMS_OF_STORAGE_PATH}`} target='_blank'>More info...</a>
improve transit services in my area. {termsOfStorageSet && <a href={`/#${TERMS_OF_STORAGE_PATH}`} target='_blank'>More info...</a>}
</Checkbox>
</FormGroup>
</div>
)
}

export default TermsOfUsePane
const mapStateToProps = (state) => {
return {
termsOfStorageSet: state.otp.config.persistence?.terms_of_storage
}
}
export default connect(mapStateToProps)(TermsOfUsePane)
7 changes: 0 additions & 7 deletions lib/util/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,6 @@ export const accountLinks = [
{
text: 'My account',
url: ACCOUNT_PATH
},
{
// Add a target attribute if you need the link to open in a new window, etc.
// (supports the same values as <a target=... >).
// target: '_blank',
text: 'Help',
url: '/help'
}
]

Expand Down
Loading

0 comments on commit 1d881bd

Please sign in to comment.