Skip to content

Commit

Permalink
refactored questions/answered page (#5478)
Browse files Browse the repository at this point in the history
* refactored questions/answered page

* minor tweaks in tests
  • Loading branch information
ViditChitkara authored and jywarren committed May 31, 2019
1 parent fbe6111 commit faf66c0
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 22 deletions.
6 changes: 3 additions & 3 deletions app/controllers/questions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@ def show
end

def answered
@title = 'Recently answered'
@title = 'Recently Commented'
@questions = Node.questions
.where(status: 1)
@questions = filter_questions_by_tag(@questions, params[:tagnames])
.joins(:answers)
.order('answers.created_at DESC')
.joins(:comments)
.order('comments.timestamp DESC')
.group('node.nid')
.paginate(page: params[:page], per_page: 24)
@wikis = Node.limit(10)
Expand Down
6 changes: 0 additions & 6 deletions app/views/dashboard/_node_question.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,6 @@
<% end %>

<h4><a href="<%= node.path(:question) %>"><%= node.title %></a></h4>

<% if node.answers.collect(&:accepted).include?(true) %>
<p><span class="badge accepted">Answered</span></p>
<% end %>

<a href="<%= node.path(:question) %>#post-answer" class="btn btn-outline-secondary btn-sm float-right respond answer"><%= t('dashboard._node_question.post_answer') %></a>

<p class="meta"><%= t('dashboard._node_question.question') %> <%= render partial: "dashboard/node_meta", locals: { node: node } %></p>

Expand Down
7 changes: 0 additions & 7 deletions app/views/questions/_questions.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,11 @@
<h4><a <% if @widget %>target="_blank"<% end %> href="<%= node.path(:question) %>"><%= node.title %></a></h4>
<% if node.answers.collect(&:accepted).include?(true) %>
<p><span class="label accepted">Answered</span></p>
<% end %>
<span id="tags">
<% node.tags.limit(4).each do |tag| %>
<span id="tag_<%= tag.id %>" ><a class="badge badge-primary" href="/questions/tag/<%= tag.name %>"><%= tag.name %></a></span>
<% end %>
</span>
<a href="<%= node.path(:question) %>#post-answer" class="btn btn-outline-secondary btn-sm">Post an answer</a></p>
<p class="meta">asked <%= render partial: "dashboard/node_meta", locals: { node: node } %></p>
</div>
</div>
Expand Down
8 changes: 4 additions & 4 deletions app/views/questions/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div class="col-lg-12">

<% if params[:action] == 'answered' %>
<h2>Recently Answered <small class="d-md-none d-lg-inline">Recently answered questions</small></h2>
<h2>Recently Commented <small class="d-md-none d-lg-inline">Recently commented questions</small></h2>
<% elsif params[:action] == 'popular' %>
<h2>Popular Questions <small class="d-md-none d-lg-inline">Most viewed questions</small></h2>
<% elsif params[:action] == 'unanswered' %>
Expand Down Expand Up @@ -53,9 +53,9 @@
<i class="fa fa-refresh"></i> <span class="d-none d-lg-inline"> Recently Asked</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link <% if params[:action] == "answered" %> active <% end %>" href="/questions/answered/">
<i class="fa fa-check"></i> <span class="d-none d-lg-inline"> Recently Answered</span>
<li<% if params[:action] == "answered" %> class="active"<% end %>>
<a href="/questions/answered/">
<i class="fa fa-check"></i> <span class="d-none d-lg-inline"> Recently Commented</span>
</a>
</li>
<li class="nav-item">
Expand Down
2 changes: 1 addition & 1 deletion test/functional/questions_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def setup
test 'should get answered' do
get :answered
assert_response :success
assert_equal assigns(:title), 'Recently answered'
assert_equal assigns(:title), 'Recently Commented'
assert_not_nil assigns(:questions)
assert_template :index
end
Expand Down
1 change: 0 additions & 1 deletion test/integration/I18n_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ class I18nTest < ActionDispatch::IntegrationTest
status: 1
}
get '/dashboard'
assert_select 'a[class=?]', 'btn btn-outline-secondary btn-sm float-right respond answer', I18n.t('dashboard._node_question.post_answer')
end
end

Expand Down

0 comments on commit faf66c0

Please sign in to comment.