Skip to content

Commit 94ce188

Browse files
committed
yellow status for uses and experiments with partially online devices
1 parent d8bfd70 commit 94ce188

9 files changed

Lines changed: 37 additions & 7 deletions

File tree

app/assets/stylesheets/bootstrap_variables.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ $green: #00E597;
3333
$teal: #2CB5AE;
3434
$yellow: #FFC100;
3535

36+
$darker-yellow: #CC9900;
37+
3638
$primary: $yellow;
3739
$info: $purple;
3840

app/assets/stylesheets/global.scss

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,16 @@ a.subtle-link {
318318
fill: $green;
319319
}
320320

321+
&.partially-online {
322+
color: $yellow;
323+
fill: $yellow;
324+
}
325+
326+
.darker &.partially-online {
327+
color: $darker-yellow;
328+
fill: $darker-yellow;
329+
}
330+
321331
&.offline {
322332
color: $red;
323333
fill: $red;

app/helpers/application_helper.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,16 @@ def flash_class(level)
1414
end
1515
end
1616

17+
def device_collection_status_class(container)
18+
if container.all_devices_online?
19+
"online"
20+
elsif container.all_devices_offline?
21+
"offline"
22+
else
23+
"partially-online"
24+
end
25+
end
26+
1727
def local_time_zone
1828
current_user&.time_zone || ActiveSupport::TimeZone["Etc/UTC"]
1929
end

app/models/experiment.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,14 @@ def components_for_measurement(measurement)
4141
}.uniq
4242
end
4343

44-
def all_online?
44+
def all_devices_online?
4545
devices.all? { |d| d.online? }
4646
end
4747

48+
def all_devices_offline?
49+
devices.all? { |d| !d.online? }
50+
end
51+
4852
def online_device_count
4953
devices.filter { |d| d.online? }.length
5054
end

app/models/user.rb

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

158-
def any_devices_online?
159-
devices.any? { |d| d.online? }
158+
def all_devices_online?
159+
devices.all? { |d| d.online? }
160+
end
161+
162+
def all_devices_offline?
163+
devices.all? { |d| !d.online? }
160164
end
161165

162166
def online_device_count

app/views/ui/devices/_device.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<%= render partial: "ui/shared/map", locals: { points: [{lat: device.latitude, lng: device.longitude}] } %>
88
<% end %>
99
</div>
10-
<div class="col-12 col-md-9 p-3 pb-4">
10+
<div class="col-12 col-md-9 p-3 pb-4 darker">
1111
<h3 class="mb-1 text-break"><%= device.name %></h3>
1212
<%= render partial: "ui/devices/meta", locals: { device: device, hide_owner: local_assigns[:hide_owner] } %>
1313
<% if local_assigns[:with_actions] %>

app/views/ui/experiments/_experiment.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
}
1212
%>
1313
</div>
14-
<div class="col-12 col-md-9 p-3 pb-4">
14+
<div class="col-12 col-md-9 p-3 pb-4 darker">
1515
<h3 class="mb-1 text-break"><%= experiment.name %></h3>
1616
<%= render partial: "ui/experiments/meta", locals: { experiment: experiment, hide_owner: local_assigns[:hide_owner] } %>
1717
<% if local_assigns[:with_actions] %>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<p class="mb-0 device-status <%= experiment.all_online? ? "online" : "offline" %>">
1+
<p class="mb-0 device-status <%= device_collection_status_class(experiment) %>">
22
<span class="pe-1"><%= show_svg("status_icon.svg") %></span>
33
<strong><%= pluralize(experiment.devices.length, t(:experiment_meta_device_noun)) %> (<%= experiment.online_device_count %> <%= t(:experiment_meta_online_adjective) %>)</strong>
44
</p>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<%= link_to(user.url, user.url, class: "link-white") %>
1111
</p>
1212
<% end %>
13-
<p class="mb-0 device-status <%= user.any_devices_online? ? "online" : "offline" %>">
13+
<p class="mb-0 device-status <%= device_collection_status_class(user) %>">
1414
<span class="pe-1"><%= show_svg("status_icon.svg") %></span>
1515
<strong>
1616
<%= pluralize(user.devices.length, t(:user_meta_device_noun)) %>

0 commit comments

Comments
 (0)