Skip to content

Commit

Permalink
Merge branch 'fix/handle-missing-portal-info-in-home-portals' into stage
Browse files Browse the repository at this point in the history
  • Loading branch information
Bilelkihal committed Nov 13, 2024
2 parents ebfe055 + 24acad1 commit 72e2f31
Show file tree
Hide file tree
Showing 19 changed files with 98 additions and 132 deletions.
1 change: 0 additions & 1 deletion app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
//
//= require bioportal
//= require admin/licenses
//= require bp_notes
//= require bp_form_complete
//= require bp_admin
//= require concepts
Expand Down
42 changes: 0 additions & 42 deletions app/assets/javascripts/bp_notes.js

This file was deleted.

2 changes: 1 addition & 1 deletion app/assets/stylesheets/home.scss
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ i.fa.fa-caret-square-o-down {
.home-statistics-container > div {
display: flex;
align-items: start;
justify-content: center;
justify-content: flex-start;
flex-wrap: wrap;
}
.home-agroportal-figures{
Expand Down
3 changes: 2 additions & 1 deletion app/assets/stylesheets/ontologies.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ $ont-metadata-bg-color: #e2ebf0;
$widget-table-border-color: #EFEFEF;



.admin-background{
a.chip_button_container_clickable{
color: var(--admin-color) !important;
Expand Down Expand Up @@ -314,4 +315,4 @@ $widget-table-border-color: #EFEFEF;
color: white;
border-radius: 10px;
position: relative;
}
}
2 changes: 1 addition & 1 deletion app/controllers/agents_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def show
end

def ajax_agents
filters = { query: params[:query], qf: "identifiers_texts^20 acronym_text^15 name_text^10 email_text^10"}
filters = { query: "#{params[:query]}*", qf: "identifiers_texts^20 acronym_text^15 name_text^10 email_text^10"}
@agents = LinkedData::Client::HTTP.get('/search/agents', filters)
agents_json = @agents.collection.map do |x|
{
Expand Down
5 changes: 4 additions & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# Likewise, all the methods added will be available for all controllers.

class ApplicationController < ActionController::Base
include InternationalisationHelper
include InternationalisationHelper, MultiLanguagesHelper

before_action :set_locale

Expand All @@ -26,6 +26,9 @@ def set_locale
I18n.locale = cookies[:locale] || detect_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)

session[:locale] = I18n.locale
end

Expand Down
19 changes: 15 additions & 4 deletions app/controllers/home_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,20 @@ def index

@anal_ont_names = []
@anal_ont_numbers = []
@analytics.sort_by{|ont, count| -count}[0..4].each do |ont, count|
@anal_ont_names << ont
@anal_ont_numbers << count
if @analytics.empty?
all_metrics = LinkedData::Client::Models::Metrics.all
all_metrics.sort_by{|x| -(x.classes + x.individuals)}[0..4].each do |x|
@anal_ont_names << x.id.split('/')[-4]
@anal_ont_numbers << (x.classes + x.individuals) || 0
end
else
@analytics.sort_by{|ont, count| -count}[0..4].each do |ont, count|
@anal_ont_names << ont
@anal_ont_numbers << count
end
end


end

def set_cookies
Expand All @@ -39,8 +48,10 @@ 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
return @portal_config = {} if @portal_config.any?{|_, value| value.blank?}
return @portal_config
else
@portal_config = {}
return @portal_config = {}
end
end

Expand Down
5 changes: 3 additions & 2 deletions app/controllers/language_controller.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
class LanguageController < ApplicationController

include MultiLanguagesHelper
# set locale to the language selected by the user
def set_locale_language
language = params[:language].strip.downcase.to_sym
supported_languages = I18n.available_locales

if language
if language && portal_language_enabled?(language)
if supported_languages.include?(language)
cookies.permanent[:locale] = language
else
Expand Down
3 changes: 1 addition & 2 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,9 @@ def admin_block(ontology: @ontology, user: session[:user], class_css: "admin-bor
end

def subscribed_to_ontology?(ontology_acronym, user)
user = LinkedData::Client::Models::User.find(user.username, {include: 'subscription'}) if user.subscription.nil?
user = LinkedData::Client::Models::User.find(user.username, {include: 'all'}) if user.subscription.nil?
return false if user.subscription.nil? or user.subscription.empty?
user.subscription.each do |sub|
#sub = {ontology: ontology_acronym, notification_type: "NOTES"}
sub_ont_acronym = sub[:ontology] ? sub[:ontology].split('/').last : nil # make sure we get the acronym, even if it's a full URI
return true if sub_ont_acronym == ontology_acronym
end
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/components_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def paginated_list_component(id:, results:, next_page_url:, child_url:, child_tu
end

def resolvability_check_tag(url)
content_tag(:span, check_resolvability_container(url), style: 'display: inline-block;', onClick: "window.open('#{check_resolvability_url(url: url)}', '_blank');")
content_tag(:span, check_resolvability_container(url), class: 'resolvability-check',style: 'display: inline-block;', onClick: "window.open('#{check_resolvability_url(url: url)}', '_blank');")
end

def rounded_button_component(link)
Expand Down
2 changes: 2 additions & 0 deletions app/helpers/home_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ def render_footer_link(options = {})


def format_number_abbreviated(number)
number = 0 if number.nil?

if number >= 1_000_000
(number / 1_000_000).to_s + 'M'
elsif number >= 1_000
Expand Down
4 changes: 4 additions & 0 deletions app/helpers/multi_languages_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ def portal_languages
}
end

def portal_language_enabled?(lang)
portal_languages.reject { |_k, x| x[:disabled] }.keys.include?(lang)
end

def portal_language_selector
languages = portal_languages
selected_language = portal_lang
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/ontologies_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ def ontology_depiction_card

def count_subscriptions(ontology_id)
ontology_id = ontology_id.split('/').last
users = LinkedData::Client::Models::User.all(include: 'subscription', display_context: false, display_links: false)
users = LinkedData::Client::Models::User.all(include: 'all', display_context: false, display_links: false)
users.select { |u| u.subscription.find { |s| s.ontology && s.ontology.split('/').last.eql?(ontology_id) } }.count
end

Expand Down
117 changes: 58 additions & 59 deletions app/views/home/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@
.home-bubble.home-bubble-one
%a.h5{href:"/ontologies/#{@anal_ont_names[0]}", style: "color: white !important"}
= @anal_ont_names[0]
%p
= @anal_ont_numbers[0].to_s + " " + t('visits.visits')
%p
= format_number_abbreviated(@anal_ont_numbers[0]) + " " + (@analytics.empty? ? t('visits.count') : t('visits.visits'))
.home-bubble.home-bubble-two
%a.h5{href:"/ontologies/#{@anal_ont_names[1]}", style: "color: white !important"}
= @anal_ont_names[1]
%p
= @anal_ont_numbers[1].to_s + " " + t('visits.visits')
%p
= format_number_abbreviated(@anal_ont_numbers[1]) + " " + (@analytics.empty? ? t('visits.count') : t('visits.visits'))
.home-bubble.home-bubble-three
%a.h5{href:"/ontologies/#{@anal_ont_names[2]}", style: "color: white !important"}
= @anal_ont_names[2]
%p
= @anal_ont_numbers[2].to_s + " " + t('visits.visits')
%p
= format_number_abbreviated(@anal_ont_numbers[2]) + " " + (@analytics.empty? ? t('visits.count') : t('visits.visits'))
%a.home-bubble.home-bubble-four{:href => "/visits"}
.h5 ...

Expand All @@ -47,7 +47,7 @@

.home-body-container
.home-section
%h4= t('home.ontology_upload')
%h4= t('home.ontology_upload', site: portal_name)
%hr.home-section-line/
%p= t('home.ontology_upload_desc')
%p= t('home.ontology_upload_benefits', site: $SITE)
Expand All @@ -62,6 +62,56 @@
= upload_ontology_button
.discover-ontologies
= discover_ontologies_button
.home-section
%h4
= t('home.agroportal_figures', site: current_slice_name || portal_name)
%hr.home-section-line/
.home-statistics-container
.home-statistics
.home-statistics-item
%hr/
%div
%h4
= format_number_abbreviated(@metrics[:ontologies_count])
%p= t("home.ontologies")
.home-statistics-item
%hr/
%div
%h4
= format_number_abbreviated(@metrics[:class_count])
%p= t("home.classes")
.home-statistics-item
%hr/
%div
%h4
= format_number_abbreviated(@metrics[:individuals_count])
%p= t("home.individuals")
.home-statistics-item
%hr/
%div
%h4
= format_number_abbreviated(@metrics[:properties_count])
%p= t("home.properties")
.home-statistics-item
%hr/
%div
%h4
= format_number_abbreviated(@metrics[:projects_count])
%p= t("home.projects")
.home-statistics-item
%hr/
%div
%h4
= format_number_abbreviated(@metrics[:mappings_count])
%p= t("home.mappings")
.home-statistics-item
%hr/
%div
%h4
= format_number_abbreviated(@metrics[:users_count])
%p= t("home.users")
.home-statistics-link.justify-content-end{style: @analytics.empty? && "visibility: hidden"}
= link_to t("home.see_details"),'/statistics', target: "_blank"

.home-section
%h4
Expand Down Expand Up @@ -125,57 +175,6 @@
= render LoaderComponent.new(type: 'pulsing')
%script{:async => "", :charset => "utf-8", :src => "https://platform.twitter.com/widgets.js"}

.home-section
%h4
= t('home.agroportal_figures', site: current_slice_name || portal_name)
%hr.home-section-line/
.home-statistics-container
.home-statistics
.home-statistics-item
%hr/
%div
%h4
= format_number_abbreviated(@metrics[:ontologies_count])
%p= t("home.ontologies")
.home-statistics-item
%hr/
%div
%h4
= format_number_abbreviated(@metrics[:class_count])
%p= t("home.classes")
.home-statistics-item
%hr/
%div
%h4
= format_number_abbreviated(@metrics[:individuals_count])
%p= t("home.individuals")
.home-statistics-item
%hr/
%div
%h4
= format_number_abbreviated(@metrics[:properties_count])
%p= t("home.properties")
.home-statistics-item
%hr/
%div
%h4
= format_number_abbreviated(@metrics[:projects_count])
%p= t("home.projects")
.home-statistics-item
%hr/
%div
%h4
= format_number_abbreviated(@metrics[:mappings_count])
%p= t("home.mappings")
.home-statistics-item
%hr/
%div
%h4
= format_number_abbreviated(@metrics[:users_count])
%p= t("home.users")
.home-statistics-link.justify-content-end{style: @analytics.empty? && "visibility: hidden"}
= link_to t("home.see_details"),'/statistics', target: "_blank"

- if slices_enabled?
.home-section
.home-section-title
Expand Down Expand Up @@ -238,4 +237,4 @@
}
function submitRecommender(){
document.getElementById("recommender_submit").click()
}
}
15 changes: 1 addition & 14 deletions app/views/notes/_notes.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,12 @@
= add_comment_button(parent_id, parent_type)
.add_proposal.mx-1
= add_proposal_button(parent_id, parent_type)
%div.ont_notes_filter.my-1.d-flex.justify-content-end.align-items-baseline
Filter:
%input#hide_archived_ont.mx-1{:checked => "true", :name => "hide_archived_ont", :type => "checkbox"}
%label{:for => "hide_archived_ont"}= t('notes.filter_hide_archived')
= render_alerts_container("notes_#{parent_type}_list_table_alerts")

.ont_notes_table_container
- cols = [ (current_user_admin? ? 'Action' : nil), 'Subject', 'Author', 'Type', (parent_type.eql?('ontology') ? 'Class' : nil),'Created'].compact
= render TableComponent.new(id:"#{parent_type}_notes") do |t|
= render TableComponent.new(id:"#{parent_type}_notes", searching: true, paging: true, sort_column: @notes.empty? ? nil : (cols.size - 1).to_s, custom_class: 'border rounded p-1') do |t|
- t.header do |row|
- row.create(*cols.map{|col| {th: col}})

Expand All @@ -28,12 +24,3 @@
- else
- @notes.each do |note|
= render partial: 'notes/note_line', locals: {note: note, ontology_acronym: @ontology.acronym, parent_type: parent_type}

:javascript
jQuery(".ontologies.show").ready(function(){
jQuery("#hide_archived_ont").click(function(){
hideOrUnhideArchivedOntNotes();
});

wireOntTable(jQuery("##{notes_table_id}"), #{parent_type.eql?('ontology')}, #{current_user_admin?})
});
Loading

0 comments on commit 72e2f31

Please sign in to comment.