Add pagination to {project}/starrers view

This commit is contained in:
Camil Staps 2019-01-28 18:51:49 +01:00
parent 6baff6504b
commit a052f68116
No known key found for this signature in database
GPG Key ID: 4A9BFD4F6A415F83
5 changed files with 12 additions and 20 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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