Skip to content

Commit

Permalink
use the last part of ids for browse counts independently of its origin
Browse files Browse the repository at this point in the history
  • Loading branch information
syphax-bouazzouni committed May 9, 2024
1 parent 9aa288e commit de3cf62
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
1 change: 1 addition & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,7 @@ GEM
zeitwerk (2.6.13)

PLATFORMS
x86_64-linux
x86_64-linux-musl

DEPENDENCIES
Expand Down
14 changes: 10 additions & 4 deletions app/controllers/concerns/submission_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,10 @@ def filters_params(params, includes: BROWSE_ATTRIBUTES.join(','), page: 1, pages
@filters[:search] = params[:search]
end

unless params[:portals].blank?
@filters[:portals] = params[:portals]
end

request_params.delete(:order_by) if %w[visits fair].include?(request_params[:sort_by].to_s)
request_params
end
Expand Down Expand Up @@ -215,7 +219,7 @@ def ontology_hash(ont, submissions)

o[:note_count] = ont.notes&.length || 0
o[:project_count] = ont.projects&.length || 0
o[:popularity] = @analytics[ont.acronym] || 0
o[:popularity] = @analytics[ont.id.to_s] || 0
o[:rank] = sub ? sub[:rank] : 0

o
Expand Down Expand Up @@ -324,10 +328,12 @@ def check_id(name_value, objects, name_key)

def object_filter(objects, object_name, name_key = 'acronym')
checks = params[object_name]&.split(',') || []
checks = checks.map { |x| check_id(x, objects, name_key) }.compact
checks = checks.map { |x| helpers.link_last_part(check_id(x, objects, name_key)) }.compact

ids = objects.map { |x| x['id'] }
objects.uniq! { |x| helpers.link_last_part(x['id']) }
ids = objects.map { |x| helpers.link_last_part(x['id']) }
count = ids.count { |x| checks.include?(x) }

[objects, checks, count]
end

Expand All @@ -348,7 +354,7 @@ def count_objects(ontologies)
object_names.each do |name|
values = Array(ontology[name])
values.each do |v|
v.gsub!('http://data.bioontology.org', rest_url)
v = helpers.link_last_part(v)

objects_count[name] = {} unless objects_count[name]
objects_count[name][v] = (objects_count[name][v] || 0) + 1
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/ontologies_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ def ontologies_filter
streams = [prepend("ontologies_list_view-page-#{@page.page}", partial: 'ontologies/browser/ontologies')]
streams += @count_objects.map do |section, values_count|
values_count.map do |value, count|
replace("count_#{section}_#{value}") do
helpers.turbo_frame_tag("count_#{section}_#{value}") do
replace("count_#{section}_#{link_last_part(value)}") do
helpers.turbo_frame_tag("count_#{section}_#{link_last_part(value)}") do
helpers.content_tag(:span, count.to_s, class: "hide-if-loading #{count.zero? ? 'disabled' : ''}")
end
end
Expand Down

0 comments on commit de3cf62

Please sign in to comment.