Skip to content

Commit

Permalink
add tab buttons to tag_pages (publiclab#2385)
Browse files Browse the repository at this point in the history
  • Loading branch information
noordean authored and jywarren committed Feb 23, 2018
1 parent 4b0e82c commit ac942f1
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 5 deletions.
6 changes: 5 additions & 1 deletion app/controllers/tag_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def show
@wildcard = true
@tags = Tag.where('name LIKE (?)', params[:id][0..-2] + '%')
nodes = Node.where(status: 1, type: node_type)
.includes(:revision, :tag)
.includes(:revision, :tag, :answers)
.references(:term_data, :node_revisions)
.where('term_data.name LIKE (?) OR term_data.parent LIKE (?)', params[:id][0..-2] + '%', params[:id][0..-2] + '%')
.paginate(page: params[:page], per_page: 24)
Expand All @@ -104,6 +104,10 @@ def show

@notes = nodes.where('node.nid NOT IN (?)', qids) if @node_type == 'note'
@questions = nodes.where('node.nid IN (?)', qids) if @node_type == 'questions'
@answered_questions = []
if @questions
@questions.each { |question| @answered_questions << question if question.answers.any? { |answer| answer.accepted } }
end
@wikis = nodes if @node_type == 'wiki'
@nodes = nodes if @node_type == 'maps'
@title = params[:id]
Expand Down
25 changes: 23 additions & 2 deletions app/views/tag/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,24 @@
<% if @node_type == "questions" %>
<div class="tab-pane active" id="questions">
<%= render :partial => "questions/questions" %>
<div class="tab-pane" id="questions-tab">
<div class="btn-group text-center">
<a href="#asked-tab" class="btn btn-default active" data-toggle="tab">Asked</a>
<a href="#answered-tab" class="btn btn-default" data-toggle="tab">Answered</a>
</div>

<div class="tab-content">
<div class="tab-pane active" id="asked-tab">
<%= render :partial => "questions/questions" %>
</div>

<div class="tab-pane" id="answered-tab">
<% if @answered_questions %>
<%= render :partial => "users/answered" %>
<% end %>
</div>
</div>
</div>
</div>
<% end %>
Expand Down Expand Up @@ -130,7 +147,11 @@
<hr />

</div>

<script type="text/javascript">
$('#questions .btn-group .btn').click(function(){
$(this).addClass('active').siblings().removeClass('active');
});
</script>
</div>
<%= stylesheet_link_tag "dashboard" %>
<%= javascript_include_tag "dashboard" %>
4 changes: 2 additions & 2 deletions app/views/users/_answered.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div id="answered-question">
<div class="row">
<% @answered_questions.each_with_index do |question,i| %>
<% answers = question.answers.where(uid: @user.uid) %>
<% answers = if @user then question.answers.where(uid: @user.uid) else question.answers end %>
<div class="col-md-4" style="margin-top:30px;">
<div class="note note-pane note-answer">
<div class="header-icon"><i class="fa fa-question-circle"></i></div>
Expand All @@ -13,7 +13,7 @@
<a href="/profile/<%= question.author.name %>"><%= question.author.name %></a>
asked about <span style="color:#888;"><%= time_ago_in_words(question.created_at) %> ago</span>
</p>
<div class="text-center"><span id="question-<%= question.nid %>-toggle" class="btn btn-default btn-xs">Answers by <%= @user.name %><i class="fa fa-caret-down"></i></span></div>
<div class="text-center"><span id="question-<%= question.nid %>-toggle" class="btn btn-default btn-xs">Answers <%= if @user then "by #{@user.name}" end %><i class="fa fa-caret-down"></i></span></div>
<div id="question-<%= question.nid %>" class="user-answer">
<% answers.each do |answer| %>
<p>answered on <a href="<%= question.path(:question) %>#a<%= answer.id %>" style="color:#888;"><%= answer.created_at.strftime("%b %d, %Y") %></a><span class="pull-right"><% if answer.accepted %><i class="fa fa-check-square" style="color: #1fa67a;"></i> <% end %><i class="fa fa-star" style="color: #FFEB3B;"></i> <%= answer.likers.length %></span></p>
Expand Down
13 changes: 13 additions & 0 deletions test/functional/tag_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,19 @@ def setup
assert_select '#note-graph', 0
end

test 'wildcard tag should list answered questions' do
get :show, id: 'question:*'

assert_not_nil assigns(:answered_questions)
end

test 'wildcard tag should have a active asked and an inactive answered tab for question' do
get :show, id: 'question:*'

assert_select '#asked-tab.active', 1
assert_select '#answered-tab', 1
end

test "wildcard tag show wiki pages with author" do
get :show_for_author, node_type: 'wiki', id: 'awes*', author: 'Bob'
assert :success
Expand Down

0 comments on commit ac942f1

Please sign in to comment.