Skip to content
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

LTI-415: implement pagination with new totalElements value returned #373

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions app/controllers/concerns/bbb_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,22 +128,17 @@ def recordings(page = 1)
res = Rails.cache.fetch("rooms/#{@chosen_room.handler}/#{RECORDINGS_KEY}", expires_in: Rails.configuration.cache_expires_in_minutes.minutes) if Rails.configuration.cache_enabled
offset = (page.to_i - 1) * RECORDINGS_PER_PAGE # The offset is an index that starts at 0.
res ||= bbb.get_recordings(meetingID: @chosen_room.handler, offset: offset, limit: RECORDINGS_PER_PAGE) # offset and limit are for pagination purposes
@num_of_recs = res[:totalElements]&.to_i
recordings_formatted(res)
end

def recordings_count
res = Rails.cache.fetch("rooms/#{@chosen_room.handler}/#{RECORDINGS_KEY}", expires_in: Rails.configuration.cache_expires_in_minutes.minutes) if Rails.configuration.cache_enabled
res ||= bbb.get_recordings(meetingID: @chosen_room.handler)
res[:recordings].length
end

def paginate?
recordings_count > RECORDINGS_PER_PAGE
@num_of_recs ? @num_of_recs > RECORDINGS_PER_PAGE : false
end

# returns the amount of pages for recordings
def pages_count
(recordings_count.to_f / RECORDINGS_PER_PAGE).ceil
@num_of_recs ? (@num_of_recs.to_f / RECORDINGS_PER_PAGE).ceil : 1
end

# on the last page, we don't want recordings that were in the second-to-last page to show
Expand Down