Skip to content

Commit

Permalink
Merge branch 'development' into stage
Browse files Browse the repository at this point in the history
  • Loading branch information
syphax-bouazzouni committed Oct 28, 2024
2 parents afabee9 + fea0612 commit 637a9b5
Show file tree
Hide file tree
Showing 13 changed files with 63 additions and 37 deletions.
5 changes: 3 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,9 @@ gem 'string-similarity'
gem 'inline_svg'

# ISO language codes and flags
gem "iso-639", "~> 0.3.6"
gem "flag-icons-rails", "~> 3.4"
gem 'flag-icons-rails', '~> 3.4'
gem 'iso-639', '~> 0.3.6'
gem 'countries', '~> 5.7'

# Custom API client
gem 'ontologies_api_client', git: 'https://github.com/ontoportal-lirmm/ontologies_api_ruby_client.git', branch: 'development'
Expand Down
6 changes: 5 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ GEM
coderay (1.1.3)
color (1.8)
concurrent-ruby (1.3.4)
countries (5.7.2)
unaccent (~> 0.3)
crack (1.0.0)
bigdecimal
rexml
Expand Down Expand Up @@ -530,7 +532,8 @@ GEM
railties (>= 6.0.0)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
unicode-display_width (2.6.0)
unaccent (0.4.0)
unicode-display_width (2.5.0)
uri (0.13.1)
version_gem (1.1.4)
view_component (2.83.0)
Expand Down Expand Up @@ -575,6 +578,7 @@ DEPENDENCIES
capybara
chart-js-rails
color (~> 1.8)
countries (~> 5.7)
dalli
debug
deepl-rb
Expand Down
11 changes: 4 additions & 7 deletions app/components/language_field_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,17 @@

class LanguageFieldComponent < ViewComponent::Base

include FlagIconsRails::Rails::ViewHelpers
include FlagIconsRails::Rails::ViewHelpers, MultiLanguagesHelper

def initialize(value:, label: nil, auto_label: false, icon: nil)
super
@value = value
@lang_code = nil
@label = label
@icon = icon

iso = ISO_639.find(value.to_s.split('/').last)
if iso
@lang_code = iso.alpha2
@label ||= iso.english_name if auto_label
end
@lang_code, label = find_language_code_name(value)
@label ||= label if auto_label
@lang_code = @lang_code.split('-').last if @lang_code
end

def lang_code
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/concerns/search_aggregator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ def aggregate_results(query, results)
format_search_result(group, all_ontologies)
end

if federation_enabled?
search_results = merge_sort_federated_results(query, search_results) if federation_enabled?
if federated_request?
search_results = merge_sort_federated_results(query, search_results)
search_results = swap_canonical_portal_results_first(search_results)
end

Expand Down Expand Up @@ -90,7 +90,7 @@ def search_result_elem(class_object, ontology_id, title)
definition: class_object.definition,
}

result.merge!(class_federation_configuration(class_object)) if federation_enabled?
result.merge!(class_federation_configuration(class_object)) if federated_request?

result
end
Expand Down
5 changes: 3 additions & 2 deletions app/controllers/search_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ def index

set_federated_portals

params[:ontologies] = nil if federation_enabled?
params[:ontologies] = nil if federated_request?

@time = Benchmark.realtime do
results = LinkedData::Client::Models::Class.search(@search_query, params)
@federation_errors = federation_error(results) if federation_error?(results)
results = results[:collection]
results = results.collection


@search_results = aggregate_results(@search_query, results)
Expand All @@ -48,6 +48,7 @@ def json_search
params.delete("ontologies")
end
search_page = LinkedData::Client::Models::Class.search(params[:q], params)

@results = search_page.collection

response = ""
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class UsersController < ApplicationController

before_action :verify_owner, only: [:edit, :show, :subscribe, :un_subscribe]
before_action :verify_owner, only: [:edit, :subscribe, :un_subscribe]
before_action :authorize_admin, only: [:index,:subscribe, :un_subscribe]
layout :determine_layout

Expand Down
4 changes: 2 additions & 2 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ def error_message_alert
end
end

def onts_for_select
ontologies ||= LinkedData::Client::Models::Ontology.all(include: "acronym,name")
def onts_for_select(include_views: false)
ontologies ||= LinkedData::Client::Models::Ontology.all({include: "acronym,name", include_views: include_views})
onts_for_select = [['', '']]
ontologies.each do |ont|
next if ( ont.acronym.nil? or ont.acronym.empty? )
Expand Down
3 changes: 1 addition & 2 deletions app/helpers/collections_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def link_to_collection(collection, selected_collection_id)
pref_label_lang, pref_label_html = get_collection_label(collection)
tooltip = pref_label_lang.to_s.eql?('@none') ? '' : "data-controller='tooltip' data-tooltip-position-value='right' title='#{pref_label_lang.upcase}'"
<<-EOS
<a id="#{collection['@id']}" href="#{collection_path(collection['@id'], request_lang)}"
<a id="#{collection['@id']}" href="#{collection_path(collection['@id'], request_lang)}"
data-turbo="true" data-turbo-frame="collection" data-collectionid="#{collection['@id']}"
#{tooltip}
class="#{selected_collection_id.eql?(collection['@id']) ? 'active' : nil}">
Expand All @@ -91,4 +91,3 @@ def generate_collections_colors(collections)
end
end
end

1 change: 1 addition & 0 deletions app/helpers/components_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def group_chip_component(id: nil, name: , object: , checked: , value: nil, title
checked: checked,
value: value, tooltip: title, disabled: disabled, &block)
end
alias :category_chip_component :group_chip_component

def rdf_highlighter_container(format, content)
render Display::RdfHighlighterComponent.new(format: format, text: content)
Expand Down
9 changes: 7 additions & 2 deletions app/helpers/federation_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,15 @@ def request_portals_names(counts, time)
"#{output} in #{sprintf("%.2f", time)}s"
end

def federation_enabled?
def federated_request?
params[:portals]
end

def federation_enabled?
!federated_portals.blank?
end


def federation_error?(response)
!response[:errors].blank?
end
Expand Down Expand Up @@ -189,7 +194,7 @@ def federation_input_chips(name: nil)
federated_portals.map do |key, config|
turbo_frame_component = TurboFrameComponent.new(
id: "federation_portals_status_#{key}",
src: "status/#{key}?name=#{name}&acronym=#{config[:name]}&checked=#{request_portals.include?(key.to_s)}"
src: "/status/#{key}?name=#{name}&acronym=#{config[:name]}&checked=#{request_portals.include?(key.to_s)}"
)

content_tag :div do
Expand Down
24 changes: 20 additions & 4 deletions app/helpers/multi_languages_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,31 @@ def content_languages(submission = @submission || @submission_latest)

# Transform each language into a select option
submission_lang = submission_lang.map do |lang|
lang = lang.split('/').last.upcase
lang = ISO_639.find(lang.to_s.downcase)
next nil unless lang
[lang.alpha2, lang.english_name]
code, name = find_language_code_name(lang)
next nil unless code
[code, name]
end.compact

[submission_lang, current_lang]
end

def find_language_code_name(language)
original_lang = language.to_s.split('/').last.upcase
lang, country = original_lang.split('-')

if country
lang = ISO3166::Country.find_country_by_alpha2(country)
return nil unless lang

[original_lang, lang.nationality]
else
lang = ISO_639.find(lang.to_s.downcase)
return nil unless lang

[lang.alpha2, lang.english_name]
end
end

def content_language_help_text
content_tag(:div, style: 'width: 350px;') do
concat content_tag(:div, t('language.content_language_help_text_1'))
Expand Down
11 changes: 6 additions & 5 deletions app/views/ontologies/browser/browse.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,12 @@
- d.title { browse_filter_section_header(key: key, count: count)}
= browse_filter_section_body(key: key, checked_values: checked_values, objects: objects)

%div{ data:{action: "change->browse-filters#federationChange"}}
= dropdown_component(id: "browse-portal-filter", is_open: !request_portals.empty?) do |d|
- d.title { browse_filter_section_header(title: t('federation.results_from_external_portals'))}
.px-1.browse-federation-input-chips
= federation_input_chips(name: "portals")
- if federation_enabled?
%div{ data:{action: "change->browse-filters#federationChange"}}
= dropdown_component(id: "browse-portal-filter", is_open: !request_portals.empty?) do |d|
- d.title { browse_filter_section_header(title: t('federation.results_from_external_portals'))}
.px-1.browse-federation-input-chips
= federation_input_chips(name: "portals")

.browse-second-row
.browse-search-bar
Expand Down
13 changes: 7 additions & 6 deletions app/views/search/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@
.title
= t("search.advanced_options.ontologies")
.field
= ontologies_selector(id:'search_page_ontologies' ,name: 'ontologies[]', selected: params[:ontologies]&.split(','))
.filter-container
.title
= t('federation.results_from_external_portals')
.field.d-flex
= federation_input_chips(name: "portals[]")
= ontologies_selector(id:'search_page_ontologies' ,name: 'ontologies[]', selected: params[:ontologies]&.split(','), ontologies: onts_for_select(include_views: true))
- if federation_enabled?
.filter-container
.title
= t('federation.results_from_external_portals')
.field.d-flex
= federation_input_chips(name: "portals[]")
.right
.filter-container
.title
Expand Down

0 comments on commit 637a9b5

Please sign in to comment.