From 1e4204f815c10d50807b5f46ba09ae4e8905ed3e Mon Sep 17 00:00:00 2001 From: Bilel Kihal <61744974+Bilelkihal@users.noreply.github.com> Date: Thu, 25 Jul 2024 16:37:49 +0200 Subject: [PATCH 1/5] Feature: Enhance agents search input component (#703) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * make agents search field component results unlimited to only 4 * make agents cherchable by acronym, affiliations, email and home page * Update the agent search input to display the result in this format Orga name (ACRONYM) – ROR:003vg9w96 and for persons Person Name – ORCID:0000-1524-5487-5487 * chagne display mode value type from string to boolean in search input component * remove agents search logic from UI side and limit it to only name, acronym and identifiers * use the endpoint '/search/agents' for the agents search input component --- .../stylesheets/components/search_input.scss | 6 +++++ .../agent_search_input_component.html.haml | 4 ++-- app/components/search_input_component.rb | 7 +++++- .../search_input_component.html.haml | 5 ++-- .../search_input_component_controller.js | 23 +++++++++++-------- app/controllers/agents_controller.rb | 16 ++++++------- 6 files changed, 39 insertions(+), 22 deletions(-) diff --git a/app/assets/stylesheets/components/search_input.scss b/app/assets/stylesheets/components/search_input.scss index dd721562a..883899fbc 100644 --- a/app/assets/stylesheets/components/search_input.scss +++ b/app/assets/stylesheets/components/search_input.scss @@ -9,6 +9,12 @@ position: absolute; } +.search-container.search-container-scroll{ + max-height: 400px; + overflow-y: auto; +} + + .search-content{ display: flex; flex-wrap: wrap; diff --git a/app/components/agent_search_input_component/agent_search_input_component.html.haml b/app/components/agent_search_input_component/agent_search_input_component.html.haml index 02b022ae1..9da8101b5 100644 --- a/app/components/agent_search_input_component/agent_search_input_component.html.haml +++ b/app/components/agent_search_input_component/agent_search_input_component.html.haml @@ -1,11 +1,11 @@ = hidden_field_tag "#{@name_prefix}[#{@id}]" -= render SearchInputComponent.new(id: 'agent' + @id, name:'agent' + @id, ajax_url: "/ajax/agents?agent_type=#{@agent_type}&name=", += render SearchInputComponent.new(id: 'agent' + @id, name:'agent' + @id, ajax_url: "/ajax/agents?query=", display_all: true, item_base_url:"/agents/#{@id}?parent_id=#{@parent_id}&edit_on_modal=#{@edit_on_modal}&name_prefix=#{@name_prefix}&deletable=#{@deletable}&agent_id=", id_key: 'id', use_cache: false, actions_links: {create_new_agent: {link: "/agents/new?name=&id=#{@id}&parent_id=#{@parent_id}&type=#{@agent_type}&show_affiliations=#{@show_affiliations}&deletable=#{@deletable}&edit_on_modal=#{@edit_on_modal}&name_prefix=#{@name_prefix}[#{@id}]", target:'_self'}}) do |s| - s.template do %a{href: "LINK", class: "search-content", 'data-turbo-frame': '_self'} %p.search-element.home-searched-ontology - NAME (IDENTIFIERS) + NAME ACRONYM IDENTIFIERS %p.home-result-type TYPE diff --git a/app/components/search_input_component.rb b/app/components/search_input_component.rb index 941b03d2e..9390797d3 100644 --- a/app/components/search_input_component.rb +++ b/app/components/search_input_component.rb @@ -11,7 +11,8 @@ def initialize(id: '', item_base_url:, id_key:, links_target: '_top', - search_icon_type: nil) + search_icon_type: nil, + display_all: false) @id = id @name = name @placeholder = placeholder @@ -23,6 +24,7 @@ def initialize(id: '', @id_key = id_key @links_target = links_target @search_icon_type = search_icon_type + @display_all = display_all end def action_link_info(value) if value.is_a?(Hash) @@ -34,4 +36,7 @@ def action_link_info(value) def nav_icon_class @search_icon_type.eql?('nav') ? 'search-input-nav-icon' : '' end + def display_all_mode_class + @display_all ? 'search-container-scroll' : '' + end end diff --git a/app/components/search_input_component/search_input_component.html.haml b/app/components/search_input_component/search_input_component.html.haml index fb0d79f28..9d5e19384 100644 --- a/app/components/search_input_component/search_input_component.html.haml +++ b/app/components/search_input_component/search_input_component.html.haml @@ -4,7 +4,8 @@ 'data-search-input-id-key-value': @id_key, 'data-search-input-cache-value': @use_cache.to_s, 'data-search-input-scroll-down-value': @scroll_down.to_s, - 'data-search-input-selected-item-value': 0 + 'data-search-input-selected-item-value': 0, + 'data-search-input-display-all-value': @display_all } - if @search_icon_type @@ -21,7 +22,7 @@ = render Input::InputFieldComponent.new(name: @name, placeholder: @placeholder, data: {'action': 'input->search-input#search blur->search-input#blur keydown.down->search-input#arrow_down keydown.up->search-input#arrow_up keydown.enter->search-input#enter_key', 'search-input-target': 'input'}) - .search-container{'data-search-input-target': 'dropDown', 'data-action': 'mousedown->search-input#prevent'} + %div{class: "search-container #{display_all_mode_class}", 'data-search-input-target': 'dropDown', 'data-action': 'mousedown->search-input#prevent'} - @actions_links.each do |key, value| - link, target = action_link_info(value) %a.search-content#search-content{href: link, 'data-turbo-frame': target, 'data-search-input-target': 'actionLink'} diff --git a/app/components/search_input_component/search_input_component_controller.js b/app/components/search_input_component/search_input_component_controller.js index 5c8d07cad..957dc6f04 100644 --- a/app/components/search_input_component/search_input_component_controller.js +++ b/app/components/search_input_component/search_input_component_controller.js @@ -12,7 +12,8 @@ export default class extends Controller { idKey: String, cache: {type: Boolean, default: true}, selectedItem: Number, - searchEndpoint: {type: String, default: '/search'} + searchEndpoint: {type: String, default: '/search'}, + displayAll: Boolean } connect() { @@ -114,14 +115,14 @@ export default class extends Controller { this.dropDown.innerHTML = "" let breaker = 0 for (let i = 0; i < this.items.length; i++) { - if (breaker === 4) { + if (!this.displayAllValue && breaker === 4) { break; } // Get the current item from the ontologies array const item = this.items[i]; let text = Object.values(item).reduce((acc, value) => acc + value, "") - + // Check if the item contains the substring if (!this.cacheValue || text.toLowerCase().includes(inputValue.toLowerCase())) { results_list.push(item); @@ -149,18 +150,22 @@ export default class extends Controller { #renderLine(item) { let template = this.templateTarget.content - let newElement = template.firstElementChild - let string = newElement.outerHTML - + let newElement = template.firstElementChild.outerHTML Object.entries(item).forEach( ([key, value]) => { key = key.toString().toUpperCase() if (key === 'TYPE'){ value = value.toString().split('/').slice(-1) } + if (key === 'ACRONYM'){ + value = value ? `(${value.toString()})` : '' + } + if (key === 'IDENTIFIERS'){ + value = value ? `- ${value.toString()}` : '' + } const regex = new RegExp('\\b' + key + '\\b', 'gi'); - string = string.replace(regex, value ? value.toString() : "") + newElement = newElement.replace(regex, value ? value.toString() : "") }) - - return new DOMParser().parseFromString(string, "text/html").body.firstElementChild + + return new DOMParser().parseFromString(newElement, "text/html").body.firstElementChild } } diff --git a/app/controllers/agents_controller.rb b/app/controllers/agents_controller.rb index 08411245f..678892a7f 100644 --- a/app/controllers/agents_controller.rb +++ b/app/controllers/agents_controller.rb @@ -18,15 +18,15 @@ def show end def ajax_agents - filters = { name: params[:name] } - filters[:agentType] = params[:agent_type] if params[:agent_type] - @agents = LinkedData::Client::Models::Agent.all(filters) - agents_json = @agents.map do |x| + filters = { query: params[:query]} + @agents = LinkedData::Client::HTTP.get('/search/agents', filters) + agents_json = @agents.collection.map do |x| { - id: x.id, - name: x.name, - type: x.agentType, - identifiers: x.identifiers.map { |i| "#{i.schemaAgency}:#{i.notation}" }.join(', ') + id: x.resource_id, + name: x.name_text, + type: x.agentType_t, + identifiers: x.identifiers_texts&.join(', '), + acronym: x.acronym_text } end From 4dfcc83dc7b90a8e8fe4e8eb1652784071863243 Mon Sep 17 00:00:00 2001 From: Syphax bouazzouni Date: Thu, 1 Aug 2024 16:58:20 +0200 Subject: [PATCH 2/5] Fix: saving and cancel button locals text capitalization (#724) --- config/locales/en.yml | 6 +++--- config/locales/fr.yml | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/config/locales/en.yml b/config/locales/en.yml index fd083756c..63fd0b572 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -946,7 +946,7 @@ en: synonym: Synonym definition: Definition parent: Parent - save: save + save: Save note_line: alert_text: "Are you sure you want to delete the note ''%{subject}'' created by %{creator}?
This action CAN NOT be undone!!!" delete: Delete @@ -957,8 +957,8 @@ en: reply: about_note_decorator: about %{note_decorator} comment: Comment - save: save - cancel: cancel + save: Save + cancel: Cancel ontolobridge: problem_of_creating_new_term: "Problem creating a new term %{endpoint}: %{class} - %{message}" new_term_instructions_saved: New term request instructions for %{acronym} saved diff --git a/config/locales/fr.yml b/config/locales/fr.yml index fd6bde39e..e83bd927c 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -964,7 +964,7 @@ fr: synonym: Synonyme definition: Définition parent: Parent - save: sauvegarder + save: Sauvegarder note_line: alert_text: "Êtes-vous sûr de vouloir supprimer la note ''%{subject}'' créée par %{creator}?
Cette action NE PEUT PAS être annulée !!!" delete: Supprimer @@ -975,8 +975,8 @@ fr: reply: about_note_decorator: à propos de %{note_decorator} comment: Commentaire - save: sauvegarder - cancel: annuler + save: Sauvegarder + cancel: Annuler ontolobridge: problem_of_creating_new_term: "Problème de création d'un nouveau terme %{endpoint} : %{class} - %{message}" From 49a4c43a0e649dc87d45b066248fcd5217dc15fe Mon Sep 17 00:00:00 2001 From: Bilel Kihal <61744974+Bilelkihal@users.noreply.github.com> Date: Fri, 2 Aug 2024 12:10:46 +0200 Subject: [PATCH 3/5] Feature: add qf param in agents search (#727) --- app/controllers/agents_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/agents_controller.rb b/app/controllers/agents_controller.rb index 678892a7f..652e01a40 100644 --- a/app/controllers/agents_controller.rb +++ b/app/controllers/agents_controller.rb @@ -18,7 +18,7 @@ def show end def ajax_agents - filters = { query: params[:query]} + filters = { query: params[:query], qf: "identifiers_texts^20 acronym_text^15 name_text^10 email_text^10"} @agents = LinkedData::Client::HTTP.get('/search/agents', filters) agents_json = @agents.collection.map do |x| { From c6d7c8ec63a58e8f0695e182e039b54e642f77ac Mon Sep 17 00:00:00 2001 From: Bilel Kihal <61744974+Bilelkihal@users.noreply.github.com> Date: Sun, 4 Aug 2024 09:54:16 +0200 Subject: [PATCH 4/5] Fix: Hide affiliations when agent is organization in agent form (#696) * Hide affiliations when the agent is an organization in the agents form * Change the name of the function affliations? to is_organization? to make it more clear * fix submission flows test after the fix of the PR #713 * fix agent tests after changing the behavior of displaying affiliations --------- Co-authored-by: Syphax --- app/helpers/agent_helper.rb | 16 ++++----- app/views/agents/_form.html.haml | 10 +++--- bin/run_api | 4 +-- test/application_system_test_case.rb | 10 +++--- test/fixtures/agents.yml | 53 ---------------------------- test/fixtures/ontologies.yml | 7 ++-- test/system/agent_flows_test.rb | 10 +++--- test/system/submission_flows_test.rb | 9 +++-- 8 files changed, 35 insertions(+), 84 deletions(-) diff --git a/app/helpers/agent_helper.rb b/app/helpers/agent_helper.rb index af3902fbd..513854f0f 100644 --- a/app/helpers/agent_helper.rb +++ b/app/helpers/agent_helper.rb @@ -69,7 +69,7 @@ def agent_search_input(id, agent_type, parent_id: , name_prefix:, deletable: fal end - def affiliation?(agent) + def is_organization?(agent) agent.agentType.eql?('organization') end @@ -163,7 +163,7 @@ def display_agent(agent, link: true) def agent_tooltip(agent) name = agent.name email = agent.email - type = agent.agentType + type = agent.agentType identifiers = display_identifiers(agent.identifiers, link: false) identifiers = orcid_number(identifiers) if agent.affiliations && agent.affiliations != [] @@ -203,7 +203,7 @@ def generate_agent_tooltip(agent_icon, name, email = nil, identifiers = nil, aff end end end - + def agent_chip_component(agent) person_icon = inline_svg_tag 'icons/person.svg' , class: 'agent-type-icon' @@ -219,16 +219,16 @@ def agent_chip_component(agent) title = agent_tooltip(agent) end render_chip_component(title, agent_icon, name) - end + end def render_chip_component(title,agent_icon,name) - render ChipButtonComponent.new(type: "static",'data-controller':' tooltip', title: title , class: 'text-truncate', style: 'max-width: 280px; display:block; line-height: unset') do + render ChipButtonComponent.new(type: "static",'data-controller':' tooltip', title: title , class: 'text-truncate', style: 'max-width: 280px; display:block; line-height: unset') do content_tag(:div, class: 'agent-chip') do content_tag(:div, agent_icon, class: 'agent-chip-circle') + content_tag(:div, name, class: 'agent-chip-name text-truncate') - end - end + end + end end def orcid_number(orcid) @@ -236,5 +236,5 @@ def orcid_number(orcid) end - + end diff --git a/app/views/agents/_form.html.haml b/app/views/agents/_form.html.haml index 60b02f33e..20c35857d 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 affiliation?(agent) && params[:parent_id] + - if is_organization?(agent) && params[:parent_id] = hidden_field_tag agent_field_name(:agentType, name_prefix), agent.agentType - else %tr @@ -30,19 +30,19 @@ %span.asterik * %td.top = text_field_tag agent_field_name(:name, name_prefix), agent.name, class: "form-control" - %tr{'data-form-options-display-target':"option1", class: affiliation?(agent) && 'd-none'} + %tr{'data-form-options-display-target':"option1", class: is_organization?(agent) && 'd-none'} %th = t("agents.form.email") %span.asterik %td.top = email_field_tag agent_field_name(:email, name_prefix), agent.email, class: "form-control" - %tr{'data-form-options-display-target':"option2", class: !affiliation?(agent) && 'd-none'} + %tr{'data-form-options-display-target':"option2", class: !is_organization?(agent) && 'd-none'} %th = t("agents.form.acronym") %span.asterik %td.top = text_field_tag agent_field_name(:acronym, name_prefix), agent.acronym,class: "form-control" - %tr{'data-form-options-display-target':"option2", class: !affiliation?(agent) && 'd-none'} + %tr{'data-form-options-display-target':"option2", class: !is_organization?(agent) && 'd-none'} %th = t("agents.form.homepage") %td.top @@ -78,7 +78,7 @@ - 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) - if show_affiliations - %tr + %tr{'data-form-options-display-target':"option1", class: is_organization?(agent) && 'd-none'} %th = t("agents.form.affiliations") %td.top.agents-affiliations.agents-inputs diff --git a/bin/run_api b/bin/run_api index 8ed4d11dc..5d1634b2f 100755 --- a/bin/run_api +++ b/bin/run_api @@ -52,7 +52,7 @@ image_tag="${image_tag:-$API_IMAGE_TAG}" starter_ontology="${starter_ontology:-$STARTER_ONTOLOGY}" remote_api_url="${remote_api_url:-$OP_API_URL}" -if curl -sSf http://localhost:9393 > /dev/null 2>&1; then +if curl -sSf http://localhost:9393 > /dev/null 2>&1; then echo "API is already running in http://localhost:9393" exit 0 fi @@ -62,7 +62,7 @@ docker compose ls -a --filter "name=ontoportal_docker" | grep -q "ontoportal_doc ( cd tmp/ontoportal_docker || exit 1 command="./run -k $api_key -r $image_repository -t $image_tag -s $starter_ontology -u $remote_api_url" - [ "$no_provision" = true ] && command="$command --no-provision" + [ "$no_provision" = true ] && command="$command" echo "Run: $command" eval "$command" ) diff --git a/test/application_system_test_case.rb b/test/application_system_test_case.rb index b4457f965..a33ff79e4 100644 --- a/test/application_system_test_case.rb +++ b/test/application_system_test_case.rb @@ -151,11 +151,11 @@ def agent_search(name) end - def agent_fill(agent, parent_id: nil, enable_affiliations: true) + def agent_fill(agent, parent_id: nil, is_affiliation: false) id = agent.id ? "/#{agent.id}": '' form = all("form[action=\"/agents#{id}\"]").first within form do - choose "", option: agent.agentType, allow_label_click: true if enable_affiliations + choose "", option: agent.agentType, allow_label_click: true unless is_affiliation fill_in 'name', with: agent.name if agent.agentType.eql?('organization') @@ -171,8 +171,9 @@ def agent_fill(agent, parent_id: nil, enable_affiliations: true) list_inputs ".agents-identifiers", "[identifiers]", agent.identifiers - unless enable_affiliations + if is_affiliation || agent.agentType.eql?('organization') refute_selector ".agents-affiliations" + click_on "Save" if agent.agentType.eql?('organization') return end @@ -184,8 +185,7 @@ def agent_fill(agent, parent_id: nil, enable_affiliations: true) agent_id = agent_search(aff.name) id = parent_id && !parent_id.eql?('NEW_RECORD') ? "#{parent_id}_#{agent_id}" : agent_id within "turbo-frame[id=\"#{id}\"]" do - agent_fill(aff, enable_affiliations: false) - click_on "Save" + agent_fill(aff, is_affiliation: true) sleep 1 end end diff --git a/test/fixtures/agents.yml b/test/fixtures/agents.yml index ce32845e0..7c1a33704 100644 --- a/test/fixtures/agents.yml +++ b/test/fixtures/agents.yml @@ -97,25 +97,6 @@ organization1: agentType: "organization" identifiers: - notation: "1234-5678" - affiliations: - - name: "Research Consortium A" - agentType: "organization" - identifiers: - - notation: "9876-5432" - affiliations: [ ] - email: "contact@researchconsortiumA.com" - acronym: "RCA" - homepage: "https://www.researchconsortiumA.com/" - - - name: "Innovation Hub B" - agentType: "organization" - identifiers: - - notation: "3456-7890" - affiliations: [ ] - email: "info@innovationhubb.com" - acronym: "IHB" - homepage: "https://www.innovationhubb.com/" - email: "info@techsolutionsgroup.com" acronym: "TSG" homepage: "https://www.techsolutionsgroup.com/" @@ -125,23 +106,6 @@ organization2: agentType: "organization" identifiers: - notation: "5678-9012" - affiliations: - - name: "Space Exploration Consortium" - agentType: "organization" - identifiers: - - notation: "1234-1234" - affiliations: [] - email: "contact@spaceconsortium.com" - acronym: "SEC" - homepage: "https://www.spaceconsortium.com/" - - name: "Tech Innovators Guild" - agentType: "organization" - identifiers: - - notation: "7890-1234" - affiliations: [] - email: "info@techinnovatorsguild.com" - acronym: "TIG" - homepage: "https://www.techinnovatorsguild.com/" email: "info@quantumdynamics.com" acronym: "QDS" homepage: "https://www.quantumdynamics.com/" @@ -151,23 +115,6 @@ organization3: agentType: "organization" identifiers: - notation: "2345-6789" - affiliations: - - name: "Health Research Alliance" - agentType: "organization" - identifiers: - - notation: "5678-9012" - affiliations: [] - email: "contact@healthresearchalliance.com" - acronym: "HRA" - homepage: "https://www.healthresearchalliance.com/" - - name: "GreenTech Innovations" - agentType: "organization" - identifiers: - - notation: "8901-2345" - affiliations: [] - email: "info@greentechinnovations.com" - acronym: "GTI" - homepage: "https://www.greentechinnovations.com/" email: "info@biotechsolutions.com" acronym: "BSI" homepage: "https://www.biotechsolutions.com/" diff --git a/test/fixtures/ontologies.yml b/test/fixtures/ontologies.yml index 1d9fa0daf..100d00b3a 100644 --- a/test/fixtures/ontologies.yml +++ b/test/fixtures/ontologies.yml @@ -83,10 +83,10 @@ resource_content_formats: "metadata_def:mappingSameURI": "@id": "ns0:T071" "metadata_def:mappingLoom": "entity" - - "@id": "ns0:T077" + - "@id": "ns0:T072" "rdfs:subClassOf": "@id": "ns0:T071" - - "@id": "ns0:T072" + - "@id": "ns0:T077" "rdfs:subClassOf": "@id": "ns0:T071" @@ -119,9 +119,10 @@ resource_content_formats: "T071" . . "entity" . + . . . - . + turtle: | @prefix rdf: . diff --git a/test/system/agent_flows_test.rb b/test/system/agent_flows_test.rb index 91be5fc8b..953c4d2e4 100644 --- a/test/system/agent_flows_test.rb +++ b/test/system/agent_flows_test.rb @@ -41,7 +41,7 @@ def teardown click_on "Persons & organizations" # Creation test - create_agent_flow(@new_organization, person_count: 0, organization_count: 3) + create_agent_flow(@new_organization, person_count: 0, organization_count: 1) # Edition test @new_organization2 = fixtures(:agents)[:organization2] @@ -50,7 +50,7 @@ def teardown @new_organization2.id = edit_link['href'].split('/')[-2] edit_link.click - edit_agent_flow(@new_organization2, person_count: 0, organization_count: 5) + edit_agent_flow(@new_organization2, person_count: 0, organization_count: 1) end @@ -61,7 +61,7 @@ def create_agent_flow(new_agent, person_count: , organization_count:) # Creation test click_on "Create New Agent" wait_for_text "TYPE" - agent_fill(new_agent) + agent_fill(new_agent, is_affiliation: false) sleep 1 assert_text "New Agent added successfully" find('.close').click @@ -75,7 +75,7 @@ def create_agent_flow(new_agent, person_count: , organization_count:) assert_text 'person', count: person_count assert_text 'organization', count: organization_count - new_agent.affiliations.map do |aff| + Array(new_agent.affiliations).map do |aff| aff["identifiers"] = aff["identifiers"].each{|x| x["schemaAgency"] = 'ORCID'} assert_text aff['name'] end @@ -97,7 +97,7 @@ def edit_agent_flow(agent, person_count: , organization_count: ) assert_text 'person', count: person_count assert_text 'organization', count: organization_count - agent.affiliations.map do |aff| + Array(agent.affiliations).map do |aff| aff["identifiers"] = aff["identifiers"].each{|x| x["schemaAgency"] = 'ORCID'} assert_text aff['name'] end diff --git a/test/system/submission_flows_test.rb b/test/system/submission_flows_test.rb index 635045cda..54adbeab5 100644 --- a/test/system/submission_flows_test.rb +++ b/test/system/submission_flows_test.rb @@ -203,12 +203,15 @@ class SubmissionFlowsTest < ApplicationSystemTestCase open_dropdown "#projects_section" usage_properties = [ :coverage, :knownUsage, - :hasDomain, :example + :example ] usage_properties.each do |property| Array(submission_2[property]).each { |v| assert_text v } # check end + has_domain_values = ["Has Domain2.1", "Has Domain2.2", "Has Domain2.3"] + has_domain_values.each { |v| assert_text v } + submission_2.designedForOntologyTask.each do |task| assert_text task.delete(' ') # TODO fix in the UI the disaply of taskes end @@ -329,7 +332,7 @@ class SubmissionFlowsTest < ApplicationSystemTestCase assert_equal existent_submission.pullLocation, find_field('submission[pullLocation]').value click_button 'Next' - + assert_equal Date.parse(existent_submission.modificationDate).to_s, find('[name="submission[modificationDate]"]', visible: false).value assert_equal existent_submission.contact.map(&:values).flatten.sort, all('[name^="submission[contact]"]').map(&:value).sort @@ -651,4 +654,4 @@ def fill_ontology(new_ontology, new_submission, add_submission: false) click_button 'Finish' end end -end \ No newline at end of file +end From 5925571f01326e98880d30e6f70a058e66b1c95a Mon Sep 17 00:00:00 2001 From: Bilel Kihal <61744974+Bilelkihal@users.noreply.github.com> Date: Sun, 4 Aug 2024 11:46:47 +0200 Subject: [PATCH 5/5] Feature: Make agent indentifiers field set by default based on agent 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 --- app/assets/stylesheets/agents.scss | 19 ++++++++ app/controllers/agents_controller.rb | 4 ++ app/helpers/agent_helper.rb | 18 +++++++ app/views/agents/_form.html.haml | 36 +++++++------- app/views/layouts/_header.html.erb | 72 +++++++++++++++++----------- app/views/users/_form.html.haml | 4 +- test/system/agent_flows_test.rb | 4 +- 7 files changed, 110 insertions(+), 47 deletions(-) diff --git a/app/assets/stylesheets/agents.scss b/app/assets/stylesheets/agents.scss index df7b74d71..bed9b6b14 100644 --- a/app/assets/stylesheets/agents.scss +++ b/app/assets/stylesheets/agents.scss @@ -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; } \ No newline at end of file diff --git a/app/controllers/agents_controller.rb b/app/controllers/agents_controller.rb index 652e01a40..7ee6f3808 100644 --- a/app/controllers/agents_controller.rb +++ b/app/controllers/agents_controller.rb @@ -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| diff --git a/app/helpers/agent_helper.rb b/app/helpers/agent_helper.rb index 513854f0f..6c5366bf7 100644 --- a/app/helpers/agent_helper.rb +++ b/app/helpers/agent_helper.rb @@ -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| diff --git a/app/views/agents/_form.html.haml b/app/views/agents/_form.html.haml index 20c35857d..2e8aa35d4 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 is_organization?(agent) && params[:parent_id] = hidden_field_tag agent_field_name(:agentType, name_prefix), agent.agentType - else %tr @@ -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 diff --git a/app/views/layouts/_header.html.erb b/app/views/layouts/_header.html.erb index 244d0a15b..07d28d73d 100644 --- a/app/views/layouts/_header.html.erb +++ b/app/views/layouts/_header.html.erb @@ -1,25 +1,28 @@ - lang="<%=I18n.locale%>"> + lang="<%= I18n.locale %>"> - <%= render partial: 'ga_tracking' %> - + <%= render partial: 'ga_tracking' %> + - - + + - <% unless Rails.env.appliance? %> + <% unless Rails.env.appliance? %> - + <% end %> - - <%= csrf_meta_tag %> - - <%if @title.nil?%><%=$ORG_SITE%><%else%><%="#{@title} | #{$ORG_SITE}"%><%end%> - - - - - + + <%= csrf_meta_tag %> + + + <% if @title.nil? %><%= $ORG_SITE %> + <% else %><%= "#{@title} | #{$ORG_SITE}" %> + <% end %> + + + + + <%= 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" %> @@ -27,19 +30,34 @@ <%= javascript_include_tag "vendor" %> - + - <%=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?) %> -
- <%=render partial: 'layouts/notices'%> \ No newline at end of file +
+<%= render partial: 'layouts/notices' %> \ No newline at end of file diff --git a/app/views/users/_form.html.haml b/app/views/users/_form.html.haml index 3a2f38b52..02fde4988 100644 --- a/app/views/users/_form.html.haml +++ b/app/views/users/_form.html.haml @@ -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') diff --git a/test/system/agent_flows_test.rb b/test/system/agent_flows_test.rb index 953c4d2e4..5eeb72055 100644 --- a/test/system/agent_flows_test.rb +++ b/test/system/agent_flows_test.rb @@ -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 @@ -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