diff --git a/app/controllers/agents_controller.rb b/app/controllers/agents_controller.rb index 49ba3ea86..c058eb130 100644 --- a/app/controllers/agents_controller.rb +++ b/app/controllers/agents_controller.rb @@ -275,6 +275,7 @@ def agent_params v end end + p[:identifiers] = p[:identifiers].reject{ |key, value| value["notation"].empty? } identifiers_schemaAgency = params[:agentType].eql?('person') ? 'ORCID' : 'ROR' p[:identifiers]&.each_value do |identifier| identifier[:schemaAgency] = identifiers_schemaAgency diff --git a/app/views/agents/_form.html.haml b/app/views/agents/_form.html.haml index 2e8aa35d4..3a688a6ca 100644 --- a/app/views/agents/_form.html.haml +++ b/app/views/agents/_form.html.haml @@ -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 params[:show_affiliations].eql?('false') = hidden_field_tag agent_field_name(:agentType, name_prefix), agent.agentType - else %tr @@ -55,31 +55,19 @@ %tr %th = t("agents.form.identifiers") + - identifier = agent&.identifiers&.first %td.top - %div.agents-identifiers{'data-form-options-display-target':"option1", class: is_organization?(agent) && 'd-none'} - = render NestedFormInputsComponent.new do |c| - - c.template do - = 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 - = 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 identifier&.schemaAgency&.eql?('ROR') + = agent_identifier_input('0', name_prefix, identifier.notation) + - else + = agent_identifier_input('0', name_prefix) + %div.agents-identifiers{'data-form-options-display-target':"option1", class: is_organization?(agent) && 'd-none'} + - if identifier&.schemaAgency&.eql?('ORCID') + = agent_identifier_input('1', name_prefix, identifier.notation, is_organization: false) + - else + = agent_identifier_input('1', name_prefix, is_organization: false) - if show_affiliations %tr{'data-form-options-display-target':"option1", class: is_organization?(agent) && 'd-none'} diff --git a/test/application_system_test_case.rb b/test/application_system_test_case.rb index a33ff79e4..9ed6c19be 100644 --- a/test/application_system_test_case.rb +++ b/test/application_system_test_case.rb @@ -104,7 +104,6 @@ def tom_select(selector, values, open_to_add: false) element = find(ts_wrapper_selector) element.click - return unless page.has_selector?("#{ts_wrapper_selector} > .ts-dropdown") if multiple @@ -152,10 +151,10 @@ def agent_search(name) end def agent_fill(agent, parent_id: nil, is_affiliation: false) - id = agent.id ? "/#{agent.id}": '' + id = agent.id ? "/#{agent.id}" : '' form = all("form[action=\"/agents#{id}\"]").first - within form do - choose "", option: agent.agentType, allow_label_click: true unless is_affiliation + within form do + choose "", option: agent.agentType, allow_label_click: true unless is_affiliation fill_in 'name', with: agent.name if agent.agentType.eql?('organization') @@ -168,8 +167,13 @@ def agent_fill(agent, parent_id: nil, is_affiliation: false) fill_in 'email', with: agent.email end - list_inputs ".agents-identifiers", - "[identifiers]", agent.identifiers + identifier = agent.identifiers.first + + if agent.agentType.eql?('organization') + fill_in "_identifiers_0_notation", with: identifier['notation'] + else + fill_in "_identifiers_1_notation", with: identifier['notation'] + end if is_affiliation || agent.agentType.eql?('organization') refute_selector ".agents-affiliations" diff --git a/test/fixtures/agents.yml b/test/fixtures/agents.yml index 7c1a33704..73554419d 100644 --- a/test/fixtures/agents.yml +++ b/test/fixtures/agents.yml @@ -4,8 +4,6 @@ agent1: email: "jonh@test.com" identifiers: - notation: "0000-0001-2345-6789" - - notation: "0000-0001-2345-6788" - - notation: "0000-0001-2345-6788" affiliations: - name: "Research Institute X" agentType: "organization"