Skip to content

Commit

Permalink
add again the multilingual feature to the classes tab
Browse files Browse the repository at this point in the history
  • Loading branch information
syphax-bouazzouni committed Oct 19, 2024
1 parent 0f5f9c2 commit 0e42984
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 30 deletions.
3 changes: 2 additions & 1 deletion app/controllers/concepts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ def show_concept

# Note that find_by_acronym includes views by default
@ontology = LinkedData::Client::Models::Ontology.find_by_acronym(params[:ontology_id]).first
@concept = @ontology.explore.single_class({full: true}, params[:id])
@submission = get_ontology_submission_ready(@ontology)
@concept = @ontology.explore.single_class({full: true, lang: helpers.request_lang(@submission)}, params[:id])

not_found if @concept.nil?
gather_details
Expand Down
27 changes: 14 additions & 13 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ def remove_owl_notation(string)
string
end

def draw_tree(root, id = nil, type = "Menu")
def draw_tree(root, id = nil, submission = @submission || @submission_latest)
if id.nil?
id = root.children.first.id
end
# TODO: handle tree view for obsolete classes, e.g. 'http://purl.obolibrary.org/obo/GO_0030400'
raw build_tree(root, "", id) # returns a string, representing nested list items
raw build_tree(root, "", id, submission) # returns a string, representing nested list items
end

def build_tree(node, string, id)
def build_tree(node, string, id, submission)
if node.children.nil? || node.children.length < 1
return string # unchanged
end
Expand All @@ -70,19 +70,20 @@ def build_tree(node, string, id)

# This fake root will be present at the root of "flat" ontologies, we need to keep the id intact
li_id = child.id.eql?('bp_fake_root') ? 'bp_fake_root' : short_uuid

lang = request_lang(submission)
ontology_acronym = submission.ontology.acronym
if child.id.eql?('bp_fake_root')
string << tree_link_to_concept(li_id: li_id, child: child, ontology_acronym: '',
active_style: active_style)
active_style: active_style, lang: lang)
else
string << tree_link_to_concept(li_id: li_id, child: child, ontology_acronym: child.explore.ontology.acronym,
active_style: active_style)
string << tree_link_to_concept(li_id: li_id, child: child, ontology_acronym: ontology_acronym,
active_style: active_style, lang: lang)

if child.hasChildren && !child.expanded?
string << tree_link_to_children(li_id: li_id, child: child)
string << tree_link_to_children(li_id: li_id, child: child, ontology_acronym: ontology_acronym, lang: lang)
elsif child.expanded?
string << '<ul>'
build_tree(child, string, id)
build_tree(child, string, id, submission)
string << '</ul>'
end
string << '</li>'
Expand All @@ -92,15 +93,15 @@ def build_tree(node, string, id)
string
end

def tree_link_to_concept(li_id:, child:, ontology_acronym:, active_style:)
def tree_link_to_concept(li_id:, child:, ontology_acronym:, active_style:, lang: )
page_name = ontology_viewer_page_name(ontology_acronym, child.prefLabel, 'Classes')
open = child.expanded? ? "class='open'" : ''
href = ontology_acronym.blank? ? '#' : "/ontologies/#{child.explore.ontology.acronym}/concepts/?id=#{CGI.escape(child.id)}"
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>"
end

def tree_link_to_children(li_id:, child:)
"<ul class='ajax'><li id='#{li_id}'><a id='#{CGI.escape(child.id)}' href='/ajax_concepts/#{child.explore.ontology.acronym}/?conceptid=#{CGI.escape(child.id)}&callback=children'>ajax_class</a></li></ul>"
def tree_link_to_children(li_id:, child:, ontology_acronym:, lang: )
"<ul class='ajax'><li id='#{li_id}'><a id='#{CGI.escape(child.id)}' href='/ajax_concepts/#{ontology_acronym}/?conceptid=#{CGI.escape(child.id)}&callback=children&lang=#{lang}'>ajax_class</a></li></ul>"
end

def loading_spinner(padding = false, include_text = true)
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 @@ -3,7 +3,7 @@

module OntologiesHelper

LANGUAGE_FILTERABLE_SECTIONS = %w[classes properties].freeze
LANGUAGE_FILTERABLE_SECTIONS = %w[classes].freeze

def additional_details
return '' if $ADDITIONAL_ONTOLOGY_DETAILS.nil? || $ADDITIONAL_ONTOLOGY_DETAILS[@ontology.acronym].nil?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import OntoportalAutocompleteController from "./ontoportal_autocomplete_controll
// Connects to data-controller="class-search"
export default class extends OntoportalAutocompleteController {
static values = {
spinnerSrc: String
spinnerSrc: String,
ontologyAcronym: String,
lang: String,
}
connect() {
super.connect()
Expand All @@ -24,7 +26,7 @@ export default class extends OntoportalAutocompleteController {
// Appropriate value selected
if (li.extra) {
let sValue = jQuery("#jump_to_concept_id").val()
Turbo.visit("/ontologies/" + jQuery(document).data().bp.ontology.acronym + "/?p=classes&conceptid=" + encodeURIComponent(sValue) + "&jump_to_nav=true")
Turbo.visit("/ontologies/" + this.ontologyAcronymValue + "/?p=classes&lang=" + this.langValue + "&conceptid=" + encodeURIComponent(sValue) + "&jump_to_nav=true")
}
}

Expand Down
19 changes: 17 additions & 2 deletions app/javascript/controllers/ontoportal_autocomplete_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import {useBioportalAutoComplete} from "../mixins/useBioportalAutoComplete";
export default class extends Controller {
static values = {
objectTypes: String, default: 'class',
ontologyAcronym: String
ontologyAcronym: String,
lang: String,
submissionLang: Array
}

connect() {
jQuery(document).ready(() => {
useBioportalAutoComplete(this.element, "/search/json_search/" + this.ontologyAcronymValue,{
extraParams: {objecttypes: this.objectTypesValue},
extraParams: this.extraParams(),
selectFirst: true,
lineSeparator: "~!~",
matchSubset: 0,
Expand Down Expand Up @@ -66,5 +68,18 @@ export default class extends Controller {
return obsolete_prefix + row0_markup + matchType + obsolete_suffix;
}

extraParams() {
let extraParams = {
objecttypes: this.objectTypesValue
};
if (this.#isNotEmpty(this.submissionLangValue)) {
extraParams["lang"] = this.langValue
}
return extraParams
}

#isNotEmpty(arr) {
return Array.isArray(arr) && arr.length > 0;
}

}
36 changes: 34 additions & 2 deletions app/javascript/controllers/turbo_frame_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,40 @@ export default class extends Controller {
this.frame.innerHTML = this.placeHolderValue
} else {
this.frame.innerHTML = ""
this.urlValue = new HistoryService().getUpdatedURL(this.urlValue, data)
this.frame.src = this.urlValue

if(this.#isCurrentPage()){
this.urlValue = this.#currentPageUrl()
}

this.urlValue = this.#updatedPageUrl(data)

this.frame.src = this.urlValue
}
}

#isCurrentPage(){

let currentDisplayedUrl = new URL(this.#currentPageUrl(), document.location.origin)

let initUrl = new URL(this.urlValue, document.location.origin)

if (currentDisplayedUrl.toString().includes(this.urlValue)){
return true
} else if (currentDisplayedUrl.searchParams.has('p') && currentDisplayedUrl.searchParams.get('p') === initUrl.searchParams.get('p')){
// this is a custom fix for only the ontology viewer page,
// that use the parameter ?p=section to tell which section is displayed
return true
}

return false
}


#currentPageUrl(){
return document.location.pathname + document.location.search
}

#updatedPageUrl(newUrlParams){
return new HistoryService().getUpdatedURL(this.urlValue, newUrlParams)
}
}
2 changes: 1 addition & 1 deletion app/javascript/mixins/useHistory.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export class HistoryService {

#updateURLFromState(urlParams, state) {
Object.entries(state).forEach(([key, val]) => {
if (key !== 'p'){
if (key !== 'p' && !urlParams.has(key)){
urlParams.set(key, val)
}
})
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(li_id: short_uuid, child: child, ontology_acronym: child.explore.ontology.acronym, active_style: '')
- output << tree_link_to_concept(li_id: short_uuid, child: child, ontology_acronym: @submission.ontology.acronym, active_style: '', lang: request_lang(@submission))
- if child.hasChildren
- output << tree_link_to_children(li_id: short_uuid, child: child)
- output << tree_link_to_children(li_id: short_uuid, child: child, ontology_acronym: @submission.ontology.acronym,lang: request_lang(@submission))
- output << "</li>"
= raw output
11 changes: 5 additions & 6 deletions app/views/ontologies/visualize.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@
%div#qsearch.input-group.pb-2.pe-1
%span.input-group-text Jump to:
= text_field_tag("search_box", nil, class: "form-control rounded-end", aria: {label: "Jump to:"},
data: {controller: 'class-search-auto-complete', 'class-search-auto-complete-ontology-acronym-value': @ontology.acronym,
data: {controller: 'class-search-auto-complete',
'class-search-auto-complete-ontology-acronym-value': @ontology.acronym,
'class-search-auto-complete-lang-value': request_lang(@submission),
'class-search-auto-complete-submission-lang-value': submission_languages(@submission),
'class-search-auto-complete-spinner-src-value': asset_path("jquery.simple.tree/spinner.gif")})
= hidden_field_tag("jump_to_concept_id")
%div#sd_content.p-1
= render TurboFrameComponent.new(id: 'concepts_tree_view' , src: "/ajax/classes/treeview?ontology=#{@ontology.acronym}&conceptid=#{escape(@concept.id)}")
= render TurboFrameComponent.new(id: 'concepts_tree_view' , src: "/ajax/classes/treeview?ontology=#{@ontology.acronym}&conceptid=#{escape(@concept.id)}&lang=#{request_lang(@submission)}")
%div#concept_content.d-flex.flex-column.card.p-1.ml-2{data:{'container-splitter-target': 'container'}}
= render partial: 'concepts/show'

Expand All @@ -21,7 +24,3 @@
= hidden_field :search, :keyword, :value=>"",:id=>"search_keyword"
- else # found an error
= "<div id=\"error\"><h2>#{@error}</h2></div>"




0 comments on commit 0e42984

Please sign in to comment.