Skip to content

Commit e164a72

Browse files
authored
Merge pull request codetriage#1795 from avcwisesa/topics_view
View For hacktoberfest labeled repo
2 parents bb79e95 + 7bc8db2 commit e164a72

File tree

5 files changed

+91
-0
lines changed

5 files changed

+91
-0
lines changed

app/controllers/pages_controller.rb

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

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

5693
def description

app/views/application/_nav.html.slim

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,40 @@ nav.application-navigation
1212
li.application-navigation-list-item= image_tag current_user.avatar_url, class: 'user-profile-image', alt: 'user avatar'
1313
li.application-navigation-list-item= link_to current_user.github, current_user
1414
li.application-navigation-list-item= link_to 'University', university_index_path
15+
li.application-navigation-list-item
16+
div.dropdown
17+
= content_tag 'a', 'Topics'
18+
div.dropdown-content
19+
=link_to 'Hacktoberfest', '/topics/hacktoberfest'
1520
li.application-navigation-list-item= link_to "Submit Repo", new_repo_path
1621
li.application-navigation-list-item= link_to "Sign Out", destroy_user_session_path, method: :delete
1722
- else
1823
li.application-navigation-list-item= link_to 'About', what_path
1924
li.application-navigation-list-item= link_to 'University', university_index_path
25+
li.application-navigation-list-item
26+
div.dropdown
27+
= content_tag 'a', 'Topics'
28+
div.dropdown-content
29+
=link_to 'Hacktoberfest', '/topics/hacktoberfest'
2030
li.application-navigation-list-item= link_to 'Log in', user_github_omniauth_authorize_path, method: :post
2131
li.application-navigation-list-item= link_to 'Sign Up', user_github_omniauth_authorize_path, method: :post
2232

2333
div.application-logo
2434
= link_to root_path
2535
span.application-logo-image
2636
span.hide-visually Code Triage Home
37+
38+
39+
scss class="class":
40+
41+
.dropdown:hover .dropdown-content {
42+
display: block;
43+
}
44+
.dropdown-content {
45+
display: none;
46+
position: absolute;
47+
background-color: #f9f9f9;
48+
min-width: 160px;
49+
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
50+
z-index: 1;
51+
}

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'

test/functional/pages_controller_test.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,9 @@ class PagesControllerTest < ActionController::TestCase
2626
assert_equal("no-cache", response.headers["Pragma"])
2727
assert_equal("Fri, 01 Jan 1990 00:00:00 GMT", response.headers["Expires"])
2828
end
29+
30+
test "redirect invalid topic" do
31+
get :topic, params: { topic: 'test' }
32+
assert_redirected_to root_url
33+
end
2934
end

0 commit comments

Comments
 (0)