Skip to content

Commit

Permalink
Merge remote-tracking branch 'ontoportal-lirmm/master'
Browse files Browse the repository at this point in the history
Align to 3.0.2 of AgroPortal
  • Loading branch information
galviset committed Dec 16, 2024
2 parents fbe2af2 + 80fc27d commit 7a05af3
Show file tree
Hide file tree
Showing 28 changed files with 178 additions and 75 deletions.
2 changes: 2 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ API_KEY=

UI_THEME=ontoportal

TWITTER_NEWS=

BIOMIXER_URL=
BIOMIXER_APIKEY=

Expand Down
1 change: 0 additions & 1 deletion app/assets/stylesheets/components/tree_view.scss
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ padding:0;
a.tree-link {
display: inline-block;
padding: 5px;
word-break: break-all;
text-wrap: wrap;
color: var(--primary-color) !important;
}
Expand Down
19 changes: 19 additions & 0 deletions app/assets/stylesheets/taxonomy.scss
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,23 @@
background-color: var(--primary-color);
}

.taxonomy-empty-illustration{
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
width: 100%;
.browse-empty-illustration {
margin-top: 40px;
}
}


.taxonomy-empty-illustration-text{
color: var(--gray-color);

}
.taxonomy-empty-illustration-button{
width: 168px;
}

5 changes: 5 additions & 0 deletions app/components/federated_portal_button_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

class FederatedPortalButtonComponent < ViewComponent::Base
attr_reader :name, :tooltip, :link, :color, :light_color
include UrlsHelper

def initialize(name:, link:, color:, tooltip:, light_color:)
@name = name
Expand All @@ -10,4 +11,8 @@ def initialize(name:, link:, color:, tooltip:, light_color:)
@color = color
@light_color = light_color
end

def internal?
!link?(@link)
end
end
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
%span{'data-controller': 'federation-portals-colors',
'data-federation-portals-colors-color-value': color,
'data-federation-portals-colors-portal-name-value': name.downcase}
%a{ href: link, target: '_blank', 'data-controller' => 'tooltip', title: tooltip, class: 'federation-portal-button button icon-right', style: color ? "background-color: #{light_color} !important" : '' }
%a{ href: link, target: internal? ? '_top' : '_blank', 'data-controller' => 'tooltip', title: tooltip, class: 'federation-portal-button button icon-right', style: color ? "background-color: #{light_color} !important" : '' }
= inline_svg_tag('logos/ontoportal.svg', class: "federated-icon-#{name.downcase}")
%div{ class: 'text', style: color ? "color: #{color} !important" : '' }
= name.humanize.gsub("portal", "Portal")
9 changes: 9 additions & 0 deletions app/controllers/admin/categories_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ class Admin::CategoriesController < ApplicationController

def index
@categories = _categories

@parents_list = Hash.new { |hash, key| hash[key] = [] }
@categories.each do |category|
category.parentCategory.each do |parent|
@parents_list[parent] << category.acronym
end
end


end

def new
Expand Down
13 changes: 8 additions & 5 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def set_locale
cookies.permanent[:locale] = I18n.locale if cookies[:locale].nil?
logger.debug "* Locale set to '#{I18n.locale}'"

I18n.locale = portal_lang if portal_language_enabled?(I18n.locale)
I18n.locale = portal_lang unless portal_language_enabled?(I18n.locale)

session[:locale] = I18n.locale
end
Expand Down Expand Up @@ -253,12 +253,15 @@ def authorize_and_redirect
end

def authorize_admin
admin = session[:user] && session[:user].admin?
redirect_to_home unless admin
redirect_to_home unless current_user_admin?
end

def current_user_admin?
session[:user] && session[:user].admin?
session[:user]&.admin? || current_login_as_admin?
end

def current_login_as_admin?
session[:admin_user]&.admin?
end

def ontology_restricted?(acronym)
Expand Down Expand Up @@ -427,7 +430,7 @@ def json_link(url, optional_params)
optional_params_str = filtered_params.map { |param, value| "#{param}=#{value}" }.join("&")
return base_url + optional_params_str + "&apikey=#{$API_KEY}"
end

def set_federated_portals
RequestStore.store[:federated_portals] = params[:portals]&.split(',')
end
Expand Down
27 changes: 15 additions & 12 deletions app/controllers/concerns/search_aggregator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -251,18 +251,21 @@ def blacklist_cls_id_components(cls_id, blacklist_words)
def merge_federated_results(search_results)
search_results.each do |element|
element[:root][:other_portals] = []

element[:reuses].reject! do |reuse|
element_ontology_id = element[:root][:ontology_id].split('/').last
element_uri = element[:root][:uri]
reuse_ontology_id = reuse[:root][:ontology_id].split('/').last
reuse_uri = reuse[:root][:uri]

if element_ontology_id == reuse_ontology_id && element_uri == reuse_uri
element[:root][:other_portals] << build_other_portal_entry(reuse)
true
else
false
element_ontology_id = element[:root][:ontology_id].split('/').last
element_uri = element[:root][:uri]
[element[:reuses], search_results].each do |collection|
collection.reject! do |entry|
next if entry == element

entry_ontology_id = entry[:root][:ontology_id].split('/').last
entry_uri = entry[:root][:uri]

if element_ontology_id == entry_ontology_id && element_uri == entry_uri
element[:root][:other_portals] << build_other_portal_entry(entry)
true
else
false
end
end
end
end
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/home_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ def portal_config
@config = $PORTALS_INSTANCES.select { |x| x[:name].downcase.eql?((params[:portal] || helpers.portal_name).downcase) }.first
if @config && @config[:api]
@portal_config = LinkedData::Client::Models::Ontology.top_level_links(@config[:api]).to_h
@color = @portal_config[:color].present? ? @portal_config[:color] : @config[:color]
@name = @portal_config[:title].present? ? @portal_config[:title] : @config[:name]
else
@portal_config = {}
end
Expand Down
12 changes: 10 additions & 2 deletions app/controllers/ontologies_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,20 @@ def ontologies_filter
end
end.flatten

unless request_portals.empty?
if federated_request?
streams += [
replace('categories_refresh_for_federation') do
key = "categories"
key = 'categories'
objects, checked_values, _ = @filters[key.to_sym]
objects = keep_only_root_categories(objects)

helpers.browse_filter_section_body(checked_values: checked_values,
key: key, objects: objects,
counts: @count_objects[key.to_sym])
end
]
end

else
streams = [replace("ontologies_list_view-page-#{@page.page}", partial: 'ontologies/browser/ontologies')]
end
Expand Down Expand Up @@ -583,4 +586,9 @@ def search_first_instance_id
return !results.blank? ? results.first[:name] : nil
end

def keep_only_root_categories(categories)
categories.select do |category|
category.id.start_with?(rest_url) || category.parentCategory.blank?
end
end
end
3 changes: 2 additions & 1 deletion app/controllers/taxonomy_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ def nest_categories_children(categories)
category_index[category[:id]] = category
end
categories.each do |category|
category[:parentCategory].each do |parent_id|
category[:parentCategory]&.each do |parent_id|
parent = category_index[parent_id]
next if parent.nil?
parent[:children] ||= []
parent[:children] << category
end
Expand Down
1 change: 1 addition & 0 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ def unescape_id

def verify_owner
return if current_user_admin?

if session[:user].nil? || (!session[:user].id.eql?(params[:id]) && !session[:user].username.eql?(params[:id]))
redirect_to controller: 'login', action: 'index', redirect: "/accounts/#{params[:id]}"
end
Expand Down
9 changes: 9 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -452,4 +452,13 @@ def categories_select(id: nil, name: nil, selected: 'None')
render Input::SelectComponent.new(id: id, name: name, value: categories_for_select, selected: selected, multiple: true)
end

def category_is_parent?(parents_list, category)
is_parent = parents_list.keys.include?(category.id)
parent_error_message = t('admin.categories.category_used_parent')
parents_list[category.id].each do |c|
parent_error_message = "#{parent_error_message} #{c}"
end
[is_parent,parent_error_message]
end

end
4 changes: 2 additions & 2 deletions app/helpers/components_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,8 @@ def properties_dropdown(id, title, tooltip, properties, is_open: false, &block)
end
end

def regular_button(id, value, variant: "secondary", state: "regular", size: "slim", &block)
render Buttons::RegularButtonComponent.new(id:id, value: value, variant: variant, state: state, size: size) do |btn|
def regular_button(id, value, variant: "secondary", state: "regular", size: "slim", href: nil, &block)
render Buttons::RegularButtonComponent.new(id:id, value: value, variant: variant, state: state, size: size, href: href) do |btn|
capture(btn, &block) if block_given?
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/fair_score_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def user_apikey
end

def fairness_service_enabled?
!$FAIRNESS_DISABLED
$FAIRNESS_DISABLED == 'false' || !$FAIRNESS_DISABLED
end

def get_fairness_service_url(apikey = user_apikey)
Expand Down
28 changes: 21 additions & 7 deletions app/helpers/federation_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ module FederationHelper

def federated_portals
$FEDERATED_PORTALS ||= LinkedData::Client.settings.federated_portals
$FEDERATED_PORTALS.each do |key, portal|
portal[:ui] += "/" unless portal[:ui].end_with?("/")
portal[:api] += "/" unless portal[:api].end_with?("/")
end
$FEDERATED_PORTALS
end

def internal_portal_config(id)
Expand Down Expand Up @@ -53,13 +58,17 @@ def ontology_portal_color(id)
end

def ontoportal_ui_link(id)
if id.include?($REST_URL)
return id.gsub($REST_URL,'')
end

portal_key, config = ontology_portal_config(id)
return nil unless portal_key

ui_link = config[:ui]
api_link = config[:api]

id.gsub(api_link, "#{ui_link}/") rescue id
id.gsub(api_link, "#{ui_link}") rescue id
end

def internal_ontology?(id)
Expand Down Expand Up @@ -210,14 +219,18 @@ def init_federation_portals_status
end

def federated_search_counts(search_results)
ids = search_results.map do |result|
result.dig(:root, :ontology_id) || rest_url
end
ids = search_results.flat_map do |result|
ontology_id = result.dig(:root, :ontology_id) || rest_url
other_portal_ids = result.dig(:root, :other_portals)&.map { |portal| portal[:link].split('?').first } || []
[ontology_id] + other_portal_ids
end.uniq
counts_ontology_ids_by_portal_name(ids)
end

def federated_browse_counts(ontologies)
ids = ontologies.map { |ontology| ontology[:id] }
ids = ontologies.flat_map do |ontology|
[ontology[:id]] + (ontology[:sources] || [])
end.uniq
counts_ontology_ids_by_portal_name(ids)
end

Expand All @@ -230,8 +243,9 @@ def counts_ontology_ids_by_portal_name(portals_ids)
counts[current_portal.downcase] += 1 if id.include?(current_portal.to_s.downcase)

federation_portals.each do |portal|
portal_api = federated_portals[portal.downcase.to_sym][:api]
counts[portal.downcase] += 1 if id.include?(portal_api)
portal_api = federated_portals[portal.downcase.to_sym][:api].sub(/^https?:\/\//, '')
portal_ui = federated_portals[portal.downcase.to_sym][:ui].sub(/^https?:\/\//, '')
counts[portal.downcase] += 1 if (id.include?(portal_api) || id.include?(portal_ui))
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/helpers/instances_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def link_to_class(ontology_acronym, conceptid)

def link_to_property(property, ontology_acronym)
link_to extract_label_from(property),
ontology_path(ontology_acronym, p: 'properties'),
ontology_path(ontology_acronym, p: 'properties', propertyid: property),
{ target: '_blank'}
end

Expand Down
12 changes: 8 additions & 4 deletions app/views/admin/categories/_category.html.haml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
%tr.human{:id => category.id.split('/').last}
- count = category.ontologies&.size || 0
- count = category.ontologies&.size || 0
- is_parent, parent_error_message = category_is_parent?(@parents_list, category)
%td
%div{style: 'width: 250px'}
%div.text-truncate{title: category.name}
Expand All @@ -18,8 +19,11 @@
= link_to_modal(nil, edit_admin_category_path(category.id.split('/').last), data: {show_modal_title_value: category.name}) do
= t('admin.categories.edit_button')
%span
- if count.zero?
= button_to t('admin.categories.delete'), CGI.unescape(admin_category_path(category.id.split('/').last)), method: :delete, class: 'btn btn-link', form: {data: { turbo: true, turbo_confirm: t('admin.categories.turbo_confirm'), turbo_frame: '_top'}}
- else
- if !count.zero?
%span{data: { controller: 'tooltip' }, title: t('admin.categories.info_error_delete')}
= link_to t('admin.categories.delete'), "", class: 'btn btn-link disabled'
- elsif is_parent
%span{data: { controller: 'tooltip' }, title: parent_error_message}
= link_to t('admin.categories.delete'), "", class: 'btn btn-link disabled'
- else
= button_to t('admin.categories.delete'), CGI.unescape(admin_category_path(category.id.split('/').last)), method: :delete, class: 'btn btn-link', form: {data: { turbo: true, turbo_confirm: t('admin.categories.turbo_confirm'), turbo_frame: '_top'}}
18 changes: 9 additions & 9 deletions app/views/home/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -165,15 +165,15 @@
%a{:href => "/landscape#fairness_assessment"}
%div.home-fair-details
%p= t('home.fair_details')

.home-sub-section-right
%h4= t('home.twitter_news')
%hr.home-section-line
.home-card.home-twitter-news
%a.twitter-timeline{"data-height" => "360", :href => "https://twitter.com/lagroportal?ref_src=twsrc%5Etfw"}
.home-twitter-loader
= render LoaderComponent.new(type: 'pulsing')
%script{:async => "", :charset => "utf-8", :src => "https://platform.twitter.com/widgets.js"}
- if !$TWITTER_NEWS.blank?
.home-sub-section-right
%h4= t('home.twitter_news')
%hr.home-section-line
.home-card.home-twitter-news
%a.twitter-timeline{"data-height" => "360", :href => $TWITTER_NEWS}
.home-twitter-loader
= render LoaderComponent.new(type: 'pulsing')
%script{:async => "", :charset => "utf-8", :src => "https://platform.twitter.com/widgets.js"}

- if slices_enabled?
.home-section
Expand Down
Loading

0 comments on commit 7a05af3

Please sign in to comment.