Module: Pipeline::InboxGroupedBySubmission::Pagination

Defined in:
app/models/pipeline/inbox_grouped_by_submission.rb

Overview

This module overrides the behaviour of will_paginate so that the requests for an individual submission appear on the same page. It does this by first paging the submission IDs, and then limiting the query so that it only includes requests from these submissions.

Instance Method Summary collapse

Instance Method Details

#paginate(*args) ⇒ Object


15
16
17
# File 'app/models/pipeline/inbox_grouped_by_submission.rb', line 15

def paginate(*args)
  super(*args.push(args.extract_options!.merge(finder: :paginated_by_submission, total_entries: submissions(:count))))
end

#paginated_by_submission(*args) ⇒ Object


19
20
21
22
23
# File 'app/models/pipeline/inbox_grouped_by_submission.rb', line 19

def paginated_by_submission(*args)
  options                      = args.extract_options!
  options_for_submission_query = Hash[[:limit, :offset].map { |k| [k, options.delete(k)] if options.key?(k) }.compact]
  all(options.deep_merge(conditions: { submission_id: submissions(:all, options_for_submission_query).map(&:submission_id) }))
end