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: Implement federatation for the browse page #621

Merged
merged 19 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
d9b0ac0
simplify the header component to use content instead of a new section
syphax-bouazzouni May 8, 2024
29c99df
update dropdown component to a custom title section instead of text
syphax-bouazzouni May 8, 2024
cef34cf
update browse page to use Dropdown component not bootsrap one
syphax-bouazzouni May 8, 2024
972adf7
add color option to square badge component
syphax-bouazzouni May 8, 2024
b3ce09a
add text and bg colors options to ontology browse card component
syphax-bouazzouni May 9, 2024
af3546a
add federation helper code and config sample
syphax-bouazzouni May 9, 2024
3fcf3e7
add portals filters in the browse page
syphax-bouazzouni May 9, 2024
4be0ada
use federation helpers to get federation ontologies information
syphax-bouazzouni May 9, 2024
ba39985
remove the filter using index code from submission filter as no used
syphax-bouazzouni May 9, 2024
513aaf7
refactor the filter_using_data function to be faster by using an hash
syphax-bouazzouni May 9, 2024
3e00462
update the browse analytics cache to change depending on portals
syphax-bouazzouni May 9, 2024
f61f2c3
add categories and groups ids on hover to know its origin when federated
syphax-bouazzouni May 9, 2024
b94c5b6
use the last part of ids for browse counts independently of its origin
syphax-bouazzouni May 9, 2024
5681984
remove binding.pry from final federation code
syphax-bouazzouni May 10, 2024
1bc246e
add an error message if one of the external portal is down
syphax-bouazzouni May 10, 2024
4cae3d6
remove $FEDERATED_PORTALS and use existent $PORTALS_INSTANCES variable
syphax-bouazzouni Sep 3, 2024
2d26bcb
handle the merging of the same ontology from different portals
syphax-bouazzouni Sep 3, 2024
13a2ed7
Merge branch 'development' into feature/federate-browse-page
syphax-bouazzouni Sep 9, 2024
47eda19
fix groups and categories selection at browse page init
syphax-bouazzouni Sep 9, 2024
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
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ gem 'flag-icons-rails', '~> 3.4'
gem 'iso-639', '~> 0.3.6'

# Custom API client
gem 'ontologies_api_client', git: 'https://github.com/ontoportal-lirmm/ontologies_api_ruby_client.git', branch: 'master'
gem 'ontologies_api_client', git: 'https://github.com/ontoportal-lirmm/ontologies_api_ruby_client.git', branch: 'development'

# Ruby 2.7.8 pinned gems (to remove when migrating to Ruby >= 3.0)
gem 'ffi', '~> 1.16.3'
Expand Down
12 changes: 8 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
GIT
remote: https://github.com/ontoportal-lirmm/ontologies_api_ruby_client.git
revision: 24fb2549f7b69841e052491439bc8375ed5acfd9
branch: master
revision: 15ad7d41d9a414ed3570c073c2b75a3fb4cc19cf
branch: development
specs:
ontologies_api_client (2.2.0)
activesupport
activesupport (~> 7.0.4)
excon
faraday
faraday-excon (~> 2.0.0)
faraday-multipart
lz4-ruby
multi_json
oj
parallel
request_store
spawnling (= 2.1.5)

GEM
Expand Down Expand Up @@ -420,6 +422,8 @@ GEM
regexp_parser (2.9.2)
reline (0.5.10)
io-console (~> 0.5)
request_store (1.7.0)
rack (>= 1.4)
rest-client (2.1.0)
http-accept (>= 1.7.0, < 2.0)
http-cookie (>= 1.0.2, < 2.0)
Expand Down Expand Up @@ -485,7 +489,7 @@ GEM
simplecov-cobertura (2.1.0)
rexml
simplecov (~> 0.19)
simplecov-html (0.13.0)
simplecov-html (0.13.1)
simplecov_json_formatter (0.1.4)
snaky_hash (2.0.1)
hashie
Expand Down
1 change: 1 addition & 0 deletions app/assets/stylesheets/components/chip_button.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
}
.chip-button-component-container {
display: inline-block;
text-wrap: nowrap !important;
}
.chip-button-component-container svg path{
fill: var(--primary-color);
Expand Down
3 changes: 1 addition & 2 deletions app/components/display/header_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ class Display::HeaderComponent < ViewComponent::Base

include ComponentsHelper

renders_one :text

def initialize(text: nil, tooltip: nil)
super
Expand All @@ -14,7 +13,7 @@ def initialize(text: nil, tooltip: nil)

def call
content_tag(:div, class: 'header-component') do
out = content_tag(:p, text || @text)
out = content_tag(:p, content&.html_safe || @text)
if @info && !@info.empty?
out = out + info_tooltip(content_tag(:div, @info, style: 'max-width: 300px'))
end
Expand Down
5 changes: 4 additions & 1 deletion app/components/dropdown_container_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@

class DropdownContainerComponent < ViewComponent::Base
renders_one :empty_state
def initialize(title:, id:, tooltip:nil, is_open: false)
renders_one :title

def initialize(title: nil, id:, tooltip:nil, is_open: false)
super
@title = title
@id = id
@tooltip = tooltip
@is_open = is_open
end

def open_class
@is_open ? "show" : ""
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
.dropdown-container
.dropdown-title-bar{"data-toggle" => "collapse", "data-target" => "##{@id}"}
= render Display::HeaderComponent.new(text: @title, tooltip: @tooltip)
- if title?
= title
- else
= render Display::HeaderComponent.new(text: @title, tooltip: @tooltip)
= image_tag("summary/arrow-down.svg", class: 'ml-2')

.collapse{id: @id, class: open_class}
Expand Down
30 changes: 28 additions & 2 deletions app/components/ontology_browse_card_component.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,40 @@
# frozen_string_literal: true

class OntologyBrowseCardComponent < ViewComponent::Base
include OntologiesHelper
include ApplicationHelper, OntologiesHelper, FederationHelper

def initialize(ontology: nil)
def initialize(ontology: nil, onto_link: nil, text_color: nil, bg_light_color: nil, portal_name: nil)
super
@ontology = ontology
@text_color = text_color
@bg_light_color = bg_light_color
@onto_link = onto_link || "/ontologies/#{@ontology[:acronym]}" if @ontology
@portal_name = portal_name
end

def ontology
@ontology
end

def external_ontology?
!internal_ontology?(@ontology[:id]) || (Array(@ontology[:sources]).size > 1)
end

def onto_link
@onto_link
end

def style_text
external_ontology? ? "color: #{@text_color} !important" : ''
end

def portal_color
@text_color
end
alias :color :portal_color

def style_bg
external_ontology? ? "#{style_text} ; background-color: #{@bg_light_color}" : ''
end

end
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
.d-flex
.browse-ontology-description
.browse-ontology-title-bar
%a.browse-ontology-title{:href => "/ontologies/#{ontology[:acronym]}", data: {'turbo': 'false'}}
%a.browse-ontology-title{:href => onto_link, data: {'turbo': 'false'} , style: style_text}
= ontology[:name]+" ("+ontology[:acronym]+")"
= private_ontology_icon(ontology[:private])
- if external_ontology?
syphax-bouazzouni marked this conversation as resolved.
Show resolved Hide resolved
= render Display::InfoTooltipComponent.new(text: "Federated ontology from #{ontology[:sources].map{|x| link_to(x,x)}.join(', ')}", icon: 'external-link.svg')
- if session[:user]&.admin?
- ontology_status = status_string(ontology)
= render Display::InfoTooltipComponent.new(text: ontology_status, icon: submission_status_icons(ontology_status))
Expand All @@ -21,27 +23,32 @@
%p.browse-fair-title
= t('components.fair_score')
.browse-progress-bar
.browse-faire-progress{:style => "width: #{ontology[:normalizedFairScore].to_s+"%"}"}
.browse-faire-progress{:style => "width: #{ontology[:normalizedFairScore].to_s+"%"}; #{color ? 'background-color:' + color : ''}"}
%p.browse-fair-score
= ontology[:fairScore]
%a.browse-fair-details{:href => "/ontologies/#{ontology[:acronym]}#fair-details", 'data-turbo': 'false'}= t('components.details_details')
%a.browse-fair-details{:href => "#{onto_link}#fair-details", 'data-turbo': 'false', style: style_text}= t('components.details_details')

.browse-ontology-cards
= render SquareBadgeComponent.new(label: t('components.classes'), count: ontology[:class_count_formatted], link: "/ontologies/#{ontology[:acronym]}?p=classes" )
.browse-ontology-cards{style: color ? "color: #{color} !important" : ''}
= render SquareBadgeComponent.new(label: t('components.classes'),
count: ontology[:class_count_formatted],
link: "#{onto_link}?p=classes",
color: color)

= render SquareBadgeComponent.new(label: ontology[:format] == 'SKOS' ? t('components.concepts') : t('components.instances'),
count: ontology[:individual_count_formatted],
link: "/ontologies/#{ontology[:acronym]}?p=#{ontology[:format] == 'SKOS' ? "classes" : "instances"}")
count: ontology[:individual_count_formatted], color: color,
link: "#{onto_link}?p=#{ontology[:format] == 'SKOS' ? "classes" : "instances"}")

= render SquareBadgeComponent.new(label: t('components.projects'), count: ontology[:project_count], link: "/ontologies/#{ontology[:acronym]}#projects_section" )
= render SquareBadgeComponent.new(label: t('components.projects'), count: ontology[:project_count], color: color,
link: "#{onto_link}#projects_section" )

= render SquareBadgeComponent.new(label: t('components.notes'), count: ontology[:note_count], link: "/ontologies/#{ontology[:acronym]}?p=notes" )
= render SquareBadgeComponent.new(label: t('components.notes'), count: ontology[:note_count], color: color,
link: "#{onto_link}?p=notes" )


.d-flex.align-items-baseline.mt-1
.d-flex.w-100.mt-1.flex-wrap
- if ontology[:creationDate]
%span.mr-1
= render ChipButtonComponent.new(type: "clickable") do
= render ChipButtonComponent.new(type: "clickable", style: style_bg) do
%span.mr-1= t('components.submitted')
%span.browse-uploaded-date{data:{controller: 'timeago', 'timeago-datetime-value': ontology[:creationDate], 'timeago-add-suffix-value': 'true'}}
- if ontology[:contact]
Expand All @@ -52,19 +59,32 @@
- if ontology[:released]
- date = render DateTimeFieldComponent.new(value: ontology[:released])
%span{data:{controller:'tooltip'}, title: t('components.creation_date', date: date)}
= render ChipButtonComponent.new(type: "clickable") do
= render ChipButtonComponent.new(type: "clickable", style: style_bg) do
= DateTime.parse(date).year rescue date

- if ontology[:format]
%span.mx-1
= render ChipButtonComponent.new(type: "clickable") do
= render ChipButtonComponent.new(type: "clickable", style: style_bg) do
= ontology[:format]
- if ontology_retired?(ontology)
%span.mx-1
= ontology_retired_badge(ontology)
- if ontology[:viewOfOnt]
%span.mx-1{data:{controller:'tooltip'}, title: t('components.view_of_the_ontology', ontology: ontology[:viewOfOnt].split('/').last )}
= render ChipButtonComponent.new(type: "clickable", text: t('components.view'))
= render ChipButtonComponent.new(type: "clickable", text: t('components.view'), style: style_bg)

- if external_ontology?
- ontology[:sources].each do |id|
- config = ontology_portal_config(id)&.last || internal_portal_config(id) || {}
- unless config.blank?
%div.mx-1{title: content_tag(:div, "Source #{config[:name]}"), data:{controller: 'tooltip', 'tooltip-interactive-value': 'true'}}
= render ChipButtonComponent.new(type: "clickable" , style: style_bg) do
= link_to ontoportal_ui_link(id), target: '_top' do
%span.d-inline
%span.mr-1
= inline_svg 'logo-white.svg', width: "20", height: "20"
%span
= config[:name]

- if session[:user]&.admin?
%div.mx-1{title: content_tag(:div, debug(ontology), style: 'height: 300px; overflow: scroll'), data:{controller: 'tooltip', 'tooltip-interactive-value': 'true'}}
Expand Down
6 changes: 4 additions & 2 deletions app/components/square_badge_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@

class SquareBadgeComponent < ViewComponent::Base

def initialize(label: , count: ,link: nil)
def initialize(label: , count: ,link: nil, color: nil)
@label = label
@count = count
@link = link
@color = color
end

def call
return if @count.to_i.zero?

link_to(@link, class: 'browse-onology-card', 'data-turbo' => 'false') do
link_to(@link, class: 'browse-onology-card', 'data-turbo' => 'false', style: @color ? "color: #{@color} !important; border-color: #{@color}" : "") do
concat(content_tag(:p, @count, class: 'browse-card-number'))
concat(content_tag(:p, @label, class: 'browse-card-text'))
end
Expand Down
3 changes: 3 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,9 @@ def bp_config_json
def rest_url
helpers.rest_url
end
def request_portals
helpers.request_portals
end

def parse_response_body(response)
return nil if response.nil?
Expand Down
Loading
Loading