Skip to content

Commit

Permalink
tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
syphax-bouazzouni committed Dec 17, 2024
1 parent affe9da commit c4baf8a
Show file tree
Hide file tree
Showing 23 changed files with 238 additions and 100 deletions.
4 changes: 2 additions & 2 deletions app/assets/stylesheets/ontologies.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ $ont-show-bg-color: #e9ecef;
}

.ontologies.show .gutter {
background-color: rgba(0, 0, 0, 0.03);
background-repeat: no-repeat;
background-position: center;

Expand Down Expand Up @@ -184,8 +183,9 @@ $ont-show-bg-color: #e9ecef;
}

#bd_content .sidebar {
overflow-x: auto;
white-space: nowrap;
min-height: 70vh;
max-height: 90vh;
}

#search_box:focus {
Expand Down
4 changes: 2 additions & 2 deletions app/assets/stylesheets/tree.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
## TREE VIEW
*********************/
#tree_wrapper {
max-height: 70vh;
overflow-y: scroll;
max-height: 75vh;
overflow-y: auto;
}

div.tree_error {
Expand Down
10 changes: 10 additions & 0 deletions app/components/chip_button_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class ChipButtonComponent < ViewComponent::Base
def initialize(url: nil, text: nil, type: "static", disabled: false, tooltip: nil ,**html_options)
@url = url
@text = text
@type = type
@disabled = disabled
@tooltip = tooltip
@html_options = html_options.merge({href: @url})
end
end
16 changes: 16 additions & 0 deletions app/components/chips_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class ChipsComponent < ViewComponent::Base

renders_one :count
def initialize(id:nil, name:, label: nil, value: nil, checked: false, tooltip: nil)
@id = id || name
@name = name
@value = value || 'true'
@checked = checked
@label = label || @value
@tooltip = tooltip
end

def checked?
@checked
end
end
9 changes: 9 additions & 0 deletions app/components/chips_component/chips_component.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.chips-container{class: @disabled ? 'disabled' : '', 'data-controller': 'tooltip', title: @tooltip}
%div
%label{:for => "chips-#{@id}-check"}
%input{:id => "chips-#{@id}-check", :name => @name, :type => "checkbox", :value => @value, checked: checked?, disabled: @disabled}
%span
= inline_svg_tag 'check.svg', class: 'chips-check-icon'
%div
= @label
= count
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,3 @@

- row_hash_properties(bottom_set, @acronym).each do |row|
- t.add_row(*row)

- if @concept_id
- t.row do |r|
- r.td(colspan: 2) do
%div.d-flex.justify-content-center.p-2#content_resource_formats
- [["json","json-ld-file"], ["xml","rdf-xml-file"] , ["ntriples","ntriples-file"], ["turtle","turtle-file"]].each do |format, icon|
%div.mx-4{data: {controller: "tooltip"}, title: "Export in #{format.upcase}"}
= link_to_format_modal(format, icon)
6 changes: 4 additions & 2 deletions app/components/rounded_button_component.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
class RoundedButtonComponent < ViewComponent::Base
def initialize(icon: "json.svg", link: "#", size: "small", target: '', title: '')
def initialize(id: nil, icon: "json.svg", link: "#", size: "small", target: '', title: '', data: nil)
@icon = icon
@link = link
@size = size
@target = target
@title = title
@data = data
@id = id
end

def size
Expand All @@ -18,4 +20,4 @@ def size
end
end

end
end
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
%a.rounded-button{:href => @link, style: "height:"+size[0]+"; width:"+size[0]+"; border-radius:"+size[2]+";", target:@target, title: @title, 'data-controller':'tooltip'}
= inline_svg_tag @icon, style: "transform: scale("+size[1]+");"
%a.rounded-button{id: @id, :href => @link, style: "height:"+size[0]+"; width:"+size[0]+"; border-radius:"+size[2]+";", target:@target, title: @title, 'data-controller':'tooltip', data: @data}
= content || inline_svg_tag(@icon, style: "transform: scale("+size[1]+");")
17 changes: 5 additions & 12 deletions app/controllers/concepts_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

class ConceptsController < ApplicationController
include MappingsHelper
include MappingsHelper, ConceptsHelper

layout 'ontology'

Expand Down Expand Up @@ -47,17 +47,10 @@ def show
end

def show_label
@ontology = LinkedData::Client::Models::Ontology.find(params[:ontology])
@ontology ||= LinkedData::Client::Models::Ontology.find_by_acronym(params[:ontology]).first
not_found unless @ontology
# Retrieve a class prefLabel or return the class ID (URI)
# - mappings may contain class URIs that are not in bioportal (e.g. obo-xrefs)
cls = @ontology.explore.single_class(params[:concept])
# TODO: log any cls.errors
# TODO: NCBO-402 might be implemented here, but it throws off a lot of ajax result rendering.
# cls_label = cls.prefLabel({:use_html => true}) || cls_id
cls_label = cls.prefLabel || params[:concept]
render plain: cls_label
cls_id = params[:concept] || params[:id] # cls_id should be a full URI
ont_id = params[:ontology] # ont_id could be a full URI or an acronym

render inline: helpers.main_language_label(concept_label(ont_id, cls_id))
end

def show_definition
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/mappings_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class MappingsController < ApplicationController
include ActionView::Helpers::NumberHelper
include MappingStatistics
include MappingStatistics,MappingsHelper

layout :determine_layout
before_action :authorize_and_redirect, only: [:create, :new, :destroy]
Expand Down Expand Up @@ -83,7 +83,7 @@ def get_concept_table
@ontology = LinkedData::Client::Models::Ontology.find_by_acronym(params[:ontologyid]).first
@concept = @ontology.explore.single_class({ full: true }, params[:conceptid])

@mappings = @concept.explore.mappings
@mappings = get_concept_mappings(@concept)
@type = params[:type]
@delete_mapping_permission = check_delete_mapping_permission(@mappings)
render partial: 'mappings/concept_mappings', layout: false
Expand Down
5 changes: 3 additions & 2 deletions app/controllers/ontologies_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,9 @@ def classes

unless @concept.id == "bp_fake_root"
@notes = @concept.explore.notes
@mappings = get_concept_mappings(@concept)
@delete_mapping_permission = check_delete_mapping_permission(@mappings)
puts 'getting mappings'
# @mappings = get_concept_mappings(@concept)
# @delete_mapping_permission = check_delete_mapping_permission(@mappings)
end

update_tab(@ontology, @concept.id)
Expand Down
73 changes: 57 additions & 16 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require 'digest/sha1'

module ApplicationHelper
include ModalHelper
include ModalHelper, MultiLanguagesHelper

RESOLVE_NAMESPACE = {:omv => "http://omv.ontoware.org/2005/05/ontology#", :skos => "http://www.w3.org/2004/02/skos/core#", :owl => "http://www.w3.org/2002/07/owl#",
:rdf => "http://www.w3.org/1999/02/22-rdf-syntax-ns#", :rdfs => "http://www.w3.org/2000/01/rdf-schema#", :metadata => "http://data.bioontology.org/metadata/",
Expand Down Expand Up @@ -152,10 +152,31 @@ def build_tree(node, string, id, submission)


def tree_link_to_concept(li_id:, child:, ontology_acronym:, active_style:, lang: )
page_name = ontology_viewer_page_name(ontology_acronym, child.prefLabel, 'Classes')
page_name = ontology_viewer_page_name(ontology_acronym, main_language_label(child.prefLabel), 'Classes')
open = child.expanded? ? "class='open'" : ''
href = ontology_acronym.blank? ? '#' : "/ontologies/#{child.explore.ontology.acronym}/concepts/?id=#{CGI.escape(child.id)}&lang=#{lang}"
"<li #{open} id='#{li_id}'><a id='#{CGI.escape(child.id)}' data-bp-ont-page-name='#{page_name}' data-turbo=true data-turbo-frame='concept_show' href='#{href}' #{active_style}> #{child.prefLabel({ use_html: true })}</a>"
pref_label_html, tooltip = tree_node_label(child)
href = ontology_acronym.blank? ? '#' : "/ontologies/#{ontology_acronym}/concepts/?id=#{CGI.escape(child.id)}&lang=#{lang}"
"<li #{open} id='#{li_id}'><a id='#{CGI.escape(child.id)}' data-bp-ont-page-name='#{page_name}' data-turbo=true data-turbo-frame='concept_show' href='#{href}' #{active_style} title='#{tooltip}'> #{pref_label_html}</a>"
end

def tree_node_label(child)
label = begin
child.prefLabel || child.label
rescue
child.id
end

if label.nil?
pref_label_html = link_last_part(child.id)
else
pref_label_lang, pref_label_html = select_language_label(label)
pref_label_lang = pref_label_lang.to_s.upcase
tooltip = pref_label_lang.eql?("@NONE") ? "" : pref_label_lang

pref_label_html = "<span class='obsolete_class'>#{pref_label_html.html_safe}</span>".html_safe if child.obsolete?
end

[pref_label_html, tooltip]
end

def tree_link_to_children(li_id:, child:, ontology_acronym:, lang: )
Expand Down Expand Up @@ -351,27 +372,47 @@ def bp_ont_link(ont_acronym)
"/ontologies/#{ont_acronym}"
end


def bp_class_link(cls_id, ont_acronym)
ontology_path(id: ont_acronym, p: 'classes', conceptid: cls_id)
"#{bp_ont_link(ont_acronym)}?p=classes&conceptid=#{escape(cls_id)}&language=#{request_lang}"
end

def label_ajax_data_h(cls_id, ont_acronym, ajax_uri, cls_url)
{ data:
{
'label-ajax-cls-id-value': cls_id,
'label-ajax-ontology-acronym-value': ont_acronym,
'label-ajax-ajax-url-value': ajax_uri,
'label-ajax-cls-id-url-value': cls_url
}
}
end

def label_ajax_data(cls_id, ont_acronym, ajax_uri, cls_url)
label_ajax_data_h(cls_id, ont_acronym, ajax_uri, cls_url)
end

def label_ajax_link(link, cls_id, ont_acronym, ajax_uri, cls_url, target = nil)
data = label_ajax_data(cls_id, ont_acronym, ajax_uri, cls_url)
options = { 'data-controller': 'label-ajax' }.merge(data)
options = options.merge({ target: target }) if target
content_tag(:span, class: 'mx-1') do
render ChipButtonComponent.new(url: link, text: cls_id, type: 'clickable', **options)
end
end

def get_link_for_cls_ajax(cls_id, ont_acronym, target = nil)
# NOTE: bp_ajax_controller.ajax_process_cls will try to resolve class labels.
# Uses 'http' as a more generic attempt to resolve class labels than .include? ont_acronym; the
# bp_ajax_controller.ajax_process_cls will try to resolve class labels and
# otherwise remove the UNIQUE_SPLIT_STR and the ont_acronym.
target = target.nil? ? '' : " target='#{target}' "

if cls_id.start_with?('http://', 'https://')
href_cls = " href='#{bp_class_link(cls_id, ont_acronym)}' "
data_cls = " data-cls='#{cls_id}' "
data_ont = " data-ont='#{ont_acronym}' "
"<a class='cls4ajax' #{data_ont} #{data_cls} #{href_cls} #{target}>#{cls_id}</a>"
if cls_id.start_with?('http://') || cls_id.start_with?('https://')
link = bp_class_link(cls_id, ont_acronym)
ajax_url = "/ajax/classes/label?language=#{request_lang}"
cls_url = "/ontologies/#{ont_acronym}?p=classes&conceptid=#{CGI.escape(cls_id)}"
label_ajax_link(link, cls_id, ont_acronym, ajax_url , cls_url ,target)
else
content_tag(:div, cls_id)
end
end


def get_link_for_ont_ajax(ont_acronym)
# Ajax call will replace the acronym with an ontology name (triggered by class='ont4ajax')
href_ont = " href='#{bp_ont_link(ont_acronym)}' "
Expand Down
14 changes: 14 additions & 0 deletions app/helpers/concepts_helper.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
# frozen_string_literal: true

module ConceptsHelper
include MultiLanguagesHelper
def concept_label(ont_id, cls_id)
@ontology = LinkedData::Client::Models::Ontology.find(ont_id)
@ontology ||= LinkedData::Client::Models::Ontology.find_by_acronym(ont_id).first
ontology_not_found(ont_id) unless @ontology
# Retrieve a class prefLabel or return the class ID (URI)
# - mappings may contain class URIs that are not in bioportal (e.g. obo-xrefs)
cls = @ontology.explore.single_class({language: request_lang, include: 'prefLabel'}, cls_id)
# TODO: log any cls.errors
# TODO: NCBO-402 might be implemented here, but it throws off a lot of ajax result rendering.
#cls_label = cls.prefLabel({:use_html => true}) || cls_id
cls.prefLabel || cls_id
end

def exclude_relation?(relation_to_check, ontology = nil)
excluded_relations = %w[type rdf:type [R] SuperClass InstanceCount]

Expand Down
4 changes: 3 additions & 1 deletion app/helpers/multi_languages_helper.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module MultiLanguagesHelper
include OntologiesHelper

def portal_language_help_text
t('language.portal_language_help_text')
Expand Down Expand Up @@ -110,6 +111,7 @@ def content_languages(submission = @submission || @submission_latest)
[lang.english_name, lang.alpha2]
end.compact

submission_lang << ['All languages', 'all']
[submission_lang, current_lang]
end

Expand Down Expand Up @@ -166,7 +168,7 @@ def display_in_multiple_languages(label)
Array(value).map do |v|
content_tag(:div, class: 'definition') do
concat content_tag(:span, v)
concat content_tag(:span, key.upcase, class: 'badge badge-secondary ml-1') unless key.to_s.upcase.eql?('NONE') || key.to_s.upcase.eql?('@NONE')
concat content_tag(:span, key.upcase, class: 'badge bg-secondary ml-1') unless key.to_s.upcase.eql?('NONE') || key.to_s.upcase.eql?('@NONE')
end
end.join
end.join)
Expand Down
10 changes: 5 additions & 5 deletions app/helpers/ontologies_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ def ontology_object_json_link(ontology_acronym, object_type, id)
end

def render_permalink_link
content_tag(:div, class: 'mx-1') do
link_to("#classPermalinkModal", class: "class-permalink nav-link", title: t('concepts.permanent_link_class'), aria: { label: t('concepts.permanent_link_class') }, data: { toggle: "modal", current_purl: @current_purl }) do
content_tag(:i, '', class: "fas fa-link", aria: { hidden: "true" })
content_tag(:div, class: 'concepts_json_button mx-2') do
render RoundedButtonComponent.new(id: 'classPermalink', link: 'javascript:void(0);', title: t('concepts.permanent_link_class'), data: { 'bs-toggle': "modal", 'bs-target': "#classPermalinkModal", current_purl: @current_purl} ) do
inline_svg_tag('icons/copy_link.svg', width: 20, height: 20)
end
end
end

def render_concepts_json_button(link)
content_tag(:div, class: 'concepts_json_button') do
render RoundedButtonComponent.new(link: link, target: '_blank')
render RoundedButtonComponent.new(link: link, target: '_blank', title: t('concepts.permanent_link_class'))
end
end

Expand Down Expand Up @@ -250,7 +250,7 @@ def visits_chart_dataset_array(visits_data, fill: true)
data: x,
borderWidth: 2,
borderRadius: 5,
borderSkipped: false,
borderSkipped: true,
cubicInterpolationMode: 'monotone',
tension: 0.4,
fill: fill
Expand Down
3 changes: 3 additions & 0 deletions app/javascript/controllers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,6 @@ application.register("turbo-frame", TurboFrameController)

import TurboFrameErrorController from "./turbo_frame_error_controller"
application.register("turbo-frame-error", TurboFrameErrorController)

import LabelAjaxController from "./label_ajax_controller"
application.register("label-ajax", LabelAjaxController)
Loading

0 comments on commit c4baf8a

Please sign in to comment.