debshots/app/helpers/packages_helper.rb

61 lines
2 KiB
Ruby

module PackagesHelper
# Return a query of all screenshots that the current user may see
# Consists of:
# - approved (public) screenshots
# - screenshots uploaded by the user
# - all screenshots if the user is an admin
# def screenshots_visible_to_user(package)
# if user_signed_in? and current_user.is_admin?
# # User is an admin and can view all screenshots
# package.screenshots
# # TODO: User logins and assigned screenshots will come in a later version
# # elsif user_signed_in?
# # package.screenshots.where(id: (current_user.screenshots.select(:id))) | \
# # package.screenshots.where(approved: true).order('created_at DESC')
# else
# package.screenshots.where(uploaderhash: session.id.to_s) | \
# package.screenshots.where(approved: true).order('created_at DESC')
# end
# end
def screenshot_uploaded_by_current_user?(screenshot)
screenshot.uploaderhash == session.id.to_s
end
# Return the description and/or the version of the package
def screenshot_caption(screenshot)
str = []
str << screenshot.description if screenshot.description.present?
str << "#{screenshot.package.name} version #{screenshot.version}" if screenshot.version.present?
str << "uploaded #{time_ago_in_words(screenshot.created_at)} ago"
str.join(' ∙ ')
end
def small_img(screenshot, cls: 'thumbnail')
if screenshot && screenshot.simage(:small)
image = screenshot.simage(:small)
image_tag(
image.url,
width: image.width,
height: image.height,
alt: screenshot.caption,
class: cls
)
else
image_tag(
'/images/dummy/no-screenshots-available.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
end