summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Provaznik <jprovaznik@gitlab.com>2018-01-29 16:22:58 +0100
committerJan Provaznik <jprovaznik@gitlab.com>2018-01-29 18:17:17 +0100
commit71f36786ba9b902aabc88679404b095f474e2ba0 (patch)
treed31d6816f7e4aa9ab42e24445384e14a4e854c81
parent501d81c523b2cf53128e62ea2d7c4dff6681928d (diff)
downloadgitlab-ce-jprovazn-pagination.tar.gz
Make pagination optional for issuablesjprovazn-pagination
On epics roadmap page we list all epics in the given time frame without pagination (at least for the first iteration), in this case it would be nice to use the existing issuables index logic except pagination (see MR gitlab-ee!4281). For this reason this patch allows to easily disable pagination. Related gitlab-ee!4281
-rw-r--r--app/controllers/concerns/issuable_collections.rb20
-rw-r--r--spec/controllers/concerns/issuable_collections_spec.rb23
2 files changed, 38 insertions, 5 deletions
diff --git a/app/controllers/concerns/issuable_collections.rb b/app/controllers/concerns/issuable_collections.rb
index b25e753a5ad..2fa0f98e344 100644
--- a/app/controllers/concerns/issuable_collections.rb
+++ b/app/controllers/concerns/issuable_collections.rb
@@ -12,11 +12,9 @@ module IssuableCollections
# rubocop:disable Gitlab/ModuleWithInstanceVariables
def set_issuables_index
- @issuables = issuables_collection
- @issuables = @issuables.page(params[:page])
- @issuable_meta_data = issuable_meta_data(@issuables, collection_type)
- @total_pages = issuable_page_count
+ @issuables = issuables_collection
+ set_pagination
return if redirect_out_of_range(@total_pages)
if params[:label_name].present?
@@ -35,14 +33,26 @@ module IssuableCollections
@users.push(author) if author
end
end
+
+ def set_pagination
+ return if pagination_disabled?
+
+ @issuables = @issuables.page(params[:page])
+ @issuable_meta_data = issuable_meta_data(@issuables, collection_type)
+ @total_pages = issuable_page_count
+ end
# rubocop:enable Gitlab/ModuleWithInstanceVariables
+ def pagination_disabled?
+ false
+ end
+
def issuables_collection
finder.execute.preload(preload_for_collection)
end
def redirect_out_of_range(total_pages)
- return false if total_pages.zero?
+ return false if total_pages.nil? || total_pages.zero?
out_of_range = @issuables.current_page > total_pages # rubocop:disable Gitlab/ModuleWithInstanceVariables
diff --git a/spec/controllers/concerns/issuable_collections_spec.rb b/spec/controllers/concerns/issuable_collections_spec.rb
index d7825364ed5..3597b18d28c 100644
--- a/spec/controllers/concerns/issuable_collections_spec.rb
+++ b/spec/controllers/concerns/issuable_collections_spec.rb
@@ -2,6 +2,7 @@ require 'spec_helper'
describe IssuableCollections do
let(:user) { create(:user) }
+ let(:params) { {} }
let(:controller) do
klass = Class.new do
@@ -13,10 +14,32 @@ describe IssuableCollections do
controller = klass.new
allow(controller).to receive(:params).and_return(ActionController::Parameters.new(params))
+ allow(controller).to receive(:current_user).and_return(user)
+ allow(controller).to receive(:set_sort_order_from_cookie).and_return(true)
controller
end
+ describe '#set_issuables_index' do
+ before do
+ controller.instance_variable_set(:@finder_type, IssuesFinder)
+ end
+
+ it 'sets pagination by default for the collection' do
+ controller.send(:set_issuables_index)
+
+ expect(controller.instance_variable_get(:@issuables).to_sql).to include('LIMIT')
+ end
+
+ it 'skips pagination if pagination is disabled' do
+ allow(controller).to receive(:pagination_disabled?).and_return(true)
+
+ controller.send(:set_issuables_index)
+
+ expect(controller.instance_variable_get(:@issuables).to_sql).not_to include('LIMIT')
+ end
+ end
+
describe '#page_count_for_relation' do
let(:params) { { state: 'opened' } }