Skip to content

Commit bd262d4

Browse files
committed
Add view for repos with a specific label
1 parent bb79e95 commit bd262d4

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed

app/controllers/pages_controller.rb

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,38 @@ def index
5151
end
5252
end
5353

54+
def topic
55+
topic_name = params['topic']
56+
57+
set_title("Open Source Project Topic: #{topic_name}")
58+
set_description(description)
59+
60+
label = Label.find_by(name: topic_name)
61+
62+
@topic_repos = Repo.with_some_issues
63+
.includes(:repo_labels)
64+
.where(repo_labels: {label_id: label.id})
65+
.select(:id, :updated_at, :issues_count, :language, :full_name, :name, :description)
66+
67+
@repos = @topic_repos.without_user_subscriptions(current_user.id) if user_signed_in?
68+
@repos = @repos.order_by_issue_count.page(valid_params[:page]).per_page(valid_params[:per_page] || 50)
69+
70+
topic_repo_ids = @topic_repos.map { |repo| repo.id }
71+
72+
if user_signed_in?
73+
@repos_subs = current_user.repo_subscriptions.page(valid_params[:page]).per_page(valid_params[:per_page] || 50).includes(:repo)
74+
@repos_subs = @repos_subs.where(repo_id: topic_repo_ids)
75+
end
76+
77+
respond_to do |format|
78+
format.html {}
79+
format.json do
80+
htmlForPage = render_to_string(partial: "repos_with_pagination", locals: { repos: @repos }, formats: ['html'])
81+
render json: { html: htmlForPage }.to_json
82+
end
83+
end
84+
end
85+
5486
private
5587

5688
def description

app/views/pages/topic.html.slim

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
.hero
2+
h1.hero-title-primary Topic: #{params["topic"]}
3+
4+
- unless user_signed_in?
5+
= link_to user_github_omniauth_authorize_path, class: 'button', method: :post
6+
| Sign up with GitHub
7+
8+
hr.section-break
9+
10+
- if @repos_subs.present?
11+
.repos-list-wrapper
12+
h2.repos-list-title Repos you are currently helping
13+
.hero-repo-list-container
14+
= render 'repo_subscriptions/list', repos_subs: @repos_subs
15+
16+
hr.section-break
17+
18+
.repos-list-wrapper
19+
h2.repos-list-title Open source projects on GitHub that need your help.
20+
21+
section.repo-list-with-pagination
22+
= render "repos_with_pagination", repos: @repos

config/routes.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828

2929
root to: "pages#index"
3030

31+
get "/topics/:topic", to: "pages#topic"
32+
3133
get 'what' => "pages#what"
3234
get 'privacy' => "pages#privacy"
3335
get 'support' => 'pages#support'

0 commit comments

Comments
 (0)