Fixed creating/updating with MeasurementRoutine
Updated Measurement links with :view
This commit is contained in:
parent
9f63c14f8a
commit
14f4c063de
@ -27,10 +27,8 @@ class MeasurementsController < ApplicationController
|
||||
# existing nested object (MeasurementRoutine) if it's not associated with outer object
|
||||
# https://stackoverflow.com/questions/6346134/
|
||||
# That's why routine needs to be found and associated before measurement initialization
|
||||
@measurement = @project.measurements.new do |m|
|
||||
routine_id = params[:measurement][:routine_attributes][:id]
|
||||
m.routine = @project.measurement_routines.find_by(id: routine_id) if routine_id
|
||||
end
|
||||
@measurement = @project.measurements.new
|
||||
update_routine_from_params
|
||||
@measurement.attributes = measurement_params
|
||||
@measurement.routine.project = @project
|
||||
@routine = @measurement.routine
|
||||
@ -51,6 +49,7 @@ class MeasurementsController < ApplicationController
|
||||
end
|
||||
|
||||
def update
|
||||
update_routine_from_params
|
||||
if @measurement.update(measurement_params)
|
||||
flash[:notice] = 'Updated measurement'
|
||||
prepare_items
|
||||
@ -117,6 +116,11 @@ class MeasurementsController < ApplicationController
|
||||
)
|
||||
end
|
||||
|
||||
def update_routine_from_params
|
||||
routine_id = params[:measurement][:routine_attributes][:id]
|
||||
@measurement.routine = @project.measurement_routines.find_by(id: routine_id) if routine_id
|
||||
end
|
||||
|
||||
def prepare_items
|
||||
params[:view] == 'index' ? prepare_measurements : prepare_readouts
|
||||
end
|
||||
|
@ -31,10 +31,10 @@ module MeasurementsHelper
|
||||
end
|
||||
end
|
||||
|
||||
def action_links(m)
|
||||
link_to(l(:button_retake), retake_measurement_path(m),
|
||||
def action_links(m, view)
|
||||
link_to(l(:button_retake), retake_measurement_path(m, view: view),
|
||||
{remote: true, class: "icon icon-reload"}) +
|
||||
link_to(l(:button_edit), edit_measurement_path(m),
|
||||
link_to(l(:button_edit), edit_measurement_path(m, view: view),
|
||||
{remote: true, class: "icon icon-edit"}) +
|
||||
delete_link(measurement_path(m), {remote: true, data: {}})
|
||||
end
|
||||
|
@ -1,3 +0,0 @@
|
||||
<% unless @routine.description.empty? %>
|
||||
<p><%= @routine.description %></p>
|
||||
<% end %>
|
@ -1,18 +1,19 @@
|
||||
<div>
|
||||
<%= f.fields_for :routine do |ff| %>
|
||||
<%= fields_for 'measurement[routine_attributes]', @routine do |ff| %>
|
||||
<p>
|
||||
<%= ff.select :id,
|
||||
options_from_collection_for_select(@project.measurement_routines,
|
||||
:id, :name, @routine.id),
|
||||
{label: :field_measurement_routine, required: true},
|
||||
onchange: "var mr_id = $('#measurement_routine_attributes_id option:selected').val();
|
||||
autocomplete: 'off',
|
||||
onchange: "var mr_id = $('#measurement_routine_attributes_id').val();
|
||||
$.ajax({
|
||||
url: '#{measurement_routine_path(id: :mr_id)}'.replace('mr_id', mr_id),
|
||||
dataType: 'script'
|
||||
});
|
||||
return false;" %>
|
||||
<%= link_to l(:button_edit), '#',
|
||||
onclick: "var mr_id = $('#measurement_routine_attributes_id option:selected').val();
|
||||
onclick: "var mr_id = $('#measurement_routine_attributes_id').val();
|
||||
$.ajax({
|
||||
url: '#{edit_measurement_routine_path(id: :mr_id)}'.replace('mr_id', mr_id),
|
||||
dataType: 'script'
|
||||
@ -21,7 +22,7 @@
|
||||
class: 'icon icon-edit' %>
|
||||
</p>
|
||||
<% end %>
|
||||
<div id='measurement-routine'>
|
||||
<%= render partial: 'measurement_routines/show' %>
|
||||
</div>
|
||||
<% unless @routine.description.empty? %>
|
||||
<p><%= @routine.description %></p>
|
||||
<% end %>
|
||||
</div>
|
||||
|
@ -1 +1 @@
|
||||
$('#measurement-routine').html('<%= j render partial: 'measurement_routines/show' %>');
|
||||
$('#measurement-routine-form').html('<%= j render partial: 'measurement_routines/show_form' %>');
|
||||
|
@ -27,7 +27,7 @@
|
||||
</div>
|
||||
</td>
|
||||
<td class="source"><%= m.source.name if m.source.present? %></td>
|
||||
<td class="action unwrappable"><%= action_links(m) %></td>
|
||||
<td class="action unwrappable"><%= action_links(m, :index) %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
|
@ -38,7 +38,7 @@
|
||||
<% @requested_r[index].each do |*, value| %>
|
||||
<td class="primary value ellipsible"><%= format_value(value) %></td>
|
||||
<% end %>
|
||||
<td class="action unwrappable"><%= action_links(m) %></td>
|
||||
<td class="action unwrappable"><%= action_links(m, :readouts) %></td>
|
||||
</tr>
|
||||
|
||||
<tr class="<%= row_class %>" style="display:none">
|
||||
@ -57,7 +57,9 @@
|
||||
<p class="value"><%= format_value(value) %></p>
|
||||
</td>
|
||||
<% end %>
|
||||
<td rowspan="<%= rows %>" class="action unwrappable"><%= action_links(m) %></td>
|
||||
<td rowspan="<%= rows %>" class="action unwrappable">
|
||||
<%= action_links(m, :readouts) %>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<% next unless @quantities.length > 0 %>
|
||||
|
Reference in New Issue
Block a user