Skip to content

Commit

Permalink
Clean terms reuses concern code
Browse files Browse the repository at this point in the history
  • Loading branch information
Bilelkihal committed Jun 11, 2024
1 parent e1aab7a commit a5cbcb4
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 25 deletions.
4 changes: 2 additions & 2 deletions app/controllers/concepts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def index
render turbo_stream: [
replace(helpers.child_id(@concept) + '_open_link') { TreeLinkComponent.tree_close_icon },
replace(helpers.child_id(@concept) + '_childs') do
helpers.concepts_tree_component(@concept, @concept, @ontology.acronym, Array(@schemes), request_lang, sub_tree: true, ontology_uri_pattern: @submission)
helpers.concepts_tree_component(@concept, @concept, @ontology.acronym, Array(@schemes), request_lang, sub_tree: true, submission: @submission)
end
]
end
Expand Down Expand Up @@ -88,7 +88,7 @@ def show_tree

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, ontology_uri_pattern: @ontology.explore.latest_submission(include:'uriRegexPattern,preferredNamespaceUri'))
id: 'concepts_tree_view', auto_click: params[:auto_click] || true, submission: @ontology.explore.latest_submission(include:'uriRegexPattern,preferredNamespaceUri'))
end
end

Expand Down
10 changes: 5 additions & 5 deletions app/controllers/concerns/terms_reuses.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ def get_submission_uri_pattern_by_id(acronym: nil)
LinkedData::Client::HTTP.get("ontologies/#{acronym}/latest_submission", {display: 'uriRegexPattern,preferredNamespaceUri'})
end

def concept_reused?(ontology_uri_pattern: nil, concept_id: nil)
if ontology_uri_pattern&.uriRegexPattern
is_reused = !(concept_id =~ Regexp.new(ontology_uri_pattern.uriRegexPattern))
elsif ontology_uri_pattern&.preferredNamespaceUri
is_reused = !(concept_id.include?(ontology_uri_pattern.preferredNamespaceUri))
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
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/instances_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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, ontology_uri_pattern: @ontology.explore.latest_submission(include:'uriRegexPattern,preferredNamespaceUri'))
results: results, next_page: next_page, total_count: total_count, submission: @ontology.explore.latest_submission(include:'uriRegexPattern,preferredNamespaceUri'))

if is_concept_instance && page.eql?(1)
render turbo_stream: view
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/properties_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def show_children
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, ontology_uri_pattern: get_submission_uri_pattern_by_id(acronym: acronym))
helpers.property_tree_component(@property, @property, acronym, request_lang, sub_tree: true, submission: get_submission_uri_pattern_by_id(acronym: acronym))
end
]
end
Expand Down Expand Up @@ -86,7 +86,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, ontology_uri_pattern: @ontology.explore.latest_submission(include:'uriRegexPattern,preferredNamespaceUri'))
id: container_id, auto_click: true, submission: @ontology.explore.latest_submission(include:'uriRegexPattern,preferredNamespaceUri'))
end

end
10 changes: 5 additions & 5 deletions app/helpers/components_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def search_page_input_component(name:, value: nil, placeholder: , button_icon: '
end
end

def paginated_list_component(id:, results:, next_page_url:, child_url:, child_turbo_frame:, child_param:, open_in_modal: false , selected: nil, auto_click: false, ontology_uri_pattern: nil)
def paginated_list_component(id:, results:, next_page_url:, child_url:, child_turbo_frame:, child_param:, open_in_modal: false , selected: nil, auto_click: false, submission: nil)
render(TreeInfiniteScrollComponent.new(
id: id,
collection: results.collection,
Expand Down Expand Up @@ -78,7 +78,7 @@ def paginated_list_component(id:, results:, next_page_url:, child_url:, child_tu
target_frame: child_turbo_frame,
data: data,
open_in_modal: open_in_modal,
is_reused: concept_reused?(ontology_uri_pattern: ontology_uri_pattern, concept_id: concept.id)
is_reused: concept_reused?(submission: submission, concept_id: concept.id)
)))
end
end
Expand Down Expand Up @@ -134,7 +134,7 @@ def link_to_with_actions(link_to_tag, acronym: nil, url: nil, copy: true, check_
tag.html_safe
end

def tree_component(root, selected, target_frame:, sub_tree: false, id: nil, auto_click: false, ontology_uri_pattern: nil, &child_data_generator)
def tree_component(root, selected, target_frame:, sub_tree: false, id: nil, auto_click: false, submission: nil, &child_data_generator)
root.children.sort! { |a, b| (a.prefLabel || a.id).downcase <=> (b.prefLabel || b.id).downcase }

render TreeViewComponent.new(id: id, sub_tree: sub_tree, auto_click: auto_click) do |tree_child|
Expand All @@ -149,9 +149,9 @@ def tree_component(root, selected, target_frame:, sub_tree: false, id: nil, auto
children_href: children_link, selected: child.id.eql?(selected&.id),
muted: child.isInActiveScheme&.empty?,
target_frame: target_frame,
data: data, is_reused: concept_reused?(ontology_uri_pattern: ontology_uri_pattern, concept_id: child.id)) do
data: data, is_reused: concept_reused?(submission: submission, concept_id: child.id)) do
tree_component(child, selected, target_frame: target_frame, sub_tree: true,
id: id, auto_click: auto_click, ontology_uri_pattern: ontology_uri_pattern, &child_data_generator)
id: id, auto_click: auto_click, submission: submission, &child_data_generator)
end
end
end
Expand Down
12 changes: 6 additions & 6 deletions app/helpers/concepts_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +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, ontology_uri_pattern: nil)
tree_component(root, selected_concept, target_frame: 'concept_show', sub_tree: sub_tree, id: id, auto_click: auto_click, ontology_uri_pattern: ontology_uri_pattern) do |child|
def concepts_tree_component(root, selected_concept, acronym, concept_schemes, language, sub_tree: false, id: nil, auto_click: false, submission: nil)
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
end
Expand Down Expand Up @@ -105,14 +105,14 @@ def same_period?(year, month, date)
year.eql?(date.year) && month.eql?(date.strftime('%B'))
end

def concepts_li_list(concepts, auto_click: false, selected_id: nil, ontology_uri_pattern: nil)
def concepts_li_list(concepts, auto_click: false, selected_id: nil, submission: nil)
out = ''
concepts.each do |concept|
children_link, data, href = concept_tree_data(@ontology.acronym, concept, request_lang, [])

out += render TreeLinkComponent.new(child: concept, href: href,
children_href: '#', selected: concept.id.eql?(selected_id) && auto_click,
target_frame: 'concept_show', data: data, is_reused: concept_reused?(ontology_uri_pattern: ontology_uri_pattern, concept_id: concept.id))
target_frame: 'concept_show', data: data, is_reused: concept_reused?(submission: submission, concept_id: concept.id))
end
out
end
Expand All @@ -124,7 +124,7 @@ def render_concepts_by_dates(auto_click: false)
first_month, first_concepts = first_month_concepts.shift
out = ''
if same_period?(first_year, first_month, @last_date)
out += "<ul>#{concepts_li_list(first_concepts, auto_click: auto_click, ontology_uri_pattern: @ontology.explore.latest_submission(include:'uriRegexPattern,preferredNamespaceUri'))}</ul>"
out += "<ul>#{concepts_li_list(first_concepts, auto_click: auto_click, submission: @ontology.explore.latest_submission(include:'uriRegexPattern,preferredNamespaceUri'))}</ul>"
else
tmp = {}
tmp[first_month] = first_concepts
Expand All @@ -137,7 +137,7 @@ def render_concepts_by_dates(auto_click: false)
@concepts_year_month.each do |year, month_concepts|
month_concepts.each do |month, concepts|
out += "<ul> #{month + ' ' + year.to_s}"
out += concepts_li_list(concepts, auto_click: auto_click, selected_id: selected_id, ontology_uri_pattern: ontology.explore.latest_submission(include:'uriRegexPattern,preferredNamespaceUri'))
out += concepts_li_list(concepts, auto_click: auto_click, selected_id: selected_id, submission: @ontology.explore.latest_submission(include:'uriRegexPattern,preferredNamespaceUri'))
out += "</ul>"
end
end
Expand Down
4 changes: 2 additions & 2 deletions app/helpers/properties_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +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, ontology_uri_pattern: nil)
tree_component(root, selected_concept, target_frame: 'property_show', sub_tree: sub_tree, id: id, auto_click: auto_click, ontology_uri_pattern: ontology_uri_pattern) do |child|
def property_tree_component(root, selected_concept, acronym, language, sub_tree: false, id: nil, auto_click: false, submission: nil)
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
end
Expand Down
4 changes: 2 additions & 2 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:, ontology_uri_pattern: nil )
auto_click: false, results: , next_page: ,total_count:, submission: nil )
query, page, _ = search_content_params

@results = OpenStruct.new
Expand Down Expand Up @@ -45,7 +45,7 @@ def render_search_paginated_list(container_id:, next_page_url:, child_url:, chil
child_turbo_frame: child_turbo_frame,
open_in_modal: show_count,
selected: selected,
auto_click: auto_click, ontology_uri_pattern: ontology_uri_pattern)
auto_click: auto_click, submission: submission)
end
end
end

0 comments on commit a5cbcb4

Please sign in to comment.