Skip to content

Commit e98debf

Browse files
committed
fix(editor): fix view all route alignments on editor map
fixes #76
1 parent a139d52 commit e98debf

File tree

7 files changed

+137
-129
lines changed

7 files changed

+137
-129
lines changed

lib/editor/actions/active.js

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,28 @@ export function updateEditSetting (setting, value, activePattern) {
1919
}
2020
}
2121

22+
export function updateActiveGtfsEntity (entity, component, props) {
23+
return {
24+
type: 'UPDATE_ACTIVE_GTFS_ENTITY',
25+
entity,
26+
component,
27+
props
28+
}
29+
}
30+
31+
export function resetActiveGtfsEntity (entity, component) {
32+
return {
33+
type: 'RESET_ACTIVE_GTFS_ENTITY',
34+
entity,
35+
component
36+
}
37+
}
38+
2239
export const clearGtfsContent = createAction('CLEAR_GTFSEDITOR_CONTENT')
2340
export const savedGtfsEntity = createAction('SAVED_GTFS_ENTITY')
41+
export const deletingEntity = createAction('DELETING_ENTITY')
2442
const settingActiveGtfsEntity = createAction('SETTING_ACTIVE_GTFS_ENTITY')
43+
export const savingActiveGtfsEntity = createAction('SAVING_ACTIVE_GTFS_ENTITY')
2544

2645
export function enterTimetableEditor () {
2746
return function (dispatch, getState) {
@@ -96,8 +115,8 @@ export function setActiveGtfsEntity (feedSourceId, component, entityId, subCompo
96115
const activeEntity = component === 'feedinfo'
97116
? clone(activeTable)[0]
98117
: activeTable && entityId
99-
? clone(activeTable.find(e => e.id === entityId))
100-
: null
118+
? clone(activeTable.find(e => e.id === entityId))
119+
: null
101120
const activeSubEntity = activeEntity && activeEntity.tripPatterns
102121
? clone(activeEntity.tripPatterns.find(p => p.id === subEntityId))
103122
: null
@@ -156,8 +175,6 @@ function constructEditorURL (feedSourceId, component, entityId, subComponent, su
156175
return url
157176
}
158177

159-
export const savingActiveGtfsEntity = createAction('SAVING_ACTIVE_GTFS_ENTITY')
160-
161178
export function saveActiveGtfsEntity (component, optionalEntity, refetch = true) {
162179
return function (dispatch, getState) {
163180
const {active} = getState().editor.data
@@ -224,8 +241,6 @@ export function saveEntity (feedId, entity, component, refetch = true) {
224241
}
225242
}
226243

227-
export const deletingEntity = createAction('DELETING_ENTITY')
228-
229244
/**
230245
* Generic delete function for editor GTFS entities.
231246
*/
@@ -259,20 +274,3 @@ export function deleteGtfsEntity (feedId, component, entityId, routeId) {
259274
})
260275
}
261276
}
262-
263-
export function updateActiveGtfsEntity (entity, component, props) {
264-
return {
265-
type: 'UPDATE_ACTIVE_GTFS_ENTITY',
266-
entity,
267-
component,
268-
props
269-
}
270-
}
271-
272-
export function resetActiveGtfsEntity (entity, component) {
273-
return {
274-
type: 'RESET_ACTIVE_GTFS_ENTITY',
275-
entity,
276-
component
277-
}
278-
}

lib/editor/actions/tripPattern.js

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@ import {savedGtfsEntity, updateEditSetting} from './active'
77
import {entityIsNew} from '../util/objects'
88
import {getEditorNamespace} from '../util/gtfs'
99

10-
// TRIP PATTERNS
11-
12-
const requestingTripPatterns = createAction('REQUESTING_TRIP_PATTERNS')
13-
const receiveTripPatterns = createAction('RECEIVE_TRIP_PATTERNS')
1410
export const undoActiveTripPatternEdits = createAction('UNDO_TRIP_PATTERN_EDITS')
1511
export const setActiveStop = createAction('SET_ACTIVE_PATTERN_STOP')
1612
export const togglingPatternEditing = createAction('TOGGLE_PATTERN_EDITING')
@@ -25,20 +21,14 @@ export function togglePatternEditing () {
2521
}
2622
}
2723

24+
/**
25+
* Fetch all trip patterns for the feed. Used to display pattern shapes in map
26+
* layer.
27+
*/
2828
export function fetchTripPatterns (feedId) {
2929
return function (dispatch, getState) {
30-
dispatch(requestingTripPatterns(feedId))
31-
const {sessionId} = getState().editor.data.lock
32-
const url = `/api/editor/secure/pattern?feedId=${feedId}&sessionId=${sessionId}`
33-
return dispatch(secureFetch(url))
34-
.then(res => {
35-
if (res.status >= 400) return []
36-
return res.json()
37-
})
38-
.then(tripPatterns => {
39-
dispatch(receiveTripPatterns({feedId, tripPatterns}))
40-
return tripPatterns
41-
})
30+
const namespace = getEditorNamespace(feedId, getState())
31+
return dispatch(fetchGTFSEntities({namespace, type: 'pattern', editor: true}))
4232
}
4333
}
4434

lib/editor/components/map/EditorMapLayersControl.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export default class EditorMapLayersControl extends Component {
3030
weight={2}
3131
color='#888'>
3232
<Tooltip sticky>
33-
<span>{tp.name}</span>
33+
<span>{tp.name} ({tp.route_id})</span>
3434
</Tooltip>
3535
</Polyline>
3636
)

lib/editor/reducers/data.js

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -222,20 +222,6 @@ const data = (state = defaultState, action) => {
222222
})
223223
}
224224
return state
225-
// Handle trip patterns to be drawn as overlay layer in editor
226-
case 'RECEIVE_TRIP_PATTERNS':
227-
return update(state, {
228-
tripPatterns: {$set:
229-
// FIXME: Update for new trip pattern data structure
230-
action.payload.tripPatterns.map(pattern => {
231-
return {
232-
id: pattern.id,
233-
name: pattern.name,
234-
latLngs: pattern.shape ? (pattern.shape.coordinates.map(c => ll.fromCoordinates(c))) : null
235-
}
236-
})
237-
}
238-
})
239225
case 'DELETING_STOP':
240226
stopIndex = stops.findIndex(s => s.id === action.stop.id)
241227
return update(state, {
@@ -251,6 +237,29 @@ const data = (state = defaultState, action) => {
251237
// for viewing validation result details).
252238
return state
253239
}
240+
if (component === 'pattern') {
241+
// Handle trip patterns to be drawn as overlay layer in editor
242+
console.log('setting trip patterns', data)
243+
return update(state, {
244+
tripPatterns: {$set:
245+
// FIXME: Update for new trip pattern data structure
246+
data.feed.patterns.map(pattern => {
247+
return {
248+
id: pattern.id,
249+
name: pattern.name,
250+
route_id: pattern.route_id,
251+
latLngs: pattern.shape_points
252+
? (pattern.shape_points.map(sp =>
253+
({
254+
lon: sp.shape_pt_lon,
255+
lat: sp.shape_pt_lat
256+
})))
257+
: null
258+
}
259+
})
260+
}
261+
})
262+
}
254263
const tableName = getKeyForId(component, 'tableName')
255264
// get entities from payload
256265
const mappingStrategy = getMapToGtfsStrategy(component)

lib/editor/util/gtfs.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export const COMPONENT_LIST = [
5151
export function getTableById (tableData: any, id: string, emptyArrayOnNull: boolean = true): any {
5252
const tableName = getKeyForId(id, 'tableName')
5353
if (!tableName) {
54-
console.error(`Component ${id} not found in list of tables.`)
54+
console.warn(`Component ${id} not found in list of tables.`)
5555
return null
5656
}
5757
const table = tableData[tableName]
@@ -315,8 +315,8 @@ export function getAbbreviatedStopName (stop: GtfsStop, maxCharactersPerWord: nu
315315
stopNameParts.length === 3 &&
316316
stop.stop_name.length > maxCharactersPerWord * 2
317317
? `${stopNameParts[0]
318-
.substr(0, maxCharactersPerWord)
319-
.trim()}... ${stopNameParts[2].substr(0, maxCharactersPerWord).trim()}`
318+
.substr(0, maxCharactersPerWord)
319+
.trim()}... ${stopNameParts[2].substr(0, maxCharactersPerWord).trim()}`
320320
: stop.stop_name
321321
}
322322

lib/gtfs/util/index.js

Lines changed: 82 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -40,77 +40,89 @@ export function getGraphQLFieldsForEntity (type: string, editor: boolean = false
4040
const entityTableString = getEntityTableString(type)
4141
const table = getGtfsSpec().find(table => table.id === entityTableString)
4242
let fields = ''
43-
if (table) {
44-
fields = table.fields
45-
// Only filter required fields if not fetching for editor
46-
// FIXME: This fetches only the required fields for feed info because there
47-
// are missing fields in the GraphQL schema and database (default color and
48-
// default route type).
49-
.filter(field => type === 'feedinfo' ? !field.datatools : editor ? field : field.required && !field.datatools)
50-
.map(field => field.name)
51-
.join('\n')
52-
// stop_times are a special case because they must be requested as a
53-
// nested list underneath a trip
54-
// console.log(type)
55-
switch (type.toLowerCase()) {
56-
case 'stoptime':
57-
return `
58-
trip_id
59-
stop_times {
60-
${fields}
61-
}
62-
`
63-
case 'fare':
64-
// console.log('getting fare fields')
65-
return `
66-
${fields}
67-
fare_rules (limit: -1) {
68-
id
69-
fare_id
70-
route_id
71-
origin_id
72-
destination_id
73-
contains_id
74-
}
75-
`
76-
case 'route':
77-
return `
43+
if (!table) {
44+
console.warn(`Could not find table fare entity ${type}`)
45+
}
46+
fields = table
47+
? table.fields
48+
// Only filter required fields if not fetching for editor
49+
// FIXME: This fetches only the required fields for feed info because there
50+
// are missing fields in the GraphQL schema and database (default color and
51+
// default route type).
52+
.filter(field => type === 'feedinfo' ? !field.datatools : editor ? field : field.required && !field.datatools)
53+
.map(field => field.name)
54+
.join('\n')
55+
: ''
56+
// stop_times are a special case because they must be requested as a
57+
// nested list underneath a trip
58+
console.log(type)
59+
const shapeFields = `shape_points: shape (limit: -1) {
60+
shape_pt_lon
61+
shape_pt_lat
62+
shape_pt_sequence
63+
point_type
64+
shape_dist_traveled
65+
}`
66+
const patternStopFields = `pattern_stops (limit: -1) {
67+
id
68+
stop_id
69+
default_travel_time
70+
default_dwell_time
71+
stop_sequence
72+
shape_dist_traveled
73+
pickup_type
74+
drop_off_type
75+
timepoint
76+
}`
77+
switch (type.toLowerCase()) {
78+
case 'stoptime':
79+
return `
80+
trip_id
81+
stop_times {
7882
${fields}
79-
tripPatterns: patterns (limit: -1) {
80-
id
81-
shape_id
82-
pattern_id
83-
trip_count
84-
route_id
85-
direction_id
86-
use_frequency
87-
name
88-
pattern_stops (limit: -1) {
89-
id
90-
stop_id
91-
default_travel_time
92-
default_dwell_time
93-
stop_sequence
94-
shape_dist_traveled
95-
pickup_type
96-
drop_off_type
97-
timepoint
98-
}
99-
shape_points: shape (limit: -1) {
100-
shape_pt_lon
101-
shape_pt_lat
102-
shape_pt_sequence
103-
point_type
104-
shape_dist_traveled
105-
}
106-
}
107-
`
108-
default:
109-
return fields
110-
}
111-
} else {
112-
console.error(`Could not find table fare entity ${type}`)
113-
return ''
83+
}
84+
`
85+
case 'fare':
86+
// console.log('getting fare fields')
87+
return `
88+
${fields}
89+
fare_rules (limit: -1) {
90+
id
91+
fare_id
92+
route_id
93+
origin_id
94+
destination_id
95+
contains_id
96+
}
97+
`
98+
case 'pattern':
99+
return `
100+
shape_id
101+
pattern_id
102+
route_id
103+
direction_id
104+
use_frequency
105+
name
106+
${shapeFields}
107+
`
108+
case 'route':
109+
return `
110+
${fields}
111+
tripPatterns: patterns (limit: -1) {
112+
id
113+
shape_id
114+
pattern_id
115+
trip_count
116+
route_id
117+
direction_id
118+
use_frequency
119+
name
120+
${patternStopFields}
121+
${shapeFields}
122+
}
123+
`
124+
default:
125+
return fields
114126
}
115127
}
116128

lib/manager/actions/versions.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,7 @@ export function fetchGTFSEntities ({namespace, id, type, editor = false, replace
190190
const idFieldType = editor ? 'Int' : '[String]'
191191
const graphQLRoot = getEntityGraphQLRoot(type)
192192
if (!graphQLRoot || !entityIdField) {
193-
console.error(`No graphql table or filter field for ${type}`)
194-
return
193+
console.warn(`No graphql table or filter field for ${type}`)
195194
}
196195
const fields = getGraphQLFieldsForEntity(type, editor)
197196
// If fetching for the editor, query on id which is an Int

0 commit comments

Comments
 (0)