jam-cloud/web/app/helpers/event_session_helper.rb

92 lines
2.8 KiB
Ruby

module EventSessionHelper
def event_session_img(event_session)
# need to figure out img, width, height
# prefer the session URL if specified; otherwise use the band/user
url = nil
width = nil
height = nil
if event_session.img_url
url = image_path(event_session.img_url)
else
url = resolve_avatarables(event_session.band, event_session.user, allow_none: true)
end
if url
width = event_session.img_width
height = event_session.img_height
else
url = image_path('web/logo-256.png')
width = 115
end
content_tag(:img, nil, src: url, width: width, height: height)
end
def event_session_title(event_session)
return event_session.band.name if event_session.band
return event_session.user.name if event_session.user
'TBD'
end
def event_session_start_hour(event_session)
timezone = ActiveSupport::TimeZone.new('Central Time (US & Canada)')
timezone.at(event_session.starts_at.to_i).strftime('%l:%M %P')
end
def event_session_button(event_session)
state = nil # can be :not_started, :over, :playing
state = event_session.pinned_state if event_session.pinned_state
if !state && (event_session.user_id || event_session.band_id)
# if no pinned state, then we try to find if there is a session currently on going during the specified time range
# if so, then we are playing.
# if there has been none, we say it's still coming,
# if there has been at least one, and it's over, we say session over
query = MusicSessionHistory.where(created_at: event_session.event.event_day..(event_session.event.event_day + 1.day))
if event_session.user_id
query = query.where(user_id: event_session.user_id)
elsif event_session.band_id
query = query.where(band_id: event_session.band_id)
else
raise 'invalid state in event_session_button'
end
music_session_history = query.order('created_at DESC').first
if music_session_history
if music_session_history.session_removed_at
state = 'over'
else
state = 'playing'
end
else
state = 'not_started'
end
end
if state == 'over'
content_tag(:a, 'SESSION ENDED', href: music_session_detail_path(music_session_history.id), class: 'button-grey')
elsif state == 'playing'
content_tag(:a, '', href: music_session_detail_path(music_session_history.id), class: 'button-orange') do
image_tag 'content/icon_playbutton.png', :width => 20, height: 20, align: 'absmiddle'
content_tag(:span, 'LISTEN NOW')
end
elsif state == 'not_started'
nil
else
nil
end
end
def event_session_description(event_session)
event_session.band.biography if event_session.band
event_session.user.biography if event_session.user
''
end
end