Skip to content

Commit a918e5f

Browse files
committed
add online kits display for users
1 parent 85b3597 commit a918e5f

3 files changed

Lines changed: 15 additions & 0 deletions

File tree

app/models/user.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,13 @@ def time_zone
155155
preferred_time_zone && ActiveSupport::TimeZone[preferred_time_zone] || ActiveSupport::TimeZone["Etc/UTC"]
156156
end
157157

158+
def all_devices_online?
159+
devices.all? { |d| d.online? }
160+
end
161+
162+
def online_device_count
163+
devices.filter { |d| d.online? }.length
164+
end
158165
private
159166

160167
def check_if_users_have_valid_email

app/views/ui/users/_meta.html.erb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,9 @@
1010
<%= link_to(user.url, user.url, class: "link-white") %>
1111
</p>
1212
<% end %>
13+
<% if user.devices.length > 0 %>
14+
<p class="mb-0 device-status <%= user.all_devices_online? ? "online" : "offline" %>">
15+
<span class="pe-1"><%= show_svg("status_icon.svg") %></span>
16+
<strong><%= pluralize(user.devices.length, t(:user_meta_device_noun)) %> (<%= user.online_device_count %> <%= t(:user_meta_online_adjective) %>)</strong>
17+
</p>
18+
<% end %>

config/locales/views/users/en.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,5 @@ en:
4444
no_experiment_cta_blurb: "Experiments let you manage multiple Smart Citizen kits in one place, and compare their readings."
4545
no_experiment_link_text: "Create your first experiment"
4646
profile_image_alt: "Profile picture for user %{username}"
47+
user_meta_device_noun: "kit"
48+
user_meta_online_adjective: "online"

0 commit comments

Comments
 (0)