mirror of
https://github.com/openSUSE/osem.git
synced 2026-08-13 19:54:02 +00:00
refractor code into different files
This commit is contained in:
parent
8320f78d0b
commit
5dece1ea48
4 changed files with 75 additions and 38 deletions
|
|
@ -1,36 +1,20 @@
|
||||||
module ApplicationHelper
|
module ApplicationHelper
|
||||||
# Returns a string build from the start and end date of the given conference.
|
include DateTimeHelper
|
||||||
|
include FormatHelper
|
||||||
|
include EventsHelper
|
||||||
|
include UsersHelper
|
||||||
|
include PathsHelper
|
||||||
|
include ChangeDescriptionHelper
|
||||||
|
##
|
||||||
|
# Checks if the voting has already started, or if it has already ended
|
||||||
#
|
#
|
||||||
# If the conference is only one day long
|
def voting_open_or_close(program)
|
||||||
# * %B %d %Y (January 17 2014)
|
return if program.voting_period?
|
||||||
# If the conference starts and ends in the same month and year
|
if program.voting_start_date > Time.current
|
||||||
# * %B %d - %d, %Y (January 17 - 21 2014)
|
return 'Voting period has not started yet!'
|
||||||
# If the conference ends in another month but in the same year
|
else # voting_end_date > Date.today because voting_start_date < voting_end_date
|
||||||
# * %B %d - %B %d, %Y (January 31 - February 02 2014)
|
return 'Voting period is over!'
|
||||||
# All other cases
|
|
||||||
# * %B %d, %Y - %B %d, %Y (December 30, 2013 - January 02, 2014)
|
|
||||||
def date_string(start_date, end_date)
|
|
||||||
startstr = 'Unknown - '
|
|
||||||
endstr = 'Unknown'
|
|
||||||
# When the conference is in the same month
|
|
||||||
if start_date.month == end_date.month && start_date.year == end_date.year
|
|
||||||
if start_date.day == end_date.day
|
|
||||||
startstr = start_date.strftime('%B %d')
|
|
||||||
endstr = end_date.strftime(' %Y')
|
|
||||||
else
|
|
||||||
startstr = start_date.strftime('%B %d - ')
|
|
||||||
endstr = end_date.strftime('%d, %Y')
|
|
||||||
end
|
|
||||||
elsif start_date.month != end_date.month && start_date.year == end_date.year
|
|
||||||
startstr = start_date.strftime('%B %d - ')
|
|
||||||
endstr = end_date.strftime('%B %d, %Y')
|
|
||||||
else
|
|
||||||
startstr = start_date.strftime('%B %d, %Y - ')
|
|
||||||
endstr = end_date.strftime('%B %d, %Y')
|
|
||||||
end
|
end
|
||||||
|
|
||||||
result = startstr + endstr
|
|
||||||
result
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# 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 proposals#new)
|
# 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 proposals#new)
|
||||||
|
|
@ -50,6 +34,15 @@ module ApplicationHelper
|
||||||
render 'shared/dynamic_association', association_name: association_name, title: title, f: form_builder, hint: options[:hint]
|
render 'shared/dynamic_association', association_name: association_name, title: title, f: form_builder, hint: options[:hint]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# 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
|
||||||
|
|
||||||
def tracks(conference)
|
def tracks(conference)
|
||||||
all = conference.program.tracks.map {|t| t.name}
|
all = conference.program.tracks.map {|t| t.name}
|
||||||
first = all[0...-1]
|
first = all[0...-1]
|
||||||
|
|
@ -112,14 +105,6 @@ module ApplicationHelper
|
||||||
object
|
object
|
||||||
end
|
end
|
||||||
|
|
||||||
def normalize_array_length(hashmap, length)
|
|
||||||
hashmap.each do |_, value|
|
|
||||||
if value.length < length
|
|
||||||
value.fill(value[-1], value.length...length)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# Same as redirect_to(:back) if there is a valid HTTP referer, otherwise redirect_to()
|
# Same as redirect_to(:back) if there is a valid HTTP referer, otherwise redirect_to()
|
||||||
def redirect_back_or_to(options = {}, response_status = {})
|
def redirect_back_or_to(options = {}, response_status = {})
|
||||||
if request.env['HTTP_REFERER']
|
if request.env['HTTP_REFERER']
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,44 @@
|
||||||
module DateTimeHelper
|
module DateTimeHelper
|
||||||
##
|
##
|
||||||
|
<<<<<<< HEAD
|
||||||
# Includes functions related to date or time manipulations
|
# Includes functions related to date or time manipulations
|
||||||
##
|
##
|
||||||
|
=======
|
||||||
|
# Returns a string build from the start and end date of the given conference.
|
||||||
|
#
|
||||||
|
# If the conference is only one day long
|
||||||
|
# * %B %d %Y (January 17 2014)
|
||||||
|
# If the conference starts and ends in the same month and year
|
||||||
|
# * %B %d - %d, %Y (January 17 - 21 2014)
|
||||||
|
# If the conference ends in another month but in the same year
|
||||||
|
# * %B %d - %B %d, %Y (January 31 - February 02 2014)
|
||||||
|
# All other cases
|
||||||
|
# * %B %d, %Y - %B %d, %Y (December 30, 2013 - January 02, 2014)
|
||||||
|
def date_string(start_date, end_date)
|
||||||
|
startstr = 'Unknown - '
|
||||||
|
endstr = 'Unknown'
|
||||||
|
# When the conference is in the same month
|
||||||
|
if start_date.month == end_date.month && start_date.year == end_date.year
|
||||||
|
if start_date.day == end_date.day
|
||||||
|
startstr = start_date.strftime('%B %d')
|
||||||
|
endstr = end_date.strftime(' %Y')
|
||||||
|
else
|
||||||
|
startstr = start_date.strftime('%B %d - ')
|
||||||
|
endstr = end_date.strftime('%d, %Y')
|
||||||
|
end
|
||||||
|
elsif start_date.month != end_date.month && start_date.year == end_date.year
|
||||||
|
startstr = start_date.strftime('%B %d - ')
|
||||||
|
endstr = end_date.strftime('%B %d, %Y')
|
||||||
|
else
|
||||||
|
startstr = start_date.strftime('%B %d, %Y - ')
|
||||||
|
endstr = end_date.strftime('%B %d, %Y')
|
||||||
|
end
|
||||||
|
|
||||||
|
result = startstr + endstr
|
||||||
|
result
|
||||||
|
end
|
||||||
|
|
||||||
|
>>>>>>> refractor code into different files
|
||||||
##
|
##
|
||||||
# Gets an EventType object, and returns its length in timestamp format (HH:MM)
|
# Gets an EventType object, and returns its length in timestamp format (HH:MM)
|
||||||
# ====Gets
|
# ====Gets
|
||||||
|
|
|
||||||
|
|
@ -195,5 +195,12 @@ module FormatHelper
|
||||||
def quantity_left_of(resource)
|
def quantity_left_of(resource)
|
||||||
return '-/-' if resource.quantity.blank?
|
return '-/-' if resource.quantity.blank?
|
||||||
"#{resource.quantity - resource.used}/#{resource.quantity}"
|
"#{resource.quantity - resource.used}/#{resource.quantity}"
|
||||||
|
|
||||||
|
def normalize_array_length(hashmap, length)
|
||||||
|
hashmap.each do |_, value|
|
||||||
|
if value.length < length
|
||||||
|
value.fill(value[-1], value.length...length)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,14 @@ module PathsHelper
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def sign_in_path
|
||||||
|
if ENV['OSEM_ICHAIN_ENABLED'] == 'true'
|
||||||
|
new_user_ichain_session_path
|
||||||
|
else
|
||||||
|
new_user_session_path
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def active_nav_li(link)
|
def active_nav_li(link)
|
||||||
if current_page?(link)
|
if current_page?(link)
|
||||||
return 'active'
|
return 'active'
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue