-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #475 from ministryofjustice/CBO-1417-hearing-day-p…
…agination [CBO-1417] hearing day pagination
- Loading branch information
Showing
36 changed files
with
1,347 additions
and
84 deletions.
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
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
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# frozen_string_literal: true | ||
|
||
module HearingHelper | ||
def paginator(...) | ||
HearingPaginator.new(...) | ||
end | ||
|
||
def earliest_day_for(hearing) | ||
hearing&.hearing_days&.map(&:to_datetime)&.sort&.first | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
# frozen_string_literal: true | ||
|
||
# Creates a chronologically sorted set of "items" | ||
# with next and previous navigation helpers. | ||
# | ||
# Next and previous correlate to navigation over all | ||
# a cases' hearing's hearing days. | ||
# | ||
class HearingPaginator | ||
include ActionView::Helpers | ||
include Rails.application.routes.url_helpers | ||
|
||
PageItem = Struct.new(:id, :hearing_date) | ||
|
||
def initialize(prosecution_case, page: 0) | ||
@prosecution_case = prosecution_case | ||
@current_page = page.to_i | ||
end | ||
|
||
def current_page | ||
@current_page ||= 0 | ||
end | ||
|
||
def current_item | ||
items[current_page || first_page] | ||
end | ||
|
||
def items | ||
@items ||= hearing_items_by_datetime | ||
end | ||
|
||
def first_page? | ||
current_page == first_page | ||
end | ||
|
||
def first_page | ||
0 | ||
end | ||
|
||
def last_page? | ||
current_page == last_page | ||
end | ||
|
||
def last_page | ||
[items.size - 1, 0].max | ||
end | ||
|
||
def next_page_link | ||
# TODO: add <span class="govuk-visually-hidden"> set of pages</span> within hyperlink ?! | ||
link_to(t('hearings.show.pagination.next_page'), | ||
hearing_path(id: next_item.id, | ||
urn: @prosecution_case.prosecution_case_reference, | ||
page: next_page), | ||
class: 'moj-pagination__link') | ||
end | ||
|
||
def previous_page_link | ||
# TODO: add <span class="govuk-visually-hidden"> set of pages</span> within hyperlink ?! | ||
link_to(t('hearings.show.pagination.previous_page'), | ||
hearing_path(id: previous_item.id, | ||
urn: @prosecution_case.prosecution_case_reference, | ||
page: previous_page), | ||
class: 'moj-pagination__link') | ||
end | ||
|
||
private | ||
|
||
def next_item | ||
items[next_page] | ||
end | ||
|
||
def next_page | ||
[current_page + 1, last_page].min | ||
end | ||
|
||
def previous_item | ||
items[previous_page] | ||
end | ||
|
||
def previous_page | ||
[current_page - 1, first_page].max | ||
end | ||
|
||
def hearing_items_by_datetime | ||
@prosecution_case.hearings_with_day_by_datetime.map do |hearing| | ||
PageItem.new(hearing.id, hearing.day) | ||
end | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
%nav#pagination-label.moj-pagination | ||
%p.govuk-visually-hidden{ 'aria-labelledby': 'pagination-label' } | ||
Pagination navigation | ||
%ul.moj-pagination__list | ||
- unless paginator.first_page? | ||
%li.moj-pagination__item.moj-pagination__item--prev | ||
= paginator.previous_page_link | ||
- unless paginator.last_page? | ||
%li.moj-pagination__item.moj-pagination__item--next | ||
= paginator.next_page_link |
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 |
---|---|---|
@@ -1,11 +1,12 @@ | ||
= govuk_page_title(@hearing_day&.strftime('%d/%m/%Y'), t('generic.hearing_day')) | ||
- hearing = decorate(@hearing) | ||
|
||
= render partial: 'listing_info', locals: { hearing: hearing, hearing_day: @hearing_day } | ||
= render partial: 'pagination', locals: { paginator: @paginator } | ||
|
||
= render partial: 'attendees', locals: { hearing: hearing } | ||
= render partial: 'listing_info', locals: { hearing: @hearing, hearing_day: @hearing_day } | ||
|
||
= render partial: 'hearing_events', locals: { hearing: hearing, hearing_day: @hearing_day } | ||
= render partial: 'attendees', locals: { hearing: @hearing } | ||
|
||
= render partial: 'hearing_events', locals: { hearing: @hearing, hearing_day: @hearing_day } | ||
|
||
- if Rails.configuration.x.display_raw_responses | ||
= render partial: 'raw_response', locals: { hearing: hearing } | ||
= render partial: 'raw_response', locals: { hearing: @hearing } |
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
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,4 @@ | ||
--- | ||
:quiet: true | ||
:exit_on_warn: true | ||
:exit_on_error: false |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
--- | ||
en: | ||
cracked_ineffective_trial: | ||
cracked_on_sentence_html: "%{type} on %{cracked_at_link}" | ||
cracked_on_sentence: "%{type} on %{cracked_at}" |
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
Oops, something went wrong.