1
0

Displaying Measurement readouts, WIP

This commit is contained in:
cryptogopher
2019-12-10 20:37:36 +01:00
parent 40e9c6f8ae
commit 98564be4b5
7 changed files with 200 additions and 11 deletions

View File

@@ -6,8 +6,8 @@
<p><%= f.text_field :name, size: 40, required: true %></p>
<p>
<%= f.date_field :taken_at_date, required: true %>
<%= f.time_field :taken_at_time, value: @measurement.taken_at.getlocal.strftime("%R"),
required: true, label: '' %>
<%= f.time_field :taken_at_time, value: format_time(@measurement), required: true,
label: '' %>
</p>
<% @measurement.readouts.each_with_index do |r, index| %>
<%= f.fields_for 'readouts_attributes', r, index: '' do |ff| %>

View File

@@ -12,9 +12,7 @@
<% @measurements.each do |m| %>
<% next if m.new_record? %>
<tr id="measurement-<%= m.id %>" class="measurement <%= 'hidden' if m.hidden %>">
<td class="date">
<%= m.taken_at.getlocal.strftime("%F <small>%R</small>").html_safe %>
</td>
<td class="date"><%= format_datetime(m) %></td>
<td class="name">
<div style="float:left;">
<%= link_to m.name, readouts_measurement_path(m) %>

View File

@@ -0,0 +1,68 @@
<% if @readouts.any? %>
<%= render partial: 'measurements/options' %>
<table class="readouts list odd-even">
<thead>
<tr>
<% total_width = 3 + @quantities.length %>
<th style="width:<%= 3 * 100/total_width%>%"><%= l(:field_name) %></th>
<% @quantities.each do |q| %>
<th style="width:<%= 100/total_width %>%"><%= q.name %></th>
<% end %>
</tr>
</thead>
<tbody>
<% @readouts.each do |m, values| %>
<% row_class = "measurement #{cycle('odd', 'even')}" %>
<tr id="measurement-<%= m.id %>" class="primary <%= row_class %>">
<td class="date" style="cursor: pointer;" onclick="$(this).closest('tr').toggle(); $(this).closest('tr').nextUntil('tr.primary', 'tr').toggle(); return false;">
<span class="icon icon-bullet-closed"><%= format_datetime(m) %></span>
</td>
<% values.each do |*, value| %>
<td class="primary value"><%= value %></td>
<% end %>
</tr>
<tr class="<%= row_class %>" style="display:none">
<td class="date" style="cursor: pointer;" onclick="$(this).closest('tr').prev('tr.primary').toggle(); $(this).closest('tr').prev('tr.primary').nextUntil('tr.primary', 'tr').toggle(); return false;">
<span class="icon icon-bullet-closed"><%= format_datetime(m) %></span>
</td>
<% values.each do |q_name, *| %>
<td class="primary quantity"><%= q_name %></td>
<% end %>
</tr>
<tr class="<%= row_class %>" style="display:none">
<td class="space"></td>
<% values.each do |*, value| %>
<td class="primary value"><%= value %></td>
<% end %>
</tr>
<% extras = @extra_readouts[i] %>
<% extras.each_slice(@quantities.length).with_index do |values, index| %>
<tr class="extra <%= row_class %>" style="display:none">
<td class="space"></td>
<% values.each do |q_name, *| %>
<td class="extra quantity"><%= q_name %></td>
<% end %>
<% if @quantities.length > values.length %>
<td class="space" colspan="<%= @quantities.length-values.length %>"></td>
<% end %>
</tr>
<tr class="extra <%= row_class %>" style="display:none">
<td class="space"></td>
<% values.each do |*, value| %>
<td class="extra value"><%= value %></td>
<% end %>
<% if @quantities.length > values.length %>
<td class="space" colspan="<%= @quantities.length-values.length %>"></td>
<% end %>
</tr>
<% end %>
<% end %>
</tbody>
</table>
<% else %>
<p class="nodata"><%= l(:label_no_data) %></p>
<% end %>