forked from fixin.me/fixin.me
Implement measurements create/destroy and display existing readouts
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
12
app/views/measurements/_readout.html.erb
Normal file
12
app/views/measurements/_readout.html.erb
Normal file
@@ -0,0 +1,12 @@
|
||||
<%= tag.tr id: dom_id(readout) do %>
|
||||
<td><%= readout.quantity %></td>
|
||||
<td class="ralign"><%= readout.value %></td>
|
||||
<td><%= readout.unit %></td>
|
||||
<td><%= l(readout.created_at) %></td>
|
||||
<% if current_user.at_least(:active) %>
|
||||
<td class="flex">
|
||||
<%= image_button_to t('.destroy'), 'delete-outline', measurement_path(readout),
|
||||
method: :delete, data: {turbo_stream: true} %>
|
||||
</td>
|
||||
<% end %>
|
||||
<% end %>
|
||||
11
app/views/measurements/create.turbo_stream.erb
Normal file
11
app/views/measurements/create.turbo_stream.erb
Normal file
@@ -0,0 +1,11 @@
|
||||
<% if @readouts.all?(&:persisted?) %>
|
||||
<%= turbo_stream.update :flashes %>
|
||||
<%= turbo_stream.remove :measurement_form %>
|
||||
<%= turbo_stream.enable :new_measurement_link %>
|
||||
<%= turbo_stream.remove :no_items %>
|
||||
<% @readouts.each do |readout| %>
|
||||
<%= turbo_stream.prepend :measurements, readout %>
|
||||
<% end %>
|
||||
<% else %>
|
||||
<%= turbo_stream.update :flashes %>
|
||||
<% end %>
|
||||
3
app/views/measurements/destroy.turbo_stream.erb
Normal file
3
app/views/measurements/destroy.turbo_stream.erb
Normal file
@@ -0,0 +1,3 @@
|
||||
<%= turbo_stream.update :flashes %>
|
||||
<%= turbo_stream.remove @readout %>
|
||||
<%= turbo_stream.append(:measurements, render_no_items) if current_user.readouts.empty? %>
|
||||
@@ -7,7 +7,18 @@
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<table class="main-area">
|
||||
<table class="main-area items-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th><%= Quantity.model_name.human %></th>
|
||||
<th><%= Readout.human_attribute_name(:value) %></th>
|
||||
<th><%= Unit.model_name.human %></th>
|
||||
<th><%= Readout.human_attribute_name(:created_at) %></th>
|
||||
<% if current_user.at_least(:active) %>
|
||||
<th></th>
|
||||
<% end %>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="measurements">
|
||||
<%= render(@measurements) || render_no_items %>
|
||||
</tbody>
|
||||
|
||||
Reference in New Issue
Block a user