Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/development' into fix/propertyId…
Browse files Browse the repository at this point in the history
…-param-auto-added-in-summary-page
  • Loading branch information
syphax-bouazzouni committed Aug 4, 2024
2 parents e3a2fad + 5925571 commit 1da04e9
Show file tree
Hide file tree
Showing 20 changed files with 192 additions and 163 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;
}
6 changes: 6 additions & 0 deletions app/assets/stylesheets/components/search_input.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
position: absolute;
}

.search-container.search-container-scroll{
max-height: 400px;
overflow-y: auto;
}


.search-content{
display: flex;
flex-wrap: wrap;
Expand Down
Original file line number Diff line number Diff line change
@@ -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
7 changes: 6 additions & 1 deletion app/components/search_input_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
}
}
20 changes: 12 additions & 8 deletions app/controllers/agents_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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], 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|
{
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

Expand Down 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
8 changes: 3 additions & 5 deletions app/controllers/ontologies_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,12 @@ def properties
@acronym = @ontology.acronym
@properties = LinkedData::Client::HTTP.get("/ontologies/#{@acronym}/properties/roots", { lang: request_lang })

unless @property
@property = get_property(@properties.first.id, @acronym, include: 'all')
end
@property = get_property(@properties.first.id, @acronym, include: 'all') unless @property || @properties.empty?

if request.xhr?
return render 'ontologies/sections/properties', layout: false
render 'ontologies/sections/properties', layout: false
else
return render 'ontologies/sections/properties', layout: 'ontology_viewer'
render 'ontologies/sections/properties', layout: 'ontology_viewer'
end
end

Expand Down
34 changes: 26 additions & 8 deletions app/helpers/agent_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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 Expand Up @@ -163,7 +181,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 != []
Expand Down Expand Up @@ -203,7 +221,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'
Expand All @@ -219,22 +237,22 @@ 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)
return orcid.split("/").last
end



end
44 changes: 24 additions & 20 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 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
Expand All @@ -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
Expand All @@ -56,29 +56,33 @@
%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
= 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
%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, is_organization: false)


- 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
Expand Down
Loading

0 comments on commit 1da04e9

Please sign in to comment.