-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Disruption list route filter #1133
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
4af8a2e
feat: display type filters on disruptions v2 page
lemald 2b1ba8e
test: port old filters tests over with some omissions
lemald 1b7c79d
feat: apply kind filters to listed disruptions
lemald ba89215
feat: add include past and only approved filters
lemald File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
lib/arrow_web/controllers/disruption_v2_controller/index.ex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
defmodule ArrowWeb.DisruptionV2Controller.Index do | ||
@moduledoc """ | ||
Applies filters on disruptions for index view | ||
""" | ||
|
||
alias Arrow.Disruptions | ||
alias Arrow.Disruptions.DisruptionV2 | ||
alias ArrowWeb.DisruptionV2Controller.Filters | ||
alias ArrowWeb.DisruptionV2Controller.Filters.Table | ||
|
||
@disruption_kind_routes %{ | ||
blue_line: ["Blue"], | ||
orange_line: ["Orange"], | ||
red_line: ["Red"], | ||
mattapan_line: ["Mattapan"], | ||
green_line: ["Green-B", "Green-C", "Green-D", "Green-E"], | ||
green_line_b: ["Green-B"], | ||
green_line_c: ["Green-C"], | ||
green_line_d: ["Green-D"], | ||
green_line_e: ["Green-E"] | ||
} | ||
|
||
@empty_set MapSet.new() | ||
|
||
@spec all(Filters.t() | nil) :: [DisruptionV2.t()] | ||
def all(filters), | ||
do: apply_to_disruptions(Disruptions.list_disruptionsv2(), filters) | ||
|
||
@spec apply_to_disruptions([DisruptionV2.t()], Filters.t()) :: [DisruptionV2.t()] | ||
def apply_to_disruptions(disruptions, filters) do | ||
Enum.filter( | ||
disruptions, | ||
&(apply_kinds_filter(&1, filters) and apply_only_approved_filter(&1, filters) and | ||
apply_past_filter(&1, filters)) | ||
) | ||
end | ||
|
||
defp apply_kinds_filter(_disruption, %Filters{kinds: kinds}) when kinds == @empty_set, | ||
do: true | ||
|
||
defp apply_kinds_filter(disruption, %Filters{kinds: kinds}) do | ||
kind_routes = kinds |> Enum.map(&@disruption_kind_routes[&1]) |> List.flatten() | ||
|
||
Enum.any?(disruption.limits, fn limit -> limit.route.id in kind_routes end) | ||
end | ||
|
||
defp apply_only_approved_filter(disruption, %Filters{only_approved?: true}), | ||
do: disruption.is_active | ||
|
||
defp apply_only_approved_filter(_disruption, %Filters{only_approved?: false}), | ||
do: true | ||
|
||
defp apply_past_filter(disruption, %Filters{view: %Table{include_past?: false}}) do | ||
cutoff = Date.utc_today() |> Date.add(-7) | ||
|
||
{_start_date, end_date} = Disruptions.start_end_dates(disruption) | ||
|
||
is_nil(end_date) or Date.after?(end_date, cutoff) | ||
end | ||
|
||
defp apply_past_filter(_disruption, _filter), do: true | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,36 @@ | |
</div> | ||
|
||
<div class="row my-3"> | ||
<div class="col"> | ||
<div class="col flex"> | ||
<%= for kind <- disruption_kinds() do %> | ||
<% show_as_active? = MapSet.size(@filters.kinds) == 0 or kind in @filters.kinds %> | ||
<% active_class = if(show_as_active?, do: "active", else: "") %> | ||
|
||
<.link | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if we should look into this page using LiveView in the future? Would be nice if the filters worked without a page load. |
||
class={"d-flex mr-1 m-disruption-index__route_filter #{active_class}"} | ||
aria-label={kind |> to_string() |> String.replace("_", " ")} | ||
href={update_filters_path(@conn, Filters.toggle_kind(@filters, kind))} | ||
> | ||
{disruption_kind_icon(@conn, kind, "lg")} | ||
</.link> | ||
<% end %> | ||
|
||
<%= if not Filters.calendar?(@filters) do %> | ||
{link("include past", | ||
class: | ||
"mx-2 btn btn-outline-secondary" <> | ||
if(@filters.view.include_past?, do: " active", else: ""), | ||
to: update_view_path(@conn, @filters, :include_past?, [email protected]_past?) | ||
)} | ||
<% end %> | ||
|
||
{link("approved", | ||
class: | ||
"mx-2 btn btn-outline-secondary" <> | ||
if(@filters.only_approved?, do: " active", else: ""), | ||
to: update_filters_path(@conn, Filters.toggle_only_approved(@filters)) | ||
)} | ||
|
||
{link("⬒ #{if(Filters.calendar?(@filters), do: "list", else: "calendar")} view", | ||
class: "ml-auto btn btn-outline-secondary", | ||
to: update_filters_path(@conn, Filters.toggle_view(@filters)) | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: I know
kinds
is a term from v1, but it feels odd to me. Does it make sense to just go withroutes
instead since it will always hold route IDs anyway?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, that's a good point. The one thing that gives me pause about that though is that it will eventually also include Commuter Rail, which is a mode as opposed to a route, so it's actually kind of a heterogeneous mix of routes and modes, and I'm not really sure of a better term that captures both of those things.