Commit a052f681 authored by Camil Staps's avatar Camil Staps

Add pagination to {project}/starrers view

parent 6baff650
...@@ -6,14 +6,12 @@ class Projects::StarrersController < Projects::ApplicationController ...@@ -6,14 +6,12 @@ class Projects::StarrersController < Projects::ApplicationController
# Authorize # Authorize
before_action :require_non_empty_project before_action :require_non_empty_project
# rubocop: disable CodeReuse/ActiveRecord
def index def index
@sort = params[:sort].presence || sort_value_name @sort = params[:sort].presence || sort_value_name
params[:project] = @project
@starrers = UsersStarProjectsFinder.new(params).execute @starrers = UsersStarProjectsFinder.new(params).execute
@starrers = @starrers.sort_by_attribute(@sort) @starrers = @starrers.by_project(@project)
@starrers = @starrers.sort_by_attribute(@sort).page(params[:page])
end end
# rubocop: enable CodeReuse/ActiveRecord
end end
...@@ -12,7 +12,6 @@ class UsersStarProjectsFinder ...@@ -12,7 +12,6 @@ class UsersStarProjectsFinder
def execute def execute
stars = UsersStarProject.all.order_id_desc stars = UsersStarProject.all.order_id_desc
stars = by_search(stars) stars = by_search(stars)
stars = by_project(stars)
stars stars
end end
...@@ -20,12 +19,6 @@ class UsersStarProjectsFinder ...@@ -20,12 +19,6 @@ class UsersStarProjectsFinder
private private
def by_search(items) def by_search(items)
return items unless params[:search].present? params[:search].present? ? items.search(params[:search]) : items
items.search(params[:search])
end
def by_project(items)
params[:project].present? ? items.by_project(params[:project]) : items
end end
end end
...@@ -601,6 +601,11 @@ module ProjectsHelper ...@@ -601,6 +601,11 @@ module ProjectsHelper
end end
end end
def filter_starrer_path(options = {})
options = params.slice(:sort).merge(options).permit!
"#{request.path}?#{options.to_param}"
end
def sidebar_projects_paths def sidebar_projects_paths
%w[ %w[
projects#show projects#show
......
...@@ -108,9 +108,4 @@ module UsersHelper ...@@ -108,9 +108,4 @@ module UsersHelper
items items
end end
def filter_user_path(options = {})
options = params.slice(:sort).merge(options).permit!
"#{request.path}?#{options.to_param}"
end
end end
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
.nav-text .nav-text
%span.flex-project-title %span.flex-project-title
= _("Starrers of <strong>%{project_name}</strong>").html_safe % { project_name: sanitize_project_name(@project.name) } = _("Starrers of <strong>%{project_name}</strong>").html_safe % { project_name: sanitize_project_name(@project.name) }
%span.badge.badge-pill= @starrers.size %span.badge.badge-pill= @starrers.total_count
- if @starrers.size > 0 - if @starrers.size > 0
.nav-controls .nav-controls
= form_tag request.original_url, method: :get, class: 'form-inline user-search-form flex-users-form' do = form_tag request.original_url, method: :get, class: 'form-inline user-search-form flex-users-form' do
...@@ -20,10 +20,11 @@ ...@@ -20,10 +20,11 @@
= _("Sort by") = _("Sort by")
- starrers_sort_options_hash.each do |value, title| - starrers_sort_options_hash.each do |value, title|
%li %li
= link_to filter_user_path(sort: value), class: ("is-active" if @sort == value) do = link_to filter_starrer_path(sort: value), class: ("is-active" if @sort == value) do
= title = title
- if @starrers.size > 0 - if @starrers.size > 0
.row.prepend-top-10 .row.prepend-top-10
= render partial: 'starrer', collection: @starrers, as: :starrer = render partial: 'starrer', collection: @starrers, as: :starrer
= paginate @starrers, theme: 'gitlab'
- else - else
.nothing-here-block Nobody has starred this repository yet .nothing-here-block Nobody has starred this repository yet
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment