Skip to content

Commit

Permalink
changed params and include fancy multi-select to select obs unit in ui
Browse files Browse the repository at this point in the history
  • Loading branch information
stuzart committed Oct 22, 2024
1 parent 98e35e2 commit 8fa6d80
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 9 deletions.
3 changes: 1 addition & 2 deletions app/controllers/data_files_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -532,10 +532,9 @@ def data_file_params
{ special_auth_codes_attributes: [:code, :expiration_date, :id, :_destroy] },
{ assay_assets_attributes: [:assay_id, :relationship_type_id] },
{ creator_ids: [] }, { assay_assets_attributes: [:assay_id, :relationship_type_id] },
{ observation_unit_assets_attributes: [:observation_unit_id] },
:file_template_id,
{ data_format_annotations: [] }, { data_type_annotations: [] },
{ publication_ids: [] }, { workflow_ids: [] },
{ publication_ids: [] }, { workflow_ids: [] },{ observation_unit_ids: [] },
{ extended_metadata_attributes: determine_extended_metadata_keys },
{ workflow_data_files_attributes:[:id, :workflow_id, :workflow_data_file_relationship_id, :_destroy] },
discussion_links_attributes:[:id, :url, :label, :_destroy])
Expand Down
1 change: 0 additions & 1 deletion app/models/data_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ class DataFile < ApplicationRecord

has_many :observation_unit_assets, dependent: :delete_all, as: :asset, foreign_key: :asset_id, autosave: true, inverse_of: :asset
has_many :observation_units, through: :observation_unit_assets
accepts_nested_attributes_for :observation_unit_assets, allow_destroy: true

has_many :workflow_data_files, dependent: :destroy, autosave: true
has_many :workflows, ->{ distinct }, through: :workflow_data_files
Expand Down
1 change: 1 addition & 0 deletions app/views/data_files/_associate_observation_units.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%= f.fancy_multiselect(:observation_units, other_projects_checkbox: true) %>
2 changes: 2 additions & 0 deletions app/views/data_files/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@

<%= render :partial => "assays/associate_assays", :locals=>{:resource => @data_file} -%>

<%= render partial: 'associate_observation_units', locals: {f: f, resource: @data_file} if Seek::Config.observation_units_enabled %>

<%= f.fancy_multiselect :events, { other_projects_checkbox: true, sort_by: :start_date } if Seek::Config.events_enabled %>

<%= render partial: 'associate_workflow', locals: {:f=>f, :resource => @data_file } if Seek::Config.workflows_enabled %>
Expand Down
2 changes: 2 additions & 0 deletions app/views/data_files/multi-steps/_other_properties.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

<%= render partial: 'associate_workflow', locals: {:f=>f, :resource => @data_file } if Seek::Config.workflows_enabled %>

<%= render partial: 'associate_observation_units', locals: {f: f, resource: @data_file} if Seek::Config.observation_units_enabled %>

<div class='multi-step-buttons'>
<%= multi_step_start_button %>
<%= multi_step_back_button %>
Expand Down
12 changes: 6 additions & 6 deletions test/functional/data_files_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3687,13 +3687,15 @@ def test_show_item_attributed_to_jerm_file
refute bad_obs_unit.can_edit?

assert_difference('ObservationUnitAsset.count') do
put :update, params: { id: data_file.id, data_file: { title: data_file.title, observation_unit_assets_attributes: [{ observation_unit_id: obs_unit.id }] } }
put :update, params: { id: data_file.id, data_file: { title: data_file.title, observation_unit_ids:[obs_unit.id] } }
end
data_file.reload
assert_equal [obs_unit], data_file.observation_units

assert_no_difference('ObservationUnitAsset.count') do
put :update, params: { id: data_file.id, data_file: { title: data_file.title, observation_unit_assets_attributes: [{ observation_unit_id: bad_obs_unit.id }] } }
assert_raises(ActiveRecord::RecordNotSaved) do
put :update, params: { id: data_file.id, data_file: { title: data_file.title, observation_unit_ids:[bad_obs_unit.id] } }
end
end
data_file.reload
assert_equal [obs_unit], data_file.observation_units
Expand All @@ -3712,7 +3714,7 @@ def test_show_item_attributed_to_jerm_file

assert_difference('ObservationUnitAsset.count') do
assert_difference('DataFile.count') do
post :create, params: { data_file: data_file.merge(observation_unit_assets_attributes: [{ observation_unit_id: obs_unit.id }]), content_blobs: [blob], policy_attributes: valid_sharing }
post :create, params: { data_file: data_file.merge(observation_unit_ids:[obs_unit.id]), content_blobs: [blob], policy_attributes: valid_sharing }
assert_redirected_to data_file_path(assigns(:data_file))
end
end
Expand All @@ -3723,11 +3725,9 @@ def test_show_item_attributed_to_jerm_file
data_file, blob = valid_data_file
assert_no_difference('ObservationUnitAsset.count') do
assert_no_difference('DataFile.count') do
post :create, params: { data_file: data_file.merge(observation_unit_assets_attributes: [{ observation_unit_id: bad_obs_unit.id }]), content_blobs: [blob], policy_attributes: valid_sharing }
post :create, params: { data_file: data_file.merge(observation_unit_ids:[bad_obs_unit.id]), content_blobs: [blob], policy_attributes: valid_sharing }
end
end
data_file = assigns(:data_file)
assert_equal [], data_file.observation_units
end

test 'when updating, assay linked to must be editable' do
Expand Down

0 comments on commit 8fa6d80

Please sign in to comment.