From 4d00fca853a131bef1580a11272cd32c1702e640 Mon Sep 17 00:00:00 2001 From: Stuart Owen Date: Fri, 20 Sep 2024 16:34:06 +0100 Subject: [PATCH] crude controller action and views for investigation to support updating from FDS #1981 for testing out --- app/controllers/investigations_controller.rb | 14 +++++++++++++- app/views/investigations/_buttons.html.erb | 6 ++++++ .../update_from_fairdata_station.html.erb | 14 ++++++++++++++ app/views/projects/_buttons.html.erb | 8 +++++--- config/routes.rb | 2 ++ lib/seek/permissions/translator.rb | 1 + 6 files changed, 41 insertions(+), 4 deletions(-) create mode 100644 app/views/investigations/update_from_fairdata_station.html.erb diff --git a/app/controllers/investigations_controller.rb b/app/controllers/investigations_controller.rb index 2d42e2e150..827b64bce5 100644 --- a/app/controllers/investigations_controller.rb +++ b/app/controllers/investigations_controller.rb @@ -6,7 +6,7 @@ class InvestigationsController < ApplicationController before_action :investigations_enabled? before_action :find_assets, :only=>[:index] - before_action :find_and_authorize_requested_item,:only=>[:edit, :manage, :update, :manage_update, :destroy, :show,:new_object_based_on_existing_one] + before_action :find_and_authorize_requested_item,:only=>[:edit, :manage, :update, :manage_update, :destroy, :show, :update_from_fairdata_station, :submit_fairdata_station, :new_object_based_on_existing_one] #project_membership_required_appended is an alias to project_membership_required, but is necesary to include the actions #defined in the application controller @@ -34,6 +34,18 @@ def new_object_based_on_existing_one end + def submit_fairdata_station + path = params[:datastation_data].path + datastation_inv = Seek::FairDataStation::Reader.new.parse_graph(path).first + raise 'identifiers dont match' if datastation_inv.external_id != @investigation.external_identifier + @investigation = Seek::FairDataStation::Writer.new.update_isa(@investigation, datastation_inv, current_person, @investigation.projects, @investigation.policy) + @investigation.save! + + respond_to do |format| + format.html { redirect_to(@investigation) } + end + end + def export_isatab_json the_hash = IsaTabConverter.convert_investigation(Investigation.find(params[:id])) send_data JSON.pretty_generate(the_hash) , filename: 'isatab.json' diff --git a/app/views/investigations/_buttons.html.erb b/app/views/investigations/_buttons.html.erb index 26ccd792f2..b449e8fc55 100644 --- a/app/views/investigations/_buttons.html.erb +++ b/app/views/investigations/_buttons.html.erb @@ -47,5 +47,11 @@ <%= order_icon(item, current_user, order_studies_investigation_path(item), item.studies, 'study') -%> + <% if Seek::Config.fair_data_station_enabled && item.can_manage? %> +
  • + <%= image_tag_for_key('import', update_from_fairdata_station_investigation_path(item), "Update from FAIRData Station", nil, "Update from FAIRData Station") -%> +
  • + <% end %> + <%= delete_icon item, current_user -%> <% end -%> diff --git a/app/views/investigations/update_from_fairdata_station.html.erb b/app/views/investigations/update_from_fairdata_station.html.erb new file mode 100644 index 0000000000..3843ae3756 --- /dev/null +++ b/app/views/investigations/update_from_fairdata_station.html.erb @@ -0,0 +1,14 @@ +<%= render :partial => "general/page_title",:locals=>{:title=>"Update from FAIRData Station for #{ t('investigation') } #{link_to(@investigation.title, @investigation)}".html_safe} %> + +<%= form_tag submit_fairdata_station_investigation_path(@investigation), multipart: true do %> + + <%= panel('FAIR Data Station turtle (ttl) metadata file') do %> + + <%= file_field_tag "datastation_data", accept: '.ttl' -%> + + <% end %> + +
    + <%= submit_tag("Submit", class: 'btn btn-primary') %> +
    +<% end %> \ No newline at end of file diff --git a/app/views/projects/_buttons.html.erb b/app/views/projects/_buttons.html.erb index 7f7a4fa504..46cf515965 100644 --- a/app/views/projects/_buttons.html.erb +++ b/app/views/projects/_buttons.html.erb @@ -62,14 +62,16 @@ <%= order_icon(item,current_user, order_investigations_project_path(item), item.investigations, 'investigation') %> <% end %> - <% if admin_logged_in? || item.can_manage? -%> - <%= delete_icon(item,current_user,"Any members will also be removed from the #{t('project')}, are you sure?") %> - <% end -%> <% if Seek::Config.fair_data_station_enabled %>
  • <%= image_tag_for_key('import', import_from_fairdata_station_project_path(item), "Import from FAIRData Station", nil, "Import from FAIRData Station") -%>
  • <% end %> + <% if admin_logged_in? || item.can_manage? -%> + <%= delete_icon(item,current_user,"Any members will also be removed from the #{t('project')}, are you sure?") %> + <% end -%> + + <% end -%> <% end -%> diff --git a/config/routes.rb b/config/routes.rb index 8d9cf068e8..b5a1db955b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -420,6 +420,8 @@ get :manage get :order_studies patch :manage_update + get :update_from_fairdata_station + post :submit_fairdata_station end resources :people, :programmes, :projects, :assays, :studies, :models, :sops, :workflows, :data_files, :publications, :documents, :observation_units, :samples, only: [:index] end diff --git a/lib/seek/permissions/translator.rb b/lib/seek/permissions/translator.rb index 861164795c..c35c5ec6a8 100644 --- a/lib/seek/permissions/translator.rb +++ b/lib/seek/permissions/translator.rb @@ -30,6 +30,7 @@ class Translator manage manage_update notification read_interaction write_interaction report_problem storage_report select_sample_type extraction_status persistence_status extract_samples confirm_extraction cancel_extraction upload_fulltext upload_pdf soft_delete_fulltext has_matching_sample_type unzip unzip_status confirm_unzip unzip_persistence_status cancel_unzip + update_from_fairdata_station submit_fairdata_station ]).freeze }.freeze