-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement questions answered vs questions asked #4256
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
module QuestionsHelper | ||
SORTING_OPTIONS = %w(All Week Month Year).freeze | ||
|
||
def filtering(period) | ||
return if period.nil? | ||
|
||
if period == 'All' | ||
Rails.cache.fetch("all_stats", expires_in: 1.days) do | ||
@asked = Node.questions.to_a.size | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think if you use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jywarren tried |
||
@answered = Answer.all.map(&:node).uniq.size | ||
"#{@asked} questions asked and #{@answered} questions answered" | ||
end | ||
else | ||
Rails.cache.fetch("#{period}_stats", expires_in: 1.days) do | ||
@asked = Node.questions.where('created >= ?', 1.send(period.downcase).ago.to_i).to_a.size | ||
@answered = Answer.where("created_at >= ?", 1.send(period.downcase).ago).map(&:node).uniq.size | ||
"#{@asked} questions asked and #{@answered} questions answered in the past #{period}" | ||
end | ||
end | ||
end | ||
|
||
def options | ||
SORTING_OPTIONS | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,14 @@ | ||
<div class="col-md-12"> | ||
<div class ="row"> | ||
<div class="col-md-6" > | ||
<h4><b> <%= @stats if params[:period].present? %></b></h4> | ||
</div> | ||
<div class="col-md-4"> | ||
<%= form_tag request.url, :method => 'get' do %> | ||
<%= select_tag :period, options_for_select(options),onchange: "this.form.submit();", include_blank: "Filter stats", class: "form-control"%> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ooh this is cool, could you share a screenshot? Thanks! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jywarren a screenshot is ☝️ above. Thanks for the feedback. |
||
<% end %> | ||
</div> | ||
</div> | ||
|
||
<% if params[:action] == 'answered' %> | ||
<h2>Recently Answered <small class="hidden-sm">Recently answered questions</small></h2> | ||
|
@@ -14,7 +24,7 @@ | |
<%= feature('questions-header') %> | ||
<% end %> | ||
</div> | ||
<% end %> | ||
<% end %> | ||
|
||
<hr /> | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good but perhaps it could have a more descriptive name -- something describing how it's related to stats, or Q&A? Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, I'd love to see a simple test for these methods. Where would that live?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me try and figure out where the tests will go. Thanks