Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Additions to the observation unit UI #1975

Merged
merged 11 commits into from
Aug 23, 2024
1 change: 1 addition & 0 deletions app/controllers/admin_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ def update_features_enabled
Seek::Config.documents_enabled = string_to_boolean params[:documents_enabled]
Seek::Config.events_enabled = string_to_boolean params[:events_enabled]
Seek::Config.isa_enabled = string_to_boolean params[:isa_enabled]
Seek::Config.observation_units_enabled = string_to_boolean params[:observation_units_enabled]
Seek::Config.models_enabled = string_to_boolean params[:models_enabled]
Seek::Config.organisms_enabled = string_to_boolean params[:organisms_enabled]
Seek::Config.programmes_enabled = string_to_boolean params[:programmes_enabled]
Expand Down
3 changes: 3 additions & 0 deletions app/controllers/observation_units_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ class ObservationUnitsController < ApplicationController
before_action :login_required,:except=>[:show,:index]
before_action :find_assets, only: [:index]

include Seek::Publishing::PublishingCommon
include Seek::IsaGraphExtensions

api_actions :index, :show, :create, :update, :destroy

def show
Expand Down
3 changes: 2 additions & 1 deletion app/views/admin/features_enabled.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@

<%= admin_checkbox_setting(:isa_enabled, 1, Seek::Config.isa_enabled,
"ISA enabled", "Whether the ISA framework is enabled. The ISA framework allows users to create Investigations, Studies and Assays to organize their work.") %>

<%= admin_checkbox_setting(:observation_units_enabled, 1, Seek::Config.observation_units_enabled,
"Observation Units enabled", "Whether the users can register Observation Units to organize their work.") %>
<%= admin_checkbox_setting(:models_enabled, 1, Seek::Config.models_enabled,
"Models enabled", "Whether the users can register computational models in SEEK.") %>

Expand Down
2 changes: 1 addition & 1 deletion app/views/assets/_resource_preview.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<%= list_item_contributors resource -%>

<%= list_item_simple_list resource.creators, t('contributor').capitalize -%>
<%= list_item_simple_list resource.creators, t('creator').capitalize.pluralize -%>

<%= list_item_description resource.description -%>
</div>
Expand Down
34 changes: 34 additions & 0 deletions app/views/observation_units/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<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 } %>

<% if action == :new %>
<%= render partial: "projects/project_selector", locals: { resource: @observation_unit } %>
<% end %>

<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, attribution_enable: false, f: f} %>
<%= f.fancy_multiselect :data_files, other_projects_checkbox: true %>
<%= f.fancy_multiselect :samples, other_projects_checkbox: true %>


<%= form_submit_buttons(@observation_unit) %>

</div>
26 changes: 2 additions & 24 deletions app/views/observation_units/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,5 @@
<h1>Editing <%= t('observation_unit') %>: <%= link_to(h(@observation_unit.title), observation_unit_path(@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: "assets/asset_form_bottom", locals: {show_publications:false, attribution_enable: false, f: f}-%>


<%= form_submit_buttons(@observation_unit) %>

</div>
<% end %>
<%= render partial: "form", locals: { f: f, action: :edit } -%>
<% end %>
52 changes: 19 additions & 33 deletions app/views/observation_units/new.html.erb
Copy link
Collaborator

@AndrewWood94 AndrewWood94 Aug 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Text for no Investigation/Study available is still referencing Assay not Obs Unit

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good spot

Original file line number Diff line number Diff line change
@@ -1,35 +1,21 @@

<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" -%>
<% if Investigation.authorized_for('view').none? %>
<%= alert_box('info') do %>
<%= "No #{t('study')} and #{t('investigation')} available, you have to create a new #{t('investigation')} first before creating your #{t('study')} and #{t('observation_unit')}!" %>
<% end %>
<div class="text-center">
<%= button_link_to("New #{t('investigation')}", 'arrow_right', new_investigation_path) -%>
</div>

<div class="form-group">
<label>Description</label>
<%= f.text_area :description, class: "form-control rich-text-edit", rows: 5 -%>
<% elsif Study.authorized_for('view').none? %>
<%= alert_box('info') do %>
<%= "No #{t('study')} available, you have to create a new #{t('study')} before creating your #{t('observation_unit')}!" %>
<% end %>
<div class="text-center">
<%= button_link_to("New #{t('study')}", 'arrow_right', new_study_path) -%>
</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, attribution_enable: false, f: f}-%>


<%= form_submit_buttons(@observation_unit) %>

</div>
<% end %>
<% else %>
<h1>New <%= t('observation_unit') %></h1>
<%= index_and_new_help_icon controller_name %>
<%= form_for @observation_unit do |f| %>
<%= render partial: "form", locals: { f: f, action: :new } -%>
<% end %>
<% end %>
17 changes: 16 additions & 1 deletion app/views/samples/_resource_preview.html.erb
Original file line number Diff line number Diff line change
@@ -1 +1,16 @@
<strong>Preview Not Yet Implemented</strong>
<% unless resource.nil? -%>

<div data-tooltip='<%= tooltip(h(resource.title)) %>'>
<p class="title">
<%= list_item_title resource -%>
</p>

<%= render :partial => 'projects/show_project_relationship', :locals => {:resource => resource, :list_item => false} -%>

<%= list_item_contributors resource -%>

<%= list_item_simple_list resource.creators, t('creator').capitalize.pluralize -%>
<%= sample_type_list_item_attribute(t('sample_type'),resource) %>
</div>

<% end -%>
1 change: 1 addition & 0 deletions config/initializers/seek_configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ def load_seek_config_defaults!
Seek::Config.default :data_files_enabled,true
Seek::Config.default :events_enabled,true
Seek::Config.default :isa_enabled, true
Seek::Config.default :observation_units_enabled,true
Seek::Config.default :models_enabled,true
Seek::Config.default :organisms_enabled,true
Seek::Config.default :programmes_enabled, false
Expand Down
1 change: 1 addition & 0 deletions config/initializers/seek_testing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def load_seek_testing_defaults!
Settings.defaults[:file_templates_enabled] = true
Settings.defaults[:human_diseases_enabled] = true
Settings.defaults[:isa_enabled] = true
Settings.defaults[:observation_units_enabled] = true
Settings.defaults[:models_enabled] = true
Settings.defaults[:organisms_enabled] = true
Settings.defaults[:programmes_enabled] = true
Expand Down
1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ en:
investigation: &investigation "Investigation"
study: &study "Study"
assay: &assay "Assay"
observation_unit: &observation_unit "Observation Unit"
assays:
assay: "Assay"
experimental_assay: "Experimental assay"
Expand Down
3 changes: 2 additions & 1 deletion lib/seek/add_buttons.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ class AddButtons
[Workflow, 'workflow[project_ids][]']
],
'Investigation' => [[Study, 'study[investigation_id]']],
'Study' => [[Assay, 'assay[study_id]']],
'Study' => [[Assay, 'assay[study_id]'],
[ObservationUnit, 'observation_unit[study_id]']],
'Modelling Analysis' => [[DataFile, 'data_file[assay_assets_attributes[][assay_id]]'],
[Document, 'document[assay_assets_attributes[][assay_id]]'],
[Sop, 'sop[assay_assets_attributes[][assay_id]]'],
Expand Down
4 changes: 0 additions & 4 deletions lib/seek/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -340,10 +340,6 @@ def strains_enabled
organisms_enabled
end

def observation_units_enabled
fair_data_station_enabled
end

def omniauth_elixir_aai_config
if omniauth_elixir_aai_legacy_mode
{
Expand Down
1 change: 1 addition & 0 deletions lib/seek/config_setting_attributes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ data_files_enabled:
documents_enabled:
events_enabled:
isa_enabled:
observation_units_enabled:
models_enabled:
organisms_enabled:
programmes_enabled:
Expand Down
31 changes: 26 additions & 5 deletions test/functional/observation_units_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,19 @@ def rdf_test_object
login_as(unit.contributor)
get :edit, params: { id: unit.id}
assert_response :success
assert_select 'form.edit_observation_unit' do
assert_select 'div#project-selector', count: 0
end
end

test 'manage' do
unit = FactoryBot.create(:max_observation_unit)
login_as(unit.contributor)
get :manage, params: { id: unit.id}
assert_response :success
assert_select 'form.edit_observation_unit' do
assert_select 'div#project-selector'
end
end

test 'manage update' do
Expand Down Expand Up @@ -83,12 +89,16 @@ def rdf_test_object
test 'update' do
obs_unit = FactoryBot.create(:observation_unit)
emt = FactoryBot.create(:simple_observation_unit_extended_metadata_type)
datafile = FactoryBot.create(:data_file, contributor: obs_unit.contributor)
sample = FactoryBot.create(:sample, contributor: obs_unit.contributor)
login_as(obs_unit.contributor)

patch :update, params: { id: obs_unit,
observation_unit:{
title: 'updated title',
description: 'updated description',
data_file_ids: [datafile.id],
sample_ids: [sample.id],
extended_metadata_attributes: {
extended_metadata_type_id: emt.id,
data: {
Expand All @@ -109,20 +119,27 @@ def rdf_test_object
assert_equal 'updated name', obs_unit.extended_metadata.get_attribute_value('name')
assert_equal 'updated strain', obs_unit.extended_metadata.get_attribute_value('strain')
assert_equal %w[fish soup], obs_unit.tags.sort
assert_equal [datafile], obs_unit.data_files
assert_equal [sample], obs_unit.samples
end

test 'new' do
person = FactoryBot.create(:person)
FactoryBot.create(:study, contributor: person)
login_as(person)
get :new
assert_response :success
assert_select 'form.new_observation_unit'
assert_select 'form.new_observation_unit' do
assert_select 'div#project-selector'
end
end

test 'create' do
emt = FactoryBot.create(:simple_observation_unit_extended_metadata_type)
contributor = FactoryBot.create(:person)
study = FactoryBot.create(:study, contributor: contributor)
datafile = FactoryBot.create(:data_file, contributor: contributor)
sample = FactoryBot.create(:sample, contributor: contributor)
project = contributor.projects.first
other_person = FactoryBot.create(:person)
creator = FactoryBot.create(:person)
Expand All @@ -132,7 +149,9 @@ def rdf_test_object
title: 'new title',
description: 'new description',
creator_ids: [creator.id],
project_ids: [project],
project_ids: [project.id],
data_file_ids: [datafile.id],
sample_ids: [sample.id],
study_id: study,
extended_metadata_attributes: {
extended_metadata_type_id: emt.id,
Expand All @@ -158,18 +177,20 @@ def rdf_test_object
assert_equal 'new strain', obs_unit.extended_metadata.get_attribute_value('strain')
assert_equal %w[fish soup], obs_unit.tags.sort
assert_equal contributor, obs_unit.contributor
assert_equal [project],obs_unit.projects.sort_by(&:id)
assert_equal [project],obs_unit.projects
assert_equal [creator],obs_unit.creators
assert_equal [datafile],obs_unit.data_files
assert_equal [sample],obs_unit.samples
assert_equal Policy::VISIBLE,obs_unit.policy.access_type
assert_equal 1,obs_unit.policy.permissions.count
assert_equal other_person,obs_unit.policy.permissions.first.contributor
assert_equal Policy::MANAGING,obs_unit.policy.permissions.first.access_type
end

test 'no access if fair data station disabled' do
test 'no access if observation units disabled' do
unit = FactoryBot.create(:max_observation_unit)
login_as(unit.contributor)
with_config_value(:fair_data_station_enabled, false) do
with_config_value(:observation_units_enabled, false) do
get :show, params: { id: unit.id }
assert_redirected_to :root
refute_nil flash[:error]
Expand Down