Skip to content

Commit

Permalink
add agents search input component and show action
Browse files Browse the repository at this point in the history
  • Loading branch information
syphax-bouazzouni committed Jul 7, 2023
1 parent c4e8fcc commit 3dd7493
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 0 deletions.
10 changes: 10 additions & 0 deletions app/components/agent_search_input_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# frozen_string_literal: true

class AgentSearchInputComponent < ViewComponent::Base

def initialize(id:, organization_only: false )
super
@id = id
@organization_only = organization_only
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
= render SearchInputComponent.new(name:'agent' + @id, ajax_url: "/ajax/agents?organization_only=#{@organization_only}&name=",
item_base_url:"/agents/fake_id?parent_id=#{@id}&name=", id_key: 'name',
use_cache: false,
actions_links: {create_new_agent: {link: "/agents/new?name=&parent_id=#{@id}&new_agent=false&type=organization", target:'_self'}}) do |s|
- s.template do
%a{href: "LINK", class: "home-search-ontology-content", 'data-turbo-frame': '_self'}
%p#seached-ontology.home-searched-ontology
NAME (IDENTIFIERS)
%p.home-result-type
TYPE
5 changes: 5 additions & 0 deletions app/controllers/agents_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ def index
@agents = LinkedData::Client::Models::Agent.all
end

def show
id = params[:id]&.eql?('fake_id') ? params[:name] : params[:id]
@agent = LinkedData::Client::Models::Agent.all(name: id).find { |x| x.name.eql?(id) }
@name_prefix = params[:parent_id] ? "[affiliations][#{params[:parent_id]}]" : ''
end

def ajax_agents
@agents = LinkedData::Client::Models::Agent.all(name: params[:name], agentType: params[:organization_only]&.eql?('true') ? 'organization' : '')
Expand Down
3 changes: 3 additions & 0 deletions app/views/agents/_agent_show.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- if agent.id
= hidden_field_tag agent_field_name(:id, name_prefix), agent.id
= text_field_tag '', agent.name + '(' + agent.identifiers.map {|i| i.schemaAgency+':'+i.notation}.join(', ') + ')', class: "form-control", disabled: true
2 changes: 2 additions & 0 deletions app/views/agents/show.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
= turbo_frame_tag params[:parent_id] || 'application_modal_content' do
= render partial: 'agents/agent_show', locals: {agent: @agent, name_prefix: @name_prefix}

0 comments on commit 3dd7493

Please sign in to comment.