From 4cdc1aaefb84c1e8609e88e4ec70041e82631abb Mon Sep 17 00:00:00 2001 From: Bilel KIHAL Date: Wed, 11 Sep 2024 10:21:14 +0200 Subject: [PATCH 1/8] limite taxonomy card ontologies chips number and add a see all button --- .../taxonomy_card_component.html.haml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/components/display/taxonomy_card_component/taxonomy_card_component.html.haml b/app/components/display/taxonomy_card_component/taxonomy_card_component.html.haml index 05903f4f4..ab55aa41d 100644 --- a/app/components/display/taxonomy_card_component/taxonomy_card_component.html.haml +++ b/app/components/display/taxonomy_card_component/taxonomy_card_component.html.haml @@ -11,9 +11,12 @@ .description = render TextAreaFieldComponent.new(value: @taxonomy.description) .ontologies-cards - - @taxonomy.ontologies.each do |ontology| + - @taxonomy.ontologies.each_with_index do |ontology, index| + - if index>10 + = render ChipButtonComponent.new(url: "/ontologies?#{@taxonomy.id.split('/')[-2]}=#{@taxonomy.acronym}", text: "...", tooltip:"See all ontologies ...", type: "clickable") + - break = render ChipButtonComponent.new(url: "/ontologies/#{ontology.split('/').last}", text: ontology.split('/').last, tooltip: @ontologies_names[ontology], type: "clickable") - + - if @taxonomy.children .taxonomy-children-reveal{'data-action': "click->reveal-component#toggle", 'data-id': reveal_id} .text From 504d02d3cebb1d30f2a8e17159d613a52d3c1822 Mon Sep 17 00:00:00 2001 From: Bilel KIHAL Date: Thu, 3 Oct 2024 10:10:55 +0200 Subject: [PATCH 2/8] fix infinit login page redirection when trying to access accout page --- app/controllers/users_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index a3749d463..520ab1b86 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -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 From db8e86394596031e36f1c8ff765ca9c875b7b618 Mon Sep 17 00:00:00 2001 From: Bilel KIHAL Date: Mon, 7 Oct 2024 14:39:49 +0200 Subject: [PATCH 3/8] Support coutries as languages --- Gemfile | 3 ++- Gemfile.lock | 4 ++++ app/components/language_field_component.rb | 11 ++++------ app/helpers/collections_helper.rb | 5 ++--- app/helpers/multi_languages_helper.rb | 24 ++++++++++++++++++---- 5 files changed, 32 insertions(+), 15 deletions(-) diff --git a/Gemfile b/Gemfile index c40e3640c..8309654a1 100644 --- a/Gemfile +++ b/Gemfile @@ -94,6 +94,7 @@ gem 'inline_svg' # ISO language codes and flags 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: 'master' @@ -179,4 +180,4 @@ group :test do # Testing framework for Rails gem 'rspec-rails' -end \ No newline at end of file +end diff --git a/Gemfile.lock b/Gemfile.lock index 51f97081a..97facd1e1 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -137,6 +137,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 @@ -523,6 +525,7 @@ GEM railties (>= 6.0.0) tzinfo (2.0.6) concurrent-ruby (~> 1.0) + unaccent (0.4.0) unicode-display_width (2.5.0) uri (0.13.1) version_gem (1.1.4) @@ -568,6 +571,7 @@ DEPENDENCIES capybara chart-js-rails color (~> 1.8) + countries (~> 5.7) dalli debug deepl-rb diff --git a/app/components/language_field_component.rb b/app/components/language_field_component.rb index 7998432a9..10f215fe5 100644 --- a/app/components/language_field_component.rb +++ b/app/components/language_field_component.rb @@ -3,7 +3,7 @@ class LanguageFieldComponent < ViewComponent::Base - include FlagIconsRails::Rails::ViewHelpers + include FlagIconsRails::Rails::ViewHelpers, MultiLanguagesHelper def initialize(value:, label: nil, auto_label: false, icon: nil) super @@ -11,12 +11,9 @@ def initialize(value:, label: nil, auto_label: false, icon: nil) @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 diff --git a/app/helpers/collections_helper.rb b/app/helpers/collections_helper.rb index bb81e39ce..a577f4190 100644 --- a/app/helpers/collections_helper.rb +++ b/app/helpers/collections_helper.rb @@ -4,7 +4,7 @@ module CollectionsHelper def get_collections(ontology, add_colors: false) collections = ontology.explore.collections(language: request_lang) generate_collections_colors(collections) if add_colors - collections + collections.sort_by{ |x| helpers.main_language_label(x.prefLabel) } end def get_collection(ontology, collection_uri) @@ -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 - @@ -91,4 +91,3 @@ def generate_collections_colors(collections) end end end - diff --git a/app/helpers/multi_languages_helper.rb b/app/helpers/multi_languages_helper.rb index d21d41a30..9e21f2e0e 100644 --- a/app/helpers/multi_languages_helper.rb +++ b/app/helpers/multi_languages_helper.rb @@ -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')) From 227f5633dc38954153bc00b256dfc3fc54a4d814 Mon Sep 17 00:00:00 2001 From: Bilel Kihal <61744974+Bilelkihal@users.noreply.github.com> Date: Fri, 25 Oct 2024 07:37:35 +0200 Subject: [PATCH 4/8] Fix: put back category chip component alias to group chip component (#783) --- app/helpers/components_helper.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/helpers/components_helper.rb b/app/helpers/components_helper.rb index c13580479..a63ba8edb 100644 --- a/app/helpers/components_helper.rb +++ b/app/helpers/components_helper.rb @@ -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) From 817c1f5f1d9cdd97862ca14e9caca292908a011f Mon Sep 17 00:00:00 2001 From: Bilel Kihal <61744974+Bilelkihal@users.noreply.github.com> Date: Fri, 25 Oct 2024 14:56:24 +0200 Subject: [PATCH 5/8] Fix: Summary page scroll up auto multiple times (#781) * fix summary page scroll up auto multiple times * clean center tree view code and use it for: 'classes', 'properties', 'schemes', 'collections', 'instances' * revert adding useVisibility, and extract tree_view_pages to a constant --- .../controllers/simple_tree_controller.js | 38 +++++++++++++------ 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/app/javascript/controllers/simple_tree_controller.js b/app/javascript/controllers/simple_tree_controller.js index 858bfde2c..4cece829a 100644 --- a/app/javascript/controllers/simple_tree_controller.js +++ b/app/javascript/controllers/simple_tree_controller.js @@ -1,4 +1,7 @@ import { Controller } from '@hotwired/stimulus' + +const TREE_VIEW_PAGES = ['classes', 'properties', 'schemes', 'collections', 'instances'] + // Connects to data-controller="simple-tree" export default class extends Controller { @@ -7,17 +10,7 @@ export default class extends Controller { } connect () { - setTimeout(() => { - let activeElem = this.element.querySelector('.tree-link.active'); - if (activeElem) { - activeElem.scrollIntoView({ block: 'center' }); - window.scrollTo({top: 0,}); - if (this.autoClickValue) { - activeElem.click(); - } - } - this.#onClickTooManyChildrenInit(); - }, 0); + this.#centerTreeView() } select (event) { @@ -33,6 +26,29 @@ export default class extends Controller { event.target.nextElementSibling.nextElementSibling.classList.toggle('hidden') } + #centerTreeView() { + setTimeout(() => { + const location = window.location.href; + + const isTreeViewPage = TREE_VIEW_PAGES.some(param => location.includes(`p=${param}`)); + + if (isTreeViewPage) { + const activeElem = this.element.querySelector('.tree-link.active'); + + if (activeElem) { + activeElem.scrollIntoView({ block: 'center' }); + window.scrollTo({ top: 0 }); + + if (this.autoClickValue) { + activeElem.click(); + } + } + + this.#onClickTooManyChildrenInit(); + } + }, 0); + } + #onClickTooManyChildrenInit () { jQuery('.too_many_children_override').live('click', (event) => { event.preventDefault() From a69658dadf13116adaa3c76dcc65977fc38a4240 Mon Sep 17 00:00:00 2001 From: Bilel Kihal <61744974+Bilelkihal@users.noreply.github.com> Date: Sat, 26 Oct 2024 10:31:23 +0200 Subject: [PATCH 6/8] Feature: Add enable/disable federation option (#780) * add enable/disable federation * hide federation inputs in browse page when federation is disabled * hide federation inputs in search page when federation is disabled * fix federation enabled function name in ontologies controller * put @federation_enabled variable in the right place in search controller index * rename federation_portals_enabled? to federated_request? * remove the usage of "@federation_enabled" to use directly the helper * fix a bug of the url of federation status, to add "/" to sure to always go to the correct route --------- Co-authored-by: Syphax --- app/controllers/concerns/search_aggregator.rb | 6 +++--- app/controllers/search_controller.rb | 2 +- app/helpers/federation_helper.rb | 9 +++++++-- app/views/ontologies/browser/browse.html.haml | 11 ++++++----- app/views/search/index.html.haml | 11 ++++++----- 5 files changed, 23 insertions(+), 16 deletions(-) diff --git a/app/controllers/concerns/search_aggregator.rb b/app/controllers/concerns/search_aggregator.rb index 24cc2b292..078c89c5c 100644 --- a/app/controllers/concerns/search_aggregator.rb +++ b/app/controllers/concerns/search_aggregator.rb @@ -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 @@ -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 diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb index 680d58cce..9a7efa151 100644 --- a/app/controllers/search_controller.rb +++ b/app/controllers/search_controller.rb @@ -21,7 +21,7 @@ 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) diff --git a/app/helpers/federation_helper.rb b/app/helpers/federation_helper.rb index 135cae288..d961712bc 100644 --- a/app/helpers/federation_helper.rb +++ b/app/helpers/federation_helper.rb @@ -95,10 +95,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 @@ -185,7 +190,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 diff --git a/app/views/ontologies/browser/browse.html.haml b/app/views/ontologies/browser/browse.html.haml index e912fe323..d6632fbc2 100644 --- a/app/views/ontologies/browser/browse.html.haml +++ b/app/views/ontologies/browser/browse.html.haml @@ -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 diff --git a/app/views/search/index.html.haml b/app/views/search/index.html.haml index e109c8f18..a53fccdbe 100644 --- a/app/views/search/index.html.haml +++ b/app/views/search/index.html.haml @@ -15,11 +15,12 @@ = 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[]") + - if federation_enabled? + .filter-container + .title + = t('federation.results_from_external_portals') + .field.d-flex + = federation_input_chips(name: "portals[]") .right .filter-container .title From d83e3049aeeaf66bcac042b5522c7076afc5a8b0 Mon Sep 17 00:00:00 2001 From: Bilel Kihal <61744974+Bilelkihal@users.noreply.github.com> Date: Sat, 26 Oct 2024 10:32:36 +0200 Subject: [PATCH 7/8] Fix: Jump to infinit loading after search federation work (#782) * fix jump to infinit loading * search result as an object instead of hash in search controller --- app/controllers/search_controller.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb index 9a7efa151..e0d15048d 100644 --- a/app/controllers/search_controller.rb +++ b/app/controllers/search_controller.rb @@ -26,7 +26,7 @@ def index @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) @@ -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 = "" From fea06125af71bfa1a918cb2c7e61f3b798bebae2 Mon Sep 17 00:00:00 2001 From: Bilel Kihal <61744974+Bilelkihal@users.noreply.github.com> Date: Sat, 26 Oct 2024 11:01:39 +0200 Subject: [PATCH 8/8] Fix: Include views in ontologies selector of search page (#784) * include views in ontologies selector * refactored onts_for_select to have the option to include views and by default no --------- Co-authored-by: Syphax --- app/helpers/application_helper.rb | 4 ++-- app/views/search/index.html.haml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 1ad824206..3f69732af 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -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? ) diff --git a/app/views/search/index.html.haml b/app/views/search/index.html.haml index a53fccdbe..c193b6cd0 100644 --- a/app/views/search/index.html.haml +++ b/app/views/search/index.html.haml @@ -14,8 +14,8 @@ .title = t("search.advanced_options.ontologies") .field - = ontologies_selector(id:'search_page_ontologies' ,name: 'ontologies[]', selected: params[:ontologies]&.split(',')) - - if federation_enabled? + = 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')