@@ -6,21 +6,14 @@ defmodule DotcomWeb.StopController do
66 use Dotcom.Gettext.Sigils
77 use DotcomWeb , :controller
88
9- import Alerts.Alert , only: [ global_banner_alert?: 1 , routewide?: 1 ]
10- import Dotcom.Alerts.StartTime , only: [ active_in_next_n_days?: 3 ]
11-
12- alias Alerts.Repo , as: AlertsRepo
139 alias Dotcom.TransitNearMe
1410 alias Leaflet.MapData.Polyline
1511 alias Plug.Conn
1612 alias RoutePatterns.RoutePattern
1713 alias Routes.Route
1814 alias Services.Service
1915 alias Stops.Stop
20- alias Util.AndOr
2116
22- @ alerts_repo Application . compile_env! ( :dotcom , :repo_modules ) [ :alerts ]
23- @ facilities_repo Application . compile_env! ( :dotcom , :repo_modules ) [ :facilities ]
2417 @ route_patterns_repo Application . compile_env! ( :dotcom , :repo_modules ) [ :route_patterns ]
2518 @ routes_repo Application . compile_env! ( :dotcom , :repo_modules ) [ :routes ]
2619 @ stops_repo Application . compile_env! ( :dotcom , :repo_modules ) [ :stops ]
@@ -31,10 +24,11 @@ defmodule DotcomWeb.StopController do
3124 }
3225
3326 def index ( conn , _params ) do
34- redirect ( conn , to: stop_path ( conn , :show , :subway ) )
27+ redirect ( conn , to: subway_stops_path ( conn , :list ) )
3528 end
3629
37- def show ( conn , % { "id" => mode } ) when mode in [ "subway" , "commuter-rail" , "ferry" ] do
30+ def list ( conn , _params ) do
31+ [ "stops" , mode ] = conn . path_info
3832 mode_atom = Route . type_atom ( mode )
3933 { mattapan , stop_info } = get_stop_info ( )
4034
@@ -49,90 +43,6 @@ defmodule DotcomWeb.StopController do
4943 |> render ( "index.html" )
5044 end
5145
52- @ spec show ( Plug.Conn . t ( ) , map ( ) ) :: Plug.Conn . t ( )
53- def show ( conn , % { "id" => stop_id } = params ) do
54- stop =
55- stop_id
56- |> URI . decode_www_form ( )
57- |> @ stops_repo . get ( )
58-
59- if stop do
60- if @ stops_repo . has_parent? ( stop ) do
61- conn
62- |> redirect ( to: stop_path ( conn , :show , @ stops_repo . get_parent ( stop ) ) )
63- |> halt ( )
64- else
65- routes_by_stop = @ routes_repo . by_stop ( stop_id , include: "stop.connecting_stops" )
66- one_way_fares = Fares.Format . one_way_ranges ( routes_by_stop )
67- accessible? = accessible? ( stop )
68-
69- amenities =
70- @ facilities_repo . get_for_stop ( stop_id )
71- |> Dotcom.StopAmenity . from_stop_facilities ( )
72-
73- conn
74- |> assign ( :breadcrumbs , breadcrumbs ( stop , routes_by_stop ) )
75- |> meta_description ( stop , routes_by_stop )
76- |> assign_alerts ( )
77- |> assign_stop_banner_alerts ( routes_by_stop |> Enum . map ( & & 1 . id ) , conn . assigns . date_time )
78- |> render ( "show.html" , % {
79- stop: stop ,
80- amenity_param: Map . get ( params , "amenity" , "" ) |> String . to_atom ( ) ,
81- one_way_fares: one_way_fares ,
82- routes_by_stop: routes_by_stop ,
83- parking_amenity: Enum . find ( amenities , & ( & 1 . type == :parking ) ) ,
84- bike_amenity: Enum . find ( amenities , & ( & 1 . type == :bike ) ) ,
85- elevator_amenity: Enum . find ( amenities , & ( & 1 . type == :elevator ) ) ,
86- escalator_amenity: Enum . find ( amenities , & ( & 1 . type == :escalator ) ) ,
87- accessibility_amenity: Enum . find ( amenities , & ( & 1 . type == :accessibility ) ) ,
88- fare_amenity: Enum . find ( amenities , & ( & 1 . type == :fare ) ) ,
89- accessible?: accessible?
90- } )
91- end
92- else
93- check_cms_or_404 ( conn )
94- end
95- end
96-
97- defp assign_stop_banner_alerts ( conn , route_ids , date_time ) do
98- all_alerts_for_stop = conn . assigns . alerts
99-
100- all_routewide_alerts =
101- @ alerts_repo . by_route_ids ( route_ids , date_time )
102- |> Enum . filter ( & routewide? / 1 )
103-
104- banner_alerts =
105- ( all_alerts_for_stop ++ all_routewide_alerts )
106- |> Enum . filter ( & banner_alert? ( & 1 , date_time ) )
107-
108- assign ( conn , :banner_alerts , banner_alerts )
109- end
110-
111- defp banner_alert? ( alert , now ) do
112- ! global_banner_alert? ( alert ) &&
113- banner_alert_active_effect? ( alert ) &&
114- active_in_next_n_days? ( alert , 7 , now )
115- end
116-
117- defp banner_alert_active_effect? ( alert ) do
118- alert . effect in [
119- :access_issue ,
120- :detour ,
121- :dock_closure ,
122- :dock_issue ,
123- :service_change ,
124- :elevator_closure ,
125- :notice ,
126- :shuttle ,
127- :station_closure ,
128- :station_issue ,
129- :stop_closure ,
130- :stop_moved ,
131- :stop_shoveling ,
132- :suspension
133- ]
134- end
135-
13646 @ spec get ( Conn . t ( ) , map ) :: Conn . t ( )
13747 def get ( conn , % { "id" => stop_id } ) do
13848 json ( conn , @ stops_repo . get ( stop_id ) )
@@ -240,15 +150,6 @@ defmodule DotcomWeb.StopController do
240150 Map . put ( route_pattern , :representative_trip_polyline , polyline )
241151 end
242152
243- @ doc "Redirect users who type in a URL with a slash to the correct URL"
244- def stop_with_slash_redirect ( conn , % { "path" => path } ) do
245- real_id = Enum . join ( path , "/" )
246-
247- conn
248- |> redirect ( to: stop_path ( conn , :show , real_id ) )
249- |> halt
250- end
251-
252153 @ spec get_stop_info :: { DetailedStopGroup . t ( ) , [ DetailedStopGroup . t ( ) ] }
253154 defp get_stop_info do
254155 [ :subway , :commuter_rail , :ferry ]
@@ -325,87 +226,4 @@ defmodule DotcomWeb.StopController do
325226
326227 @ spec includes_predictions? ( TransitNearMe . headsign_data ( ) ) :: boolean
327228 defp includes_predictions? ( % { times: times } ) , do: Enum . any? ( times , & ( & 1 . prediction != nil ) )
328-
329- defp assign_alerts ( % { assigns: % { alerts: alerts } } = conn ) do
330- assign ( conn , :all_alerts_count , length ( alerts ) )
331- end
332-
333- defp assign_alerts ( % { path_params: % { "id" => id } } = conn ) do
334- stop_id = URI . decode_www_form ( id )
335- alerts = @ alerts_repo . by_stop_id ( stop_id )
336-
337- conn
338- |> assign ( :alerts , alerts )
339- |> assign ( :all_alerts_count , length ( alerts ) )
340- end
341-
342- defp assign_alerts ( conn ) do
343- assign ( conn , :alerts , AlertsRepo . all ( conn . assigns . date_time ) )
344- end
345-
346- @ spec breadcrumbs ( Stop . t ( ) , [ Route . t ( ) ] ) :: [ Util.Breadcrumb . t ( ) ]
347- def breadcrumbs ( % Stop { name: name } , [ ] ) do
348- breadcrumbs_for_station_type ( nil , name )
349- end
350-
351- def breadcrumbs ( % Stop { station?: true , name: name } , routes ) do
352- routes
353- |> Enum . min_by ( & & 1 . type )
354- |> Route . path_atom ( )
355- |> breadcrumbs_for_station_type ( name )
356- end
357-
358- def breadcrumbs ( % Stop { name: name } , _routes ) do
359- breadcrumbs_for_station_type ( nil , name )
360- end
361-
362- defp breadcrumbs_for_station_type ( breadcrumb_tab , name )
363- when breadcrumb_tab in ~w( subway commuter-rail ferry) a do
364- [
365- Breadcrumb . build ( ~t" Stations" , stop_path ( DotcomWeb.Endpoint , :show , breadcrumb_tab ) ) ,
366- Breadcrumb . build ( name )
367- ]
368- end
369-
370- defp breadcrumbs_for_station_type ( _ , name ) do
371- [ Breadcrumb . build ( name ) ]
372- end
373-
374- @ spec meta_description ( Conn . t ( ) , Stop . t ( ) , [ Route . t ( ) ] ) :: Conn . t ( )
375- defp meta_description ( conn , stop , routes ) ,
376- do:
377- assign (
378- conn ,
379- :meta_description ,
380- gettext (
381- "Station serving MBTA %{lines} lines%{location}." ,
382- lines: lines ( routes ) ,
383- location: location ( stop )
384- )
385- )
386-
387- @ spec lines ( [ Route . t ( ) ] ) :: iolist
388- defp lines ( routes ) do
389- routes
390- |> Enum . map ( & ( & 1 . type |> Route . type_atom ( ) |> Route . type_name ( ) ) )
391- |> Enum . uniq ( )
392- |> AndOr . join ( :and )
393- end
394-
395- @ spec location ( Stop . t ( ) ) :: String . t ( )
396- defp location ( stop ) do
397- if stop . address && stop . address != "" do
398- gettext ( " at %{address}" , address: stop . address )
399- else
400- ""
401- end
402- end
403-
404- # A stop is accessible if it is labeled as accessible in GTFS or it doesn't have a parent stop and it serves a bus route.
405- def accessible? ( stop ) do
406- routes = @ routes_repo . by_stop ( stop . id )
407-
408- Enum . member? ( stop . accessibility , "accessible" ) ||
409- ( is_nil ( stop . parent_id ) && Enum . any? ( routes , & ( & 1 . type === 3 ) ) )
410- end
411229end
0 commit comments