Skip to content

Commit

Permalink
Fix: Bug missing roots display (#311)
Browse files Browse the repository at this point in the history
* remove dead code

* return the first concept if there is no roots

* return AlertMessageComponent if skos and empty roots

* revert removing missing class error in get_class helper

---------

Co-authored-by: Syphax Bouazzouni <gs_bouazzouni@esi.dz>
  • Loading branch information
SirineMhedhbi and syphax-bouazzouni authored Aug 6, 2023
1 parent d312181 commit 5725ebf
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
25 changes: 14 additions & 11 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -452,13 +452,15 @@ def get_class(params)
if ignore_concept_param
# get the top level nodes for the root
# TODO_REV: Support views? Replace old view call: @ontology.top_level_classes(view)
roots = @ontology.explore.roots(concept_schemes: params[:concept_schemes])
if roots.nil? || roots.empty?
LOG.add :debug, "Missing roots for #{@ontology.acronym}"
not_found("Missing roots for #{@ontology.acronym}")
@roots = @ontology.explore.roots(concept_schemes: params[:concept_schemes])
if @roots.nil? || @roots.empty?
LOG.add :debug, "Missing @roots for #{@ontology.acronym}"
@concept = @ontology.explore.classes.collection.first.explore.self(full: true)
return
end

@root = LinkedData::Client::Models::Class.new(read_only: true)
@root.children = roots.sort{|x,y| (x.prefLabel || "").downcase <=> (y.prefLabel || "").downcase}
@root.children = @roots.sort{|x,y| (x.prefLabel || "").downcase <=> (y.prefLabel || "").downcase}

# get the initial concept to display
root_child = @root.children.first
Expand All @@ -480,13 +482,14 @@ def get_class(params)
# Create the tree
rootNode = @concept.explore.tree(include: "prefLabel,hasChildren,obsolete", concept_schemes: params[:concept_schemes])
if rootNode.nil? || rootNode.empty?
roots = @ontology.explore.roots(concept_schemes: params[:concept_schemes])
if roots.nil? || roots.empty?
LOG.add :debug, "Missing roots for #{@ontology.acronym}"
not_found("Missing roots for #{@ontology.acronym}")
@roots = @ontology.explore.roots(concept_schemes: params[:concept_schemes])
if @roots.nil? || @roots.empty?
LOG.add :debug, "Missing @roots for #{@ontology.acronym}"
@concept = @ontology.explore.classes.collection.first.explore.self(full: true)
return
end
if roots.any? {|c| c.id == @concept.id}
rootNode = roots
if @roots.any? {|c| c.id == @concept.id}
rootNode = @roots
else
rootNode = [@concept]
end
Expand Down
2 changes: 0 additions & 2 deletions app/controllers/ontologies_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,6 @@ def classes
@notes = @concept.explore.notes
end

update_tab(@ontology, @concept.id)

if request.xhr?
render 'ontologies/sections/visualize', layout: false
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
'chosen-enable-colors-value': 'true'}}
-# Class tree
%div#sd_content.card.p-1.py-3{style: 'overflow-y: scroll; height: 60vh;'}
= render TurboFrameComponent.new(id: 'concepts_tree_view',
- if skos? && @roots.empty?
%div.text-wrap
= render AlertMessageComponent.new do
Missing roots for #{@ontology.acronym}
- else
= 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",
data: {'turbo-frame-target': 'frame'})
data: {'turbo-frame-target': 'frame'})

0 comments on commit 5725ebf

Please sign in to comment.