Skip to content

Commit

Permalink
update select_language_label helper to select f no english found any …
Browse files Browse the repository at this point in the history
…language remaining over the not tagged
  • Loading branch information
syphax-bouazzouni committed Oct 30, 2024
1 parent 8bf8a9d commit 9c4bb90
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 17 deletions.
46 changes: 30 additions & 16 deletions app/components/tree_link_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,19 @@

class TreeLinkComponent < ViewComponent::Base
include MultiLanguagesHelper, ModalHelper, ApplicationHelper
def initialize(child:, href:, children_href: , selected: false , data: {}, muted: false, target_frame: nil, open_in_modal: false, is_reused: nil)

def initialize(child:, href:, children_href:, selected: false, data: {}, muted: false, target_frame: nil, open_in_modal: false, is_reused: nil)
super

@child = child
@active_style = selected ? 'active' : ''
#@icons = child.relation_icon(node)
@muted_style = muted ? 'text-muted' : ''
@href = href
@children_link = children_href
label = (@child.prefLabel || @child.label) rescue @child.id
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

if child.obsolete?
@pref_label_html = "<span class='obsolete_class'>#{@pref_label_html}</span>".html_safe
end
end
@data ||= { controller: 'tooltip', 'tooltip-position-value': 'right', turbo: true, 'turbo-frame': target_frame, action: 'click->simple-tree#select'}
@pref_label_html, @tooltip = node_label(child)

@data ||= { controller: 'tooltip', 'tooltip-position-value': 'right', turbo: true, 'turbo-frame': target_frame, action: 'click->simple-tree#select' }

@data.merge!(data) do |_, old, new|
"#{old} #{new}"
Expand All @@ -32,7 +25,6 @@ def initialize(child:, href:, children_href: , selected: false , data: {}, muted
@is_reused = is_reused
end


# This gives a very hacky short code to use to uniquely represent a class
# based on its parent in a tree. Used for unique ids in HTML for the tree view
def short_uuid
Expand All @@ -49,7 +41,7 @@ def open?
end

def border_left
!@child.hasChildren ? 'pl-3 tree-border-left' : ''
!@child.hasChildren ? 'pl-3 tree-border-left' : ''
end

def li_id
Expand All @@ -75,4 +67,26 @@ def open_children_link

end

private

def 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}</span>".html_safe if child.obsolete?
end

[pref_label_html, tooltip]
end

end
2 changes: 1 addition & 1 deletion app/helpers/multi_languages_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def select_language_label(concept_label, platform_languages = %i[en fr])
end
end

concept_value || concept.to_a.first
concept_value || concept.reject { |k| k.to_s.eql?('@none') }.first || concept.first
end

def main_language_label(label)
Expand Down

0 comments on commit 9c4bb90

Please sign in to comment.