Skip to content

Commit

Permalink
update display agent to show agent affiliations
Browse files Browse the repository at this point in the history
  • Loading branch information
syphax-bouazzouni committed Jul 28, 2023
1 parent ce249cd commit 211b5a4
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 12 deletions.
38 changes: 32 additions & 6 deletions app/helpers/agent_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ def agent_id_frame_id(agent_id, parent_id)
end

def agent_id(agent)
agent_id = agent.id
agent_id ? agent.id.split('/').last : ''
return if agent.nil?

agent_id = agent.is_a?(String) ? agent : agent.id
agent_id ? agent_id.split('/').last : ''
end

def link_to_agent_edit_modal(agent, parent_id = nil)
Expand All @@ -54,13 +56,37 @@ def affiliation?(agent)
agent.agentType.eql?('organization')
end

def display_identifiers(identifiers)
Array(identifiers).map { |i| "#{i["schemaAgency"]}:#{i["notation"]}" }.join(', ')
def identifier_link(link, link_to: true)
if link_to
link_to(link, link, target: '_blank')
else
link
end

end

def display_identifiers(identifiers, link: true)
schemes_urls = { ORCID: 'https://orcid.org/', ISNI: 'https://isni.org/', ROR: 'https://ror.org/', GRID: 'https://www.grid.ac/' }
Array(identifiers).map do |i|
if i["schemaAgency"]
schema_agency, notation = [i["schemaAgency"], i["notation"]]
else
schema_agency, notation = (i["id"] || i["@id"]).split('Identifiers/').last.delete(' ').split(':')
end
value = "#{schemes_urls[schema_agency.to_sym]}#{notation}"
identifier_link(value, link_to: link)
end.join(', ')
end

def display_agent(agent)
agent.name + '(' + display_identifiers(agent.identifiers) + ')'
def display_agent(agent, link: true)
out = agent.name.to_s.humanize
identifiers = display_identifiers(agent.identifiers, link: link)
out = "#{out} (#{identifiers})" unless identifiers.empty?
affiliations = agent.affiliations.map { |a| display_agent(a, link: link) }.join(', ')
out = "#{out} (affiliations: #{affiliations})" unless affiliations.empty?
out
end

def agent_field_name(name, name_prefix = '')
name_prefix&.empty? ? name : "#{name_prefix}[#{name}]"
end
Expand Down
11 changes: 8 additions & 3 deletions app/helpers/ontologies_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ def display_data_catalog(sub)
end
end

def agent?(sub_metadata, attr)
metadata = sub_metadata.select{ |x| x['@id'][attr] }.first
metadata && Array(metadata['enforce']).include?('Agent')
end

# Display data catalog metadata under visits (in _metadata.html.haml)
def display_logo(sub)
logo_attributes = ["logo", "depiction"]
Expand Down Expand Up @@ -128,7 +133,7 @@ def additional_metadata(sub)
end)
end

elsif metadata.eql?("hasCreator") || metadata.eql?("publisher")
elsif agent?(json_metadata, metadata)
html << content_tag(:tr) do
if label.nil?
concat(content_tag(:td, metadata.gsub(/(?=[A-Z])/, " ")))
Expand All @@ -139,10 +144,10 @@ def additional_metadata(sub)
metadata_array = []

sub.send(metadata).each do |metadata_value|
metadata_array << display_agent(metadata_value)
metadata_array << "<div> #{display_agent(metadata_value)} </div>"
end

concat(content_tag(:td, raw(metadata_array.join(", "))))
concat(content_tag(:td, raw(metadata_array.join(""))))
end
else
html << content_tag(:tr) do
Expand Down
2 changes: 1 addition & 1 deletion app/views/agents/_agent_show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
- if agent.id
= hidden_field_tag agent_field_name(:id, name_prefix), agent.id

= text_field_tag '', display_agent(agent), class: "form-control", disabled: true
= text_field_tag '', display_agent(agent, link: false), class: "form-control", disabled: true

- if current_user_admin? || agent.creator.eql?(current_user&.id.to_s)
- if edit_on_modal
Expand Down
4 changes: 2 additions & 2 deletions app/views/agents/_show_line.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
%td
= agent.name
%td
= display_identifiers(agent.identifiers)
= raw display_identifiers(agent.identifiers)
%td
= agent.affiliations.map{|i| "#{i["name"]} ( #{display_identifiers(i["identifiers"])} )"}.join(', ')
= raw agent.affiliations.map{|i| "#{i["name"]} ( #{display_identifiers(i["identifiers"])} )"}.join(', ')
%td
= agent.agentType
%td{:class => 'delete_mappings_column'}
Expand Down

0 comments on commit 211b5a4

Please sign in to comment.