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
2015-02-26 12:58:28 +05:30
result =
case
when progress > = 90 then 'green'
when progress < 90 && progress > = 80 then 'orange'
else 'red'
2014-06-26 09:08:26 +02:00
end
2015-02-26 12:58:28 +05:30
2014-06-26 09:08:26 +02:00
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 )
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
2015-03-12 23:53:57 +01:00
'alert-warning'
2014-05-13 14:17:39 +02:00
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
2014-08-15 18:03:05 -07:00
return 'fa fa-check'
2014-06-03 16:27:10 +02:00
else
2014-08-15 18:03:05 -07:00
return 'fa fa-times'
2014-06-03 16:27:10 +02:00
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 )
2014-08-18 21:54:43 +03:00
DateTime . parse ( registration . send ( field . to_sym ) ) . strftime ( '%d %b %H:%M' ) if registration . send ( field . to_sym )
2013-07-12 12:30:31 +03:00
else
2014-08-18 21:54:43 +03:00
registration . send ( field . to_sym ) . strftime ( '%d %b %H:%M' ) if registration . send ( field . to_sym )
2013-07-12 12:30:31 +03:00
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 )
2014-08-18 21:54:43 +03:00
DateTime . parse ( var ) . strftime ( '%a, %d %b' )
2013-07-12 12:30:31 +03:00
else
2014-08-18 21:54:43 +03:00
var . strftime ( '%a, %d %b' )
2013-07-12 12:30:31 +03:00
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 )
2014-08-18 21:54:43 +03:00
@conference . events . joins ( :registrations ) . where ( 'events.id = ?' , event . id )
2013-07-11 08:21:02 +03:00
end
2013-01-07 09:04:09 +01:00
def add_association_link ( association_name , form_builder , div_class , html_options = { } )
2014-08-18 21:54:43 +03: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-08-18 21:54:43 +03: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-08-18 21:54:43 +03: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 = { } )
2014-08-18 21:54:43 +03:00
if request . env [ 'HTTP_REFERER' ]
2013-06-14 13:17:40 +02:00
redirect_to ( :back )
else
redirect_to ( options , response_status )
end
end
2014-11-20 14:57:03 +01:00
def event_types ( conference )
all = conference . event_types . map { | et | et . title . pluralize }
first = all [ 0 ... - 1 ]
last = all [ - 1 ]
ets = ''
if all . length > 1
ets << first . join ( ', ' )
ets << " and #{ last } "
else
ets = all . join
end
return ets
end
def tracks ( conference )
all = conference . tracks . map { | t | t . name }
first = all [ 0 ... - 1 ]
last = all [ - 1 ]
ts = ''
if all . length > 1
ts << first . join ( ', ' )
ts << " and #{ last } "
else
ts = all . join
end
return ts
end
2014-12-05 16:04:34 +01:00
# rubocop:disable Lint/EndAlignment
def word_pluralize ( count , singular , plural = nil )
word = if ( count == 1 || count =~ / ^1( \ .0+)?$ / )
singular
else
plural || singular . pluralize
end
" #{ word } "
end
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
2014-08-18 21:54:43 +03:00
def markdown_hint ( text = '' )
2014-06-29 17:44:27 +05:30
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
2014-11-12 10:20:53 +01:00
def sign_in_path
if CONFIG [ 'authentication' ] [ 'ichain' ] [ 'enabled' ]
new_user_ichain_session_path
else
new_user_session_path
end
end
def sign_up_path
if CONFIG [ 'authentication' ] [ 'ichain' ] [ 'enabled' ]
new_user_ichain_registration_path
else
new_user_registration_path
end
end
2013-01-07 09:04:09 +01:00
end