debshots/app/helpers/packages_helper.rb
Christoph Haas 323b7004ed Expose which search strategy produced each result
query_packages now assigns @search_sources - a hash mapping package
ids to the matching strategy that put them into the results: :exact,
:name_prefix, :name_contains, :semantic or :fulltext. The grid and
list views render a small badge with a humanized label per result,
making the search tiers observable. semantic_results() was folded
into search_packages() so each branch tags its own source. Adds the
rails-controller-testing gem for assigns() in tests.
2026-08-23 10:39:50 +02:00

64 lines
2 KiB
Ruby

module PackagesHelper
# Human readable label for the search strategy that put a package
# into the search results (see PackagesController#search_packages)
def search_source_label(source)
{
exact: 'exact match',
name_prefix: 'name match',
name_contains: 'name match',
semantic: 'similar',
fulltext: 'full-text'
}[source]
end
# Return the description and/or the version of the package
def screenshot_caption(screenshot)
str = []
str << screenshot.description if screenshot.description.present?
if screenshot.version.present?
str << "#{screenshot.package.name} version #{screenshot.version}"
end
str << "uploaded #{time_ago_in_words(screenshot.created_at)} ago"
str.join(' ∙ ')
end
def small_img(screenshot, cls: 'thumbnail')
if screenshot&.simage(:small)
image = screenshot.simage(:small)
# image = screenshot_image_path(name: screenshot.package.name)
image_tag(
small_image_with_id_path(name: screenshot.package.name, screenshot_id: screenshot.id),
width: image.width,
height: image.height,
alt: screenshot.caption,
class: cls
)
else
image_tag(
'/images/dummy/no-screenshots-upload-one.svg',
width: 220,
height: 220 * 3 / 4
)
end
end
# Show filled/empty star icons from FontAwesome
# depending on the rating (1-5)
# def star_rating(rating)
# filled_stars = fa_icon('star') * rating
# empty_stars = fa_icon('star-o') * (5-rating)
# (filled_stars+empty_stars).html_safe
# end
# Return a readable status of a screenshot and a matching CSS color class
def status(screenshot)
if screenshot.approved && !screenshot.hidden
["#{icon('eye', class: 'icon')} Public".html_safe, 'public']
elsif screenshot.hidden
["#{icon('eye-closed', class: 'icon')} Hidden".html_safe, 'hidden']
elsif !screenshot.approved
["#{icon('hourglass', class: 'icon')} Unapproved".html_safe, 'unapproved']
end
end
end