Skip to content

Commit

Permalink
Merge branch 'seek_ena_upload' of github.com:ELIXIR-Belgium/seek into…
Browse files Browse the repository at this point in the history
… fairdom_test

Pulling in latest commits from 'seek_ena_upload' branch
  • Loading branch information
Kevin De Pelseneer committed Oct 10, 2023
2 parents 690a145 + 143a543 commit e69ea10
Show file tree
Hide file tree
Showing 81 changed files with 1,282 additions and 1,253 deletions.
2 changes: 1 addition & 1 deletion app/assets/stylesheets/application.css
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,5 @@
*= require jquery.splitter/jquery.splitter
*= require select2.min
*= require select2.bootstrap.min
*= require linked_custom_metadata
*= require linked_extended_metadata
*/
Original file line number Diff line number Diff line change
@@ -1,57 +1,57 @@
.linked_custom_metdata .panel-default .panel-heading {
.linked_extended_metdata .panel-default .panel-heading {
font-weight: bold;
color: #333;
background-color: #ffffff;
border: 0;
padding-left:0px;
}

.linked_custom_metdata .panel-body {
.linked_extended_metdata .panel-body {
background-color: rgb(248,248,248);
padding: 10px 15px;
border-radius: 5px;
}


.linked_custom_metdata .panel {
.linked_extended_metdata .panel {
border: 0;
}

.linked_custom_metdata_even {
.linked_extended_metdata_even {
background-color: rgb(248,248,248);
padding: 10px 15px 10px 15px;
border-radius: 5px;
}

.linked_custom_metdata_odd {
.linked_extended_metdata_odd {
background-color: rgb(224,224,224);

padding: 10px 15px 10px 15px;
border-radius: 5px;
}

.multi_linked_custom_metdata {
.multi_linked_extended_metdata {
background-color: rgb(246, 246, 246);
padding: 10px 15px 10px 15px;
border-radius: 5px;
margin-bottom: 15px;
}

.linked_custom_metdata_display .panel-default .panel-heading {
.linked_extended_metdata_display .panel-default .panel-heading {
font-weight: bold;
border: none;
background-color: #ffffff;
padding: 0px 0px;
}


.linked_custom_metdata_display .panel {
.linked_extended_metdata_display .panel {
border: none;
box-shadow: none;
margin-bottom: 0px;
}

.linked_custom_metdata_display .panel-body {
.linked_extended_metdata_display .panel-body {
padding: 0px 0px;
border-radius: 5px;
}
18 changes: 9 additions & 9 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -596,29 +596,29 @@ def relationify_collection(collection)
end
end

def determine_custom_metadata_keys(asset = nil)
def determine_extended_metadata_keys(asset = nil)
keys = []
if asset
type_id = params.dig(controller_name.singularize.to_sym, asset, :custom_metadata_attributes, :custom_metadata_type_id)
type_id = params.dig(controller_name.singularize.to_sym, asset, :extended_metadata_attributes, :extended_metadata_type_id)
else
type_id = params.dig(controller_name.singularize.to_sym, :custom_metadata_attributes, :custom_metadata_type_id)
type_id = params.dig(controller_name.singularize.to_sym, :extended_metadata_attributes, :extended_metadata_type_id)
end
if type_id.present?
metadata_type = CustomMetadataType.find(type_id)
keys = [:custom_metadata_type_id, :id, data: recursive_determine_custom_metadata_keys(metadata_type)]
metadata_type = ExtendedMetadataType.find(type_id)
keys = [:extended_metadata_type_id, :id, data: recursive_determine_extended_metadata_keys(metadata_type)]
end
keys
end

def recursive_determine_custom_metadata_keys(metadata_type)
def recursive_determine_extended_metadata_keys(metadata_type)
keys = []
metadata_type.custom_metadata_attributes.each do |attr|
metadata_type.extended_metadata_attributes.each do |attr|
key = attr.title.to_sym
if attr.sample_attribute_type.controlled_vocab? || attr.sample_attribute_type.seek_sample_multi? || attr.sample_attribute_type.seek_sample?
keys << key
keys << { key => [] }
elsif attr.linked_custom_metadata? || attr.linked_custom_metadata_multi?
keys << { key => recursive_determine_custom_metadata_keys(attr.linked_custom_metadata_type) }
elsif attr.linked_extended_metadata? || attr.linked_extended_metadata_multi?
keys << { key => recursive_determine_extended_metadata_keys(attr.linked_extended_metadata_type) }
else
keys << key
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/assays_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def assay_params
{ data_files_attributes: [:asset_id, :direction, :relationship_type_id] },
{ placeholders_attributes: [:asset_id, :direction, :relationship_type_id] },
{ publication_ids: [] },
{ custom_metadata_attributes: determine_custom_metadata_keys },
{ extended_metadata_attributes: determine_extended_metadata_keys },
{ discussion_links_attributes:[:id, :url, :label, :_destroy] }
).tap do |assay_params|
assay_params[:document_ids].select! { |id| Document.find_by_id(id).try(:can_view?) } if assay_params.key?(:document_ids)
Expand Down
37 changes: 0 additions & 37 deletions app/controllers/custom_metadata_types_controller.rb

This file was deleted.

37 changes: 37 additions & 0 deletions app/controllers/extended_metadata_types_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
class ExtendedMetadataTypesController < ApplicationController
respond_to :json

before_action :find_extended_metadata_type, only: [:show]

# generated for form, to display fields for selected metadata type
def form_fields
id = params[:id]
parent_resource = params[:parentResource] unless params[:parentResource]&.empty?
respond_to do |format|
if id.blank?
format.html { render html: '' }
else
cm = ExtendedMetadataType.find(id)
resource = safe_class_lookup(cm.supported_type).new
resource.extended_metadata = ExtendedMetadata.new(extended_metadata_type: cm)
format.html do
render partial: 'extended_metadata/extended_metadata_fields',
locals: { extended_metadata_type: cm, resource:, parent_resource: }
end
end
end
end

def show
respond_to do |format|
format.json {render json: @extended_metadata_type}
end
end

private

def find_extended_metadata_type
@extended_metadata_type = ExtendedMetadataType.find(params[:id])
end

end
2 changes: 1 addition & 1 deletion app/controllers/investigations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def investigation_params
params.require(:investigation).permit(:title, :description, { project_ids: [] }, *creator_related_params,
:position, { publication_ids: [] },
{ discussion_links_attributes:[:id, :url, :label, :_destroy] },
{ custom_metadata_attributes: determine_custom_metadata_keys })
{ extended_metadata_attributes: determine_extended_metadata_keys })
end

def check_studies_are_for_this_investigation
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/isa_assays_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def assay_params
{ samples_attributes: %i[asset_id direction] },
{ data_files_attributes: %i[asset_id direction relationship_type_id] },
{ publication_ids: [] },
{ custom_metadata_attributes: determine_custom_metadata_keys(:assay) },
{ extended_metadata_attributes: determine_extended_metadata_keys(:assay) },
{ discussion_links_attributes: %i[id url label _destroy] }]
end

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/isa_studies_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def study_params
[:title, :description, :experimentalists, :investigation_id, { sop_ids: [] },
*creator_related_params, :position, { scales: [] }, { publication_ids: [] },
{ discussion_links_attributes: %i[id url label _destroy] },
{ custom_metadata_attributes: determine_custom_metadata_keys(:study) }]
{ extended_metadata_attributes: determine_extended_metadata_keys(:study) }]
end

def sample_type_params(params, field)
Expand Down
14 changes: 7 additions & 7 deletions app/controllers/studies_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def batch_create
# e.g: Study.new(title: 'title', investigation: investigations(:metabolomics_investigation), policy: FactoryBot.create(:private_policy))
# study.policy = Policy.create(name: 'default policy', access_type: 1)
# render plain: params[:studies].inspect
metadata_types = CustomMetadataType.where(title: 'MIAPPE metadata', supported_type: 'Study').last
metadata_types = ExtendedMetadataType.where(title: 'MIAPPE metadata', supported_type: 'Study').last
studies_length = params[:studies][:title].length
studies_uploaded = false
data_file_uploaded = false
Expand All @@ -211,14 +211,14 @@ def batch_create
title: params[:studies][:title][index],
description: params[:studies][:description][index],
investigation_id: params[:study][:investigation_id],
custom_metadata: CustomMetadata.new(
custom_metadata_type: metadata_types,
extended_metadata: ExtendedMetadata.new(
extended_metadata_type: metadata_types,
data: metadata
)
}
@study = Study.new(study_params)
StudyBatchUpload.check_study_is_MIAPPE_compliant(@study, metadata)
if @study.valid? && @study.save! && @study.custom_metadata.valid?
if @study.valid? && @study.save! && @study.extended_metadata.valid?
studies_uploaded = true if @study.save
end
data_file_uploaded = create_batch_assay_asset(params, index)
Expand Down Expand Up @@ -262,7 +262,7 @@ def create_batch_assay_asset(params, index)
data_file_names.length.times do |data_file_index|

study_metadata_id = params[:studies][:id][index]
study_id = CustomMetadata.where('json_metadata LIKE ?', "%\"id\":\"#{study_metadata_id}\"%").last.item_id
study_id = ExtendedMetadata.where('json_metadata LIKE ?', "%\"id\":\"#{study_metadata_id}\"%").last.item_id
assay_class_id = AssayClass.where(title: 'Experimental assay').first.id
data_file_description = params[:studies][:data_file_description][index].remove(' ').split(',')
assay_params = {
Expand Down Expand Up @@ -343,7 +343,7 @@ def remove_existing_studies(studies)
metadata_id = JSON.parse(study.gsub("=>",":"))["metadata_id"].to_i

Study.where(id: study_id).delete_all
CustomMetadata.where(id: metadata_id).delete_all
ExtendedMetadata.where(id: metadata_id).delete_all
assays = Assay.where(study_id: study_id)
assays.each do |assay|
AssayAsset.where(assay_id: assay.id).delete_all
Expand All @@ -357,7 +357,7 @@ def study_params
params.require(:study).permit(:title, :description, :experimentalists, :investigation_id,
*creator_related_params, :position, { publication_ids: [] },
{ discussion_links_attributes:[:id, :url, :label, :_destroy] },
{ custom_metadata_attributes: determine_custom_metadata_keys })
{ extended_metadata_attributes: determine_extended_metadata_keys })
end
end

Expand Down
50 changes: 0 additions & 50 deletions app/helpers/custom_metadata_helper.rb

This file was deleted.

50 changes: 50 additions & 0 deletions app/helpers/extended_metadata_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
module ExtendedMetadataHelper
include SamplesHelper

def extended_metadata_form_field_for_attribute(attribute, resource, parent_resource = nil)
element_class = "extended_metadata_attribute_#{attribute.sample_attribute_type.base_type.downcase}"

if parent_resource
element_name = "#{parent_resource}[#{resource.class.name.underscore}][extended_metadata_attributes][data][#{attribute.title}]"
else
element_name = "#{resource.class.name.underscore}[extended_metadata_attributes][data][#{attribute.title}]"
end

if attribute.linked_extended_metadata? || attribute.linked_extended_metadata_multi?
content_tag(:span, class: 'linked_extended_metdata') do
folding_panel(attribute.label, false, id:attribute.title) do
attribute_form_element(attribute, resource.extended_metadata.get_attribute_value(attribute.title), element_name, element_class)
end
end
else
content_tag(:label,attribute.label, class: attribute.required? ? 'required' : '') +
attribute_form_element(attribute, resource.extended_metadata.get_attribute_value(attribute.title), element_name, element_class)
end
end

def extended_metadata_attribute_description(description)
html = '<p class="help-block">'
html += '<small>'+description+'</small>'
html += '</p>'
html.html_safe
end

def render_extended_metadata_value(attribute, resource)

if resource.extended_metadata.data[attribute.title].blank?
return '' # Return an empty string if the extended metadata is blank.
end

content_tag(:div, class: 'extended_metadata') do
if attribute.linked_extended_metadata? || attribute.linked_extended_metadata_multi?
content_tag(:span, class: 'linked_extended_metdata_display') do
folding_panel(attribute.label, true, id: attribute.title) do
display_attribute(resource.extended_metadata, attribute, link: true)
end
end
else
label_tag("#{attribute.label} : ") + " " + display_attribute(resource.extended_metadata, attribute, link: true)
end
end
end
end
2 changes: 1 addition & 1 deletion app/helpers/sample_types_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def sample_attribute_pid_help_icon
private

def displayed_sample_attribute_types
SampleAttributeType.all.reject{ |x|x.linked_custom_metadata? || x.linked_custom_metadata_multi? }
SampleAttributeType.all.reject{ |x|x.linked_extended_metadata? || x.linked_extended_metadata_multi? }
end

def attribute_type_link(sample_type_attribute)
Expand Down
Loading

0 comments on commit e69ea10

Please sign in to comment.