Skip to content

Commit

Permalink
form to create the obs unit #1961
Browse files Browse the repository at this point in the history
  • Loading branch information
stuzart committed Aug 12, 2024
1 parent 695e2c6 commit 33a1ac6
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 14 deletions.
10 changes: 0 additions & 10 deletions app/helpers/assays_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,6 @@ def list_assay_human_diseases(attribute, assay_human_diseases, html_options = {}
result.html_safe
end

# the selection dropdown box for selecting the study for an assay
def assay_study_selection(element_name, current_study)
grouped_options = grouped_options_for_study_selection(current_study)
blank = current_study.blank? ? 'Not specified' : nil
disabled = current_study && !current_study.can_edit?
options = grouped_options_for_select(grouped_options, current_study.try(:id))
select_tag(element_name, options,
class: 'form-control', include_blank: blank, disabled: disabled).html_safe
end

# a lightway way to select a SOP - specifically for the assay creation during data file creation
def assay_sop_selection(element_name, current_sop)
sops = authorised_sops(User.current_user.person.projects)
Expand Down
10 changes: 10 additions & 0 deletions app/helpers/studies_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,14 @@ def authorised_studies(projects = nil)
def show_batch_miappe_button?
ExtendedMetadataType.where(supported_type: 'Study', title: ExtendedMetadataType::MIAPPE_TITLE, enabled: true).any?
end

# the selection dropdown box for selecting the study for a resource, such as assay or observation unit
def resource_study_selection(element_name, current_study)
grouped_options = grouped_options_for_study_selection(current_study)
blank = current_study.blank? ? 'Not specified' : nil
disabled = current_study && !current_study.can_edit?
options = grouped_options_for_select(grouped_options, current_study.try(:id))
select_tag(element_name, options,
class: 'form-control', include_blank: blank, disabled: disabled).html_safe
end
end
2 changes: 1 addition & 1 deletion app/views/assays/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<div class="form-group">
<label class="required"><%= t('study') -%></label>

<%= assay_study_selection('assay[study_id]',@assay.study) %>
<%= resource_study_selection('assay[study_id]', @assay.study) %>
</div>

<div class="form-group">
Expand Down
2 changes: 1 addition & 1 deletion app/views/data_files/multi-steps/_assays.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
</div>
<div class='form-group'>
<label>Study <span class='required'>*</span></label>
<%= assay_study_selection('assay[study_id]', @assay.study) %>
<%= resource_study_selection('assay[study_id]', @assay.study) %>
</div>
<div class='form-group'>
<label>SOP</label>
Expand Down
35 changes: 35 additions & 0 deletions app/views/observation_units/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@

<h1>New <%= t('observation_unit') %></h1>

<%= form_for(@observation_unit) do |f| %>
<div class="asset_form">
<%= f.error_messages %>

<div class="form-group">
<label class="required">Title</label>
<%= f.text_field :title, class: "form-control" -%>
</div>

<div class="form-group">
<label>Description</label>
<%= f.text_area :description, class: "form-control rich-text-edit", rows: 5 -%>
</div>

<%= render partial: 'extended_metadata/extended_metadata_type_selection', locals: { f: f, resource: @observation_unit } %>
<%= render partial: 'extended_metadata/extended_metadata_attribute_input', locals: { f: f, resource: @observation_unit } %>
<%= render :partial => "projects/project_selector", :locals => { :resource => @observation_unit } %>

<div class="form-group">
<label class="required"><%= t('study') -%></label>

<%= resource_study_selection('observation_unit[study_id]', @observation_unit.study) %>
</div>

<%= render partial: "assets/asset_form_bottom", locals: {show_publications:false, f: f}-%>
<%= form_submit_buttons(@observation_unit) %>

</div>
<% end %>
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<%= form_for(Assay.new) do |f| %>
<div class="form-group">
<label>Register under Study </label><span class="required">*</span>
<%= assay_study_selection('assay[study_id]', nil) %>
<%= resource_study_selection('assay[study_id]', nil) %>
</div>
<div class="form-group">
<%= check_box_tag('link_dependent', 1, true) %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/openbis_zamples/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<% if not_registered %>
<div class="form-group">
<label>Register under Study </label><span class="required">*</span>
<%= assay_study_selection('assay[study_id]', @assay.study) %>
<%= resource_study_selection('assay[study_id]', @assay.study) %>
</div>
<% else %>
<div class="form-group">
Expand Down
12 changes: 12 additions & 0 deletions test/functional/observation_units_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,14 @@ def rdf_test_object
assert_equal 'updated strain', obs_unit.extended_metadata.get_attribute_value('strain')
end

test 'new' do
person = FactoryBot.create(:person)
login_as(person)
get :new
assert_response :success
assert_select 'form.new_observation_unit'
end

test 'create' do
emt = FactoryBot.create(:simple_observation_unit_extended_metadata_type)
contributor = FactoryBot.create(:person)
Expand Down Expand Up @@ -163,6 +171,10 @@ def rdf_test_object
assert_redirected_to :root
refute_nil flash[:error]

get :new
assert_redirected_to :root
refute_nil flash[:error]

get :edit, params: { id: unit.id }
assert_redirected_to :root
refute_nil flash[:error]
Expand Down

0 comments on commit 33a1ac6

Please sign in to comment.