Skip to content

Commit

Permalink
migrated to pagy for question related resources (publiclab#8445)
Browse files Browse the repository at this point in the history
  • Loading branch information
tyler-wel authored and lagunasmel committed Mar 2, 2021
1 parent 06131d3 commit 6c03dab
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
20 changes: 8 additions & 12 deletions app/controllers/questions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,16 @@ def filter_questions_by_tag(questions, tagnames)
def index
@title = 'Questions and Answers'
set_sidebar
@questions = Node.questions
@pagy, @questions = pagy(Node.questions
.where(status: 1)
.order('node.nid DESC')
.paginate(page: params[:page], per_page: 24)
.order('node.nid DESC'), items: 24)
end

def index_shadow
@title = 'Questions and Answers'
@questions = Node.questions
@pagy, @questions = pagy(Node.questions
.where(status: 1)
.order('node.nid DESC')
.paginate(page: params[:page], per_page: 24)
.order('node.nid DESC'), items: 24)

@populartitle = 'Popular Questions'
@popularquestions = Node.questions
Expand Down Expand Up @@ -95,11 +93,10 @@ def answered
@title = 'Recently Commented'
@questions = Node.questions
.where(status: 1)
@questions = filter_questions_by_tag(@questions, params[:tagnames])
@pagy, @questions = pagy(filter_questions_by_tag(@questions, params[:tagnames])
.joins(:comments)
.order('comments.timestamp DESC')
.group('node.nid')
.paginate(page: params[:page], per_page: 24)
.group('node.nid'), items: 24)
@wikis = Node.limit(10)
.where(type: 'page', status: 1)
.order('nid DESC')
Expand All @@ -108,13 +105,12 @@ def answered

def unanswered
@title = 'Unanswered questions'
@questions = Node.questions
@pagy, @questions = pagy(Node.questions
.where(status: 1)
.left_outer_joins(:comments)
.where(comments: { cid: nil })
.order('node.nid DESC')
.group('node.nid')
.paginate(page: params[:page], per_page: 24)
.group('node.nid'), items: 24)
render template: 'questions/index'
end

Expand Down
4 changes: 2 additions & 2 deletions app/views/questions/_new_question.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<% questions = questions || @questions # accept local if present, default to instance %>
<div id="notes">
<div class="row">
<div class="row">
<% questions.each_with_index do |node,i| %>
<div class="<% if @widget %>col-4 <% end %>col-lg-4 note note-container-question" style="margin-top:20px;">
<div class="card">
Expand Down Expand Up @@ -110,7 +110,7 @@
<% if @pagy %>
<%== pagy_bootstrap_nav @pagy %>
<% else %>
<%= will_paginate questions, :renderer => WillPaginate::ActionView::BootstrapLinkRenderer unless @unpaginated || questions.empty? %>
<%= will_paginate questions, :renderer => WillPaginate::ActionView::BootstrapLinkRenderer unless @unpaginated || questions.empty? %>
<% end %>
</div>

Expand Down
8 changes: 7 additions & 1 deletion app/views/questions/_questions.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,10 @@
<% end %>
<% end %>
</div>
<div class="text-center mt-3"><%= will_paginate questions, :renderer => WillPaginate::ActionView::BootstrapLinkRenderer unless @unpaginated || questions.empty? %></div>
<div class="text-center mt-3">
<% if @pagy %>
<%== pagy_bootstrap_nav @pagy %>
<% else %>
<%= will_paginate questions, :renderer => WillPaginate::ActionView::BootstrapLinkRenderer unless @unpaginated || questions.empty? %>
<% end %>
</div>

0 comments on commit 6c03dab

Please sign in to comment.