Skip to content

Commit

Permalink
beginnings of device profile w/ reusable maps and metadata components
Browse files Browse the repository at this point in the history
  • Loading branch information
timcowlishaw committed Dec 17, 2024
1 parent b7f1b0b commit 6d40923
Show file tree
Hide file tree
Showing 12 changed files with 53 additions and 27 deletions.
1 change: 1 addition & 0 deletions app/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@
@import "device";
@import "components/profile_header";
@import "components/copyable_input";
@import "components/device_map";
4 changes: 4 additions & 0 deletions app/assets/stylesheets/components/device_map.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.device-map {
width: 100%;
height: 100%;
}
10 changes: 9 additions & 1 deletion app/assets/stylesheets/components/profile_header.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
.user-profile-header {
.profile-header {
h1 {
line-height: 1.6rem !important;
padding-bottom: 0.4rem !important;
}

a {
color: $white !important;
text-decoration: underline;
&:hover {
text-decoration: none;
}
}
}
2 changes: 0 additions & 2 deletions app/assets/stylesheets/device.scss
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
}

.device-map {
width:100%;
height: 100%;
aspect-ratio: 1.66;
}

Expand Down
2 changes: 2 additions & 0 deletions app/controllers/ui/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ class ApplicationController < ActionController::Base
layout "application"
include SharedControllerMethods

include UserHelper

def add_breadcrumbs(*crumbs)
crumbs.each do |crumb|
add_breadcrumb(*crumb)
Expand Down
5 changes: 4 additions & 1 deletion app/controllers/ui/devices_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ class DevicesController < ApplicationController
def show
find_device!
@title = I18n.t(:show_device_title, name: @device.name)
add_breadcrumb(@title, ui_device_path(@device.id))
add_breadcrumbs(
[I18n.t(:show_user_title, owner: possessive(@device.owner, current_user)), ui_user_path(@device.owner.username)],
[@title, ui_device_path(@device.id)]
)
render "show", layout: "base"
end

Expand Down
20 changes: 2 additions & 18 deletions app/views/ui/devices/_device.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,10 @@
<span class="sr-only"><%= device.name %></span>
<% end %>
<div class="col-12 col-md-3">
<div class="device-map" data-latitude="<%= device.latitude %>" data-longitude="<%= device.longitude %>" data-marker-url="<%= asset_url("map-pin.svg") %>" data-marker-shadow-url="<%= asset_url("map-pin-shadow.png") %>"></div>
<%= render partial: "ui/devices/map", locals: { device: device} %>
</div>
<div class="col-12 col-md-9 p-3 pb-4">
<h3 class="mb-1"><%= device.name %></h3>
<p class="mb-0 small"><strong><%= device.hardware_name %></strong></p>
<p class="mb-0 small">
<%= image_tag("location_icon.svg", class: "pe-1") %>
<%= [device.city, device.country_name].compact.join(", ") %>
</p>
<p class="mb-0 small">
<%= image_tag("clock-fill.svg", class: "pe-1") %>
<% if device.last_reading_at %>
<%= t :device_last_reading_at, time: time_ago_in_words(device.last_reading_at) %>
<% else %>
<%= t :device_no_readings_message %>
<% end %>
</p>
<p class="mb-0 small">
<%= image_tag("tag_icon.svg", class: "pe-1") %>
<%= device.all_tags.join(", ") %>
</p>
<%= render partial: "ui/devices/meta", locals: { device: device, hide_owner: local_assigns[:hide_owner] } %>
</div>
</div>
1 change: 1 addition & 0 deletions app/views/ui/devices/_map.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div class="device-map" data-latitude="<%= device.latitude %>" data-longitude="<%= device.longitude %>" data-marker-url="<%= asset_url("map-pin.svg") %>" data-marker-shadow-url="<%= asset_url("map-pin-shadow.png") %>"></div>
23 changes: 23 additions & 0 deletions app/views/ui/devices/_meta.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<p class="mb-0 small"><strong><%= device.hardware_name %></strong></p>
<% unless local_assigns[:hide_owner] %>
<p class="mb-0 small">
<span class="pe-1"><%= show_svg("user_details_icon_light.svg") %></span>
<%= link_to(device.owner.username, ui_user_path(device.owner.username)) %>
</p>
<% end %>
<p class="mb-0 small">
<span class="pe-1"><%= show_svg("location_icon.svg") %></span>
<%= [device.city, device.country_name].compact.join(", ") %>
</p>
<p class="mb-0 small">
<span class="pe-1"><%= show_svg("clock-fill.svg") %></span>
<% if device.last_reading_at %>
<%= t :device_meta_last_reading_at, time: time_ago_in_words(device.last_reading_at) %>
<% else %>
<%= t :device_meta_no_readings_message %>
<% end %>
</p>
<p class="mb-0 small">
<span class="pe-1"><%= show_svg("tag_icon.svg") %></span>
<%= device.all_tags.join(", ") %>
</p>
6 changes: 4 additions & 2 deletions app/views/ui/devices/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<% content_for :profile_header_image do %>
IMAGE
<div class="circular-image-crop">
<%= render partial: "ui/devices/map", locals: { device: @device } %>
</div>
<% end %>
<% content_for :profile_header_meta do %>
META
<%= render partial: "ui/devices/meta", locals: { device: @device } %>
<% end %>
<% content_for :profile_header_actions do %>
ACTIONS
Expand Down
2 changes: 1 addition & 1 deletion app/views/ui/users/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<% end %>
<% end %>
</div>
<%= render partial: "ui/devices/device", collection: @user.devices.for_user(current_user) %>
<%= render partial: "ui/devices/device", collection: @user.devices.for_user(current_user), locals: { hide_owner: true } %>
<% end %>
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions config/locales/views/devices/en.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
en:
device_last_reading_at: "Last reading %{time} ago"
device_no_readings_message: "No readings received yet!"
device_meta_last_reading_at: "Last reading %{time} ago"
device_meta_no_readings_message: "No readings received yet!"

0 comments on commit 6d40923

Please sign in to comment.