Skip to content

Commit

Permalink
Fix: AGROVOC concept seed not displaying and a better handling of con…
Browse files Browse the repository at this point in the history
…cept not in a scheme information (#355)

* Fix bug of roots

* fix JQuery simple tree script removing css class of elements on click

* add concept tree links muted title text if skos and not in a scheme

* make the concept_scheme request parameter nil if ressource is not skos

* optimimze the build tree function by passing to the childs  the acronym instead  of requesting ontology.aconym for each child

---------

Co-authored-by: Syphax Bouazzouni <[email protected]>
  • Loading branch information
SirineMhedhbi and syphax-bouazzouni committed Oct 17, 2023
1 parent 0935380 commit afd2472
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 34 deletions.
2 changes: 1 addition & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ def get_class(params)
end

# Create the tree
rootNode = @concept.explore.tree(include: "prefLabel,hasChildren,obsolete", concept_schemes: params[:concept_schemes])
rootNode = @concept.explore.tree(concept_schemes: params[:concept_schemes])
if rootNode.nil? || rootNode.empty?
@roots = @ontology.explore.roots(concept_schemes: params[:concept_schemes])
if @roots.nil? || @roots.empty?
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/concepts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def show
display = params[:callback].eql?('load') ? {full: true} : {display: "prefLabel"}
@concept = @ontology.explore.single_class(display, params[:id])
concept_not_found(params[:id]) if @concept.nil?
@schemes = params[:concept_schemes].split(',')
@schemes = params[:concept_schemes]&.split(',')
show_ajax_request # process an ajax call
else
# Get the latest 'ready' submission, or fallback to any latest submission
Expand Down Expand Up @@ -189,7 +189,7 @@ def show_ajax_request
gather_details
render :partial => 'load'
when 'children' # Children is called only for drawing the tree
@children = @concept.explore.children(pagesize: 750, concept_schemes: @schemes.join(',')).collection || []
@children = @concept.explore.children(pagesize: 750, concept_schemes: params[:concept_schemes]).collection || []
@children.sort! { |x, y| (x.prefLabel || "").downcase <=> (y.prefLabel || "").downcase } unless @children.empty?
render :partial => 'child_nodes'
end
Expand Down
34 changes: 18 additions & 16 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,14 @@ def draw_note_tree_leaves(notes,level,output,key)
end
end

def draw_tree(root, id = nil, concept_schemes = [])
def draw_tree(root, acronym, id = nil, concept_schemes = nil)
id = root.children.first.id if id.nil?

# TODO: handle tree view for obsolete classes, e.g. 'http://purl.obolibrary.org/obo/GO_0030400'
raw build_tree(root, '', id, concept_schemes: concept_schemes)
raw build_tree(root, '', id, acronym, concept_schemes: concept_schemes)
end

def build_tree(node, string, id, concept_schemes: [])
def build_tree(node, string, id, acronym, concept_schemes: nil)

return string if node.children.nil? || node.children.empty?

Expand All @@ -161,16 +161,16 @@ def build_tree(node, string, id, concept_schemes: [])
# This fake root will be present at the root of "flat" ontologies, we need to keep the id intact

if child.id.eql?('bp_fake_root')
string << tree_link_to_concept(child: child, ontology_acronym: '',
active_style: active_style, node: node)
string << tree_link_to_concept(child: child, ontology_acronym: acronym,
active_style: active_style, node: node, skos: !concept_schemes.nil?)
else
string << tree_link_to_concept(child: child, ontology_acronym: child.explore.ontology.acronym,
active_style: active_style, node: node)
string << tree_link_to_concept(child: child, ontology_acronym: acronym,
active_style: active_style, node: node, skos: !concept_schemes.nil?)
if child.hasChildren && !child.expanded?
string << tree_link_to_children(child: child, concept_schemes: concept_schemes)
string << tree_link_to_children(child: child, acronym: acronym, concept_schemes: concept_schemes)
elsif child.expanded?
string << '<ul>'
build_tree(child, string, id, concept_schemes: concept_schemes)
build_tree(child, string, id, acronym, concept_schemes: concept_schemes)
string << '</ul>'
end
string << '</li>'
Expand All @@ -179,30 +179,32 @@ def build_tree(node, string, id, concept_schemes: [])
string
end

def tree_link_to_concept(child:, ontology_acronym:, active_style:, node: nil)
def tree_link_to_concept(child:, ontology_acronym:, active_style:, node: nil, skos: false)
li_id = child.id.eql?('bp_fake_root') ? 'bp_fake_root' : short_uuid
open = child.expanded? ? "class='open'" : ''
icons = child.relation_icon(node)
muted_style = child.isInActiveScheme&.empty? ? 'text-muted' : ''
muted_style = skos && Array(child.isInActiveScheme).empty? ? 'text-muted' : nil
muted_title = muted_style && !child.obsolete? ? "title='is not in a scheme'" : nil
href = ontology_acronym.blank? ? '#' : "/ontologies/#{child.explore.ontology.acronym}/concepts/?id=#{CGI.escape(child.id)}"
link = <<-EOS
<a id='#{child.id}' data-conceptid='#{child.id}'
data-turbo=true data-turbo-frame='concept_show' href='#{href}'
data-collections-value='#{child.memberOf || []}'
data-active-collections-value='#{child.isInActiveCollection || []}'
data-skos-collection-colors-target='collection'
class='#{muted_style} #{active_style}'>
class='#{muted_style} #{active_style}' #{muted_title}>
#{child.prefLabel ? child.prefLabel({ use_html: true }) : child.id}
</a>
EOS

"<li #{open} id='#{li_id}'>#{link} #{icons}"
end

def tree_link_to_children(child:, concept_schemes: [])
def tree_link_to_children(child:, acronym: ,concept_schemes: nil)
li_id = child.id.eql?('bp_fake_root') ? 'bp_fake_root' : short_uuid
concept_schemes = concept_schemes.map{|x| CGI.escape(x)}.join(',')
link = "<a id='#{child.id}' href='/ajax_concepts/#{child.explore.ontology.acronym}/?conceptid=#{CGI.escape(child.id)}&concept_schemes=#{concept_schemes}&callback=children'>ajax_class</a>"
concept_schemes = "&concept_schemes=#{concept_schemes.map{|x| CGI.escape(x)}.join(',')}" if concept_schemes

link = "<a id='#{child.id}' href='/ajax_concepts/#{acronym}/?conceptid=#{CGI.escape(child.id)}#{concept_schemes}&callback=children'>ajax_class</a>"
"<ul class='ajax'><li id='#{li_id}'>#{link}</li></ul>"
end

Expand Down Expand Up @@ -397,7 +399,7 @@ def add_proposal_button(parent_id, parent_type)

def subscribe_button(ontology_id)
if session[:user].nil?
return link_to 'Subscribe to notes emails', "/login?redirect=#{request.url}", {style:'font-size: .9em;', class:'link_button'}
return link_to 'Subscribe to notes emails', "/login?redirect=#{request.url}", {style:'font-size: .9em;', class: 'link_button'}
end

user = LinkedData::Client::Models::User.find(session[:user].id)
Expand Down
4 changes: 2 additions & 2 deletions app/views/concepts/_child_nodes.html.haml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
- output =""
- for child in @children
- output << tree_link_to_concept(child: child, ontology_acronym: child.explore.ontology.acronym, active_style: '', node: @concept)
- output << tree_link_to_concept(child: child, ontology_acronym: @ontology.acronym, active_style: '', node: @concept, skos: [email protected]?)
- if child.hasChildren
- output << tree_link_to_children(child: child, concept_schemes: @schemes)
- output << tree_link_to_children(child: child, acronym: @ontology.acronym, concept_schemes: @schemes)
- output << "</li>"
= raw output
2 changes: 1 addition & 1 deletion app/views/ontologies/_treeview.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
action: 'clicked->history#updateURL'}}
%li.root
%ul
= draw_tree(@root, @concept.id, (params[:concept_schemes] || '').split(','))
= draw_tree(@root, params[:ontology], @concept.id, params[:concept_schemes]&.split(','))


Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@
'chosen-enable-colors-value': 'true'}}
-# Class tree
%div#sd_content.card.p-1.py-3{style: 'overflow-y: scroll; height: 60vh;'}
- if skos? && @roots.empty?
- if skos? && @roots&.empty?
%div.text-wrap
= render AlertMessageComponent.new do
Missing roots for #{@ontology.acronym} (skos:topConceptOf)
- else
- concept_schemes = skos? ? "&concept_schemes=#{params[:concept_schemes]}" : ''
= render TurboFrameComponent.new(id: 'concepts_tree_view',
src: "/ajax/classes/treeview?ontology=#{@ontology.acronym}&conceptid=#{escape(@concept.id)}&concept_schemes=#{params[:concept_schemes]}&auto_click=false",
src: "/ajax/classes/treeview?ontology=#{@ontology.acronym}&conceptid=#{escape(@concept.id)}#{concept_schemes}&auto_click=false",
data: {'turbo-frame-target': 'frame'})
14 changes: 4 additions & 10 deletions vendor/assets/javascripts/jquery.simple.tree.js.erb
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,8 @@ $.fn.simpleTree = function(opt){
.bind('selectstart', function() {
return false;
}).click(function(){
$('.active',TREE).attr('class','text');
if(this.className=='text')
{
this.className='active';
}
$('.active',TREE).removeClass('active');
this.classList.add('active');
if(typeof TREE.option.afterClick == 'function')
{
TREE.option.afterClick($(this).parent());
Expand All @@ -177,11 +174,8 @@ $.fn.simpleTree = function(opt){
// added by Erik Dohmen (2BinBusiness.nl) to make context menu actions
// available
}).bind("contextmenu",function(){
$('.active',TREE).attr('class','text');
if(this.className=='text')
{
this.className='active';
}
$('.active',TREE).removeClass('active');
this.classList.add('active');
if(typeof TREE.option.afterContextMenu == 'function')
{
TREE.option.afterContextMenu($(this).parent());
Expand Down

0 comments on commit afd2472

Please sign in to comment.