Skip to content

Commit

Permalink
Refactor collections controller to include owner filter
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew committed Jun 13, 2024
1 parent ba7228b commit a0bd9a5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
6 changes: 5 additions & 1 deletion app/controllers/collections_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ def show
scope = @collection.dependency_projects(params[:dependency])
end

if params[:language].present? || params[:keyword].present? || params[:committer].present? || params[:dependency].present?
if params[:owner].present?
scope = @collection.owner_projects(params[:owner])
end

if params[:language].present? || params[:keyword].present? || params[:committer].present? || params[:dependency].present? || params[:owner].present?
@pagy, @projects = pagy_array(scope)
else
@pagy, @projects = pagy_countless(scope)
Expand Down
4 changes: 4 additions & 0 deletions app/models/collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ def dependency_projects(dependency)
projects.select{|p| p.dependency_packages.include?(dependency.split(':')) }
end

def owner_projects(owner)
projects.select{|p| p.owner_name == owner }
end

def owners
projects.map(&:owner_name).flatten.group_by(&:itself).transform_values(&:count).sort_by{|k,v| v}.reverse
end
Expand Down

0 comments on commit a0bd9a5

Please sign in to comment.