-
-
Notifications
You must be signed in to change notification settings - Fork 9
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
2400 next eventful period #2438
Conversation
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.
Works well but just a few changes to make it more robust
app/controllers/events_controller.rb
Outdated
@@ -28,6 +28,18 @@ def index | |||
@events = sort_events(@events, @sort) | |||
@multiple_days = true | |||
|
|||
@next = if params[:year] |
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.
maybe params[:year].present?
?
@@ -24,5 +24,5 @@ | |||
</ol> | |||
<% end %> | |||
<% else %> | |||
<p>No events with this selection.</p> | |||
<p>No events with this selection.<% if @next.present? %> <a href=<%= next_url(@next, period, sort, repeating)%>>skip to next date with events</a>.<% end %></p> |
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.
I think this should be a link_to
so something like
<%= link_to 'skip to next date with events', next_url(@next) if @next.present? %>
app/helpers/events_helper.rb
Outdated
@@ -35,4 +35,13 @@ def online_link | |||
def html_to_plaintext(input) | |||
Nokogiri::HTML.fragment(input).text | |||
end | |||
|
|||
def next_url(next_event, period, sort, repeating) | |||
opts = [] |
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.
building URLs like this seems very un-railsy as it has some hard-coded strings in it
it would be better to use a named route (like how there's an events_path
) so if the routing changes we don't get caught out with old-style routes.
unfortunately you'll have to modify the route file to give that path a name.
In config/routes.rb
you'll want to
get '/events/:year/:month/:day' => 'events#index', constraints: ymd
# and add at the end to be
get '/events/:year/:month/:day' => 'events#index', constraints: ymd, as: :events_by_date
Then the URL can be built with
def next_url(next_event)
opts = {
year: next_event.dtstart.year,
month: next_event.dtstart.month,
day: next_event.dtstart.day,
anchor: 'paginator',
period: @period,
sort: @sort,
repeating: @repeating
}.keep_if { |_key, value| value.present? }
events_by_date_path(opts)
end
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.
Nice work
fixes #2400
Grabs the next future event, takes it's start date and links to it using the same logic as the paginator. Retains "period" mode and won't show if there's no future events.
next_date.mp4