Create Readouts controller
Move #readouts + #toggle_exposure from Measurements to Readouts
This commit is contained in:
90
app/views/readouts/_index.html.erb
Normal file
90
app/views/readouts/_index.html.erb
Normal file
@@ -0,0 +1,90 @@
|
||||
<%= render partial: 'measurements/filters',
|
||||
locals: {url: filter_project_measurements_path(@project, @view_params)} %>
|
||||
|
||||
<% if @measurements.any? %>
|
||||
<%= render partial: 'readouts/options' %>
|
||||
|
||||
<% formulas = @quantities.collect(&:formula) %>
|
||||
<% formulas.unshift(@filter_q.formula) if @filter_q %>
|
||||
<%= error_messages_for *formulas %>
|
||||
|
||||
<table id="readouts" class="list odd-even">
|
||||
<thead>
|
||||
<tr>
|
||||
<% total_width = 3 + @quantities.length %>
|
||||
<th style="width:<%= 2 * 100/total_width%>%"><%= l(:field_taken_at_date) %></th>
|
||||
<% @quantities.each do |q| %>
|
||||
<th style="width:<%= 100/total_width %>%" class="closable ellipsible">
|
||||
<div style="float:right;position:relative;">
|
||||
<%= link_to '',
|
||||
measurement_routine_toggle_exposure_path(@routine, quantity_id: q.id),
|
||||
{class: "icon icon-close", method: :post, remote: true} %>
|
||||
</div>
|
||||
<%= q.name %>
|
||||
</th>
|
||||
<% end %>
|
||||
<th style="width:<%= 100/total_width %>%"><%= l(:field_action) %></th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
<% extra_quantities = @measurements.values.first.keys - @quantities %>
|
||||
<% @measurements.each do |measurement, readouts| %>
|
||||
<% row_class = "measurement #{cycle('odd', 'even')}" %>
|
||||
<tr id="measurement-<%= measurement.id %>" class="primary <%= row_class %>">
|
||||
<td class="topleft unwrappable" style="cursor: pointer;"
|
||||
onclick="$(this).closest('tr').toggle(); $(this).closest('tr').nextUntil('tr.primary', '.measurement').toggle(); return false;">
|
||||
<span class="icon icon-bullet-closed">
|
||||
<%= format_datetime(measurement.taken_at) %>
|
||||
</span>
|
||||
</td>
|
||||
<% @quantities.each do |q| %>
|
||||
<td class="primary right ellipsible"><%= format_value(readouts[q]) %></td>
|
||||
<% end %>
|
||||
<td class="right shrunk unwrappable"><%= action_links(measurement) %></td>
|
||||
</tr>
|
||||
|
||||
<tr class="<%= row_class %>" style="display:none">
|
||||
<% if @quantities.length > 0
|
||||
rows = (readouts.length - 1) / @quantities.length + 1
|
||||
else
|
||||
rows = 1
|
||||
end %>
|
||||
<td rowspan="<%= rows %>" class="topleft unwrappable" style="cursor: pointer;"
|
||||
onclick="$(this).closest('tr').prev('tr.primary').toggle(); $(this).closest('tr').prev('tr.primary').nextUntil('tr.primary', '.measurement').toggle(); return false;">
|
||||
<span class="icon icon-bullet-open">
|
||||
<%= format_datetime(measurement.taken_at) %>
|
||||
</span>
|
||||
</td>
|
||||
<% @quantities.each do |q| %>
|
||||
<td class="primary topleft ellipsible">
|
||||
<%= q.name %>
|
||||
<p class="right"><%= format_value(readouts[q]) %></p>
|
||||
</td>
|
||||
<% end %>
|
||||
<td rowspan="<%= rows %>" class="right shrunk unwrappable">
|
||||
<%= action_links(measurement) %>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<% next if @quantities.empty? %>
|
||||
<% extra_quantities.each_slice(@quantities.length) do |eqs| %>
|
||||
<tr class="extra <%= row_class %>" style="display:none">
|
||||
<% eqs.each do |q| %>
|
||||
<td class="extra topleft ellipsible">
|
||||
<%= q.name if readouts[q] %>
|
||||
<p class="right"><%= format_value(readouts[q]) %></p>
|
||||
</td>
|
||||
<% end %>
|
||||
<% if @quantities.length > eqs.length %>
|
||||
<td class="space" colspan="<%= @quantities.length - eqs.length %>"></td>
|
||||
<% end %>
|
||||
</tr>
|
||||
<% end %>
|
||||
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
<% else %>
|
||||
<p class="nodata"><%= l(:label_no_data) %></p>
|
||||
<% end %>
|
||||
18
app/views/readouts/_options.html.erb
Normal file
18
app/views/readouts/_options.html.erb
Normal file
@@ -0,0 +1,18 @@
|
||||
<fieldset id="options" class="collapsible">
|
||||
<legend onclick="toggleFieldset(this);"><%= l(:label_options) %></legend>
|
||||
<div>
|
||||
<%= form_tag measurement_routine_toggle_exposure_path(@routine, @view_params),
|
||||
id: 'toggle-exposure-form', name: 'toggle-exposure-form',
|
||||
method: :post, remote: true do %>
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
<td style="width:100%"></td>
|
||||
<td><%= select_tag 'quantity_id',
|
||||
toggle_exposure_options(@routine.quantities, :measurement) %></td>
|
||||
<td><%= submit_tag l(:button_add) %></td>
|
||||
</tr>
|
||||
</table>
|
||||
<% end %>
|
||||
</div>
|
||||
</fieldset>
|
||||
15
app/views/readouts/index.html.erb
Normal file
15
app/views/readouts/index.html.erb
Normal file
@@ -0,0 +1,15 @@
|
||||
<div class="contextual">
|
||||
<%= render partial: 'measurements/contextual' %>
|
||||
</div>
|
||||
|
||||
<div id="new-measurement">
|
||||
</div>
|
||||
|
||||
<%= title [t("measurements.index.heading"), project_measurements_path(@project)],
|
||||
@routine.name %>
|
||||
<% if @routine.description? %>
|
||||
<p class="subtitle" style='white-space: pre-wrap;'><%= @routine.description %></p>
|
||||
<% end %>
|
||||
<div id='readouts'>
|
||||
<%= render partial: 'readouts/index' %>
|
||||
</div>
|
||||
1
app/views/readouts/toggle_exposure.js.erb
Normal file
1
app/views/readouts/toggle_exposure.js.erb
Normal file
@@ -0,0 +1 @@
|
||||
$('#readouts').html('<%= j render partial: 'readouts/index' %>');
|
||||
Reference in New Issue
Block a user