Skip to content

Commit

Permalink
Feature: Make agent indentifiers field set by default based on agent …
Browse files Browse the repository at this point in the history
…type (#721)

* remove the restriction for certain submission fields to create only organization type or person type agents

* make orcid or ror default input based on agent type in agent form

* fix disappeared signup form icons

* fix nested agents creation

* fix agent form not filling saved identifier values

* create an agent identifier input helper

* disable cookie banner in development and test  mode

* fix agent tests after enforcing ROR for organizations

---------

Co-authored-by: Syphax <gs_bouazzouni@esi.dz>
  • Loading branch information
Bilelkihal and syphax-bouazzouni authored Aug 4, 2024
1 parent c6d7c8e commit 5925571
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 47 deletions.
19 changes: 19 additions & 0 deletions app/assets/stylesheets/agents.scss
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,23 @@
display: flex !important;
flex-direction: column;
justify-content: center;
}
.agent-input-with-icon{
padding: 8px;
margin-bottom: 0px;
border-radius: 5px;
width: 100%;
color: #5f6573;
outline: none;
font-size: 15px;
font-weight: 500;
border: 1px solid #d7d7d7;
padding-left: 45px;
}
.agent-input-icon{
height: 20px;
width: 20px;
position: absolute;
padding: 11px 17px;
box-sizing: unset;
}
4 changes: 4 additions & 0 deletions app/controllers/agents_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,10 @@ def agent_params
v
end
end
identifiers_schemaAgency = params[:agentType].eql?('person') ? 'ORCID' : 'ROR'
p[:identifiers]&.each_value do |identifier|
identifier[:schemaAgency] = identifiers_schemaAgency
end
p[:identifiers] = (p[:identifiers] || {}).values
p[:affiliations] = (p[:affiliations] || {}).values
p[:affiliations].each do |affiliation|
Expand Down
18 changes: 18 additions & 0 deletions app/helpers/agent_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,24 @@ def identifier_link(link, link_to: true)

end


def agent_identifier_input(index, name_prefix, value = '', is_organization: true)

content_tag :div, id: index, class: 'd-flex' do
content_tag(:div, class: 'w-100') do

concat hidden_field_tag(agent_identifier_name(index , :creator, name_prefix), session[:user].id)
if is_organization
concat inline_svg_tag 'icons/ror.svg', class: 'agent-input-icon'
else
concat inline_svg_tag('orcid.svg', class: 'agent-input-icon')
end
concat text_field_tag(agent_identifier_name(index, :notation, name_prefix), value, class: 'agent-input-with-icon')
end
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|
Expand Down
36 changes: 20 additions & 16 deletions app/views/agents/_form.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
= hidden_field_tag :deletable, deletable if deletable
= hidden_field_tag agent_field_name(:id, name_prefix), agent.id if agent.id

- if is_organization?(agent) && params[:parent_id]
- if is_organization?(agent) && params[:parent_id]
= hidden_field_tag agent_field_name(:agentType, name_prefix), agent.agentType
- else
%tr
Expand Down Expand Up @@ -56,27 +56,31 @@
%th
= t("agents.form.identifiers")
%td.top
%div.agents-identifiers
%div.agents-identifiers{'data-form-options-display-target':"option1", class: is_organization?(agent) && 'd-none'}
= render NestedFormInputsComponent.new do |c|
- c.template do
%div.d-flex{id: 'NEW_RECORD'}
%div.w-100
= hidden_field_tag agent_identifier_name('NEW_RECORD' , :creator, name_prefix), session[:user].id
= text_field_tag agent_identifier_name('NEW_RECORD' , :notation, name_prefix), '', class: "form-control"
%div{style:'width: 15%'}
- values = %w[ORCID ROR ISNI GRID]
= render SelectInputComponent.new(id: "agent_identifiers_schemaAgency_NEW_RECORD", name: agent_identifier_name('NEW_RECORD', :schemaAgency, name_prefix), values: values, selected: 'ORCID')
= agent_identifier_input('NEW_RECORD', name_prefix)

- c.empty_state do
= hidden_field_tag agent_field_name('', name_prefix+"[#{Array(agent.identifiers).size}]")

- Array(agent.identifiers).each_with_index do |identifier, i|
- c.row do
%div.d-flex{id: identifier.id}
%div.w-100
= hidden_field_tag agent_identifier_name(i.to_s.upcase, :creator, name_prefix), session[:user].id
= text_field_tag agent_identifier_name(i.to_s.upcase, :notation, name_prefix), identifier.notation, class: "form-control"
%div{style:'width: 15%'}
- values = %w[ORCID ROR ISNI GRID]
= render SelectInputComponent.new(id: "#{name_prefix}_identifiers_schemaAgency_#{i.to_s.upcase}", name: agent_identifier_name(i.to_s.upcase, :schemaAgency, name_prefix), values: values, selected: identifier.schemaAgency)
= agent_identifier_input(i.to_s.upcase, name_prefix, identifier.notation)

%div.agents-identifiers{'data-form-options-display-target':"option2", class: !is_organization?(agent) && 'd-none'}
= render NestedFormInputsComponent.new do |c|
- c.template do
= agent_identifier_input('NEW_RECORD', name_prefix, is_organization: false)

- c.empty_state do
= hidden_field_tag agent_field_name('', name_prefix+"[#{Array(agent.identifiers).size}]")

- Array(agent.identifiers).each_with_index do |identifier, i|
- c.row do
= agent_identifier_input(i.to_s.upcase, name_prefix, identifier.notation, is_organization: false)


- if show_affiliations
%tr{'data-form-options-display-target':"option1", class: is_organization?(agent) && 'd-none'}
%th
Expand Down
72 changes: 45 additions & 27 deletions app/views/layouts/_header.html.erb
Original file line number Diff line number Diff line change
@@ -1,45 +1,63 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" <%="xml:lang=\"#{I18n.locale}\""%> lang="<%=I18n.locale%>">
<html xmlns="http://www.w3.org/1999/xhtml" <%= "xml:lang=\"#{I18n.locale}\"" %> lang="<%= I18n.locale %>">
<head>
<%= render partial: 'ga_tracking' %>
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
<%= render partial: 'ga_tracking' %>
<meta http-equiv="content-type" content="text/html;charset=UTF-8"/>

<!-- Force IE to use latest rendering engine -->
<meta http-equiv="X-UA-Compatible" content="IE=Edge"/>
<!-- Force IE to use latest rendering engine -->
<meta http-equiv="X-UA-Compatible" content="IE=Edge"/>

<% unless Rails.env.appliance? %>
<% unless Rails.env.appliance? %>
<!-- Google Webmaster Tools verifications -->
<meta name="google-site-verification" content="IBxfKu6VbYH9atd5OLu2zXVD2ZRWi9SgMKTi8nvw3ks" />
<meta name="google-site-verification" content="IBxfKu6VbYH9atd5OLu2zXVD2ZRWi9SgMKTi8nvw3ks"/>
<% end %>
<meta name="turbo-cache-control" content="no-cache">
<%= csrf_meta_tag %>

<title><%if @title.nil?%><%=$ORG_SITE%><%else%><%="#{@title} | #{$ORG_SITE}"%><%end%></title>

<link rel="shortcut icon" href="/fav.ico" type="image/x-icon" />
<!-- Fonts -->
<link href='//fonts.googleapis.com/css?family=Droid+Sans:400' rel='stylesheet' type='text/css'>
<!-- CSS -->
<meta name="turbo-cache-control" content="no-cache">
<%= csrf_meta_tag %>

<title>
<% if @title.nil? %><%= $ORG_SITE %>
<% else %><%= "#{@title} | #{$ORG_SITE}" %>
<% end %></title>

<link rel="shortcut icon" href="/fav.ico" type="image/x-icon"/>
<!-- Fonts -->
<link href='//fonts.googleapis.com/css?family=Droid+Sans:400' rel='stylesheet' type='text/css'>
<!-- CSS -->
<%= stylesheet_link_tag "https://use.fontawesome.com/releases/v5.2.0/css/all.css", integrity: "sha384-hWVjflwFxL6sNzntih27bfxkr27PmbbK/iSvJ+a4+0owXq79v+lsFkW54bOGbiDQ", crossorigin: "anonymous" %>
<%= stylesheet_link_tag "application" %>

<!-- JavaScript -->
<%= javascript_include_tag "vendor" %>

<script>
jQuery(document).data({bp: {config: <%=bp_config_json.html_safe%>, user: <%=(session[:user] || {}).to_hash.to_json.html_safe%>}});
jQuery(document).data().bp.ontology = <%=@ontology.to_json.html_safe%> || {};
jQuery(document).data().bp.submission_latest = <%=@submission_latest.to_json.html_safe%> || {};
jQuery(document).data().bp.ontolobridge_ontologies = <%=$NEW_TERM_REQUEST_ONTOLOGIES.to_json.html_safe%> || [];
jQuery(document).data().bp.ont_viewer = {};
jQuery(document).data().bp.ont_chart = {};
jQuery(document).data({
bp: {
config: <%=bp_config_json.html_safe%>,
user: <%=(session[:user] || {}).to_hash.to_json.html_safe%>
}
});
jQuery(document).data().bp.ontology =
<%=@ontology.to_json.html_safe%> ||
{
}
;
jQuery(document).data().bp.submission_latest =
<%=@submission_latest.to_json.html_safe%> ||
{
}
;
jQuery(document).data().bp.ontolobridge_ontologies =
<%=$NEW_TERM_REQUEST_ONTOLOGIES.to_json.html_safe%> ||
[];
jQuery(document).data().bp.ont_viewer = {};
jQuery(document).data().bp.ont_chart = {};
</script>

<!-- BioPortal-specific JavaScript is loaded in _footer.html.erb. -->
<!-- BioPortal-specific JavaScript is loaded in _footer.html.erb. -->
</head>
<body class="<%= controller_name %> <%= action_name %>">
<%=render partial: 'layouts/topnav'%>
<%= turbo_frame_tag :cookies_modal, src: cookies_path if session[:cookies_accepted].nil? %>
<%= render partial: 'layouts/topnav' %>
<%= turbo_frame_tag :cookies_modal, src: cookies_path if session[:cookies_accepted].nil? && !(Rails.env.development? || Rails.env.test?) %>

<div class="flex-grow-1">
<%=render partial: 'layouts/notices'%>
<div class="flex-grow-1">
<%= render partial: 'layouts/notices' %>
4 changes: 2 additions & 2 deletions app/views/users/_form.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@
ORCID ID
%font.register-optional
= t('register.optional')
%img.register-input-icon{:src => "#{asset_path("orcid.svg")}"}/
= inline_svg_tag 'orcid.svg', class: 'register-input-icon'
= text_field :user, :orcidId, value: @user.orcidId, class: "register-input-long register-input-with-icon"
%p.register-input-title
Github ID
%font.register-optional
= t('register.optional')
%img.register-input-icon{:src => "#{asset_path("github-icon.svg")}"}/
= inline_svg_tag 'github-icon.svg', class: 'register-input-icon'
= text_field :user, :githubId, value: @user.githubId, class: "register-input-long register-input-with-icon"
%p.register-input-title
= t('register.email')
Expand Down
4 changes: 2 additions & 2 deletions test/system/agent_flows_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def create_agent_flow(new_agent, person_count: , organization_count:)
within "table#admin_agents" do
assert_selector '.human', count: person_count + organization_count # all created agents
assert_text new_agent.name
new_agent.identifiers.map{|x| "https://orcid.org/#{x["notation"]}"}.each do |orcid|
new_agent.identifiers.map{|x| "https://#{new_agent.agentType.eql?('organization') ? 'ror' : 'orcid'}.org/#{x["notation"]}"}.each do |orcid|
assert_text orcid
end

Expand All @@ -91,7 +91,7 @@ def edit_agent_flow(agent, person_count: , organization_count: )
within "table#admin_agents" do
assert_selector '.human', count: person_count + organization_count # all created agents
assert_text agent.name
agent.identifiers.map{|x| "https://orcid.org/#{x["notation"]}"}.each do |orcid|
agent.identifiers.map{|x| "https://#{agent.agentType.eql?('organization') ? 'ror' : 'orcid'}.org/#{x["notation"]}"}.each do |orcid|
assert_text orcid
end
assert_text 'person', count: person_count
Expand Down

0 comments on commit 5925571

Please sign in to comment.