1
0

Updated create/edit/destroy to work in readouts view

This commit is contained in:
cryptogopher 2019-12-26 19:34:16 +01:00
parent e7edfb465f
commit c1f26e9bf0
8 changed files with 32 additions and 14 deletions

View File

@ -22,7 +22,12 @@ class MeasurementsController < ApplicationController
@measurement = @project.measurements.new(measurement_params) @measurement = @project.measurements.new(measurement_params)
if @measurement.save if @measurement.save
flash[:notice] = 'Created new measurement' flash[:notice] = 'Created new measurement'
prepare_measurements if session[:m_filters][:scope].empty?
prepare_measurements
else
prepare_readouts
render :create_readouts
end
else else
@measurement.readouts.new if @measurement.readouts.empty? @measurement.readouts.new if @measurement.readouts.empty?
render :new render :new
@ -35,8 +40,13 @@ class MeasurementsController < ApplicationController
def update def update
if @measurement.update(measurement_params) if @measurement.update(measurement_params)
flash[:notice] = 'Updated measurement' flash[:notice] = 'Updated measurement'
prepare_measurements if session[:m_filters][:scope].empty?
render :index prepare_measurements
render :index
else
prepare_readouts
render :readouts
end
else else
render :edit render :edit
end end
@ -65,6 +75,7 @@ class MeasurementsController < ApplicationController
def toggle_column def toggle_column
@measurement.column_view.toggle_column!(@quantity) @measurement.column_view.toggle_column!(@quantity)
prepare_readouts prepare_readouts
render :readouts
end end
private private

View File

@ -11,7 +11,8 @@
<tbody> <tbody>
<% @measurements.each do |m| %> <% @measurements.each do |m| %>
<% next if m.new_record? %> <% next if m.new_record? %>
<tr id="measurement-<%= m.id %>" class="measurement <%= 'hidden' if m.hidden %>"> <tr id="measurement-<%= m.id %>"
class="primary measurement <%= 'hidden' if m.hidden %>">
<td class="date"><%= format_datetime(m) %></td> <td class="date"><%= format_datetime(m) %></td>
<td class="name"> <td class="name">
<div style="float:left;"> <div style="float:left;">

View File

@ -8,7 +8,7 @@
<th style="width:<%= 2 * 100/total_width%>%"><%= l(:field_taken_at_date) %></th> <th style="width:<%= 2 * 100/total_width%>%"><%= l(:field_taken_at_date) %></th>
<% @quantities.each do |q| %> <% @quantities.each do |q| %>
<th style="width:<%= 100/total_width %>%"> <th style="width:<%= 100/total_width %>%">
<div style="float:right;"> <div style="float:right;position:relative;">
<%= link_to '', toggle_column_measurement_path(@measurement, quantity_id: q.id), <%= link_to '', toggle_column_measurement_path(@measurement, quantity_id: q.id),
{class: "icon icon-close", method: :post, remote: true} %> {class: "icon icon-close", method: :post, remote: true} %>
</div> </div>
@ -22,7 +22,7 @@
<% @measurements.each_with_index do |m, index| %> <% @measurements.each_with_index do |m, index| %>
<% row_class = "measurement #{cycle('odd', 'even')}" %> <% row_class = "measurement #{cycle('odd', 'even')}" %>
<tr id="measurement-<%= m.id %>" class="primary <%= row_class %>"> <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;"> <td class="date" 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(m) %></span> <span class="icon icon-bullet-closed"><%= format_datetime(m) %></span>
</td> </td>
<% @requested_r[index].each do |*, value| %> <% @requested_r[index].each do |*, value| %>
@ -37,8 +37,8 @@
else else
rows = 1 rows = 1
end %> end %>
<td rowspan="<%= rows %>" 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;"> <td rowspan="<%= rows %>" class="date" 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-closed"><%= format_datetime(m) %></span> <span class="icon icon-bullet-open"><%= format_datetime(m) %></span>
</td> </td>
<% @requested_r[index].each do |q_name, value| %> <% @requested_r[index].each do |q_name, value| %>
<td class="primary quantity"> <td class="primary quantity">

View File

@ -0,0 +1,4 @@
$('div[id^=flash_]').remove();
$('#content').prepend('<%= j render_flash_messages %>');
$('#new-measurement').empty();
$('#readouts').html('<%= j render partial: 'measurements/readouts' %>');

View File

@ -1,5 +1,5 @@
$('div[id^=flash_]').remove(); $('div[id^=flash_]').remove();
$('#content').prepend('<%= j render_flash_messages %>'); $('#content').prepend('<%= j render_flash_messages %>');
<% if @measurement.destroyed? %> <% if @measurement.destroyed? %>
$('tr[id=measurement-<%= @measurement.id %>]').remove(); $('tr[id=measurement-<%= @measurement.id %>]').nextUntil('tr.primary').addBack().remove();
<% end %> <% end %>

View File

@ -1,4 +1,6 @@
$('div[id^=flash_]').remove(); $('div[id^=flash_]').remove();
$('#content').prepend('<%= j render_flash_messages %>'); $('#content').prepend('<%= j render_flash_messages %>');
$('tr[id=measurement-<%= @measurement.id %>]').nextUntil('tr.measurement').remove(); $('tr[id=measurement-<%= @measurement.id %>]').nextUntil('tr.primary', ':not(.measurement)')
$('tr[id=measurement-<%= @measurement.id %>]').after('<tr><td class="form" colspan="5"><div id="edit-measurement"><%= j render partial: "measurements/edit_form" %></div></td></tr>'); .remove();
$('tr[id=measurement-<%= @measurement.id %>]').nextAll('tr.primary').first()
.before('<tr><td class="form" colspan="5"><div id="edit-measurement"><%= j render partial: "measurements/edit_form" %></div></td></tr>');

View File

@ -0,0 +1,3 @@
$('div[id^=flash_]').remove();
$('#content').prepend('<%= j render_flash_messages %>');
$('#readouts').html('<%= j render partial: 'measurements/readouts' %>');

View File

@ -1,3 +0,0 @@
$('div[id^=flash_]').remove();
$('#content').prepend('<%= escape_javascript(render_flash_messages) %>');
$('#readouts').html('<%= escape_javascript(render partial: 'measurements/readouts') %>');