2013-01-07 09:04:09 +01:00
module ApplicationHelper
2014-06-26 09:08:26 +02:00
def target_progress_color ( progress )
progress = progress . to_i
if progress > 90
result = 'green'
elsif progress < 90 && progress > 80
result = 'orange'
else
result = 'red'
end
result
end
def days_left_color ( days_left )
days_left = days_left . to_i
if days_left > 30
result = 'green'
elsif days_left < 30 && days_left > 10
result = 'orange'
else
result = 'red'
end
result
end
2014-05-13 14:17:39 +02:00
def bootstrap_class_for ( flash_type )
logger . debug " flash_type is #{ flash_type } "
case flash_type
when 'success'
'alert-success'
when 'error'
2014-05-16 19:52:41 +02:00
'alert-danger'
2014-05-13 14:17:39 +02:00
when 'alert'
2014-05-16 19:52:41 +02:00
'alert-warning'
2014-05-13 14:17:39 +02:00
when 'notice'
'alert-info'
else
flash_type . to_s
end
end
2014-06-04 16:11:33 +02:00
def label_for ( event_state )
result = ''
case event_state
2014-06-06 10:23:01 +02:00
when 'new'
2014-06-04 16:11:33 +02:00
result = 'label label-primary'
2014-06-06 10:23:01 +02:00
when 'withdrawn'
result = 'label label-danger'
when 'unconfirmed'
2014-06-04 16:11:33 +02:00
result = 'label label-success'
2014-06-06 10:23:01 +02:00
when 'confirmed'
2014-06-04 16:11:33 +02:00
result = 'label label-success'
2014-06-06 10:23:01 +02:00
when 'rejected'
2014-06-04 16:11:33 +02:00
result = 'label label-warning'
2014-06-06 10:23:01 +02:00
when 'canceled'
2014-06-04 16:11:33 +02:00
result = 'label label-danger'
end
result
end
2014-06-03 16:27:10 +02:00
def icon_for_todo ( bool )
if bool
return 'glyphicon glyphicon-ok'
else
return 'glyphicon glyphicon-remove'
end
end
def class_for_todo ( bool )
if bool
return 'list-group-item todolist-ok'
else
return 'list-group-item todolist-missing'
end
end
2014-06-02 12:37:57 +02:00
def normalize_array_length ( hashmap , length )
2014-07-21 14:37:26 +02:00
hashmap . each do | _ , value |
2014-06-02 12:37:57 +02:00
if value . length < length
value . fill ( value [ - 1 ] , value . length ... length )
end
end
end
2014-03-04 10:10:07 +01:00
def active_nav_li ( link )
if current_page? ( link )
return 'active'
else
return ''
end
end
2013-07-12 12:30:31 +03:00
def getdatetime ( registration , field )
if registration . send ( field . to_sym ) . kind_of? ( String )
DateTime . parse ( registration . send ( field . to_sym ) ) . strftime ( " %d %b %H:%M " ) if registration . send ( field . to_sym )
else
registration . send ( field . to_sym ) . strftime ( " %d %b %H:%M " ) if registration . send ( field . to_sym )
end
end
2014-05-28 13:44:37 -07:00
2013-07-12 12:30:31 +03:00
def getdate ( var )
if var . kind_of? ( String )
DateTime . parse ( var ) . strftime ( " %a, %d %b " )
else
var . strftime ( " %a, %d %b " )
end
end
2013-01-07 09:04:09 +01:00
2013-09-01 18:19:25 +03:00
def show_time ( length )
h = length / 60
min = length - h * 60
if h != 0
if min != 0
" #{ h } h #{ min } min "
else
" #{ h } h "
end
else
" #{ min } min "
end
end
2013-07-11 08:21:02 +03:00
def pre_registered ( event )
@conference . events . joins ( :registrations ) . where ( " events.id = ? " , event . id )
end
2013-01-07 09:04:09 +01:00
def add_association_link ( association_name , form_builder , div_class , html_options = { } )
2014-07-21 14:49:05 +02:00
link_to_add_association " Add " + association_name . to_s . singularize , form_builder , div_class , html_options . merge ( class : " assoc btn btn-success " )
2013-01-07 09:04:09 +01:00
end
def remove_association_link ( association_name , form_builder )
2014-07-21 14:49:05 +02:00
link_to_remove_association ( " Remove " + association_name . to_s . singularize , form_builder , class : " assoc btn btn-danger " ) + tag ( :hr )
2013-01-07 09:04:09 +01:00
end
def dynamic_association ( association_name , title , form_builder , options = { } )
2014-07-21 14:49:05 +02:00
render " shared/dynamic_association " , association_name : association_name , title : title , f : form_builder , hint : options [ :hint ]
2013-01-07 09:04:09 +01:00
end
2013-06-14 13:17:40 +02:00
# Same as redirect_to(:back) if there is a valid HTTP referer, otherwise redirect_to()
def redirect_back_or_to ( options = { } , response_status = { } )
if request . env [ " HTTP_REFERER " ]
redirect_to ( :back )
else
redirect_to ( options , response_status )
end
end
2013-01-07 09:04:09 +01:00
# TODO Output better html
def format_comments ( comment , padding = 0 )
result = " "
result += " <div style='padding-left: #{ padding } px'> "
result += " <div class='well'> "
2014-06-23 19:07:50 +03:00
result += " <b> #{ comment . user . name } </b> <i> #{ comment . created_at } </i><br><br> "
2013-01-07 09:04:09 +01:00
result += comment . body
result += " <br><div><a href=' # ' class='pull-right comment-reply-link'>Reply</a><br><br> "
result += " <div class='comment-reply'> "
result += " <form method='post' action=' #{ comment_admin_conference_event_path ( @conference . short_title , comment . commentable_id ) } '> "
result += " <input type=hidden name=parent value=' #{ comment . id } '/> "
result += " <input name='authenticity_token' type='hidden' value=' #{ form_authenticity_token } ' /> "
result += " <textarea name='comment'></textarea> "
result += " <button class='btn btn-primary pull-right' name='button' type='submit'>Add Reply</button> "
result += " </form></div></div> "
result += " </div> "
#result += edit_admin_conference_event_path(@conference.short_title, @event)
comment . children . each do | child |
result += format_comments ( child , 50 )
result += " </div> "
end
result
end
2014-05-28 13:44:37 -07:00
2014-06-29 17:44:27 +05:30
def markdown ( text )
2014-06-29 17:13:53 +05:30
options = {
2014-06-29 17:44:27 +05:30
autolink : true ,
space_after_headers : true ,
no_intra_emphasis : true
2014-06-29 17:13:53 +05:30
}
markdown = Redcarpet :: Markdown . new ( Redcarpet :: Render :: HTML , options )
markdown . render ( text ) . html_safe
end
2014-06-29 17:44:27 +05:30
def markdown_hint ( text = " " )
markdown ( " #{ text } Please look at #{ link_to '**Markdown Syntax**' , 'https://daringfireball.net/projects/markdown/syntax' , target : '_blank' } to format your text " )
end
2014-07-23 14:55:06 +02:00
def omniauth_configured
providers = [ ]
Devise . omniauth_providers . each do | provider |
provider_key = " #{ provider } _key "
provider_secret = " #{ provider } _secret "
unless Rails . application . secrets . send ( provider_key ) . blank? || Rails . application . secrets . send ( provider_secret ) . blank?
providers << provider
end
end
return providers
end
2014-08-13 14:37:15 +03:00
# Receives a hash, generated from User model, function get_roles
# Outputs the roles of a user, including the conferences for which the user has the roles
# Eg. organizer(oSC13, oSC14), cfp(oSC12, oSC13)
def show_roles ( roles )
roles . map { | x | x [ 0 ] . titleize + ' ' + x [ 1 ] } . join ', '
end
2014-08-13 22:46:41 +03:00
def can_manage_volunteers ( conference )
if ( current_user . has_role? :organizer , conference ) || ( current_user . has_role? :volunteer_coordinator , conference )
true
else
false
end
end
2013-01-07 09:04:09 +01:00
end