Skip to content

Commit

Permalink
show boolean facets
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Apr 15, 2021
1 parent ef1ab4a commit a324e5d
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 3 deletions.
12 changes: 12 additions & 0 deletions app/controllers/concerns/facetable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,18 @@ def facet_by_key(arr)
end
end

def facet_by_bool(arr)
values = { 0 => "no", 1 => "yes" }

arr.map do |hsh|
{
"id" => hsh["key"] ,
"title" => values[hsh["key"]],
"count" => hsh["doc_count"],
}
end
end

def facet_by_software(arr)
arr.map do |hsh|
{
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/providers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def index
end
has_required_contacts =
if total > 0
facet_by_key(
facet_by_bool(
response.response.aggregations.has_required_contacts.buckets,
)
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/v3/providers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def index
end
has_required_contacts =
if total > 0
facet_by_key(
facet_by_bool(
response.response.aggregations.has_required_contacts.buckets,
)
end
Expand Down
12 changes: 12 additions & 0 deletions app/graphql/types/base_connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,18 @@ def facet_by_key(arr)
end
end

def facet_by_bool(arr)
values = { 0 => "no", 1 => "yes" }

arr.map do |hsh|
{
"id" => hsh["key"] ,
"title" => values[hsh["key"]],
"count" => hsh["doc_count"],
}
end
end

def facet_by_resource_type(arr)
arr.map do |hsh|
{
Expand Down
2 changes: 1 addition & 1 deletion app/graphql/types/member_connection_with_total_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ def non_profit_statuses
end

def has_required_contacts
facet_by_key(object.aggregations.has_required_contacts.buckets)
facet_by_bool(object.aggregations.has_required_contacts.buckets)
end
end

0 comments on commit a324e5d

Please sign in to comment.