Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Add agent tooltip in summary page #404

Merged
merged 14 commits into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/assets/images/icons/organization.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions app/assets/images/icons/person.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 29 additions & 0 deletions app/assets/stylesheets/agent_tooltip.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
.agent-container{
display: flex;
align-items: center;
margin: 10px;
}
.agent-circle{
width: 70px;
height: 70px;
background-color: var(--light-color);
display: flex;
justify-content: center;
align-items: center;
border-radius: 35px;
margin-right: 12px;
}
.agent-name{
font-size: 18px;
font-weight: 600;
margin-bottom: 3px;
}
.agent-dependency{
font-size: 16px;
font-weight: 400;
color: #767676;
margin-bottom: 3px;
}
.agent-type-icon path{
fill: var(--primary-color)
}
25 changes: 25 additions & 0 deletions app/assets/stylesheets/agents.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,29 @@
.agents-inputs input {
@extend .form-control !optional;
height: 100% !important;
}
.agent-chip{
display: flex;
justify-content: center;
align-items: center;
}

.agent-chip-circle svg{
height: 15px;
}

.agent-chip-circle{
height: 30px;
width: 30px;
background-color: rgba(128, 128, 128, 0.08);
border-radius: 15px;
display: flex;
justify-content: center;
align-items: center;
margin-right:10px;
}

.agent-chip-name{
color: #8C8E8D;
font-size: 15px;
}
1 change: 1 addition & 0 deletions app/assets/stylesheets/application.css.scss.erb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
/* Bootstrap and Font Awesome */
@import "bootstrap";
@import "bootstrap_overrides";
@import "agent_tooltip";

<% if (ui_theme = $UI_THEME.to_s.parameterize).present? && File.exists?(Rails.root.join('app', 'assets', 'stylesheets', 'themes', ui_theme)) %>
@import "themes/<%= ui_theme %>/main";
Expand Down
2 changes: 1 addition & 1 deletion app/components/layout/horizontal_list_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def call
content_tag(:div, class: 'd-flex flex-wrap align-items-center') do
out = ''
elements.each do |element|
out = out + content_tag(:div, element, class: 'mr-1 mb-1 text-truncate-scroll')
out = out + content_tag(:div, element, class: 'mr-1 mb-1 text-truncate')
end
raw out
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
- c.empty_state do
= hidden_field_tag agent_field_name('', @name_prefix+"[#{Array(@agents).size}]")
- Array(@agents).each_with_index do |agent, i|
- if agent&.agentType
- if agent.is_a?(String)
- c.row do
= agent
- elsif agent&.agentType
- c.row do
= render partial: 'agents/agent_show', locals: {agent_id: i, agent: agent, name_prefix: @name_prefix, edit_on_modal: @edit_on_modal, parent_id: @parent_id}
75 changes: 64 additions & 11 deletions app/helpers/agent_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,6 @@ def display_identifiers(identifiers, link: true)
end.join(', ')
end

def display_agent(agent, link: true)
Bilelkihal marked this conversation as resolved.
Show resolved Hide resolved
return agent if agent.is_a?(String)

out = agent.name.to_s
identifiers = display_identifiers(agent.identifiers, link: link)
out = "#{out} ( #{identifiers} )" unless identifiers.empty?
affiliations = Array(agent.affiliations).map { |a| display_agent(a, link: link) }.join(', ')
out = "#{out} (affiliations: #{affiliations})" unless affiliations.empty?
out
end

def agent_field_name(name, name_prefix = '')
name_prefix&.empty? ? name : "#{name_prefix}[#{name}]"
end
Expand Down Expand Up @@ -166,4 +155,68 @@ def agent_usage_error_display(error)
details.values.join(', ').html_safe
end.join('. ').html_safe
end

def display_agent(agent, link: true)
Bilelkihal marked this conversation as resolved.
Show resolved Hide resolved
agent_chip_component(agent)
end

def agent_tooltip(agent)
name = agent.name
email = agent.email
type = agent.agentType
identifiers = display_identifiers(agent.identifiers, link: false)
#binding.pry
if agent.affiliations && agent.affiliations != []
affiliations = "affiliations: "
agent.affiliations.each do |affiliation|
affiliations = affiliations + affiliation.name + ". "
end
end
person_icon = inline_svg_tag 'icons/person.svg' , class: 'agent-type-icon'
organization_icon = inline_svg_tag 'icons/organization.svg', class: 'agent-type-icon'
agent_icon = type == "organization" ? organization_icon : person_icon
tooltip_html = generate_agent_tooltip(agent_icon, name, email, identifiers, affiliations)
return tooltip_html
end

def generate_agent_tooltip(agent_icon, name, email = nil, identifiers = nil, affiliations = nil)
content_tag(:div, class: 'agent-container') do
content_tag(:div, agent_icon, class: 'agent-circle') +
content_tag(:div) do
content_tag(:div, name, class: 'agent-name') +
content_tag(:div, email || '', class: 'agent-dependency') +
content_tag(:div, identifiers || '', class: 'agent-dependency') +
content_tag(:div, affiliations || '', class: 'agent-dependency')
end
end
end

def agent_chip_component(agent)
person_icon = inline_svg_tag 'icons/person.svg' , class: 'agent-type-icon'
organization_icon = inline_svg_tag 'icons/organization.svg', class: 'agent-type-icon'
agent_icon = person_icon

if agent.is_a?(String)
name = agent
title = nil
else
name = agent.name
agent_icon = agent.agentType.eql?("organization") ? organization_icon : person_icon
title = agent_tooltip(agent)
end
render_chip_component(title, agent_icon, name)
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
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
2 changes: 1 addition & 1 deletion app/views/agents/_agent_show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
- if agent.id
= hidden_field_tag agent_field_name(:id, agent_field_name), agent.id

= text_field_tag '', display_agent(agent, link: false), class: "form-control", disabled: true
= display_agent(agent, link: false)

- if current_user_admin? || agent.creator.eql?(current_user&.id.to_s)
- if edit_on_modal
Expand Down
6 changes: 2 additions & 4 deletions app/views/ontologies/sections/_metadata.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@

= properties_dropdown('person_and_organization','Persons and organizations','', @agents_properties) do |values|
= horizontal_list_container(values) do |v|
= render ChipButtonComponent.new(type: "static",'data-controller':' tooltip', title: '', class: 'text-truncate', style: 'max-width: 280px; display:block; line-height: unset') do
= display_agent(v, link: false)


= agent_chip_component(v)

= properties_dropdown('link','Other links','Metadata properties that highlight the links enabling access to datasets, downloading semantic resources, etc', @links_properties) do |values|
= horizontal_list_container(values) do |v|
= render LinkFieldComponent.new(value: v, raw: true)
Expand Down
5 changes: 5 additions & 0 deletions test/helpers/application_test_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ def create_user(user , admin: false)
existent_user
end

def delete_users(ontologies = LinkedData::Client::Models::Ontology.all)
Array(ontologies).each do |o|
LinkedData::Client::Models::Ontology.find_by_acronym(o.acronym).first&.delete
end
end
def delete_user(user)
LinkedData::Client::Models::User.find_by_username(user.username).first&.delete
end
Expand Down
7 changes: 4 additions & 3 deletions test/system/agent_flows_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class AgentFlowsTest < ApplicationSystemTestCase
include AgentHelper

setup do
teardown
@logged_user = fixtures(:users)[:john]
@new_person = fixtures(:agents)[:agent1]
@new_organization = fixtures(:agents)[:organization1]
Expand All @@ -12,7 +13,7 @@ class AgentFlowsTest < ApplicationSystemTestCase

def teardown
delete_agents
delete_user(@logged_user)
delete_users
end

test "go admin page and create an agent person and edit it" do
Expand Down Expand Up @@ -75,7 +76,7 @@ def create_agent_flow(new_agent, person_count: , organization_count:)

new_agent.affiliations.map do |aff|
aff["identifiers"] = aff["identifiers"].each{|x| x["schemaAgency"] = 'ORCID'}
assert_text display_agent(OpenStruct.new(aff), link: false)
assert_text aff['name']
end
end
end
Expand All @@ -96,7 +97,7 @@ def edit_agent_flow(agent, person_count: , organization_count: )

agent.affiliations.map do |aff|
aff["identifiers"] = aff["identifiers"].each{|x| x["schemaAgency"] = 'ORCID'}
assert_text display_agent(OpenStruct.new(aff), link: false)
assert_text aff['name']
end
end
end
Expand Down