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
# Authorize
before_action :require_non_empty_project
# rubocop: disable CodeReuse/ActiveRecord
def index
@sort = params[:sort].presence || sort_value_name
params[:project] = @project
@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
# rubocop: enable CodeReuse/ActiveRecord
end
......@@ -12,7 +12,6 @@ class UsersStarProjectsFinder
def execute
stars = UsersStarProject.all.order_id_desc
stars = by_search(stars)
stars = by_project(stars)
stars
end
......@@ -20,12 +19,6 @@ class UsersStarProjectsFinder
private
def by_search(items)
return items unless params[:search].present?
items.search(params[:search])
end
def by_project(items)
params[:project].present? ? items.by_project(params[:project]) : items
params[:search].present? ? items.search(params[:search]) : items
end
end
......@@ -601,6 +601,11 @@ module ProjectsHelper
end
end
def filter_starrer_path(options = {})
options = params.slice(:sort).merge(options).permit!
"#{request.path}?#{options.to_param}"
end
def sidebar_projects_paths
%w[
projects#show
......
......@@ -108,9 +108,4 @@ module UsersHelper
items
end
def filter_user_path(options = {})
options = params.slice(:sort).merge(options).permit!
"#{request.path}?#{options.to_param}"
end
end
......@@ -4,7 +4,7 @@
.nav-text
%span.flex-project-title
= _("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
.nav-controls
= form_tag request.original_url, method: :get, class: 'form-inline user-search-form flex-users-form' do
......@@ -20,10 +20,11 @@
= _("Sort by")
- starrers_sort_options_hash.each do |value, title|
%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
- if @starrers.size > 0
.row.prepend-top-10
= render partial: 'starrer', collection: @starrers, as: :starrer
= paginate @starrers, theme: 'gitlab'
- else
.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