Make pagination optional for issuables
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
This commit is contained in:
parent
501d81c523
commit
b02a6bed85
2 changed files with 27 additions and 5 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -102,6 +102,18 @@ describe Projects::IssuesController do
|
|||
|
||||
expect(response).to redirect_to(namespace_project_issues_path(page: last_page, state: controller.params[:state], scope: controller.params[:scope]))
|
||||
end
|
||||
|
||||
it 'does not use pagination if disabled' do
|
||||
allow(controller).to receive(:pagination_disabled?).and_return(true)
|
||||
|
||||
get :index,
|
||||
namespace_id: project.namespace.to_param,
|
||||
project_id: project,
|
||||
page: (last_page + 1).to_param
|
||||
|
||||
expect(response).to have_gitlab_http_status(200)
|
||||
expect(assigns(:issues).size).to eq(2)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue