Skip to content

Commit

Permalink
Clean terms reuses code
Browse files Browse the repository at this point in the history
  • Loading branch information
Bilelkihal committed Jun 20, 2024
1 parent 788a370 commit 9205693
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 36 deletions.
3 changes: 2 additions & 1 deletion app/controllers/collections_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ def index
next_page_url: "/ontologies/#{@ontology.acronym}/collections",
child_url: "/ontologies/#{@ontology.acronym}/collections/show", child_turbo_frame: 'collection',
child_param: :collectionid,
results: results, next_page: next_page, total_count: total_count, submission: @submission
results: results, next_page: next_page,
total_count: total_count
)
end
end
Expand Down
9 changes: 4 additions & 5 deletions app/controllers/concepts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ def index
@ontology = LinkedData::Client::Models::Ontology.find_by_acronym(params[:ontology]).first
@ob_instructions = helpers.ontolobridge_instructions_template(@ontology)

# Get the latest 'ready' submission, or fallback to any latest submission
# TODO: change the logic here if the fallback will crash the visualization
@submission = get_ontology_submission_ready(@ontology) # application_controller
@submission = @ontology.explore.latest_submission(include: 'all')

@concept = @ontology.explore.single_class({full: true}, params[:id])
concept_not_found(params[:id]) if @concept.nil?
Expand Down Expand Up @@ -79,16 +77,17 @@ def show_definition

def show_tree
@ontology = LinkedData::Client::Models::Ontology.find_by_acronym(params[:ontology]).first
@submission = @ontology.explore.latest_submission(include:'uriRegexPattern,preferredNamespaceUri')
if @ontology.nil? || @ontology.errors
ontology_not_found(params[:ontology])
else
get_class(params) #application_controller

not_found(t('concepts.missing_roots')) if @root.nil?

render inline: helpers.concepts_tree_component(@root, @concept,
@ontology.acronym, Array(params[:concept_schemes]&.split(',')), request_lang,
id: 'concepts_tree_view', auto_click: params[:auto_click] || true, submission: @ontology.explore.latest_submission(include:'uriRegexPattern,preferredNamespaceUri'))
id: 'concepts_tree_view', auto_click: params[:auto_click] || true)
end
end

Expand Down
20 changes: 9 additions & 11 deletions app/controllers/concerns/terms_reuses.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
module TermsReuses
extend ActiveSupport::Concern

def get_submission_uri_pattern_by_id(acronym: nil)
LinkedData::Client::HTTP.get("ontologies/#{acronym}/latest_submission", {display: 'uriRegexPattern,preferredNamespaceUri'})
end

def concept_reused?(submission: nil, concept_id: nil)
if submission&.uriRegexPattern
is_reused = !(concept_id =~ Regexp.new(submission.uriRegexPattern))
elsif submission&.preferredNamespaceUri
is_reused = !(concept_id.include?(submission.preferredNamespaceUri))
end
return is_reused
uri_regex_pattern?(submission, concept_id) || preffered_namespace_uri?(submission, concept_id)
end

end
private
def uri_regex_pattern?(submission, concept_id)
!(concept_id =~ Regexp.new(submission&.uriRegexPattern || ''))
end
def preffered_namespace_uri?(submission, concept_id)
!(concept_id.include?(submission&.preferredNamespaceUri || ''))
end
end
6 changes: 3 additions & 3 deletions app/controllers/instances_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def index
end

get_ontology(params)

@submission = @ontology.explore.latest_submission(include:'uriRegexPattern,preferredNamespaceUri')
query, page, page_size = helpers.search_content_params

results, _, next_page, total_count = search_ontologies_content(query: query,
Expand All @@ -26,7 +26,7 @@ def index
child_param: :instanceid,
show_count: is_concept_instance,
auto_click: params[:instanceid].blank? && page.eql?(1),
results: results, next_page: next_page, total_count: total_count, submission: @ontology.explore.latest_submission(include:'uriRegexPattern,preferredNamespaceUri'))
results: results, next_page: next_page, total_count: total_count)

if is_concept_instance && page.eql?(1)
render turbo_stream: view
Expand All @@ -50,4 +50,4 @@ def get_ontology(params)
@ontology = LinkedData::Client::Models::Ontology.find_by_acronym(params[:ontology] || params[:acronym] || params[:ontology_id]).first
ontology_not_found(params[:ontology]) if @ontology.nil?
end
end
end
13 changes: 10 additions & 3 deletions app/controllers/properties_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ class PropertiesController < ApplicationController
def index
acronym = params[:ontology]
@ontology = LinkedData::Client::Models::Ontology.find_by_acronym(acronym).first
@submission = @ontology.explore.latest_submission(include:'uriRegexPattern,preferredNamespaceUri')

ontology_not_found(acronym) if @ontology.nil?

if params[:search].blank?
Expand All @@ -23,7 +25,7 @@ def index
child_url: "/ontologies/#{@ontology.acronym}/properties/show",
child_turbo_frame: 'property_show',
child_param: :propertyid,
results: results, next_page: next_page, total_count: total_count, submission: @ontology.explore.latest_submission(include:'uriRegexPattern,preferredNamespaceUri'))
results: results, next_page: next_page, total_count: total_count)
end
end

Expand All @@ -43,10 +45,15 @@ def show_children
id = params[:propertyid]
@property = get_property(id, acronym)
@property.children = property_children(id, acronym)

@ontology = LinkedData::Client::Models::Ontology.find_by_acronym(acronym).first
@submission = @ontology.explore.latest_submission({include: 'uriRegexPattern,preferredNamespaceUri'})


render turbo_stream: [
replace(helpers.child_id(@property) + '_open_link') { TreeLinkComponent.tree_close_icon },
replace(helpers.child_id(@property) + '_childs') do
helpers.property_tree_component(@property, @property, acronym, request_lang, sub_tree: true, submission: get_submission_uri_pattern_by_id(acronym: acronym))
helpers.property_tree_component(@property, @property, acronym, request_lang, sub_tree: true, submission: @submission)
end
]
end
Expand Down Expand Up @@ -86,7 +93,7 @@ def index_tree(container_id)
end
render inline: helpers.property_tree_component(@root, @property,
@ontology.acronym, request_lang,
id: container_id, auto_click: true, submission: @ontology.explore.latest_submission(include:'uriRegexPattern,preferredNamespaceUri'))
id: container_id, auto_click: true)
end

end
8 changes: 4 additions & 4 deletions app/controllers/schemes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ def index
acronym = params[:ontology]
@ontology = LinkedData::Client::Models::Ontology.find_by_acronym(acronym).first
ontology_not_found(acronym) if @ontology.nil?
@submission_latest = @submission = @ontology.explore.latest_submission(include: 'all')

if params[:search].blank?
@submission_latest = @ontology.explore.latest_submission(include: 'all', invalidate_cache: invalidate_cache?) rescue @ontology.explore.latest_submission(include: '')
@schemes = get_schemes(@ontology)

render partial: 'schemes/tree_view'
Expand All @@ -21,13 +21,13 @@ def index
filter_by_ontologies: [acronym],
filter_by_types: ['ConceptScheme'])


render inline: helpers.render_search_paginated_list(container_id: 'schemes_sorted_list',
next_page_url: "/ontologies/#{@ontology.acronym}/schemes",
child_url: "/ontologies/#{@ontology.acronym}/schemes/show", child_turbo_frame: 'scheme',
child_param: :schemeid,
results: results, next_page: next_page, total_count: total_count, submission: @ontology.explore.latest_submission(include:'uriRegexPattern,preferredNamespaceUri'))
results: results, next_page: next_page, total_count: total_count)

end
end

Expand Down
5 changes: 3 additions & 2 deletions app/helpers/concepts_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ def concept_tree_data(acronym, child, language, concept_schemes)
}
[children_link, data, href]
end
def concepts_tree_component(root, selected_concept, acronym, concept_schemes, language, sub_tree: false, id: nil, auto_click: false, submission: nil)
def concepts_tree_component(root, selected_concept, acronym, concept_schemes, language, sub_tree: false, id: nil, auto_click: false, submission: @submission)
#binding.pry
tree_component(root, selected_concept, target_frame: 'concept_show', sub_tree: sub_tree, id: id, auto_click: auto_click, submission: submission) do |child|
concept_tree_data(acronym, child, language, concept_schemes)
end
Expand Down Expand Up @@ -199,4 +200,4 @@ def synonym_qualifier_select(form)
def concept_redirect_path
ontology_path(@ontology.acronym, p: 'classes', conceptid: @concept.id)
end
end
end
5 changes: 3 additions & 2 deletions app/helpers/properties_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ def property_tree_data(acronym, child, language)
}
[children_link, data, href]
end
def property_tree_component(root, selected_concept, acronym, language, sub_tree: false, id: nil, auto_click: false, submission: nil)

def property_tree_component(root, selected_concept, acronym, language, sub_tree: false, id: nil, auto_click: false, submission: @submission)
tree_component(root, selected_concept, target_frame: 'property_show', sub_tree: sub_tree, id: id, auto_click: auto_click, submission: submission) do |child|
property_tree_data(acronym, child, language)
end
Expand All @@ -32,4 +33,4 @@ def no_properties_alert
t('properties.no_properties_alert', acronym: @ontology.acronym)
end
end
end
end
4 changes: 2 additions & 2 deletions app/helpers/schemes_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def schemes_data
[schemes_labels, main_scheme, selected_scheme]
end

def schemes_tree(schemes_labels, main_scheme_label, selected_scheme_id)
def schemes_tree(schemes_labels, main_scheme_label, selected_scheme_id, submission: @submission_latest)
selected_scheme = nil
schemes = sorted_labels(schemes_labels).map do |s|
next nil unless main_scheme_label.nil? || s['prefLabel'] != main_scheme_label['prefLabel']
Expand All @@ -104,7 +104,7 @@ def schemes_tree(schemes_labels, main_scheme_label, selected_scheme_id)
root = OpenStruct.new
root.children = children
selected_scheme = selected_scheme || main_scheme || root.children.first
tree_component(root, selected_scheme, target_frame: 'scheme', auto_click: false, submission: @ontology.explore.latest_submission(include:'uriRegexPattern,preferredNamespaceUri')) do |child|
tree_component(root, selected_scheme, target_frame: 'scheme', auto_click: false, submission: submission) do |child|
href = scheme_path(child['@id'], request_lang) rescue ''
data = { schemeid: (child['@id'] rescue '')}
["#", data, href]
Expand Down
6 changes: 3 additions & 3 deletions app/helpers/search_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def search_content_params

def render_search_paginated_list(container_id:, next_page_url:, child_url:, child_turbo_frame:,
child_param:, show_count: nil, lang: request_lang,
auto_click: false, results: , next_page: ,total_count:, submission: nil )
auto_click: false, results: , next_page: ,total_count:, submission: @submission )
query, page, _ = search_content_params

@results = OpenStruct.new
Expand All @@ -34,7 +34,7 @@ def render_search_paginated_list(container_id:, next_page_url:, child_url:, chil
child_param: child_param,
child_turbo_frame: child_turbo_frame,
open_in_modal: show_count,
selected: selected))
selected: selected, submission: submission))
]
else
render inline: paginated_list_component(id: container_id,
Expand All @@ -48,4 +48,4 @@ def render_search_paginated_list(container_id:, next_page_url:, child_url:, chil
auto_click: auto_click, submission: submission)
end
end
end
end

0 comments on commit 9205693

Please sign in to comment.