Skip to content

Commit

Permalink
Add some extra filter options
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew committed Sep 13, 2023
1 parent a201f9f commit 8edd496
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 10 deletions.
24 changes: 24 additions & 0 deletions app/controllers/projects_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@ def show
def index
@scope = Project.reviewed

if params[:keyword].present?
@scope = @scope.keyword(params[:keyword])
end

if params[:owner].present?
@scope = @scope.owner(params[:owner])
end

if params[:language].present?
@scope = @scope.language(params[:language])
end

if params[:sort]
@scope = @scope.order("#{params[:sort]} #{params[:order]}")
else
Expand All @@ -27,6 +39,18 @@ def lookup
def review
@scope = Project.unreviewed.matching_criteria.where('vote_score > ?', -3).includes(:votes)

if params[:keyword].present?
@scope = @scope.keyword(params[:keyword])
end

if params[:owner].present?
@scope = @scope.owner(params[:owner])
end

if params[:language].present?
@scope = @scope.language(params[:language])
end

if params[:sort]
@scope = @scope.order("#{params[:sort]} #{params[:order]}")
else
Expand Down
1 change: 1 addition & 0 deletions app/models/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class Project < ApplicationRecord
has_many :votes, dependent: :destroy

scope :language, ->(language) { where("(repository ->> 'language') = ?", language) }
scope :owner, ->(owner) { where("(repository ->> 'owner') = ?", owner) }
scope :keyword, ->(keyword) { where("keywords @> ARRAY[?]::varchar[]", keyword) }
scope :reviewed, -> { where(reviewed: true) }
scope :unreviewed, -> { where(reviewed: nil) }
Expand Down
2 changes: 1 addition & 1 deletion app/views/projects/_project.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<p>
<% project.keywords.each do |keyword| %>
<span class="badge bg-light text-dark">
<%= keyword %>
<%= link_to keyword, url_for(keyword: keyword) %>
</span>
<% end %>
</p>
Expand Down
33 changes: 24 additions & 9 deletions app/views/projects/_project_review.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<br/>
<% project.keywords.each do |keyword| %>
<span class="badge bg-light text-dark">
<%= keyword %>
<%= link_to keyword, url_for(keyword: keyword) %>
</span>
<% end %>
<% end %>
Expand All @@ -28,7 +28,7 @@
</p>

<div class='row small'>
<div class='col-6'>
<div class='col-4'>
<ul>
<li>
Relevant topics? <span title='<%= project.matching_topics.join(', ') %>'><%= project.good_topics? %></span>
Expand All @@ -42,30 +42,45 @@
<li>
Active? <%= project.active? %>
</li>
</ul>
</div>
<div class='col-4'>
<ul>

<li>
Fork? <%= project.fork? %>
Commits: <%= project.commits && project.commits['total_commits'] %>
</li>
<li>
Committers: <%= project.commits && project.commits['total_committers'] %>
</li>
<li>
Issues: <%= project.issues && project.issues['issues_count'] %>
</li>
<li>
Pull Requests: <%= project.issues && project.issues['pull_requests_count'] %>
</li>
</ul>
</div>
<div class='col-6'>
<div class='col-4'>
<ul>
<li>
Stars: <%= project.repository['stargazers_count'] %>
Main Language: <%= link_to project.language, url_for(language: project.language) %>
</li>
<li>
Forks: <%= project.repository['forks_count'] %>
Owner: <%= link_to project.owner_name, url_for(owner: project.owner_name) %>
</li>
<li>
Commits: <%= project.commits && project.commits['total_commits'] %>
Stars: <%= project.repository['stargazers_count'] %>
</li>
<li>
Issues: <%= project.issues && project.issues['issues_count'] %>
Forks: <%= project.repository['forks_count'] %>
</li>
<li>
Pull Requests: <%= project.issues && project.issues['pull_requests_count'] %>
Fork? <%= project.fork? %>
</li>
</ul>
</div>

</div>

<%= button_to "👍 #{project.votes.select{|v| v.score > 0}.length}", project_votes_path(project_id: project, vote: {score: 1}), class: "btn btn-light", form_class: 'd-inline' %>
Expand Down

0 comments on commit 8edd496

Please sign in to comment.