Skip to content

Commit

Permalink
Consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
miharekar committed Dec 14, 2024
1 parent 470d4ec commit 80540d5
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 87 deletions.
2 changes: 1 addition & 1 deletion app/models/shot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class Shot < ApplicationRecord
include DateParseable

DAILY_LIMIT = 50
LIST_ATTRIBUTES = %i[id coffee_bag_id start_time profile_title user_id bean_weight drink_weight drink_tds drink_tds drink_ey espresso_enjoyment barista bean_brand bean_type duration grinder_model grinder_setting].freeze
LIST_ATTRIBUTES = %i[id coffee_bag_id start_time profile_title user_id bean_weight drink_weight drink_tds drink_tds drink_ey espresso_enjoyment barista bean_brand bean_type duration grinder_model grinder_setting roast_level roast_date].freeze

before_validation :refresh_coffee_bag_fields, if: -> { coffee_bag_id_changed? }

Expand Down
111 changes: 111 additions & 0 deletions app/views/shots/_table_row_shot.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
<% owner = Current.user && shot.user == Current.user %>
<% show_start_time = owner || !shot.user&.hide_shot_times? %>
<% bean_weight = shot.bean_weight.to_f %>
<% drink_weight = shot.drink_weight.to_f %>
<% ratio = drink_weight / bean_weight %>
<% tds = shot.drink_tds.to_f %>
<% ey = shot.drink_ey.to_f %>
<tr class="cursor-pointer hover:bg-neutral-50 dark:hover:bg-neutral-800" id="<%= dom_id(shot) %>" data-action="click->shot#view" data-url="<%= shot_path(shot) %>">
<td class="px-1 py-4 sm:px-4">
<div class="flex items-center">
<% if shot.espresso_enjoyment.to_i > 0 %>
<div class="w-8 h-8 mr-2 rounded-full shrink-0 sm:mr-4" style="background-color: <%= enjoyment_hex(shot.espresso_enjoyment) %>;">
<div class="py-1 text-center text-white">
<%= shot.espresso_enjoyment %>
</div>
</div>
<% end %>
<div class="sm">
<div class="text-sm text-neutral-500 dark:text-neutral-400">
<%= shot.profile_title %>
</div>
<% if show_start_time %>
<div class="text-sm text-neutral-500 dark:text-neutral-400">
<%= shot.start_time.in_time_zone(@timezone).to_formatted_s(:long) %>
</div>
<% end %>
<% if include_person %>
<div class="flex items-center">
<div class="text-sm text-neutral-500 dark:text-neutral-400"><%= shot.user.display_name %></div>
<% if shot.user.premium? %>
<%= link_to premium_index_path do %>
<svg class="w-4 h-4 ml-1 text-terracotta-600 hover:text-terracotta-800" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12l2 2 4-4M7.835 4.697a3.42 3.42 0 001.946-.806 3.42 3.42 0 014.438 0 3.42 3.42 0 001.946.806 3.42 3.42 0 013.138 3.138 3.42 3.42 0 00.806 1.946 3.42 3.42 0 010 4.438 3.42 3.42 0 00-.806 1.946 3.42 3.42 0 01-3.138 3.138 3.42 3.42 0 00-1.946.806 3.42 3.42 0 01-4.438 0 3.42 3.42 0 00-1.946-.806 3.42 3.42 0 01-3.138-3.138 3.42 3.42 0 00-.806-1.946 3.42 3.42 0 010-4.438 3.42 3.42 0 00.806-1.946 3.42 3.42 0 013.138-3.138z"/>
</svg>
<% end %>
<% end %>
</div>
<% end %>
<% if shot.barista.present? %>
<div class="text-sm text-neutral-500 dark:text-neutral-400">
Barista: <%= shot.barista %>
</div>
<% end %>
</div>
</div>
</td>
<td class="px-1 py-4 sm:px-4">
<div class="flex flex-col">
<span class="text-sm text-neutral-500 dark:text-neutral-400">
<% if shot.bean_brand.present? %>
<%= shot.bean_brand %>
<% end %>
<% if shot.bean_type.present? %>
<%= shot.bean_type %>
<% end %>
<% if shot.roast_level.present? %>
(<%= shot.roast_level %>)
<% end %>
<% if shot.roast_date.present? %>
on <%= shot.parsed_roast_date&.to_fs(:long) %>
<% end %>
</span>
<div class="flex flex-wrap items-center text-sm gap-x-1 text-neutral-500 dark:text-neutral-400">
<% if bean_weight > 0 %>
<span><%= shot.bean_weight %>g</span>
<% end %>
<% if bean_weight > 0 && drink_weight > 0 %>
<span>&rarr;</span>
<% end %>
<% if drink_weight > 0 %>
<span><%= shot.drink_weight %>g</span>
<% if bean_weight > 0 && drink_weight > 0 && ratio > 0 && ratio.finite? %>
<span>(1:<%= ratio.round(1) %>)</span>
<% end %>
<% end %>
<span>in <%= shot.duration.round(1) %>s</span>
</div>
<div class="flex flex-wrap items-center text-sm gap-x-1 text-neutral-500 dark:text-neutral-400">
<% if shot.grinder_model.present? %>
<span><%= shot.grinder_model %></span>
<% end %>
<% if shot.grinder_setting.present? && shot.grinder_setting != "0" && shot.grinder_setting != "0.0" %>
<span>@ <%= shot.grinder_setting %></span>
<% end %>
</div>
<div class="flex items-center text-sm gap-x-2 text-neutral-500 dark:text-neutral-400">
<% if tds > 0 %>
<span>TDS <%= tds %>%</span>
<% end %>
<% if ey > 0 %>
<span>EY <%= ey %>%</span>
<% end %>
</div>
</div>
</td>
<td class="px-1 py-4 sm:px-4">
<div class="flex flex-col lg:flex-row">
<div class="grow"></div>
<span>
<a class="inline-flex items-center px-4 py-2 text-sm font-medium bg-white border rounded-md shadow-sm cursor-pointer border-neutral-300 dark:border-neutral-600 text-neutral-700 dark:bg-neutral-800 dark:text-neutral-300 hover:bg-neutral-50 dark:hover:bg-neutral-900" href="<%= shot_path(shot) %>">
<%# Heroicon name: eye %>
<svg class="w-4 h-4 -ml-1 -mr-1 text-neutral-500 dark:text-neutral-300" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor">
<path d="M10 12a2 2 0 100-4 2 2 0 000 4z"/>
<path fill-rule="evenodd" d="M.458 10C1.732 5.943 5.522 3 10 3s8.268 2.943 9.542 7c-1.274 4.057-5.064 7-9.542 7S1.732 14.057.458 10zM14 10a4 4 0 11-8 0 4 4 0 018 0z" clip-rule="evenodd"/>
</svg>
<span class="hidden ml-2 xl:block">View</span>
</a>
</span>
</div>
</td>
</tr>
86 changes: 0 additions & 86 deletions app/views/shots/_table_row_shot.html.slim

This file was deleted.

0 comments on commit 80540d5

Please sign in to comment.