Add view count to video items

This commit is contained in:
Omar Roth 2019-04-14 17:43:44 -05:00
parent efe86c37b2
commit b51fd7fc13
13 changed files with 28 additions and 16 deletions

View file

@ -189,7 +189,9 @@ def number_to_short_text(number)
text = text.rchop(".0")
if number / 1000000 != 0
if number / 1_000_000_000 != 0
text += "B"
elsif number / 1_000_000 != 0
text += "M"
elsif number / 1000 != 0
text += "K"

View file

@ -71,7 +71,12 @@
<% if item.responds_to?(:premiere_timestamp) && item.premiere_timestamp && item.premiere_timestamp.not_nil! > Time.now %>
<h5><%= translate(locale, "Premieres in `x`", recode_date((item.premiere_timestamp.as(Time) - Time.now).ago, locale)) %></h5>
<% elsif Time.now - item.published > 1.minute %>
<h5><%= translate(locale, "Shared `x` ago", recode_date(item.published, locale)) %></h5>
<h5 class="pure-g">
<div class="pure-u-2-3"><%= translate(locale, "Shared `x` ago", recode_date(item.published, locale)) %></div>
<div class="pure-u-1-3" style="text-align: right">
<%= item.responds_to?(:views) ? translate(locale, "`x` views", number_to_short_text(item.views)) : "" %>
</div>
</h5>
<% end %>
<% else %>
<% if env.get("preferences").as(Preferences).thin_mode %>
@ -108,7 +113,12 @@
<% if item.responds_to?(:premiere_timestamp) && item.premiere_timestamp && item.premiere_timestamp.not_nil! > Time.now %>
<h5><%= translate(locale, "Premieres in `x`", recode_date((item.premiere_timestamp.as(Time) - Time.now).ago, locale)) %></h5>
<% elsif Time.now - item.published > 1.minute %>
<h5><%= translate(locale, "Shared `x` ago", recode_date(item.published, locale)) %></h5>
<h5 class="pure-g">
<div class="pure-u-2-3"><%= translate(locale, "Shared `x` ago", recode_date(item.published, locale)) %></div>
<div class="pure-u-1-3" style="text-align: right">
<%= item.responds_to?(:views) ? translate(locale, "`x` views", number_to_short_text(item.views)) : "" %>
</div>
</h5>
<% end %>
<% end %>
</div>