Skip to content

Commit

Permalink
Merge pull request #1795 from avcwisesa/topics_view
Browse files Browse the repository at this point in the history
View For hacktoberfest labeled repo
  • Loading branch information
schneems authored Oct 13, 2023
2 parents bb79e95 + 7bc8db2 commit e164a72
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 0 deletions.
37 changes: 37 additions & 0 deletions app/controllers/pages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,43 @@ def index
end
end

def topic
topic_name = params['topic']

if not ['hacktoberfest'].include?(topic_name)
redirect_back fallback_location: root_path
return
end

set_title("Open Source Project Topic: #{topic_name}")
set_description(description)

label = Label.find_by(name: topic_name)

@repos = Repo.with_some_issues
.includes(:repo_labels)
.where(repo_labels: { label_id: label.id })
.select(:id, :updated_at, :issues_count, :language, :full_name, :name, :description)

topic_repo_ids = @repos.map { |repo| repo.id }

@repos = @repos.without_user_subscriptions(current_user.id) if user_signed_in?
@repos = @repos.order_by_issue_count.page(valid_params[:page]).per_page(valid_params[:per_page] || 50)

if user_signed_in?
@repos_subs = current_user.repo_subscriptions.page(valid_params[:page]).per_page(valid_params[:per_page] || 50).includes(:repo)
@repos_subs = @repos_subs.where(repo_id: topic_repo_ids)
end

respond_to do |format|
format.html {}
format.json do
htmlForPage = render_to_string(partial: "repos_with_pagination", locals: { repos: @repos }, formats: ['html'])
render json: { html: htmlForPage }.to_json
end
end
end

private

def description
Expand Down
25 changes: 25 additions & 0 deletions app/views/application/_nav.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,40 @@ nav.application-navigation
li.application-navigation-list-item= image_tag current_user.avatar_url, class: 'user-profile-image', alt: 'user avatar'
li.application-navigation-list-item= link_to current_user.github, current_user
li.application-navigation-list-item= link_to 'University', university_index_path
li.application-navigation-list-item
div.dropdown
= content_tag 'a', 'Topics'
div.dropdown-content
=link_to 'Hacktoberfest', '/topics/hacktoberfest'
li.application-navigation-list-item= link_to "Submit Repo", new_repo_path
li.application-navigation-list-item= link_to "Sign Out", destroy_user_session_path, method: :delete
- else
li.application-navigation-list-item= link_to 'About', what_path
li.application-navigation-list-item= link_to 'University', university_index_path
li.application-navigation-list-item
div.dropdown
= content_tag 'a', 'Topics'
div.dropdown-content
=link_to 'Hacktoberfest', '/topics/hacktoberfest'
li.application-navigation-list-item= link_to 'Log in', user_github_omniauth_authorize_path, method: :post
li.application-navigation-list-item= link_to 'Sign Up', user_github_omniauth_authorize_path, method: :post

div.application-logo
= link_to root_path
span.application-logo-image
span.hide-visually Code Triage Home


scss class="class":

.dropdown:hover .dropdown-content {
display: block;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}
22 changes: 22 additions & 0 deletions app/views/pages/topic.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
.hero
h1.hero-title-primary Topic: #{params["topic"]}

- unless user_signed_in?
= link_to user_github_omniauth_authorize_path, class: 'button', method: :post
| Sign up with GitHub

hr.section-break

- if @repos_subs.present?
.repos-list-wrapper
h2.repos-list-title Repos you are currently helping
.hero-repo-list-container
= render 'repo_subscriptions/list', repos_subs: @repos_subs

hr.section-break

.repos-list-wrapper
h2.repos-list-title Open source projects on GitHub that need your help.

section.repo-list-with-pagination
= render "repos_with_pagination", repos: @repos
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

root to: "pages#index"

get "/topics/:topic", to: "pages#topic"

get 'what' => "pages#what"
get 'privacy' => "pages#privacy"
get 'support' => 'pages#support'
Expand Down
5 changes: 5 additions & 0 deletions test/functional/pages_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,9 @@ class PagesControllerTest < ActionController::TestCase
assert_equal("no-cache", response.headers["Pragma"])
assert_equal("Fri, 01 Jan 1990 00:00:00 GMT", response.headers["Expires"])
end

test "redirect invalid topic" do
get :topic, params: { topic: 'test' }
assert_redirected_to root_url
end
end

0 comments on commit e164a72

Please sign in to comment.