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