Skip to content

View stats for Protip cards - WIP #290 #116

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

Merged
merged 1 commit into from
Jul 26, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion app/helpers/protips_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ def formatted_best_stat_value(protip)
value =
case best_stat_name(protip).to_sym
when :views
best_stat_value(protip) * Protip::COUNTABLE_VIEWS_CHUNK
views_stat_value(protip)
else
best_stat_value(protip)
end
Expand Down Expand Up @@ -348,4 +348,17 @@ def default_featured_job_banner
def protip_display_mode
mobile_device? ? "fullpage" : "popup"
end

def views_stat_value(protip)
best_stat_value(protip) * Protip::COUNTABLE_VIEWS_CHUNK
end

def display_protip_stats?(protip)
stat_name = best_stat_name(protip)
# if stat is present, and the stat we're displaying is views over 50, display.
# otherwise, we're showing stats for something other than views.
return true if protip.best_stat.present? && stat_name == :views && views_stat_value(protip) > 50
return true if protip.best_stat.present? && stat_name != :views
return false
end
end
4 changes: 2 additions & 2 deletions app/views/protips/_mini.html.haml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
- protip = protip.load #this is simply a hack, fix ES indexed json
%article{:class => dom_class(protip), :id => protip.public_id}
%header
-unless protip.best_stat.nil? || best_stat_value(protip) == 0
-if display_protip_stats?(protip)
%header
%span{:class => protip_stat_class(protip)}
= formatted_best_stat_value(protip) unless best_stat_name(protip) =~ /hawt/

Expand Down