Skip to content

Commit c04dea9

Browse files
committed
Merge pull request #116 from Mileshosky/feature/protip-stats
View stats for Protip cards - WIP #290
2 parents 6718249 + 3c28d3b commit c04dea9

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

app/helpers/protips_helper.rb

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ def formatted_best_stat_value(protip)
298298
value =
299299
case best_stat_name(protip).to_sym
300300
when :views
301-
best_stat_value(protip) * Protip::COUNTABLE_VIEWS_CHUNK
301+
views_stat_value(protip)
302302
else
303303
best_stat_value(protip)
304304
end
@@ -348,4 +348,17 @@ def default_featured_job_banner
348348
def protip_display_mode
349349
mobile_device? ? "fullpage" : "popup"
350350
end
351+
352+
def views_stat_value(protip)
353+
best_stat_value(protip) * Protip::COUNTABLE_VIEWS_CHUNK
354+
end
355+
356+
def display_protip_stats?(protip)
357+
stat_name = best_stat_name(protip)
358+
# if stat is present, and the stat we're displaying is views over 50, display.
359+
# otherwise, we're showing stats for something other than views.
360+
return true if protip.best_stat.present? && stat_name == :views && views_stat_value(protip) > 50
361+
return true if protip.best_stat.present? && stat_name != :views
362+
return false
363+
end
351364
end

app/views/protips/_mini.html.haml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
- protip = protip.load #this is simply a hack, fix ES indexed json
22
%article{:class => dom_class(protip), :id => protip.public_id}
3-
%header
4-
-unless protip.best_stat.nil? || best_stat_value(protip) == 0
3+
-if display_protip_stats?(protip)
4+
%header
55
%span{:class => protip_stat_class(protip)}
66
= formatted_best_stat_value(protip) unless best_stat_name(protip) =~ /hawt/
77

0 commit comments

Comments
 (0)