From 0734b580b9ca5a60a759dfe7a885c65f4e2f5f35 Mon Sep 17 00:00:00 2001 From: Bilel KIHAL Date: Wed, 3 Jul 2024 15:32:41 +0200 Subject: [PATCH 1/6] make agents search field component results unlimited to only 4 --- app/assets/stylesheets/components/search_input.scss | 6 ++++++ .../agent_search_input_component.html.haml | 2 +- app/components/search_input_component.rb | 7 ++++++- .../search_input_component.html.haml | 5 +++-- .../search_input_component_controller.js | 5 +++-- 5 files changed, 19 insertions(+), 6 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..3f030172f 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,5 +1,5 @@ = 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?agent_type=#{@agent_type}&name=", display_mode: 'all', 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| diff --git a/app/components/search_input_component.rb b/app/components/search_input_component.rb index 941b03d2e..76eca1f2e 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_mode: 'limited') @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_mode = display_mode 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_mode.eql?('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..d53e5dfe6 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-mode-value': @display_mode } - 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..a6770fca8 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'}, + displayMode: String } connect() { @@ -114,7 +115,7 @@ 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.displayModeValue != 'all' && breaker === 4) { break; } // Get the current item from the ontologies array From ee7cf04db5a65767c9f7942d25d9300dcbc170d1 Mon Sep 17 00:00:00 2001 From: Bilel KIHAL Date: Wed, 3 Jul 2024 17:15:43 +0200 Subject: [PATCH 2/6] make agents cherchable by acronym, affiliations, email and home page --- .../agent_search_input_component.html.haml | 2 +- .../search_input_component_controller.js | 2 +- app/controllers/agents_controller.rb | 10 ++++++---- 3 files changed, 8 insertions(+), 6 deletions(-) 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 3f030172f..211954ef5 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,7 +1,7 @@ = hidden_field_tag "#{@name_prefix}[#{@id}]" = render SearchInputComponent.new(id: 'agent' + @id, name:'agent' + @id, ajax_url: "/ajax/agents?agent_type=#{@agent_type}&name=", display_mode: 'all', 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, + use_cache: true, 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'} 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 a6770fca8..df0b5e409 100644 --- a/app/components/search_input_component/search_input_component_controller.js +++ b/app/components/search_input_component/search_input_component_controller.js @@ -122,7 +122,7 @@ export default class extends Controller { 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); diff --git a/app/controllers/agents_controller.rb b/app/controllers/agents_controller.rb index 651c02b10..2a5f5423f 100644 --- a/app/controllers/agents_controller.rb +++ b/app/controllers/agents_controller.rb @@ -18,15 +18,17 @@ 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 = LinkedData::Client::Models::Agent.all agents_json = @agents.map do |x| { id: x.id, name: x.name, type: x.agentType, - identifiers: x.identifiers.map { |i| "#{i.schemaAgency}:#{i.notation}" }.join(', ') + identifiers: x.identifiers.map { |i| "#{i.schemaAgency}:#{i.notation}" }.join(', '), + acronym: x.acronym, + affiliations: x.affiliations.to_s, + email: x.email, + homepage: x.homepage } end From 44e65ae6854c962a6785a7e7c60f95fb5ef8b84e Mon Sep 17 00:00:00 2001 From: Bilel KIHAL Date: Thu, 4 Jul 2024 15:28:20 +0200 Subject: [PATCH 3/6] =?UTF-8?q?Update=20the=20agent=20search=20input=20to?= =?UTF-8?q?=20display=20the=20result=20in=20this=20format=20Orga=20name=20?= =?UTF-8?q?(ACRONYM)=20=E2=80=93=20ROR:003vg9w96=20and=20for=20persons=20P?= =?UTF-8?q?erson=20Name=20=E2=80=93=20ORCID:0000-1524-5487-5487?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../agent_search_input_component.html.haml | 2 +- .../search_input_component_controller.js | 16 ++++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) 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 211954ef5..6f13da5dd 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 @@ -6,6 +6,6 @@ - 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/search_input_component_controller.js b/app/components/search_input_component/search_input_component_controller.js index df0b5e409..abcfc7da5 100644 --- a/app/components/search_input_component/search_input_component_controller.js +++ b/app/components/search_input_component/search_input_component_controller.js @@ -150,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 } } From 705b6d2bb8e9347bb049646abc706fedc075defc Mon Sep 17 00:00:00 2001 From: Bilel KIHAL Date: Thu, 18 Jul 2024 10:32:06 +0200 Subject: [PATCH 4/6] chagne display mode value type from string to boolean in search input component --- .../agent_search_input_component.html.haml | 2 +- app/components/search_input_component.rb | 6 +++--- .../search_input_component/search_input_component.html.haml | 2 +- .../search_input_component_controller.js | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) 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 6f13da5dd..9911cd4b3 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,5 +1,5 @@ = hidden_field_tag "#{@name_prefix}[#{@id}]" -= render SearchInputComponent.new(id: 'agent' + @id, name:'agent' + @id, ajax_url: "/ajax/agents?agent_type=#{@agent_type}&name=", display_mode: 'all', += render SearchInputComponent.new(id: 'agent' + @id, name:'agent' + @id, ajax_url: "/ajax/agents?agent_type=#{@agent_type}&name=", 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: true, 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| diff --git a/app/components/search_input_component.rb b/app/components/search_input_component.rb index 76eca1f2e..9390797d3 100644 --- a/app/components/search_input_component.rb +++ b/app/components/search_input_component.rb @@ -12,7 +12,7 @@ def initialize(id: '', id_key:, links_target: '_top', search_icon_type: nil, - display_mode: 'limited') + display_all: false) @id = id @name = name @placeholder = placeholder @@ -24,7 +24,7 @@ def initialize(id: '', @id_key = id_key @links_target = links_target @search_icon_type = search_icon_type - @display_mode = display_mode + @display_all = display_all end def action_link_info(value) if value.is_a?(Hash) @@ -37,6 +37,6 @@ def nav_icon_class @search_icon_type.eql?('nav') ? 'search-input-nav-icon' : '' end def display_all_mode_class - @display_mode.eql?('all') ? 'search-container-scroll' : '' + @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 d53e5dfe6..9d5e19384 100644 --- a/app/components/search_input_component/search_input_component.html.haml +++ b/app/components/search_input_component/search_input_component.html.haml @@ -5,7 +5,7 @@ '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-display-mode-value': @display_mode + 'data-search-input-display-all-value': @display_all } - if @search_icon_type 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 abcfc7da5..957dc6f04 100644 --- a/app/components/search_input_component/search_input_component_controller.js +++ b/app/components/search_input_component/search_input_component_controller.js @@ -13,7 +13,7 @@ export default class extends Controller { cache: {type: Boolean, default: true}, selectedItem: Number, searchEndpoint: {type: String, default: '/search'}, - displayMode: String + displayAll: Boolean } connect() { @@ -115,7 +115,7 @@ export default class extends Controller { this.dropDown.innerHTML = "" let breaker = 0 for (let i = 0; i < this.items.length; i++) { - if (this.displayModeValue != 'all' && breaker === 4) { + if (!this.displayAllValue && breaker === 4) { break; } // Get the current item from the ontologies array From 5e82b7a0e2da9ca94560daf80889ad2fb57bf380 Mon Sep 17 00:00:00 2001 From: Bilel KIHAL Date: Thu, 18 Jul 2024 15:28:17 +0200 Subject: [PATCH 5/6] remove agents search logic from UI side and limit it to only name, acronym and identifiers --- .../agent_search_input_component.html.haml | 4 ++-- app/controllers/agents_controller.rb | 8 +++----- 2 files changed, 5 insertions(+), 7 deletions(-) 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 9911cd4b3..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,7 +1,7 @@ = hidden_field_tag "#{@name_prefix}[#{@id}]" -= render SearchInputComponent.new(id: 'agent' + @id, name:'agent' + @id, ajax_url: "/ajax/agents?agent_type=#{@agent_type}&name=", display_all: true, += 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: true, + 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'} diff --git a/app/controllers/agents_controller.rb b/app/controllers/agents_controller.rb index 2a5f5423f..27019f27b 100644 --- a/app/controllers/agents_controller.rb +++ b/app/controllers/agents_controller.rb @@ -18,17 +18,15 @@ def show end def ajax_agents - @agents = LinkedData::Client::Models::Agent.all + filters = { query: params[:query]} + @agents = LinkedData::Client::Models::Agent.all(filters) agents_json = @agents.map do |x| { id: x.id, name: x.name, type: x.agentType, identifiers: x.identifiers.map { |i| "#{i.schemaAgency}:#{i.notation}" }.join(', '), - acronym: x.acronym, - affiliations: x.affiliations.to_s, - email: x.email, - homepage: x.homepage + acronym: x.acronym } end From 737f1b96cfe95215f8a96d00f9717bd252e3fe91 Mon Sep 17 00:00:00 2001 From: Bilel KIHAL Date: Mon, 22 Jul 2024 15:54:22 +0200 Subject: [PATCH 6/6] use the endpoint '/search/agents' for the agents search input component --- app/controllers/agents_controller.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/app/controllers/agents_controller.rb b/app/controllers/agents_controller.rb index 27019f27b..c514aa1ce 100644 --- a/app/controllers/agents_controller.rb +++ b/app/controllers/agents_controller.rb @@ -19,14 +19,14 @@ def show def ajax_agents filters = { query: params[:query]} - @agents = LinkedData::Client::Models::Agent.all(filters) - agents_json = @agents.map do |x| + @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(', '), - acronym: x.acronym + id: x.resource_id, + name: x.name_text, + type: x.agentType_t, + identifiers: x.identifiers_texts&.join(', '), + acronym: x.acronym_text } end