diff --git a/Gemfile.lock b/Gemfile.lock index 74919ff349..ae4dc02161 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -555,6 +555,7 @@ GEM zeitwerk (2.6.18) PLATFORMS + x86_64-linux x86_64-linux-musl DEPENDENCIES diff --git a/app/components/ontology_browse_card_component.rb b/app/components/ontology_browse_card_component.rb index 78fd781195..dfc2c05d0e 100644 --- a/app/components/ontology_browse_card_component.rb +++ b/app/components/ontology_browse_card_component.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true class OntologyBrowseCardComponent < ViewComponent::Base - include OntologiesHelper + include ApplicationHelper, OntologiesHelper, FederationHelper def initialize(ontology: nil, onto_link: nil, text_color: nil, bg_light_color: nil, portal_name: nil) super @@ -17,11 +17,7 @@ def ontology end def external_ontology? - !@portal_name.blank? - end - - def external_portal_name - @portal_name + !internal_ontology?(@ontology[:id]) || (Array(@ontology[:sources]).size > 1) end def onto_link diff --git a/app/components/ontology_browse_card_component/ontology_browse_card_component.html.haml b/app/components/ontology_browse_card_component/ontology_browse_card_component.html.haml index 010f454629..f609a25c7c 100644 --- a/app/components/ontology_browse_card_component/ontology_browse_card_component.html.haml +++ b/app/components/ontology_browse_card_component/ontology_browse_card_component.html.haml @@ -7,7 +7,7 @@ = ontology[:name]+" ("+ontology[:acronym]+")" = private_ontology_icon(ontology[:private]) - if external_ontology? - = render Display::InfoTooltipComponent.new(text: "Federated ontology from #{onto_link}", icon: 'external-link.svg') + = 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)) @@ -18,7 +18,7 @@ = t('components.show_more') - - unless ontology[:fairScore].nil? || ontology[:acronym] == 'AGROVOC' + - unless ontology[:fairScore].nil? || ontology[:fairScore].zero? || ontology[:acronym] == 'AGROVOC' .browse-fair %p.browse-fair-title = t('components.fair_score') @@ -45,7 +45,7 @@ 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", style: style_bg) do @@ -74,13 +74,17 @@ = render ChipButtonComponent.new(type: "clickable", text: t('components.view'), style: style_bg) - if external_ontology? - %div.mx-1{title: content_tag(:div, "Source #{external_portal_name}"), data:{controller: 'tooltip', 'tooltip-interactive-value': 'true'}} - = render ChipButtonComponent.new(type: "clickable" , style: style_bg) do - %span.d-inline - %span.mr-1 - = inline_svg 'logo-white.svg', width: "20", height: "20" - %span - = external_portal_name + - 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'}} diff --git a/app/controllers/concerns/submission_filter.rb b/app/controllers/concerns/submission_filter.rb index e090ea81f9..d804cf2cf5 100644 --- a/app/controllers/concerns/submission_filter.rb +++ b/app/controllers/concerns/submission_filter.rb @@ -1,6 +1,8 @@ module SubmissionFilter extend ActiveSupport::Concern + include FederationHelper + BROWSE_ATTRIBUTES = ['ontology', 'submissionStatus', 'description', 'pullLocation', 'creationDate', 'contact', 'released', 'naturalLanguage', 'hasOntologyLanguage', 'hasFormalityLevel', 'isOfType', 'deprecated', 'status', 'metrics'] @@ -43,7 +45,10 @@ def submissions_paginate_filter(params) groups: request_params[:group], categories: request_params[:hasDomain], formats: request_params[:hasOntologyLanguage] } - submissions = filter_using_data(@ontologies, **params) + submissions = filter_submissions(@ontologies, **params) + + submissions = merge_by_acronym(submissions) + submissions = sort_submission_by(submissions, @sort_by, @search) @@ -60,10 +65,25 @@ def ontologies_filter_url(filters, page: 1, count: false) private - def filter_using_data(ontologies, query:, status:, show_views:, private_only:, languages:, page_size:, formality_level:, is_of_type:, groups:, categories:, formats:) + def merge_by_acronym(submissions) + merged_submissions = [] + submissions.group_by { |x| x[:ontology]&.acronym }.each do |acronym, ontologies| + if ontologies.size.eql?(1) + ontology = ontologies.first + else + ontology = ontologies.select { |x| helpers.internal_ontology?(x[:id]) }.first || ontologies.first + end + + ontology[:sources] = ontologies.map { |x| x[:id] } + merged_submissions << ontology + end + merged_submissions + end + + def filter_submissions(ontologies, query:, status:, show_views:, private_only:, languages:, page_size:, formality_level:, is_of_type:, groups:, categories:, formats:) submissions = LinkedData::Client::Models::OntologySubmission.all(include: BROWSE_ATTRIBUTES.join(','), also_include_views: true, display_links: false, display_context: false) - submissions = submissions.map { |x| x[:ontology] ? [x[:ontology][:id], x] : nil}.compact.to_h + submissions = submissions.map { |x| x[:ontology] ? [x[:ontology][:id], x] : nil }.compact.to_h submissions = ontologies.map { |ont| ontology_hash(ont, submissions) } @@ -111,7 +131,7 @@ def paginate_submissions(all_submissions, page, size) end def sort_submission_by(submissions, sort_by, query = nil) - return submissions.sort_by { |x| x[:rank] ? -x[:rank] : 0} unless query.blank? + return submissions.sort_by { |x| x[:rank] ? -x[:rank] : 0 } unless query.blank? if sort_by.eql?('visits') submissions = submissions.sort_by { |x| -(x[:popularity] || 0) } @@ -221,7 +241,7 @@ def ontology_hash(ont, submissions) o[:note_count] = ont.notes&.length || 0 o[:project_count] = ont.projects&.length || 0 - o[:popularity] = @analytics[ont.id.to_s] || 0 + o[:popularity] = @analytics[ont.id.split('/').last.to_s] || 0 o[:rank] = sub ? sub[:rank] : 0 o diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index deb125bdec..821d55b07d 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -41,7 +41,7 @@ def resolve_namespaces def ontologies_analytics begin data = LinkedData::Client::Analytics.last_month.onts - data.map{|x| [x[:ont].to_s, x[:views]]}.to_h + data.map{|x| [x[:ont].split('/').last.to_s, x[:views]]}.to_h rescue StandardError {} end