Skip to content

Commit

Permalink
fix(editor): fix view all route alignments on editor map
Browse files Browse the repository at this point in the history
fixes #76
  • Loading branch information
landonreed committed Apr 29, 2018
1 parent a139d52 commit e98debf
Show file tree
Hide file tree
Showing 7 changed files with 137 additions and 129 deletions.
44 changes: 21 additions & 23 deletions lib/editor/actions/active.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,28 @@ export function updateEditSetting (setting, value, activePattern) {
}
}

export function updateActiveGtfsEntity (entity, component, props) {
return {
type: 'UPDATE_ACTIVE_GTFS_ENTITY',
entity,
component,
props
}
}

export function resetActiveGtfsEntity (entity, component) {
return {
type: 'RESET_ACTIVE_GTFS_ENTITY',
entity,
component
}
}

export const clearGtfsContent = createAction('CLEAR_GTFSEDITOR_CONTENT')
export const savedGtfsEntity = createAction('SAVED_GTFS_ENTITY')
export const deletingEntity = createAction('DELETING_ENTITY')
const settingActiveGtfsEntity = createAction('SETTING_ACTIVE_GTFS_ENTITY')
export const savingActiveGtfsEntity = createAction('SAVING_ACTIVE_GTFS_ENTITY')

export function enterTimetableEditor () {
return function (dispatch, getState) {
Expand Down Expand Up @@ -96,8 +115,8 @@ export function setActiveGtfsEntity (feedSourceId, component, entityId, subCompo
const activeEntity = component === 'feedinfo'
? clone(activeTable)[0]
: activeTable && entityId
? clone(activeTable.find(e => e.id === entityId))
: null
? clone(activeTable.find(e => e.id === entityId))
: null
const activeSubEntity = activeEntity && activeEntity.tripPatterns
? clone(activeEntity.tripPatterns.find(p => p.id === subEntityId))
: null
Expand Down Expand Up @@ -156,8 +175,6 @@ function constructEditorURL (feedSourceId, component, entityId, subComponent, su
return url
}

export const savingActiveGtfsEntity = createAction('SAVING_ACTIVE_GTFS_ENTITY')

export function saveActiveGtfsEntity (component, optionalEntity, refetch = true) {
return function (dispatch, getState) {
const {active} = getState().editor.data
Expand Down Expand Up @@ -224,8 +241,6 @@ export function saveEntity (feedId, entity, component, refetch = true) {
}
}

export const deletingEntity = createAction('DELETING_ENTITY')

/**
* Generic delete function for editor GTFS entities.
*/
Expand Down Expand Up @@ -259,20 +274,3 @@ export function deleteGtfsEntity (feedId, component, entityId, routeId) {
})
}
}

export function updateActiveGtfsEntity (entity, component, props) {
return {
type: 'UPDATE_ACTIVE_GTFS_ENTITY',
entity,
component,
props
}
}

export function resetActiveGtfsEntity (entity, component) {
return {
type: 'RESET_ACTIVE_GTFS_ENTITY',
entity,
component
}
}
22 changes: 6 additions & 16 deletions lib/editor/actions/tripPattern.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ import {savedGtfsEntity, updateEditSetting} from './active'
import {entityIsNew} from '../util/objects'
import {getEditorNamespace} from '../util/gtfs'

// TRIP PATTERNS

const requestingTripPatterns = createAction('REQUESTING_TRIP_PATTERNS')
const receiveTripPatterns = createAction('RECEIVE_TRIP_PATTERNS')
export const undoActiveTripPatternEdits = createAction('UNDO_TRIP_PATTERN_EDITS')
export const setActiveStop = createAction('SET_ACTIVE_PATTERN_STOP')
export const togglingPatternEditing = createAction('TOGGLE_PATTERN_EDITING')
Expand All @@ -25,20 +21,14 @@ export function togglePatternEditing () {
}
}

/**
* Fetch all trip patterns for the feed. Used to display pattern shapes in map
* layer.
*/
export function fetchTripPatterns (feedId) {
return function (dispatch, getState) {
dispatch(requestingTripPatterns(feedId))
const {sessionId} = getState().editor.data.lock
const url = `/api/editor/secure/pattern?feedId=${feedId}&sessionId=${sessionId}`
return dispatch(secureFetch(url))
.then(res => {
if (res.status >= 400) return []
return res.json()
})
.then(tripPatterns => {
dispatch(receiveTripPatterns({feedId, tripPatterns}))
return tripPatterns
})
const namespace = getEditorNamespace(feedId, getState())
return dispatch(fetchGTFSEntities({namespace, type: 'pattern', editor: true}))
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/editor/components/map/EditorMapLayersControl.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default class EditorMapLayersControl extends Component {
weight={2}
color='#888'>
<Tooltip sticky>
<span>{tp.name}</span>
<span>{tp.name} ({tp.route_id})</span>
</Tooltip>
</Polyline>
)
Expand Down
37 changes: 23 additions & 14 deletions lib/editor/reducers/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,20 +222,6 @@ const data = (state = defaultState, action) => {
})
}
return state
// Handle trip patterns to be drawn as overlay layer in editor
case 'RECEIVE_TRIP_PATTERNS':
return update(state, {
tripPatterns: {$set:
// FIXME: Update for new trip pattern data structure
action.payload.tripPatterns.map(pattern => {
return {
id: pattern.id,
name: pattern.name,
latLngs: pattern.shape ? (pattern.shape.coordinates.map(c => ll.fromCoordinates(c))) : null
}
})
}
})
case 'DELETING_STOP':
stopIndex = stops.findIndex(s => s.id === action.stop.id)
return update(state, {
Expand All @@ -251,6 +237,29 @@ const data = (state = defaultState, action) => {
// for viewing validation result details).
return state
}
if (component === 'pattern') {
// Handle trip patterns to be drawn as overlay layer in editor
console.log('setting trip patterns', data)
return update(state, {
tripPatterns: {$set:
// FIXME: Update for new trip pattern data structure
data.feed.patterns.map(pattern => {
return {
id: pattern.id,
name: pattern.name,
route_id: pattern.route_id,
latLngs: pattern.shape_points
? (pattern.shape_points.map(sp =>
({
lon: sp.shape_pt_lon,
lat: sp.shape_pt_lat
})))
: null
}
})
}
})
}
const tableName = getKeyForId(component, 'tableName')
// get entities from payload
const mappingStrategy = getMapToGtfsStrategy(component)
Expand Down
6 changes: 3 additions & 3 deletions lib/editor/util/gtfs.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export const COMPONENT_LIST = [
export function getTableById (tableData: any, id: string, emptyArrayOnNull: boolean = true): any {
const tableName = getKeyForId(id, 'tableName')
if (!tableName) {
console.error(`Component ${id} not found in list of tables.`)
console.warn(`Component ${id} not found in list of tables.`)
return null
}
const table = tableData[tableName]
Expand Down Expand Up @@ -315,8 +315,8 @@ export function getAbbreviatedStopName (stop: GtfsStop, maxCharactersPerWord: nu
stopNameParts.length === 3 &&
stop.stop_name.length > maxCharactersPerWord * 2
? `${stopNameParts[0]
.substr(0, maxCharactersPerWord)
.trim()}... ${stopNameParts[2].substr(0, maxCharactersPerWord).trim()}`
.substr(0, maxCharactersPerWord)
.trim()}... ${stopNameParts[2].substr(0, maxCharactersPerWord).trim()}`
: stop.stop_name
}

Expand Down
152 changes: 82 additions & 70 deletions lib/gtfs/util/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,77 +40,89 @@ export function getGraphQLFieldsForEntity (type: string, editor: boolean = false
const entityTableString = getEntityTableString(type)
const table = getGtfsSpec().find(table => table.id === entityTableString)
let fields = ''
if (table) {
fields = table.fields
// Only filter required fields if not fetching for editor
// FIXME: This fetches only the required fields for feed info because there
// are missing fields in the GraphQL schema and database (default color and
// default route type).
.filter(field => type === 'feedinfo' ? !field.datatools : editor ? field : field.required && !field.datatools)
.map(field => field.name)
.join('\n')
// stop_times are a special case because they must be requested as a
// nested list underneath a trip
// console.log(type)
switch (type.toLowerCase()) {
case 'stoptime':
return `
trip_id
stop_times {
${fields}
}
`
case 'fare':
// console.log('getting fare fields')
return `
${fields}
fare_rules (limit: -1) {
id
fare_id
route_id
origin_id
destination_id
contains_id
}
`
case 'route':
return `
if (!table) {
console.warn(`Could not find table fare entity ${type}`)
}
fields = table
? table.fields
// Only filter required fields if not fetching for editor
// FIXME: This fetches only the required fields for feed info because there
// are missing fields in the GraphQL schema and database (default color and
// default route type).
.filter(field => type === 'feedinfo' ? !field.datatools : editor ? field : field.required && !field.datatools)
.map(field => field.name)
.join('\n')
: ''
// stop_times are a special case because they must be requested as a
// nested list underneath a trip
console.log(type)
const shapeFields = `shape_points: shape (limit: -1) {
shape_pt_lon
shape_pt_lat
shape_pt_sequence
point_type
shape_dist_traveled
}`
const patternStopFields = `pattern_stops (limit: -1) {
id
stop_id
default_travel_time
default_dwell_time
stop_sequence
shape_dist_traveled
pickup_type
drop_off_type
timepoint
}`
switch (type.toLowerCase()) {
case 'stoptime':
return `
trip_id
stop_times {
${fields}
tripPatterns: patterns (limit: -1) {
id
shape_id
pattern_id
trip_count
route_id
direction_id
use_frequency
name
pattern_stops (limit: -1) {
id
stop_id
default_travel_time
default_dwell_time
stop_sequence
shape_dist_traveled
pickup_type
drop_off_type
timepoint
}
shape_points: shape (limit: -1) {
shape_pt_lon
shape_pt_lat
shape_pt_sequence
point_type
shape_dist_traveled
}
}
`
default:
return fields
}
} else {
console.error(`Could not find table fare entity ${type}`)
return ''
}
`
case 'fare':
// console.log('getting fare fields')
return `
${fields}
fare_rules (limit: -1) {
id
fare_id
route_id
origin_id
destination_id
contains_id
}
`
case 'pattern':
return `
shape_id
pattern_id
route_id
direction_id
use_frequency
name
${shapeFields}
`
case 'route':
return `
${fields}
tripPatterns: patterns (limit: -1) {
id
shape_id
pattern_id
trip_count
route_id
direction_id
use_frequency
name
${patternStopFields}
${shapeFields}
}
`
default:
return fields
}
}

Expand Down
3 changes: 1 addition & 2 deletions lib/manager/actions/versions.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,7 @@ export function fetchGTFSEntities ({namespace, id, type, editor = false, replace
const idFieldType = editor ? 'Int' : '[String]'
const graphQLRoot = getEntityGraphQLRoot(type)
if (!graphQLRoot || !entityIdField) {
console.error(`No graphql table or filter field for ${type}`)
return
console.warn(`No graphql table or filter field for ${type}`)
}
const fields = getGraphQLFieldsForEntity(type, editor)
// If fetching for the editor, query on id which is an Int
Expand Down

0 comments on commit e98debf

Please sign in to comment.