2013-01-07 09:04:09 +01:00
module ApplicationHelper
2016-04-22 18:18:46 +03:00
##
# ====Returns
# * +String+ -> number of registrations / max allowed registrations
def registered_text ( event )
return " Registered: #{ event . registrations . count } / #{ event . max_attendees } " if event . max_attendees
" Registered: #{ event . registrations . count } "
end
2015-04-22 20:40:21 +03:00
# Set resource_name for devise so that we can call the devise help links (views/devise/shared/_links) from anywhere (eg sign_up form in proposal#new)
2015-04-18 21:44:40 +03:00
def resource_name
:user
end
2015-04-22 20:40:21 +03:00
# Set devise_mapping for devise so that we can call the devise help links (views/devise/shared/_links) from anywhere (eg sign_up form in proposal#new)
2015-04-18 21:44:40 +03:00
def devise_mapping
@devise_mapping || = Devise . mappings [ :user ]
end
2015-04-16 18:34:41 +03:00
def pluralize_without_count ( count , noun , text = nil )
if count != 0
count == 1 ? " #{ noun } #{ text } " : " #{ noun . pluralize } #{ text } "
end
end
def event_status_icon ( event )
case event . state
when 'new'
'fa-eye'
when 'unconfirmed'
'fa-check text-muted'
when 'confirmed'
'fa-check text-success'
when 'rejected' , 'withdrawn' , 'canceled'
'fa-ban'
end
end
def event_progress_color ( progress )
2016-03-18 01:59:05 +05:30
progress = progress . to_i
if progress == 100
'progress-bar-success'
elsif progress > = 85
'progress-bar-info'
elsif progress > = 71
'progress-bar-warning'
else
'progress-bar-danger'
2015-04-16 18:34:41 +03:00
end
end
2015-01-12 23:13:10 +02:00
def format_role ( role )
role . parameterize . underscore
end
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
2015-04-16 18:34:41 +03:00
return 'todolist-ok'
2014-06-03 16:27:10 +02:00
else
2015-04-16 18:34:41 +03:00
return 'todolist-missing'
2014-06-03 16:27:10 +02:00
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 )
2015-10-25 13:29:02 +02:00
@conference . program . 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' ]
2016-03-11 02:08:00 +05:30
redirect_to :back
2013-06-14 13:17:40 +02:00
else
2016-03-11 02:08:00 +05:30
redirect_to options , response_status
2013-06-14 13:17:40 +02:00
end
end
2014-11-20 14:57:03 +01:00
def event_types ( conference )
2015-10-25 13:29:02 +02:00
all = conference . program . event_types . map { | et | et . title . pluralize }
2014-11-20 14:57:03 +01:00
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 )
2015-10-25 13:29:02 +02:00
all = conference . program . 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
def difficulty_levels ( conference )
all = conference . program . difficulty_levels . map { | t | t . title }
2014-11-20 14:57:03 +01:00
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 )
2016-04-17 11:32:06 +05:30
roles . map { | x | x [ 0 ] . titleize + ' (' + x [ 1 ] . join ( ', ' ) + ')' } . join ', '
2014-08-13 14:37:15 +03:00
end
2014-08-13 22:46:41 +03:00
def can_manage_volunteers ( conference )
2016-04-03 13:24:07 +05:30
if ( current_user . has_role? :organizer , conference ) || ( current_user . has_role? :volunteers_coordinator , conference )
2014-08-13 22:46:41 +03:00
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
2015-07-17 18:55:47 +02:00
def unread_notifications ( user )
2015-09-21 15:56:57 +02:00
Comment . accessible_by ( current_ability ) . find_since_last_login ( user )
2015-07-17 18:55:47 +02:00
end
2013-01-07 09:04:09 +01:00
end